atenglens commited on
Commit
59d0224
·
1 Parent(s): 51d059a

Update taiwanese_english_translation.py

Browse files
Files changed (1) hide show
  1. taiwanese_english_translation.py +9 -13
taiwanese_english_translation.py CHANGED
@@ -158,22 +158,18 @@ class TaiwaneseEnglishTranslation(datasets.GeneratorBasedBuilder):
158
  ]
159
 
160
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
161
- def _generate_examples(self, source_file, target_file):
162
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
163
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
164
  """This function returns the examples in the raw (text) form."""
165
- with open(source_file, encoding="utf-8") as f:
166
- source_sentences = f.read().split("\n")
167
- with open(target_file, encoding="utf-8") as f:
168
- target_sentences = f.read().split("\n")
169
-
170
- assert len(target_sentences) == len(source_sentences), "Sizes do not match: %d vs %d for %s vs %s." % (
171
- len(source_sentences),
172
- len(target_sentences),
173
- source_file,
174
- target_file,
175
- )
176
-
177
  source, target = self.config.language_pair
178
  for idx, (l1, l2) in enumerate(zip(source_sentences, target_sentences)):
179
  result = {"translation": {source: l1, target: l2}}
 
158
  ]
159
 
160
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
161
+ def _generate_examples(self, filepath, split):
162
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
163
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
164
  """This function returns the examples in the raw (text) form."""
165
+ with open(filepath, encoding="utf-8") as f:
166
+ csv_reader = csv.reader(f, delimiter=',')
167
+ source_sentences, target_sentences = [], []
168
+ line_count = 1
169
+ for row in csv_reader:
170
+ source_sentences.append(row[0])
171
+ target_sentences.append(row[1])
172
+ line_count += 1
 
 
 
 
173
  source, target = self.config.language_pair
174
  for idx, (l1, l2) in enumerate(zip(source_sentences, target_sentences)):
175
  result = {"translation": {source: l1, target: l2}}