quim-motger commited on
Commit
8428bc1
·
verified ·
1 Parent(s): 5515dc3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -1
README.md CHANGED
@@ -60,4 +60,40 @@ T-FREX includes a set of released, fine-tuned models which are compared in the o
60
 
61
  ## How to use
62
 
63
- You can use this model following the instructions for [model inference for token classification](https://huggingface.co/docs/transformers/tasks/token_classification#inference).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  ## How to use
62
 
63
+ Below are code snippets to demonstrate how to use the T-FREX BERT base model (uncased) for named entity recognition on app reviews:
64
+
65
+ ```python
66
+
67
+ from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
68
+
69
+ # Load the pre-trained model and tokenizer
70
+ model_name = "quim-motger/t-frex-bert-base-uncased"
71
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
72
+ model = AutoModelForTokenClassification.from_pretrained(model_name)
73
+
74
+ # Create a pipeline for named entity recognition
75
+ ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
76
+
77
+ # Example text
78
+ text = "The share note file feature is completely useless."
79
+
80
+ # Perform named entity recognition
81
+ entities = ner_pipeline(text)
82
+
83
+ # Print the recognized entities
84
+ for entity in entities:
85
+ print(f"Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']:.4f}")
86
+
87
+ # Example with multiple texts
88
+ texts = [
89
+ "Great app I've tested a lot of free habit tracking apps and this is by far my favorite.",
90
+ "The only negative feedback I can give about this app is the difficulty level to set a sleep timer on it."
91
+ ]
92
+
93
+ # Perform named entity recognition on multiple texts
94
+ for text in texts:
95
+ entities = ner_pipeline(text)
96
+ print(f"Text: {text}")
97
+ for entity in entities:
98
+ print(f" Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']:.4f}")
99
+ ```