-
Notifications
You must be signed in to change notification settings - Fork 193
MT datasets FLORES200 and WMT24pp #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
53c1ec8
0856d8f
7985a85
342674e
868f91a
f22814e
b9d9ac4
54b60a1
e7b23bd
ba14f6f
1f848d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| # settings that define how evaluation should be done by default (all can be changed from cmdline) | ||
|
|
||
| PROMPT_CONFIG = "multilingual/segment-translation" | ||
| DATASET_GROUP = "chat" | ||
| METRICS_TYPE = "translation" | ||
| EVAL_ARGS = "++eval_type=no-op" | ||
| GENERATION_ARGS = "" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from datasets import load_dataset | ||
| from langcodes import Language | ||
|
|
||
|
|
||
| def write_data_to_file(output_file, datasets, src_languages, tgt_languages): | ||
| with open(output_file, "wt", encoding="utf-8") as fout: | ||
| for src_lang in src_languages: | ||
| for tgt_lang in tgt_languages: | ||
| if src_lang != tgt_lang: | ||
| for src, tgt in zip(datasets[src_lang], datasets[tgt_lang], strict=True): | ||
| json_dict = { | ||
| "text": src, | ||
| "translation": tgt, | ||
| "source_language": src_lang, | ||
| "target_language": tgt_lang, | ||
| "source_lang_name": Language(src_lang).display_name(), | ||
| "target_lang_name": Language(tgt_lang).display_name(), | ||
| } | ||
| json.dump(json_dict, fout) | ||
| fout.write("\n") | ||
|
|
||
|
|
||
| def main(args): | ||
| all_languages = list(set(args.source_languages).union(set(args.target_languages))) | ||
|
|
||
| datasets = {} | ||
| for lang in all_languages: | ||
| iso_639_3 = Language(lang).to_alpha3() | ||
| iso_15924 = Language(lang).maximize().script | ||
| lang_code = f"{iso_639_3}_{iso_15924}" | ||
| datasets[lang] = load_dataset("openlanguagedata/flores_plus", lang_code, split=args.split)["text"] | ||
|
|
||
| data_dir = Path(__file__).absolute().parent | ||
| data_dir.mkdir(exist_ok=True) | ||
| output_file = data_dir / f"{args.split}.jsonl" | ||
| write_data_to_file(output_file, datasets, src_languages=args.source_languages, tgt_languages=args.target_languages) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--split", default="dev", choices=("dev", "devtest"), help="Dataset split to process.") | ||
| parser.add_argument( | ||
| "--source_languages", | ||
| default=["en", "de", "es", "fr", "it", "ja"], | ||
| nargs="+", | ||
| help="Languages to translate from.", | ||
| ) | ||
| parser.add_argument( | ||
| "--target_languages", | ||
| default=["en", "de", "es", "fr", "it", "ja"], | ||
| nargs="+", | ||
| help="Languages to translate to.", | ||
| ) | ||
| args = parser.parse_args() | ||
| main(args) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| # settings that define how evaluation should be done by default (all can be changed from cmdline) | ||
|
|
||
| PROMPT_CONFIG = "multilingual/segment-translation" | ||
| DATASET_GROUP = "chat" | ||
| METRICS_TYPE = "translation" | ||
| EVAL_ARGS = "++eval_type=no-op" | ||
| GENERATION_ARGS = "" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from datasets import load_dataset | ||
| from langcodes import Language | ||
|
|
||
|
|
||
| def write_data_to_file(output_file, datasets, tgt_languages): | ||
| with open(output_file, "wt", encoding="utf-8") as fout: | ||
| for tgt_lang in tgt_languages: | ||
| for src, tgt in zip(datasets[tgt_lang]["source"], datasets[tgt_lang]["target"], strict=True): | ||
| json_dict = { | ||
| "text": src, | ||
| "translation": tgt, | ||
| "source_language": "en", | ||
| "target_language": tgt_lang, | ||
| "source_lang_name": "English", | ||
| "target_lang_name": Language(tgt_lang[:2]).display_name(), | ||
| } | ||
| json.dump(json_dict, fout) | ||
| fout.write("\n") | ||
|
|
||
|
|
||
| def main(args): | ||
| datasets = {} | ||
| for lang in args.target_languages: | ||
| datasets[lang] = load_dataset("google/wmt24pp", f"en-{lang}")["train"] | ||
|
|
||
| data_dir = Path(__file__).absolute().parent | ||
| data_dir.mkdir(exist_ok=True) | ||
| output_file = data_dir / f"{args.split}.jsonl" | ||
| write_data_to_file(output_file, datasets, tgt_languages=args.target_languages) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--split", default="test", choices=("test",), help="Dataset split to process.") | ||
| parser.add_argument( | ||
| "--target_languages", | ||
| default=["de_DE", "es_MX", "fr_FR", "it_IT", "ja_JP"], | ||
| nargs="+", | ||
| help="Languages to translate to.", | ||
| ) | ||
| args = parser.parse_args() | ||
| main(args) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||
| # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||
| # limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from collections import defaultdict | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from sacrebleu import corpus_bleu | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from nemo_skills.evaluation.metrics.base import BaseMetrics, as_float | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| class TranslationMetrics(BaseMetrics): | ||||||||||||||||||||||||||||||||||||||||||||
|
AlexGrinch marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| def get_metrics(self): | ||||||||||||||||||||||||||||||||||||||||||||
| metrics_dict = {} | ||||||||||||||||||||||||||||||||||||||||||||
| for key in self.translation_dict: | ||||||||||||||||||||||||||||||||||||||||||||
| src_lang, tgt_lang = key.split("->") | ||||||||||||||||||||||||||||||||||||||||||||
| preds = self.translation_dict[key]["preds"] | ||||||||||||||||||||||||||||||||||||||||||||
| gts = self.translation_dict[key]["gts"] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| tokenize = "13a" | ||||||||||||||||||||||||||||||||||||||||||||
| if tgt_lang[:2] == "ja": | ||||||||||||||||||||||||||||||||||||||||||||
| tokenize = "ja-mecab" | ||||||||||||||||||||||||||||||||||||||||||||
| if tgt_lang[:2] == "zh": | ||||||||||||||||||||||||||||||||||||||||||||
| tokenize = "zh" | ||||||||||||||||||||||||||||||||||||||||||||
| if tgt_lang[:2] == "ko": | ||||||||||||||||||||||||||||||||||||||||||||
| tokenize = "ko-mecab" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| bleu_score = corpus_bleu(preds, [gts], tokenize=tokenize).score | ||||||||||||||||||||||||||||||||||||||||||||
| metrics_dict[key] = {"bleu": bleu_score} | ||||||||||||||||||||||||||||||||||||||||||||
| self.aggregation_dict["xx->xx"].append(bleu_score) | ||||||||||||||||||||||||||||||||||||||||||||
| self.aggregation_dict[f"{src_lang}->xx"].append(bleu_score) | ||||||||||||||||||||||||||||||||||||||||||||
| self.aggregation_dict[f"xx->{tgt_lang}"].append(bleu_score) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for key in self.aggregation_dict: | ||||||||||||||||||||||||||||||||||||||||||||
| metrics_dict[key] = {"bleu": sum(self.aggregation_dict[key]) / len(self.aggregation_dict[key])} | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return metrics_dict | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def update(self, predictions): | ||||||||||||||||||||||||||||||||||||||||||||
| """Updating the evaluation results with the current element. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||
| predictions (list[dict]): aggregated predictions across all generations. | ||||||||||||||||||||||||||||||||||||||||||||
| The content of the file is benchmark specific. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| super().update(predictions) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| for pred in predictions: | ||||||||||||||||||||||||||||||||||||||||||||
| src_lang = pred["source_language"] | ||||||||||||||||||||||||||||||||||||||||||||
| tgt_lang = pred["target_language"] | ||||||||||||||||||||||||||||||||||||||||||||
| generation = pred["generation"] | ||||||||||||||||||||||||||||||||||||||||||||
| ground_truth = pred["translation"] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| self.translation_dict[f"{src_lang}->{tgt_lang}"]["preds"].append(generation) | ||||||||||||||||||||||||||||||||||||||||||||
| self.translation_dict[f"{src_lang}->{tgt_lang}"]["gts"].append(ground_truth) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for required prediction keys. The code assumes all predictions contain Consider adding validation: for pred in predictions:
+ required_keys = ["source_language", "target_language", "generation", "translation"]
+ if not all(key in pred for key in required_keys):
+ raise ValueError(f"Prediction missing required keys. Expected {required_keys}, got {list(pred.keys())}")
src_lang = pred["source_language"]
tgt_lang = pred["target_language"]
generation = pred["generation"]
ground_truth = pred["translation"]
self.translation_dict[f"{src_lang}->{tgt_lang}"]["preds"].append(generation)
self.translation_dict[f"{src_lang}->{tgt_lang}"]["gts"].append(ground_truth)Alternatively, document the expected prediction schema in the docstring if validation is considered too strict for your use case. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def reset(self): | ||||||||||||||||||||||||||||||||||||||||||||
| super().reset() | ||||||||||||||||||||||||||||||||||||||||||||
| self.translation_dict = defaultdict(lambda: defaultdict(list)) | ||||||||||||||||||||||||||||||||||||||||||||
| self.aggregation_dict = defaultdict(list) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def evaluations_to_print(self): | ||||||||||||||||||||||||||||||||||||||||||||
| """We will log all majority/rm/pass/pass@1[avg-of-k] up to k, but only report the kth one.""" | ||||||||||||||||||||||||||||||||||||||||||||
| return list(self.translation_dict.keys()) + list(self.aggregation_dict.keys()) | ||||||||||||||||||||||||||||||||||||||||||||
|
AlexGrinch marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def metrics_to_print(self): | ||||||||||||||||||||||||||||||||||||||||||||
| metrics_to_print = {"bleu": as_float} | ||||||||||||||||||||||||||||||||||||||||||||
| return metrics_to_print | ||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Default prompt for text translation. | ||
|
|
||
| user: "Translate the following segment into {target_lang_name}, without additional explanation.\n\n{text}" |
Uh oh!
There was an error while loading. Please reload this page.