cdminix commited on
Commit
44a5db7
·
1 Parent(s): 8501562

fix padding subword labeling

Browse files
Files changed (1) hide show
  1. iwslt2011.py +4 -1
iwslt2011.py CHANGED
@@ -269,6 +269,7 @@ class IWSLT11(datasets.GeneratorBasedBuilder):
269
  raise ValueError('tokenizer argument has to be passed to load_dataset')
270
  else:
271
  words = tokens[i].words
 
272
  offsets = np.array(tokens['offset_mapping'][i])
273
  enc_labels = np.array([self.config.label_subword.name]*len(offsets), dtype=object)
274
  count = 0
@@ -276,10 +277,12 @@ class IWSLT11(datasets.GeneratorBasedBuilder):
276
  if word_id is not None and (j == 0 or words[j-1] != word_id):
277
  enc_labels[j] = labels[count].name
278
  count += 1
 
 
279
  labels = enc_labels
280
  yield i, {
281
  "ids": ids,
282
- "tokens": tokens['input_ids'][i],
283
  "labels": labels,
284
  }
285
  logging.info(f"Loaded number of tokens = {token_len}")
 
269
  raise ValueError('tokenizer argument has to be passed to load_dataset')
270
  else:
271
  words = tokens[i].words
272
+ input_ids = tokens['input_ids'][i]
273
  offsets = np.array(tokens['offset_mapping'][i])
274
  enc_labels = np.array([self.config.label_subword.name]*len(offsets), dtype=object)
275
  count = 0
 
277
  if word_id is not None and (j == 0 or words[j-1] != word_id):
278
  enc_labels[j] = labels[count].name
279
  count += 1
280
+ elif input_ids[j] == self.config.tokenizer.pad_token_id:
281
+ enc_labels[j] = LabelSubword.IGNORE.name
282
  labels = enc_labels
283
  yield i, {
284
  "ids": ids,
285
+ "tokens": input_ids,
286
  "labels": labels,
287
  }
288
  logging.info(f"Loaded number of tokens = {token_len}")