Fix: Overlaping entities issue
Browse files- app.py +9 -6
- phi3_instruct_graph.py +1 -1
app.py
CHANGED
|
@@ -78,12 +78,15 @@ def create_custom_entity_viz(data, full_text):
|
|
| 78 |
end = dataentity["end"]
|
| 79 |
|
| 80 |
if start < len(doc) and end <= len(doc):
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
doc.set_ents(spans, default="unmodified")
|
| 89 |
doc.spans["sc"] = spans
|
|
|
|
| 78 |
end = dataentity["end"]
|
| 79 |
|
| 80 |
if start < len(doc) and end <= len(doc):
|
| 81 |
+
# Check for overlapping spans
|
| 82 |
+
overlapping = any(s.start < end and start < s.end for s in spans)
|
| 83 |
+
if not overlapping:
|
| 84 |
+
span = Span(doc, start, end, label=node["type"])
|
| 85 |
+
|
| 86 |
+
# print(span)
|
| 87 |
+
spans.append(span)
|
| 88 |
+
if node["type"] not in colors:
|
| 89 |
+
colors[node["type"]] = get_random_light_color()
|
| 90 |
|
| 91 |
doc.set_ents(spans, default="unmodified")
|
| 92 |
doc.spans["sc"] = spans
|
phi3_instruct_graph.py
CHANGED
|
@@ -109,5 +109,5 @@ class Phi3InstructGraph:
|
|
| 109 |
def extract(self, text):
|
| 110 |
messages = self._get_messages(text)
|
| 111 |
pipe_output = self._generate(messages)
|
| 112 |
-
print("pipe_output json", pipe_output[0]["generated_text"])
|
| 113 |
return pipe_output[0]["generated_text"]
|
|
|
|
| 109 |
def extract(self, text):
|
| 110 |
messages = self._get_messages(text)
|
| 111 |
pipe_output = self._generate(messages)
|
| 112 |
+
# print("pipe_output json", pipe_output[0]["generated_text"])
|
| 113 |
return pipe_output[0]["generated_text"]
|