Helios9 commited on
Commit
3623498
·
verified ·
1 Parent(s): d6545f8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -7
README.md CHANGED
@@ -93,11 +93,11 @@ The output will be a list of recognized entities with their entity type, score,
93
  ]
94
  ```
95
 
96
- In some cases, we are getting multiple same entity groups so to join please use below code:
97
 
98
  ```python
99
 
100
- def merge_consecutive_entities(entities):
101
  entities = sorted(entities, key=lambda x: x['start'])
102
  merged_entities = []
103
  current_entity = None
@@ -107,12 +107,11 @@ def merge_consecutive_entities(entities):
107
  current_entity = entity
108
  elif (
109
  entity['entity_group'] == current_entity['entity_group'] and
110
- (entity['start'] <= current_entity['end'])
111
  ):
112
- new_word = entity['word']
113
- if not current_entity['word'].endswith(new_word):
114
- current_entity['word'] += " " + new_word
115
  current_entity['end'] = max(current_entity['end'], entity['end'])
 
116
  current_entity['score'] = (current_entity['score'] + entity['score']) / 2
117
  else:
118
  merged_entities.append(current_entity)
@@ -123,6 +122,7 @@ def merge_consecutive_entities(entities):
123
  return merged_entities
124
 
125
 
 
126
  from transformers import pipeline
127
 
128
  # Load the model
@@ -140,7 +140,7 @@ text = ("A 48-year-old female presented with vaginal bleeding and abnormal Pap s
140
  "hysterectomy with salpingo-oophorectomy which demonstrated positive spread to the pelvic "
141
  "lymph nodes and the parametrium.")
142
  result = pipe(text)
143
- final_result=merge_consecutive_entities(result)
144
  print(final_result)
145
 
146
  ```
 
93
  ]
94
  ```
95
 
96
+ In some cases, we are getting multiple same entity groups, so to join, please use below code:
97
 
98
  ```python
99
 
100
+ def merge_consecutive_entities(entities, text):
101
  entities = sorted(entities, key=lambda x: x['start'])
102
  merged_entities = []
103
  current_entity = None
 
107
  current_entity = entity
108
  elif (
109
  entity['entity_group'] == current_entity['entity_group'] and
110
+ (entity['start'] <= current_entity['end'])
111
  ):
112
+ # Merge based on start and end positions in the text
 
 
113
  current_entity['end'] = max(current_entity['end'], entity['end'])
114
+ current_entity['word'] = text[current_entity['start']:current_entity['end']]
115
  current_entity['score'] = (current_entity['score'] + entity['score']) / 2
116
  else:
117
  merged_entities.append(current_entity)
 
122
  return merged_entities
123
 
124
 
125
+
126
  from transformers import pipeline
127
 
128
  # Load the model
 
140
  "hysterectomy with salpingo-oophorectomy which demonstrated positive spread to the pelvic "
141
  "lymph nodes and the parametrium.")
142
  result = pipe(text)
143
+ final_result=merge_consecutive_entities(result,text)
144
  print(final_result)
145
 
146
  ```