system HF staff commited on
Commit
58c1cf2
1 Parent(s): f0dce71

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. ted_multi.py +34 -20
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  paperswithcode_id: null
3
  ---
4
 
1
  ---
2
+ pretty_name: TEDMulti
3
  paperswithcode_id: null
4
  ---
5
 
ted_multi.py CHANGED
@@ -17,7 +17,6 @@
17
  """TED talk multilingual data set."""
18
 
19
  import csv
20
- import os
21
 
22
  import datasets
23
 
@@ -134,36 +133,51 @@ class TedMultiTranslate(datasets.GeneratorBasedBuilder):
134
  )
135
 
136
  def _split_generators(self, dl_manager):
137
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
138
 
139
  return [
140
  datasets.SplitGenerator(
141
- name=datasets.Split.TRAIN, gen_kwargs={"data_file": os.path.join(dl_dir, "all_talks_train.tsv")}
 
 
 
 
142
  ),
143
  datasets.SplitGenerator(
144
- name=datasets.Split.VALIDATION, gen_kwargs={"data_file": os.path.join(dl_dir, "all_talks_dev.tsv")}
 
 
 
 
145
  ),
146
  datasets.SplitGenerator(
147
- name=datasets.Split.TEST, gen_kwargs={"data_file": os.path.join(dl_dir, "all_talks_test.tsv")}
 
 
 
 
148
  ),
149
  ]
150
 
151
- def _generate_examples(self, data_file):
152
  """This function returns the examples in the raw (text) form."""
153
- with open(data_file, encoding="utf-8") as f:
154
- reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
155
- for idx, row in enumerate(reader):
156
- # Everything in the row except for 'talk_name' will be a translation.
157
- # Missing/incomplete translations will contain the string "__NULL__" or
158
- # "_ _ NULL _ _".
159
- yield idx, {
160
- "translations": {
161
- lang: text
162
- for lang, text in row.items()
163
- if lang != "talk_name" and _is_translation_complete(text)
164
- },
165
- "talk_name": row["talk_name"],
166
- }
 
 
 
167
 
168
 
169
  def _is_translation_complete(text):
17
  """TED talk multilingual data set."""
18
 
19
  import csv
 
20
 
21
  import datasets
22
 
133
  )
134
 
135
  def _split_generators(self, dl_manager):
136
+ archive = dl_manager.download(_DATA_URL)
137
 
138
  return [
139
  datasets.SplitGenerator(
140
+ name=datasets.Split.TRAIN,
141
+ gen_kwargs={
142
+ "data_file": "all_talks_train.tsv",
143
+ "files": dl_manager.iter_archive(archive),
144
+ },
145
  ),
146
  datasets.SplitGenerator(
147
+ name=datasets.Split.VALIDATION,
148
+ gen_kwargs={
149
+ "data_file": "all_talks_dev.tsv",
150
+ "files": dl_manager.iter_archive(archive),
151
+ },
152
  ),
153
  datasets.SplitGenerator(
154
+ name=datasets.Split.TEST,
155
+ gen_kwargs={
156
+ "data_file": "all_talks_test.tsv",
157
+ "files": dl_manager.iter_archive(archive),
158
+ },
159
  ),
160
  ]
161
 
162
+ def _generate_examples(self, data_file, files):
163
  """This function returns the examples in the raw (text) form."""
164
+ for path, f in files:
165
+ if path == data_file:
166
+ lines = (line.decode("utf-8") for line in f)
167
+ reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
168
+ for idx, row in enumerate(reader):
169
+ # Everything in the row except for 'talk_name' will be a translation.
170
+ # Missing/incomplete translations will contain the string "__NULL__" or
171
+ # "_ _ NULL _ _".
172
+ yield idx, {
173
+ "translations": {
174
+ lang: text
175
+ for lang, text in row.items()
176
+ if lang != "talk_name" and _is_translation_complete(text)
177
+ },
178
+ "talk_name": row["talk_name"],
179
+ }
180
+ break
181
 
182
 
183
  def _is_translation_complete(text):