template
Browse files
nllb.py
CHANGED
@@ -124,8 +124,10 @@ class NLLB(datasets.GeneratorBasedBuilder):
|
|
124 |
"source_sentence_lid": datasets.Value("float32"),
|
125 |
"target_sentence_lid": datasets.Value("float32"),
|
126 |
"source_sentence_source": datasets.Value("string"),
|
|
|
127 |
"source_sentence_url": datasets.Value("string"),
|
128 |
"target_sentence_source": datasets.Value("string"),
|
|
|
129 |
"target_sentence_url": datasets.Value("string"),
|
130 |
}
|
131 |
)
|
@@ -167,14 +169,14 @@ class NLLB(datasets.GeneratorBasedBuilder):
|
|
167 |
)
|
168 |
]
|
169 |
|
170 |
-
def _generate_examples(self, filepath, source_lg, target_lg):
|
171 |
if self.config.source == "statmt":
|
172 |
# MT stats didn't published all the metadata
|
173 |
return self._generate_minimal_examples(filepath, source_lg, target_lg)
|
174 |
|
175 |
-
return self._generate_full_examples(filepath, source_lg, target_lg)
|
176 |
|
177 |
-
def _generate_full_examples(self, filepath, source_lg, target_lg):
|
178 |
with open(filepath, encoding="utf-8") as f:
|
179 |
# reader = csv.reader(f, delimiter="\t")
|
180 |
for id_, example in enumerate(f):
|
@@ -186,6 +188,9 @@ class NLLB(datasets.GeneratorBasedBuilder):
|
|
186 |
source_lg: datarow[0],
|
187 |
target_lg: datarow[1],
|
188 |
}
|
|
|
|
|
|
|
189 |
row["laser_score"] = float(datarow[2])
|
190 |
row["source_sentence_lid"] = float(datarow[3])
|
191 |
row["target_sentence_lid"] = float(datarow[4])
|
@@ -198,6 +203,10 @@ class NLLB(datasets.GeneratorBasedBuilder):
|
|
198 |
except:
|
199 |
print(datarow)
|
200 |
raise
|
|
|
|
|
|
|
|
|
201 |
yield id_, row
|
202 |
|
203 |
def _generate_minimal_examples(self, filepath, source_lg, target_lg):
|
|
|
124 |
"source_sentence_lid": datasets.Value("float32"),
|
125 |
"target_sentence_lid": datasets.Value("float32"),
|
126 |
"source_sentence_source": datasets.Value("string"),
|
127 |
+
"source_sentence_perplexity": datasets.Value("float32"),
|
128 |
"source_sentence_url": datasets.Value("string"),
|
129 |
"target_sentence_source": datasets.Value("string"),
|
130 |
+
"target_sentence_perplexity": datasets.Value("float32"),
|
131 |
"target_sentence_url": datasets.Value("string"),
|
132 |
}
|
133 |
)
|
|
|
169 |
)
|
170 |
]
|
171 |
|
172 |
+
def _generate_examples(self, filepath, source_lg, target_lg, source_max_perplexity=None, target_max_perplexity=None):
|
173 |
if self.config.source == "statmt":
|
174 |
# MT stats didn't published all the metadata
|
175 |
return self._generate_minimal_examples(filepath, source_lg, target_lg)
|
176 |
|
177 |
+
return self._generate_full_examples(filepath, source_lg, target_lg, source_max_perplexity=source_max_perplexity, target_max_perplexity=target_max_perplexity)
|
178 |
|
179 |
+
def _generate_full_examples(self, filepath, source_lg, target_lg, source_max_perplexity=None, target_max_perplexity=None):
|
180 |
with open(filepath, encoding="utf-8") as f:
|
181 |
# reader = csv.reader(f, delimiter="\t")
|
182 |
for id_, example in enumerate(f):
|
|
|
188 |
source_lg: datarow[0],
|
189 |
target_lg: datarow[1],
|
190 |
}
|
191 |
+
|
192 |
+
row["source_sentence_perplexity"] = None # TODO: compute the perplexity for the source sentence here
|
193 |
+
row["target_sentence_perplexity"] = None # TODO: compute the perplexity for the target sentence here
|
194 |
row["laser_score"] = float(datarow[2])
|
195 |
row["source_sentence_lid"] = float(datarow[3])
|
196 |
row["target_sentence_lid"] = float(datarow[4])
|
|
|
203 |
except:
|
204 |
print(datarow)
|
205 |
raise
|
206 |
+
if source_max_perplexity is not None and row["source_sentence_perplexity"] > source_max_perplexity:
|
207 |
+
continue
|
208 |
+
if target_max_perplexity is not None and row["target_sentence_perplexity"] > target_max_perplexity:
|
209 |
+
continue
|
210 |
yield id_, row
|
211 |
|
212 |
def _generate_minimal_examples(self, filepath, source_lg, target_lg):
|