def write_text_files(dataset_name: str, dataset: Sequence[WinoDictExample],
                     id_offset: int):
  """Dumpts dataset to csv and text."""
  with tf.io.gfile.GFile(f'{dataset_name}.csv', 'w') as csv_file:
    with tf.io.gfile.GFile(f'{dataset_name}.txt', 'w') as txt_file:
      writer = csv.writer(csv_file)
      writer.writerow([
          'id', 'lemma', 'fake_lemma', 'pos', 'tag', 'pronoun', 'definition',
          'sentence', 'option1', 'option2', 'label'
      ])
      for idx, example in enumerate(dataset):
        # Randomize option order
        label = int(random.Random(example.get_id()).random() > 0.5)
        if label:
          options = [example.answer2.option, example.answer1.option]
        else:
          options = [example.answer1.option, example.answer2.option]
        row1 = _get_answer_row(example, 0)
        row2 = _get_answer_row(example, 1)
        writer.writerow(row1 + options + [label])
        writer.writerow(row2 + options + [1 - label])
        txt_file.write(
            _SURVEY_TEMPLATE.format(
                num=2 * idx + 1 + id_offset,
                definition=_highlight(row1[-2], example.answer1.fake_lemma),
                sentence=row1[-1].replace('_', example.pronoun),
                option1=options[0],
                option2=options[1],
                pronoun=example.pronoun,
            ))
        txt_file.write(
            _SURVEY_TEMPLATE.format(
                num=2 * idx + 2 + id_offset,
                definition=_highlight(row2[-2], example.answer2.fake_lemma),
                sentence=row2[-1].replace('_', example.pronoun),
                option1=options[0],
                option2=options[1],
                pronoun=example.pronoun,
            ))
Dumpts dataset to csv and text.
language/wino_dict/utils.py