Update taiwanese_english_translation.py
Browse files
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,
|
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(
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
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}}
|