Update README.md
Browse files
README.md
CHANGED
@@ -21,7 +21,34 @@ The Token labels are Person, Organisation, Location, Building, Event, Product, A
|
|
21 |
## How to use the model
|
22 |
|
23 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
from transformers import pipeline
|
25 |
pipe = pipeline(model='RashidNLP/NER-Deberta')
|
26 |
-
pipe(["Elon Musk will be at SpaceX's Starbase facility in Boca Chica for the orbital launch of starship next month"])
|
|
|
|
|
27 |
```
|
|
|
21 |
## How to use the model
|
22 |
|
23 |
```python
|
24 |
+
def print_ner(sentences):
|
25 |
+
"""Cleaning and printing NER results
|
26 |
+
|
27 |
+
"""
|
28 |
+
for sentence in sentences:
|
29 |
+
last_entity_type = sentence[0]['entity']
|
30 |
+
last_index = sentence[0]['index']
|
31 |
+
word = sentence[0]['word']
|
32 |
+
for i, token in enumerate(sentence):
|
33 |
+
if (i > 0):
|
34 |
+
if (token['entity'] == last_entity_type) and (token['index'] == last_index + 1):
|
35 |
+
word = word + '' + token['word']
|
36 |
+
|
37 |
+
else:
|
38 |
+
word = word.replace('▁', ' ')
|
39 |
+
print(f"{word[1:]} {last_entity_type}")
|
40 |
+
word = token['word']
|
41 |
+
last_entity_type = token['entity']
|
42 |
+
last_index = token['index']
|
43 |
+
|
44 |
+
if i == len(sentence) - 1:
|
45 |
+
word = word.replace('▁', ' ')
|
46 |
+
print(f"{word[1:]} {last_entity_type}")
|
47 |
+
|
48 |
+
|
49 |
from transformers import pipeline
|
50 |
pipe = pipeline(model='RashidNLP/NER-Deberta')
|
51 |
+
sentence = pipe(["Elon Musk will be at SpaceX's Starbase facility in Boca Chica for the orbital launch of starship next month"])
|
52 |
+
print_ner(sentence)
|
53 |
+
|
54 |
```
|