anamargarida commited on
Commit
ebb441e
·
verified ·
1 Parent(s): af9e117

Rename app_19.py to app_20.py

Browse files
Files changed (1) hide show
  1. app_19.py → app_20.py +10 -6
app_19.py → app_20.py RENAMED
@@ -167,13 +167,17 @@ def extract_arguments(text, tokenizer, model, beam_search=True):
167
  this_space_splitted_tokens = copy.deepcopy(space_splitted_tokens)
168
 
169
  def safe_insert(tag, position, start=True):
170
- """Safely insert a tag, checking for None values."""
171
  if position is not None and word_ids[position] is not None:
172
- if start:
173
- this_space_splitted_tokens[word_ids[position]] = tag + this_space_splitted_tokens[word_ids[position]]
174
- else:
175
- this_space_splitted_tokens[word_ids[position]] += tag
176
-
 
 
 
 
177
  # Add argument tags safely
178
  safe_insert('<ARG0>', start_cause, start=True)
179
  safe_insert('</ARG0>', end_cause, start=False)
 
167
  this_space_splitted_tokens = copy.deepcopy(space_splitted_tokens)
168
 
169
  def safe_insert(tag, position, start=True):
170
+ """Safely insert a tag, checking for None values and index validity."""
171
  if position is not None and word_ids[position] is not None:
172
+ word_index = word_ids[position]
173
+
174
+ # Ensure word_index is within range
175
+ if 0 <= word_index < len(this_space_splitted_tokens):
176
+ if start:
177
+ this_space_splitted_tokens[word_index] = tag + this_space_splitted_tokens[word_index]
178
+ else:
179
+ this_space_splitted_tokens[word_index] += tag
180
+
181
  # Add argument tags safely
182
  safe_insert('<ARG0>', start_cause, start=True)
183
  safe_insert('</ARG0>', end_cause, start=False)