quim-motger commited on
Commit
c909704
1 Parent(s): b9fdc3e

Update README.md

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