readme: add example usage
Browse files
README.md
CHANGED
@@ -60,4 +60,36 @@ A very basic hyper-parameter search is performanced for five different seeds, wi
|
|
60 |
| `bs=16,e=10,lr=4e-05` | 94.61 | 94.39 | 94.57 | 94.65 | 94.87 | 94.61 |
|
61 |
| `bs=16,e=10,lr=5e-05` | 93.82 | 93.94 | 94.36 | 91.14 | 94.38 | 94.15 |
|
62 |
|
63 |
-
The performance of the current uploaded model is marked in bold.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
| `bs=16,e=10,lr=4e-05` | 94.61 | 94.39 | 94.57 | 94.65 | 94.87 | 94.61 |
|
61 |
| `bs=16,e=10,lr=5e-05` | 93.82 | 93.94 | 94.36 | 91.14 | 94.38 | 94.15 |
|
62 |
|
63 |
+
The performance of the current uploaded model is marked in bold.
|
64 |
+
|
65 |
+
## 📣 Usage
|
66 |
+
|
67 |
+
The following code can be used to test the model and recognize named entities for a given sentence:
|
68 |
+
|
69 |
+
```python
|
70 |
+
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
71 |
+
|
72 |
+
model_name = "stefan-it/neobert-ner-conll03"
|
73 |
+
|
74 |
+
|
75 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name, trust_remote_code=True)
|
76 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
77 |
+
|
78 |
+
ner = pipeline(task="ner",
|
79 |
+
model=model,
|
80 |
+
tokenizer=tokenizer,
|
81 |
+
trust_remote_code=True)
|
82 |
+
|
83 |
+
print(ner("George Washington lived to Washington in the US."))
|
84 |
+
```
|
85 |
+
|
86 |
+
This outputs:
|
87 |
+
|
88 |
+
```json
|
89 |
+
[
|
90 |
+
{'entity': 'B-PER', 'score': 0.9997143, 'index': 1, 'word': 'george', 'start': 0, 'end': 6},
|
91 |
+
{'entity': 'I-PER', 'score': 0.9994716, 'index': 2, 'word': 'washington', 'start': 7, 'end': 17},
|
92 |
+
{'entity': 'B-LOC', 'score': 0.9981968, 'index': 5, 'word': 'washington', 'start': 27, 'end': 37},
|
93 |
+
{'entity': 'B-LOC', 'score': 0.99851936, 'index': 8, 'word': 'us', 'start': 45, 'end': 47}
|
94 |
+
]
|
95 |
+
```
|