Instructions to use marefa-nlp/marefa-ner with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use marefa-nlp/marefa-ner with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="marefa-nlp/marefa-ner")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("marefa-nlp/marefa-ner") model = AutoModelForTokenClassification.from_pretrained("marefa-nlp/marefa-ner", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update Inference code
Browse files
README.md
CHANGED
|
@@ -68,20 +68,18 @@ ner_results = nlp(example)
|
|
| 68 |
|
| 69 |
modified_results = []
|
| 70 |
for ent in ner_results:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
modified_results[-1]["score"] = sum([modified_results[-1]["score"], ent["score"]])/2
|
| 84 |
-
modified_results[-1]["end"] = ent["end"]
|
| 85 |
|
| 86 |
for res in modified_results:
|
| 87 |
print(res["word"], "==>", res["entity_group"])
|
|
|
|
| 68 |
|
| 69 |
modified_results = []
|
| 70 |
for ent in ner_results:
|
| 71 |
+
if ent["entity_group"].lower().replace("label_","").isnumeric():
|
| 72 |
+
ent["entity_group"] = int(ent["entity_group"].lower().replace("label_",""))
|
| 73 |
+
ent["entity_group"] = labels_list[ent["entity_group"]]
|
| 74 |
+
|
| 75 |
+
if len(modified_results) > 0 and ent["start"] == modified_results[-1]["end"]:
|
| 76 |
+
modified_results[-1]["word"] += f"{ent['word']}".replace("▁"," ").strip()
|
| 77 |
+
modified_results[-1]["word"] = modified_results[-1]["word"].replace("▁"," ").strip()
|
| 78 |
+
modified_results[-1]["score"] = sum([modified_results[-1]["score"], ent["score"]])/2
|
| 79 |
+
modified_results[-1]["end"] = ent["end"]
|
| 80 |
+
else:
|
| 81 |
+
modified_results.append(ent)
|
| 82 |
+
|
|
|
|
|
|
|
| 83 |
|
| 84 |
for res in modified_results:
|
| 85 |
print(res["word"], "==>", res["entity_group"])
|