Theoreticallyhugo commited on
Commit
06477d1
·
1 Parent(s): a4a7178

got all configs to work

Browse files
Files changed (1) hide show
  1. Stab-Gurevych-Essays.py +20 -15
Stab-Gurevych-Essays.py CHANGED
@@ -380,10 +380,6 @@ class NewDataset(datasets.GeneratorBasedBuilder):
380
  for clean_ann in clean_anns:
381
  spans.append(("O", text[previous_end:clean_ann[1]]))
382
  spans.append((clean_ann[0], text[clean_ann[1]:clean_ann[2]]))
383
- # if were picking up the wrong text...
384
- if spans[-1][1] != clean_ann[3]:
385
- print(spans[-1][1])
386
- input(clean_ann[3])
387
  previous_end = clean_ann[2]
388
  # add whatever is left over to not spans
389
  spans.append(("O", text[previous_end:]))
@@ -394,29 +390,38 @@ class NewDataset(datasets.GeneratorBasedBuilder):
394
  for span in spans:
395
  span_tokens = span[1].split()
396
  label = span[0]
 
397
  if self.config.name == "simple":
398
  # with simple, the token is already correct
399
  pass
 
400
  elif self.config.name == "sep_tok":
401
  # with sep_tok, the token is correct, but a sep top needs to be inserted
402
- pass
403
- # TODO: make sure to include the sep tok!!!
 
404
  elif self.config.name == "spans":
405
  if label != "O":
 
406
  label = "I"
407
- # TODO: make sure to iclude the B and the I
408
  elif self.config.name == "full_labels":
409
- # TODO: ensure I and B
410
- pass
 
411
  elif self.config.name == "sep_tok_full_labels":
412
- # TODO: ensure I and B
413
- # TODO: make sure to include the sep tok!!!
414
- pass
415
- labels.append([label] * len(span_tokens))
 
 
 
 
 
 
416
  tokens.append(span_tokens)
417
 
418
- # flatten list of lists of labels before return
419
- labels = [ label for inner_list in labels for label in inner_list ]
420
  return tokens, labels
421
 
422
  def _process_essay(self, id, data_dir: Path):
 
380
  for clean_ann in clean_anns:
381
  spans.append(("O", text[previous_end:clean_ann[1]]))
382
  spans.append((clean_ann[0], text[clean_ann[1]:clean_ann[2]]))
 
 
 
 
383
  previous_end = clean_ann[2]
384
  # add whatever is left over to not spans
385
  spans.append(("O", text[previous_end:]))
 
390
  for span in spans:
391
  span_tokens = span[1].split()
392
  label = span[0]
393
+ first_label = span[0]
394
  if self.config.name == "simple":
395
  # with simple, the token is already correct
396
  pass
397
+
398
  elif self.config.name == "sep_tok":
399
  # with sep_tok, the token is correct, but a sep top needs to be inserted
400
+ span_tokens.insert(0, "<s>")
401
+ span_tokens.append("</s>")
402
+
403
  elif self.config.name == "spans":
404
  if label != "O":
405
+ first_label = "B"
406
  label = "I"
407
+
408
  elif self.config.name == "full_labels":
409
+ if label != "O":
410
+ first_label = "B-" + label
411
+ label = "I-" + label
412
  elif self.config.name == "sep_tok_full_labels":
413
+ # ensure I and B
414
+ if label != "O":
415
+ first_label = "B-" + label
416
+ label = "I-" + label
417
+ # make sure to include the sep tok!!!
418
+ span_tokens.insert(0, "<s>")
419
+ span_tokens.append("</s>")
420
+
421
+ labels.append(first_label)
422
+ labels.extend([label] * (len(span_tokens) - 1))
423
  tokens.append(span_tokens)
424
 
 
 
425
  return tokens, labels
426
 
427
  def _process_essay(self, id, data_dir: Path):