wagnercosta commited on
Commit
8867999
1 Parent(s): 4cfc91c

Fix: Overlaping entities issue

Browse files
Files changed (2) hide show
  1. app.py +9 -6
  2. 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
- span = Span(doc, start, end, label=node["type"])
82
-
83
- # print(span)
84
- spans.append(span)
85
- if node["type"] not in colors:
86
- colors[node["type"]] = get_random_light_color()
 
 
 
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"]