bakrianoo commited on
Commit
eff476a
·
1 Parent(s): 6b1a728

Update Inference code

Browse files
Files changed (1) hide show
  1. README.md +12 -14
README.md CHANGED
@@ -68,20 +68,18 @@ ner_results = nlp(example)
68
 
69
  modified_results = []
70
  for ent in ner_results:
71
- ent["entity_group"] = int(ent["entity_group"].lower().replace("label_",""))
72
- ent["entity_group"] = labels_list[ent["entity_group"]]
73
-
74
- if ent["entity_group"] != "O":
75
- if "B-" in ent["entity_group"]:
76
- ent["entity_group"] = ent["entity_group"].replace("B-","")
77
- modified_results.append(ent)
78
- elif "I-" in ent["entity_group"]:
79
- ## check related entity-group
80
- label = ent["entity_group"].replace("I-","")
81
- if len(modified_results) > 0 and label == modified_results[-1]["entity_group"]:
82
- modified_results[-1]["word"] += f" {ent['word']}"
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"])