quim-motger commited on
Commit
c484190
1 Parent(s): c8818a5

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