Update README.md
Browse files
README.md
CHANGED
|
@@ -42,17 +42,20 @@ It achieves the following results on the evaluation set:
|
|
| 42 |
```python
|
| 43 |
from transformers import pipeline
|
| 44 |
|
| 45 |
-
ner_pipe = pipeline(
|
| 46 |
-
inputs =
|
| 47 |
res = ner_pipe(inputs)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
for r in res:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
#==output==
|
| 57 |
{'PER': ['徐國堂'], 'LOC': ['台北']}
|
| 58 |
```
|
|
|
|
| 42 |
```python
|
| 43 |
from transformers import pipeline
|
| 44 |
|
| 45 |
+
ner_pipe = pipeline('token-classification', model='roberthsu2003/models_for_ner',aggregation_strategy='simple')
|
| 46 |
+
inputs = '徐國堂在台北上班'
|
| 47 |
res = ner_pipe(inputs)
|
| 48 |
+
print(res)
|
| 49 |
+
res_result = {}
|
| 50 |
for r in res:
|
| 51 |
+
entity_name = r['entity_group']
|
| 52 |
+
start = r['start']
|
| 53 |
+
end = r['end']
|
| 54 |
+
if entity_name not in res_result:
|
| 55 |
+
res_result[entity_name] = []
|
| 56 |
+
res_result[entity_name].append(inputs[start:end])
|
| 57 |
+
|
| 58 |
+
res_result
|
| 59 |
#==output==
|
| 60 |
{'PER': ['徐國堂'], 'LOC': ['台北']}
|
| 61 |
```
|