mathiascreutz commited on
Commit
070b7d8
1 Parent(s): e7be9f6

Adding training sets

Browse files
Files changed (1) hide show
  1. opusparcus.py +25 -15
opusparcus.py CHANGED
@@ -45,7 +45,7 @@ _LICENSE = ""
45
 
46
  _URLs = {
47
 
48
- "train": None,
49
  "validation": "validation.jsonl",
50
  "test": "test.jsonl"
51
 
@@ -135,20 +135,15 @@ class Opusparcus(datasets.GeneratorBasedBuilder):
135
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
136
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
137
 
138
- _URLs["train"] = "train_{0}.jsonl.bz2".format(self.config.lang)
 
 
 
 
139
 
140
  data_dir = dl_manager.download_and_extract(_URLs)
141
- return [
142
- datasets.SplitGenerator(
143
- name=datasets.Split.TRAIN,
144
- # These kwargs will be passed to _generate_examples
145
- gen_kwargs={
146
- "lang": self.config.lang,
147
- "quality": self.config.quality,
148
- "filepath": data_dir["train"],
149
- "split": "train",
150
- },
151
- ),
152
  datasets.SplitGenerator(
153
  name=datasets.Split.TEST,
154
  # These kwargs will be passed to _generate_examples
@@ -168,8 +163,23 @@ class Opusparcus(datasets.GeneratorBasedBuilder):
168
  "filepath": data_dir["validation"],
169
  "split": "validation",
170
  },
171
- ),
172
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  def _generate_examples(
175
  self, lang, quality, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
 
45
 
46
  _URLs = {
47
 
48
+ "train": None, # actual value set in the `_split_generators` method
49
  "validation": "validation.jsonl",
50
  "test": "test.jsonl"
51
 
 
135
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
136
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
137
 
138
+ if self.config.quality > 95:
139
+ # No training data matches this quality criterion
140
+ del _URLS["train"]
141
+ else:
142
+ _URLs["train"] = "train_{0}.jsonl.bz2".format(self.config.lang)
143
 
144
  data_dir = dl_manager.download_and_extract(_URLs)
145
+
146
+ splits = [
 
 
 
 
 
 
 
 
 
147
  datasets.SplitGenerator(
148
  name=datasets.Split.TEST,
149
  # These kwargs will be passed to _generate_examples
 
163
  "filepath": data_dir["validation"],
164
  "split": "validation",
165
  },
166
+ )
167
+ ]
168
+
169
+ if self.config.quality <= 95:
170
+ # We do have training data as well
171
+ splits.append(
172
+ datasets.SplitGenerator(
173
+ name=datasets.Split.TRAIN,
174
+ # These kwargs will be passed to _generate_examples
175
+ gen_kwargs={
176
+ "lang": self.config.lang,
177
+ "quality": self.config.quality,
178
+ "filepath": data_dir["train"],
179
+ "split": "train",
180
+ },
181
+ )
182
+ )
183
 
184
  def _generate_examples(
185
  self, lang, quality, filepath, split # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`