Update README.md
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
## How to use
|
| 62 |
|
| 63 |
+
Below are code snippets to demonstrate how to use the T-FREX RoBERTa base model for named entity recognition on app reviews:
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 67 |
+
|
| 68 |
+
# Load the pre-trained model and tokenizer
|
| 69 |
+
model_name = "quim-motger/t-frex-roberta-base"
|
| 70 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 71 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
| 72 |
+
|
| 73 |
+
# Create a pipeline for named entity recognition
|
| 74 |
+
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 75 |
+
|
| 76 |
+
# Example text
|
| 77 |
+
text = "The share note file feature is completely useless."
|
| 78 |
+
|
| 79 |
+
# Perform named entity recognition
|
| 80 |
+
entities = ner_pipeline(text)
|
| 81 |
+
|
| 82 |
+
# Print the recognized entities
|
| 83 |
+
for entity in entities:
|
| 84 |
+
print(f"Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']:.4f}")
|
| 85 |
+
|
| 86 |
+
# Example with multiple texts
|
| 87 |
+
texts = [
|
| 88 |
+
"Great app I've tested a lot of free habit tracking apps and this is by far my favorite.",
|
| 89 |
+
"The only negative feedback I can give about this app is the difficulty level to set a sleep timer on it."
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
# Perform named entity recognition on multiple texts
|
| 93 |
+
for text in texts:
|
| 94 |
+
entities = ner_pipeline(text)
|
| 95 |
+
print(f"Text: {text}")
|
| 96 |
+
for entity in entities:
|
| 97 |
+
print(f" Entity: {entity['word']}, Label: {entity['entity']}, Score: {entity['score']:.4f}")
|
| 98 |
+
|
| 99 |
+
```
|