AlzbetaStrompova commited on
Commit
9d2f4c9
1 Parent(s): ce2493d

fix output

Browse files
Files changed (1) hide show
  1. website_script.py +4 -3
website_script.py CHANGED
@@ -59,14 +59,14 @@ def run(tokenizer, model, gazetteers_for_matching, text):
59
  for pos, entity, score in zip(tokenized_inputs.offset_mapping, predicted_tags[0], scores):
60
  if pos[0] == pos[1] or entity == "O":
61
  continue
62
- if temp["entity"] == entity[2:]: # same entity
63
- space = " " if pos[0] - temp["end"] >= 1 else ""
64
  temp["end"] = pos[1]
65
- temp["word"] += space + text[pos[0]:pos[1]]
66
  temp["count"] += 1
67
  temp["score"] += max(score)
68
  else: # new entity
69
  if temp["count"] > 0:
 
70
  temp["score"] /= temp.pop("count")
71
  result.append(temp)
72
  temp = {
@@ -78,6 +78,7 @@ def run(tokenizer, model, gazetteers_for_matching, text):
78
  "count": 1
79
  }
80
  if temp["count"] > 0:
 
81
  temp["score"] /= temp.pop("count")
82
  result.append(temp)
83
  return result
 
59
  for pos, entity, score in zip(tokenized_inputs.offset_mapping, predicted_tags[0], scores):
60
  if pos[0] == pos[1] or entity == "O":
61
  continue
62
+ if "I-" + temp["entity"] == entity: # same entity
63
+ temp["word"] += text[temp["end"]:pos[0]] + text[pos[0]:pos[1]]
64
  temp["end"] = pos[1]
 
65
  temp["count"] += 1
66
  temp["score"] += max(score)
67
  else: # new entity
68
  if temp["count"] > 0:
69
+ temp["score"] += max(score)
70
  temp["score"] /= temp.pop("count")
71
  result.append(temp)
72
  temp = {
 
78
  "count": 1
79
  }
80
  if temp["count"] > 0:
81
+ temp["score"] += max(score)
82
  temp["score"] /= temp.pop("count")
83
  result.append(temp)
84
  return result