Datasets:
Convert dataset to Parquet
#8
by albertvillanova HF Staff - opened
Files changed (24)
- README.md+80-31
- cs-en/test-00000-of-00001.parquetAdded+3
- cs-en/train-00000-of-00001.parquetAdded+3
- cs-en/validation-00000-of-00001.parquetAdded+3
- de-en/test-00000-of-00001.parquetAdded+3
- de-en/train-00000-of-00003.parquetAdded+3
- de-en/train-00001-of-00003.parquetAdded+3
- de-en/train-00002-of-00003.parquetAdded+3
- de-en/validation-00000-of-00001.parquetAdded+3
- fi-en/test-00000-of-00001.parquetAdded+3
- fi-en/train-00000-of-00002.parquetAdded+3
- fi-en/train-00001-of-00002.parquetAdded+3
- fi-en/validation-00000-of-00001.parquetAdded+3
- ro-en/test-00000-of-00001.parquetAdded+3
- ro-en/train-00000-of-00001.parquetAdded+3
- ro-en/validation-00000-of-00001.parquetAdded+3
- ru-en/test-00000-of-00001.parquetAdded+3
- ru-en/train-00000-of-00001.parquetAdded+3
- ru-en/validation-00000-of-00001.parquetAdded+3
- tr-en/test-00000-of-00001.parquetAdded+3
- tr-en/train-00000-of-00001.parquetAdded+3
- tr-en/validation-00000-of-00001.parquetAdded+3
- wmt16.pyDeleted-72
- wmt_utils.pyDeleted-1025
24 unmodified lines25262728293031325 unmodified lines383940414243444546474849505152534 unmodified lines585960616263646566676869707172734 unmodified lines787980818283848586878889909192934 unmodified lines98991001011021031041051061071081091101111121134 unmodified lines1181191201211221231241251261271281291301311321334 unmodified lines13813914014114214314414514614714814915015115215324 unmodified linestask_categories:- translationtask_ids: []pretty_name: WMT16paperswithcode_id: wmt-2016dataset_info:- config_name: cs-enfeatures:5 unmodified lines- ensplits:- name: trainnum_bytes: 296006386num_examples: 997240- name: validationnum_bytes: 572203num_examples: 2656- name: testnum_bytes: 707870num_examples: 2999download_size: 1690726387dataset_size: 297286459- config_name: de-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 1373123263num_examples: 4548885- name: validationnum_bytes: 522989num_examples: 2169- name: testnum_bytes: 735516num_examples: 2999download_size: 1690726387dataset_size: 1374381768- config_name: fi-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 605146827num_examples: 2073394- name: validationnum_bytes: 306335num_examples: 1370- name: testnum_bytes: 1410515num_examples: 6000download_size: 273390220dataset_size: 606863677- config_name: ro-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 188288211num_examples: 610320- name: validationnum_bytes: 561799num_examples: 1999- name: testnum_bytes: 539216num_examples: 1999download_size: 287363574dataset_size: 189389226- config_name: ru-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 448338585num_examples: 1516162- name: validationnum_bytes: 955972num_examples: 2818- name: testnum_bytes: 1050677num_examples: 2998download_size: 1042119564dataset_size: 450345234- config_name: tr-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 60416617num_examples: 205756- name: validationnum_bytes: 240650num_examples: 1001- name: testnum_bytes: 732436num_examples: 3000download_size: 62263061dataset_size: 61389703---# Dataset Card for "wmt16"24 unmodified lines25262728293031325 unmodified lines383940414243444546474849505152534 unmodified lines585960616263646566676869707172734 unmodified lines787980818283848586878889909192934 unmodified lines98991001011021031041051061071081091101111121134 unmodified lines1181191201211221231241251261271281291301311321334 unmodified lines13813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120224 unmodified linestask_categories:- translationtask_ids: []paperswithcode_id: wmt-2016pretty_name: WMT16dataset_info:- config_name: cs-enfeatures:5 unmodified lines- ensplits:- name: trainnum_bytes: 295995226num_examples: 997240- name: validationnum_bytes: 572195num_examples: 2656- name: testnum_bytes: 707862num_examples: 2999download_size: 178250444dataset_size: 297275283- config_name: de-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 1373099816num_examples: 4548885- name: validationnum_bytes: 522981num_examples: 2169- name: testnum_bytes: 735508num_examples: 2999download_size: 827152589dataset_size: 1374358305- config_name: fi-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 605145153num_examples: 2073394- name: validationnum_bytes: 306327num_examples: 1370- name: testnum_bytes: 1410507num_examples: 6000download_size: 348306427dataset_size: 606861987- config_name: ro-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 188287711num_examples: 610320- name: validationnum_bytes: 561791num_examples: 1999- name: testnum_bytes: 539208num_examples: 1999download_size: 108584039dataset_size: 189388710- config_name: ru-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 448322024num_examples: 1516162- name: validationnum_bytes: 955964num_examples: 2818- name: testnum_bytes: 1050669num_examples: 2998download_size: 231557371dataset_size: 450328657- config_name: tr-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 60416449num_examples: 205756- name: validationnum_bytes: 240642num_examples: 1001- name: testnum_bytes: 732428num_examples: 3000download_size: 37389436dataset_size: 61389519configs:- config_name: cs-endata_files:- split: trainpath: cs-en/train-*- split: validationpath: cs-en/validation-*- split: testpath: cs-en/test-*- config_name: de-endata_files:- split: trainpath: de-en/train-*- split: validationpath: de-en/validation-*- split: testpath: de-en/test-*- config_name: fi-endata_files:- split: trainpath: fi-en/train-*- split: validationpath: fi-en/validation-*- split: testpath: fi-en/test-*- config_name: ro-endata_files:- split: trainpath: ro-en/train-*- split: validationpath: ro-en/validation-*- split: testpath: ro-en/test-*- config_name: ru-endata_files:- split: trainpath: ru-en/train-*- split: validationpath: ru-en/validation-*- split: testpath: ru-en/test-*- config_name: tr-endata_files:- split: trainpath: tr-en/train-*- split: validationpath: tr-en/validation-*- split: testpath: tr-en/test-*---# Dataset Card for "wmt16"
123version https://git-lfs.github.com/spec/v1oid sha256:0c19c35a0d4932c738a4a02e080cc473f1b5544374d97bdfbed7815d247cd172size 468787123version https://git-lfs.github.com/spec/v1oid sha256:320b8b34f7520e558122cbc04516429b92ec726544f4522abf21f4f363af3d0bsize 177391346123version https://git-lfs.github.com/spec/v1oid sha256:e5f3e29f5b49bc5c896e8fa9653a52cf2ad2b6b95d8b45dab793f8f15d06817asize 390311123version https://git-lfs.github.com/spec/v1oid sha256:bb87426aded7472ee24408639dae68ab6eb27bb2f495353b406564e72e87fd26size 475031123version https://git-lfs.github.com/spec/v1oid sha256:0a037ece172b3f42c7bf06bb50ff5f718f62720d17998d4e6cc4223c541667cfsize 282014647123version https://git-lfs.github.com/spec/v1oid sha256:96cf09052f9bc879e8a70029f7a49868fa3f4ba6e5c31254a1c51ab14a72eb2esize 267375046123version https://git-lfs.github.com/spec/v1oid sha256:d9991b85a44e6e5691cd3fac98e401f6f1b9c4c8208a77bd82234e9041b2b285size 276945174123version https://git-lfs.github.com/spec/v1oid sha256:dca6c5c1a432f7064665323555352e809b5c7e2ed620e61bbb6a27dcf2c9235esize 342691123version https://git-lfs.github.com/spec/v1oid sha256:10ac26e7da9da054054391d5dbe786b81bc9ed18b44946dff4a8a12768f52ad1size 904438123version https://git-lfs.github.com/spec/v1oid sha256:4d4f5a98fd6a407e0a4e21049d8eecc6b5d2a6e745a53ad3993218fc1ac60713size 187478084123version https://git-lfs.github.com/spec/v1oid sha256:d439321116c69a3e21f1436fcd09f39ef95f6232bbb0f444036d6f008de04fe9size 159720579123version https://git-lfs.github.com/spec/v1oid sha256:2693bb05ad4d1c2739486a29a380696c88d8495eb6b55e7e7cacf96050cb0c1asize 203326123version https://git-lfs.github.com/spec/v1oid sha256:21742f54d534024c59e0d94f92b9b8e5bf4c871027a866566275cc3ab582b218size 342174123version https://git-lfs.github.com/spec/v1oid sha256:0a3b7151736e9fc0c7cae9c6f2e96493d929e910372f5c6c29d41f716dd956a7size 107880264123version https://git-lfs.github.com/spec/v1oid sha256:9dff36e7a899121682d47f0238de1aa307f3b03f087ad411d1a2846977326082size 361601123version https://git-lfs.github.com/spec/v1oid sha256:a01917bda325d1a287dd09061cf9e8727f79c3f95fd29ce8ac0ec675ec7a227fsize 586531123version https://git-lfs.github.com/spec/v1oid sha256:a74a159275942c6b6ec11fef24f0f9b364b9e5784ff0fb84952cc7b1593b5943size 230432840123version https://git-lfs.github.com/spec/v1oid sha256:80bd5e16b06852680fb6670d99e50bbe014a4fb8777722387a7558f775d98bf6size 538000123version https://git-lfs.github.com/spec/v1oid sha256:5c2226d153ed115b81901eb32396a2b8b2c1b5f6f99035e4b1fb9e4a28c81f9fsize 465730123version https://git-lfs.github.com/spec/v1oid sha256:0195fe43ea5ed06b7d243112459a021f33780351543d853b0d6420ab19759defsize 36771180123version https://git-lfs.github.com/spec/v1oid sha256:76f7f6c9b43d09ee013ee9494009d0cd1835d773a258bc847c22f3d3ee29fa31size 152526123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172# coding=utf-8# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.## 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.
# Lint as: python3"""WMT16: Translate dataset."""
import datasets
from .wmt_utils import Wmt, WmtConfig
_URL = "http://www.statmt.org/wmt16/translation-task.html"_CITATION = """@InProceedings{bojar-EtAl:2016:WMT1, author = {Bojar, Ond\v{r}ej and Chatterjee, Rajen and Federmann, Christian and Graham, Yvette and Haddow, Barry and Huck, Matthias and Jimeno Yepes, Antonio and Koehn, Philipp and Logacheva, Varvara and Monz, Christof and Negri, Matteo and Neveol, Aurelie and Neves, Mariana and Popel, Martin and Post, Matt and Rubino, Raphael and Scarton, Carolina and Specia, Lucia and Turchi, Marco and Verspoor, Karin and Zampieri, Marcos}, title = {Findings of the 2016 Conference on Machine Translation}, booktitle = {Proceedings of the First Conference on Machine Translation}, month = {August}, year = {2016}, address = {Berlin, Germany}, publisher = {Association for Computational Linguistics}, pages = {131--198}, url = {http://www.aclweb.org/anthology/W/W16/W16-2301}}"""
_LANGUAGE_PAIRS = [(lang, "en") for lang in ["cs", "de", "fi", "ro", "ru", "tr"]]
class Wmt16(Wmt): """WMT 16 translation datasets for all {xx, "en"} language pairs."""
BUILDER_CONFIGS = [ WmtConfig( # pylint:disable=g-complex-comprehension description="WMT 2016 %s-%s translation task dataset." % (l1, l2), url=_URL, citation=_CITATION, language_pair=(l1, l2), version=datasets.Version("1.0.0"), ) for l1, l2 in _LANGUAGE_PAIRS ]
@property def _subsets(self): return { datasets.Split.TRAIN: [ "europarl_v7", "europarl_v8_16", "commoncrawl", "newscommentary_v11", "czeng_16pre", "yandexcorpus", "wikiheadlines_fi", "wikiheadlines_ru", "setimes_2", ], datasets.Split.VALIDATION: ["newsdev2016", "newstest2015"], datasets.Split.TEST: ["newstest2016", "newstestB2016"], }12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025# coding=utf-8# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.## 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.
# Lint as: python3"""WMT: Translate dataset."""
import codecsimport functoolsimport globimport gzipimport itertoolsimport osimport reimport xml.etree.cElementTree as ElementTree
import datasets
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """\Translation dataset based on the data from statmt.org.
Versions exist for different years using a combination of datasources. The base `wmt` allows you to create a custom dataset by choosingyour own data/language pair. This can be done as follows:
```pythonfrom datasets import inspect_dataset, load_dataset_builder
inspect_dataset("wmt16", "path/to/scripts")builder = load_dataset_builder( "path/to/scripts/wmt_utils.py", language_pair=("fr", "de"), subsets={ datasets.Split.TRAIN: ["commoncrawl_frde"], datasets.Split.VALIDATION: ["euelections_dev2019"], },)
# Standard versionbuilder.download_and_prepare()ds = builder.as_dataset()
# Streamable versionds = builder.as_streaming_dataset()```
"""
CWMT_SUBSET_NAMES = ["casia2015", "casict2011", "casict2015", "datum2015", "datum2017", "neu2017"]
class SubDataset: """Class to keep track of information on a sub-dataset of WMT."""
def __init__(self, name, target, sources, url, path, manual_dl_files=None): """Sub-dataset of WMT.
Args: name: `string`, a unique dataset identifier. target: `string`, the target language code. sources: `set<string>`, the set of source language codes. url: `string` or `(string, string)`, URL(s) or URL template(s) specifying where to download the raw data from. If two strings are provided, the first is used for the source language and the second for the target. Template strings can either contain '{src}' placeholders that will be filled in with the source language code, '{0}' and '{1}' placeholders that will be filled in with the source and target language codes in alphabetical order, or all 3. path: `string` or `(string, string)`, path(s) or path template(s) specifing the path to the raw data relative to the root of the downloaded archive. If two strings are provided, the dataset is assumed to be made up of parallel text files, the first being the source and the second the target. If one string is provided, both languages are assumed to be stored within the same file and the extension is used to determine how to parse it. Template strings should be formatted the same as in `url`. manual_dl_files: `<list>(string)` (optional), the list of files that must be manually downloaded to the data directory. """ self._paths = (path,) if isinstance(path, str) else path self._urls = (url,) if isinstance(url, str) else url self._manual_dl_files = manual_dl_files if manual_dl_files else [] self.name = name self.target = target self.sources = set(sources)
def _inject_language(self, src, strings): """Injects languages into (potentially) template strings.""" if src not in self.sources: raise ValueError(f"Invalid source for '{self.name}': {src}")
def _format_string(s): if "{0}" in s and "{1}" and "{src}" in s: return s.format(*sorted([src, self.target]), src=src) elif "{0}" in s and "{1}" in s: return s.format(*sorted([src, self.target])) elif "{src}" in s: return s.format(src=src) else: return s
return [_format_string(s) for s in strings]
def get_url(self, src): return self._inject_language(src, self._urls)
def get_manual_dl_files(self, src): return self._inject_language(src, self._manual_dl_files)
def get_path(self, src): return self._inject_language(src, self._paths)
# Subsets used in the training sets for various years of WMT._TRAIN_SUBSETS = [ # pylint:disable=line-too-long SubDataset( name="commoncrawl", target="en", # fr-de pair in commoncrawl_frde sources={"cs", "de", "es", "fr", "ru"}, url="https://huggingface.co/datasets/wmt/wmt13/resolve/main-zip/training-parallel-commoncrawl.zip", path=("commoncrawl.{src}-en.{src}", "commoncrawl.{src}-en.en"), ), SubDataset( name="commoncrawl_frde", target="de", sources={"fr"}, url=( "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/commoncrawl.fr.gz", "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/commoncrawl.de.gz", ), path=("", ""), ), SubDataset( name="czeng_10", target="en", sources={"cs"}, url="http://ufal.mff.cuni.cz/czeng/czeng10", manual_dl_files=["data-plaintext-format.%d.tar" % i for i in range(10)], # Each tar contains multiple files, which we process specially in # _parse_czeng. path=("data.plaintext-format/??train.gz",) * 10, ), SubDataset( name="czeng_16pre", target="en", sources={"cs"}, url="http://ufal.mff.cuni.cz/czeng/czeng16pre", manual_dl_files=["czeng16pre.deduped-ignoring-sections.txt.gz"], path="", ), SubDataset( name="czeng_16", target="en", sources={"cs"}, url="http://ufal.mff.cuni.cz/czeng", manual_dl_files=["data-plaintext-format.%d.tar" % i for i in range(10)], # Each tar contains multiple files, which we process specially in # _parse_czeng. path=("data.plaintext-format/??train.gz",) * 10, ), SubDataset( # This dataset differs from the above in the filtering that is applied # during parsing. name="czeng_17", target="en", sources={"cs"}, url="http://ufal.mff.cuni.cz/czeng", manual_dl_files=["data-plaintext-format.%d.tar" % i for i in range(10)], # Each tar contains multiple files, which we process specially in # _parse_czeng. path=("data.plaintext-format/??train.gz",) * 10, ), SubDataset( name="dcep_v1", target="en", sources={"lv"}, url="https://huggingface.co/datasets/wmt/wmt17/resolve/main-zip/translation-task/dcep.lv-en.v1.zip", path=("dcep.en-lv/dcep.lv", "dcep.en-lv/dcep.en"), ), SubDataset( name="europarl_v7", target="en", sources={"cs", "de", "es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt13/resolve/main-zip/training-parallel-europarl-v7.zip", path=("training/europarl-v7.{src}-en.{src}", "training/europarl-v7.{src}-en.en"), ), SubDataset( name="europarl_v7_frde", target="de", sources={"fr"}, url=( "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/europarl-v7.fr.gz", "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/europarl-v7.de.gz", ), path=("", ""), ), SubDataset( name="europarl_v8_18", target="en", sources={"et", "fi"}, url="https://huggingface.co/datasets/wmt/wmt18/resolve/main-zip/translation-task/training-parallel-ep-v8.zip", path=("training/europarl-v8.{src}-en.{src}", "training/europarl-v8.{src}-en.en"), ), SubDataset( name="europarl_v8_16", target="en", sources={"fi", "ro"}, url="https://huggingface.co/datasets/wmt/wmt16/resolve/main-zip/translation-task/training-parallel-ep-v8.zip", path=("training-parallel-ep-v8/europarl-v8.{src}-en.{src}", "training-parallel-ep-v8/europarl-v8.{src}-en.en"), ), SubDataset( name="europarl_v9", target="en", sources={"cs", "de", "fi", "lt"}, url="https://huggingface.co/datasets/wmt/europarl/resolve/main/v9/training/europarl-v9.{src}-en.tsv.gz", path="", ), SubDataset( name="gigafren", target="en", sources={"fr"}, url="https://huggingface.co/datasets/wmt/wmt10/resolve/main-zip/training-giga-fren.zip", path=("giga-fren.release2.fixed.fr.gz", "giga-fren.release2.fixed.en.gz"), ), SubDataset( name="hindencorp_01", target="en", sources={"hi"}, url="http://ufallab.ms.mff.cuni.cz/~bojar/hindencorp", manual_dl_files=["hindencorp0.1.gz"], path="", ), SubDataset( name="leta_v1", target="en", sources={"lv"}, url="https://huggingface.co/datasets/wmt/wmt17/resolve/main-zip/translation-task/leta.v1.zip", path=("LETA-lv-en/leta.lv", "LETA-lv-en/leta.en"), ), SubDataset( name="multiun", target="en", sources={"es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt13/resolve/main-zip/training-parallel-un.zip", path=("un/undoc.2000.{src}-en.{src}", "un/undoc.2000.{src}-en.en"), ), SubDataset( name="newscommentary_v9", target="en", sources={"cs", "de", "fr", "ru"}, url="https://huggingface.co/datasets/wmt/wmt14/resolve/main-zip/training-parallel-nc-v9.zip", path=("training/news-commentary-v9.{src}-en.{src}", "training/news-commentary-v9.{src}-en.en"), ), SubDataset( name="newscommentary_v10", target="en", sources={"cs", "de", "fr", "ru"}, url="https://huggingface.co/datasets/wmt/wmt15/resolve/main-zip/training-parallel-nc-v10.zip", path=("news-commentary-v10.{src}-en.{src}", "news-commentary-v10.{src}-en.en"), ), SubDataset( name="newscommentary_v11", target="en", sources={"cs", "de", "ru"}, url="https://huggingface.co/datasets/wmt/wmt16/resolve/main-zip/translation-task/training-parallel-nc-v11.zip", path=( "training-parallel-nc-v11/news-commentary-v11.{src}-en.{src}", "training-parallel-nc-v11/news-commentary-v11.{src}-en.en", ), ), SubDataset( name="newscommentary_v12", target="en", sources={"cs", "de", "ru", "zh"}, url="https://huggingface.co/datasets/wmt/wmt17/resolve/main-zip/translation-task/training-parallel-nc-v12.zip", path=("training/news-commentary-v12.{src}-en.{src}", "training/news-commentary-v12.{src}-en.en"), ), SubDataset( name="newscommentary_v13", target="en", sources={"cs", "de", "ru", "zh"}, url="https://huggingface.co/datasets/wmt/wmt18/resolve/main-zip/translation-task/training-parallel-nc-v13.zip", path=( "training-parallel-nc-v13/news-commentary-v13.{src}-en.{src}", "training-parallel-nc-v13/news-commentary-v13.{src}-en.en", ), ), SubDataset( name="newscommentary_v14", target="en", # fr-de pair in newscommentary_v14_frde sources={"cs", "de", "kk", "ru", "zh"}, url="http://data.statmt.org/news-commentary/v14/training/news-commentary-v14.{0}-{1}.tsv.gz", path="", ), SubDataset( name="newscommentary_v14_frde", target="de", sources={"fr"}, url="http://data.statmt.org/news-commentary/v14/training/news-commentary-v14.de-fr.tsv.gz", path="", ), SubDataset( name="onlinebooks_v1", target="en", sources={"lv"}, url="https://huggingface.co/datasets/wmt/wmt17/resolve/main-zip/translation-task/books.lv-en.v1.zip", path=("farewell/farewell.lv", "farewell/farewell.en"), ), SubDataset( name="paracrawl_v1", target="en", sources={"cs", "de", "et", "fi", "ru"}, url="https://s3.amazonaws.com/web-language-models/paracrawl/release1/paracrawl-release1.en-{src}.zipporah0-dedup-clean.tgz", # TODO(QL): use zip for streaming path=( "paracrawl-release1.en-{src}.zipporah0-dedup-clean.{src}", "paracrawl-release1.en-{src}.zipporah0-dedup-clean.en", ), ), SubDataset( name="paracrawl_v1_ru", target="en", sources={"ru"}, url="https://s3.amazonaws.com/web-language-models/paracrawl/release1/paracrawl-release1.en-ru.zipporah0-dedup-clean.tgz", # TODO(QL): use zip for streaming path=( "paracrawl-release1.en-ru.zipporah0-dedup-clean.ru", "paracrawl-release1.en-ru.zipporah0-dedup-clean.en", ), ), SubDataset( name="paracrawl_v3", target="en", # fr-de pair in paracrawl_v3_frde sources={"cs", "de", "fi", "lt"}, url="https://s3.amazonaws.com/web-language-models/paracrawl/release3/en-{src}.bicleaner07.tmx.gz", path="", ), SubDataset( name="paracrawl_v3_frde", target="de", sources={"fr"}, url=( "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/de-fr.bicleaner07.de.gz", "https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/fr-de/bitexts/de-fr.bicleaner07.fr.gz", ), path=("", ""), ), SubDataset( name="rapid_2016", target="en", sources={"de", "et", "fi"}, url="https://huggingface.co/datasets/wmt/wmt18/resolve/main-zip/translation-task/rapid2016.zip", path=("rapid2016.{0}-{1}.{src}", "rapid2016.{0}-{1}.en"), ), SubDataset( name="rapid_2016_ltfi", target="en", sources={"fi", "lt"}, url="https://tilde-model.s3-eu-west-1.amazonaws.com/rapid2016.en-{src}.tmx.zip", path="rapid2016.en-{src}.tmx", ), SubDataset( name="rapid_2019", target="en", sources={"de"}, url="https://s3-eu-west-1.amazonaws.com/tilde-model/rapid2019.de-en.zip", path=("rapid2019.de-en.de", "rapid2019.de-en.en"), ), SubDataset( name="setimes_2", target="en", sources={"ro", "tr"}, url="https://object.pouta.csc.fi/OPUS-SETIMES/v2/tmx/en-{src}.tmx.gz", path="", ), SubDataset( name="uncorpus_v1", target="en", sources={"ru", "zh"}, url="https://huggingface.co/datasets/wmt/uncorpus/resolve/main-zip/UNv1.0.en-{src}.zip", path=("en-{src}/UNv1.0.en-{src}.{src}", "en-{src}/UNv1.0.en-{src}.en"), ), SubDataset( name="wikiheadlines_fi", target="en", sources={"fi"}, url="https://huggingface.co/datasets/wmt/wmt15/resolve/main-zip/wiki-titles.zip", path="wiki/fi-en/titles.fi-en", ), SubDataset( name="wikiheadlines_hi", target="en", sources={"hi"}, url="https://huggingface.co/datasets/wmt/wmt14/resolve/main-zip/wiki-titles.zip", path="wiki/hi-en/wiki-titles.hi-en", ), SubDataset( # Verified that wmt14 and wmt15 files are identical. name="wikiheadlines_ru", target="en", sources={"ru"}, url="https://huggingface.co/datasets/wmt/wmt15/resolve/main-zip/wiki-titles.zip", path="wiki/ru-en/wiki.ru-en", ), SubDataset( name="wikititles_v1", target="en", sources={"cs", "de", "fi", "gu", "kk", "lt", "ru", "zh"}, url="https://huggingface.co/datasets/wmt/wikititles/resolve/main/v1/wikititles-v1.{src}-en.tsv.gz", path="", ), SubDataset( name="yandexcorpus", target="en", sources={"ru"}, url="https://translate.yandex.ru/corpus?lang=en", manual_dl_files=["1mcorpus.zip"], path=("corpus.en_ru.1m.ru", "corpus.en_ru.1m.en"), ), # pylint:enable=line-too-long] + [ SubDataset( # pylint:disable=g-complex-comprehension name=ss, target="en", sources={"zh"}, url="https://huggingface.co/datasets/wmt/wmt18/resolve/main/cwmt-wmt/%s.zip" % ss, path=("%s/*_c[hn].txt" % ss, "%s/*_en.txt" % ss), ) for ss in CWMT_SUBSET_NAMES]
_DEV_SUBSETS = [ SubDataset( name="euelections_dev2019", target="de", sources={"fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/euelections_dev2019.fr-de.src.fr", "dev/euelections_dev2019.fr-de.tgt.de"), ), SubDataset( name="newsdev2014", target="en", sources={"hi"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2014.hi", "dev/newsdev2014.en"), ), SubDataset( name="newsdev2015", target="en", sources={"fi"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2015-fien-src.{src}.sgm", "dev/newsdev2015-fien-ref.en.sgm"), ), SubDataset( name="newsdiscussdev2015", target="en", sources={"ro", "tr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdiscussdev2015-{src}en-src.{src}.sgm", "dev/newsdiscussdev2015-{src}en-ref.en.sgm"), ), SubDataset( name="newsdev2016", target="en", sources={"ro", "tr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2016-{src}en-src.{src}.sgm", "dev/newsdev2016-{src}en-ref.en.sgm"), ), SubDataset( name="newsdev2017", target="en", sources={"lv", "zh"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2017-{src}en-src.{src}.sgm", "dev/newsdev2017-{src}en-ref.en.sgm"), ), SubDataset( name="newsdev2018", target="en", sources={"et"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2018-{src}en-src.{src}.sgm", "dev/newsdev2018-{src}en-ref.en.sgm"), ), SubDataset( name="newsdev2019", target="en", sources={"gu", "kk", "lt"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdev2019-{src}en-src.{src}.sgm", "dev/newsdev2019-{src}en-ref.en.sgm"), ), SubDataset( name="newsdiscussdev2015", target="en", sources={"fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdiscussdev2015-{src}en-src.{src}.sgm", "dev/newsdiscussdev2015-{src}en-ref.en.sgm"), ), SubDataset( name="newsdiscusstest2015", target="en", sources={"fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdiscusstest2015-{src}en-src.{src}.sgm", "dev/newsdiscusstest2015-{src}en-ref.en.sgm"), ), SubDataset( name="newssyscomb2009", target="en", sources={"cs", "de", "es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newssyscomb2009.{src}", "dev/newssyscomb2009.en"), ), SubDataset( name="newstest2008", target="en", sources={"cs", "de", "es", "fr", "hu"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/news-test2008.{src}", "dev/news-test2008.en"), ), SubDataset( name="newstest2009", target="en", sources={"cs", "de", "es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2009.{src}", "dev/newstest2009.en"), ), SubDataset( name="newstest2010", target="en", sources={"cs", "de", "es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2010.{src}", "dev/newstest2010.en"), ), SubDataset( name="newstest2011", target="en", sources={"cs", "de", "es", "fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2011.{src}", "dev/newstest2011.en"), ), SubDataset( name="newstest2012", target="en", sources={"cs", "de", "es", "fr", "ru"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2012.{src}", "dev/newstest2012.en"), ), SubDataset( name="newstest2013", target="en", sources={"cs", "de", "es", "fr", "ru"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2013.{src}", "dev/newstest2013.en"), ), SubDataset( name="newstest2014", target="en", sources={"cs", "de", "es", "fr", "hi", "ru"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2014-{src}en-src.{src}.sgm", "dev/newstest2014-{src}en-ref.en.sgm"), ), SubDataset( name="newstest2015", target="en", sources={"cs", "de", "fi", "ru"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2015-{src}en-src.{src}.sgm", "dev/newstest2015-{src}en-ref.en.sgm"), ), SubDataset( name="newsdiscusstest2015", target="en", sources={"fr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newsdiscusstest2015-{src}en-src.{src}.sgm", "dev/newsdiscusstest2015-{src}en-ref.en.sgm"), ), SubDataset( name="newstest2016", target="en", sources={"cs", "de", "fi", "ro", "ru", "tr"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2016-{src}en-src.{src}.sgm", "dev/newstest2016-{src}en-ref.en.sgm"), ), SubDataset( name="newstestB2016", target="en", sources={"fi"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstestB2016-enfi-ref.{src}.sgm", "dev/newstestB2016-enfi-src.en.sgm"), ), SubDataset( name="newstest2017", target="en", sources={"cs", "de", "fi", "lv", "ru", "tr", "zh"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2017-{src}en-src.{src}.sgm", "dev/newstest2017-{src}en-ref.en.sgm"), ), SubDataset( name="newstestB2017", target="en", sources={"fi"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstestB2017-fien-src.fi.sgm", "dev/newstestB2017-fien-ref.en.sgm"), ), SubDataset( name="newstest2018", target="en", sources={"cs", "de", "et", "fi", "ru", "tr", "zh"}, url="https://huggingface.co/datasets/wmt/wmt19/resolve/main-zip/translation-task/dev.zip", path=("dev/newstest2018-{src}en-src.{src}.sgm", "dev/newstest2018-{src}en-ref.en.sgm"), ),]
DATASET_MAP = {dataset.name: dataset for dataset in _TRAIN_SUBSETS + _DEV_SUBSETS}
_CZENG17_FILTER = SubDataset( name="czeng17_filter", target="en", sources={"cs"}, url="http://ufal.mff.cuni.cz/czeng/download.php?f=convert_czeng16_to_17.pl.zip", path="convert_czeng16_to_17.pl",)
class WmtConfig(datasets.BuilderConfig): """BuilderConfig for WMT."""
def __init__(self, url=None, citation=None, description=None, language_pair=(None, None), subsets=None, **kwargs): """BuilderConfig for WMT.
Args: url: The reference URL for the dataset. citation: The paper citation for the dataset. description: The description of the dataset. language_pair: pair of languages that will be used for translation. Should contain 2 letter coded strings. For example: ("en", "de"). configuration for the `datasets.features.text.TextEncoder` used for the `datasets.features.text.Translation` features. subsets: Dict[split, list[str]]. List of the subset to use for each of the split. Note that WMT subclasses overwrite this parameter. **kwargs: keyword arguments forwarded to super. """ name = "%s-%s" % (language_pair[0], language_pair[1]) if "name" in kwargs: # Add name suffix for custom configs name += "." + kwargs.pop("name")
super(WmtConfig, self).__init__(name=name, description=description, **kwargs)
self.url = url or "http://www.statmt.org" self.citation = citation self.language_pair = language_pair self.subsets = subsets
# TODO(PVP): remove when manual dir works # +++++++++++++++++++++ if language_pair[1] in ["cs", "hi", "ru"]: assert NotImplementedError(f"The dataset for {language_pair[1]}-en is currently not fully supported.") # +++++++++++++++++++++
class Wmt(datasets.GeneratorBasedBuilder): """WMT translation dataset."""
BUILDER_CONFIG_CLASS = WmtConfig
def __init__(self, *args, **kwargs): super(Wmt, self).__init__(*args, **kwargs)
@property def _subsets(self): """Subsets that make up each split of the dataset.""" raise NotImplementedError("This is a abstract method")
@property def subsets(self): """Subsets that make up each split of the dataset for the language pair.""" source, target = self.config.language_pair filtered_subsets = {} subsets = self._subsets if self.config.subsets is None else self.config.subsets for split, ss_names in subsets.items(): filtered_subsets[split] = [] for ss_name in ss_names: dataset = DATASET_MAP[ss_name] if dataset.target != target or source not in dataset.sources: logger.info("Skipping sub-dataset that does not include language pair: %s", ss_name) else: filtered_subsets[split].append(ss_name) logger.info("Using sub-datasets: %s", filtered_subsets) return filtered_subsets
def _info(self): src, target = self.config.language_pair return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( {"translation": datasets.features.Translation(languages=self.config.language_pair)} ), supervised_keys=(src, target), homepage=self.config.url, citation=self.config.citation, )
def _vocab_text_gen(self, split_subsets, extraction_map, language): for _, ex in self._generate_examples(split_subsets, extraction_map, with_translation=False): yield ex[language]
def _split_generators(self, dl_manager): source, _ = self.config.language_pair manual_paths_dict = {} urls_to_download = {} for ss_name in itertools.chain.from_iterable(self.subsets.values()): if ss_name == "czeng_17": # CzEng1.7 is CzEng1.6 with some blocks filtered out. We must download # the filtering script so we can parse out which blocks need to be # removed. urls_to_download[_CZENG17_FILTER.name] = _CZENG17_FILTER.get_url(source)
# get dataset dataset = DATASET_MAP[ss_name] if dataset.get_manual_dl_files(source): # TODO(PVP): following two lines skip configs that are incomplete for now # +++++++++++++++++++++ logger.info("Skipping {dataset.name} for now. Incomplete dataset for {self.config.name}") continue # +++++++++++++++++++++
manual_dl_files = dataset.get_manual_dl_files(source) manual_paths = [ os.path.join(os.path.abspath(os.path.expanduser(dl_manager.manual_dir)), fname) for fname in manual_dl_files ] assert all( os.path.exists(path) for path in manual_paths ), f"For {dataset.name}, you must manually download the following file(s) from {dataset.get_url(source)} and place them in {dl_manager.manual_dir}: {', '.join(manual_dl_files)}"
# set manual path for correct subset manual_paths_dict[ss_name] = manual_paths else: urls_to_download[ss_name] = dataset.get_url(source)
# Download and extract files from URLs. downloaded_files = dl_manager.download_and_extract(urls_to_download) # Extract manually downloaded files. manual_files = dl_manager.extract(manual_paths_dict) extraction_map = dict(downloaded_files, **manual_files)
for language in self.config.language_pair: self._vocab_text_gen(self.subsets[datasets.Split.TRAIN], extraction_map, language)
return [ datasets.SplitGenerator( # pylint:disable=g-complex-comprehension name=split, gen_kwargs={"split_subsets": split_subsets, "extraction_map": extraction_map} ) for split, split_subsets in self.subsets.items() ]
def _generate_examples(self, split_subsets, extraction_map, with_translation=True): """Returns the examples in the raw (text) form.""" source, _ = self.config.language_pair
def _get_local_paths(dataset, extract_dirs): rel_paths = dataset.get_path(source) if len(extract_dirs) == 1: extract_dirs = extract_dirs * len(rel_paths) return [ os.path.join(ex_dir, rel_path) if rel_path else ex_dir for ex_dir, rel_path in zip(extract_dirs, rel_paths) ]
def _get_filenames(dataset): rel_paths = dataset.get_path(source) urls = dataset.get_url(source) if len(urls) == 1: urls = urls * len(rel_paths) return [rel_path if rel_path else os.path.basename(url) for url, rel_path in zip(urls, rel_paths)]
for ss_name in split_subsets: # TODO(PVP) remove following five lines when manual data works # +++++++++++++++++++++ dataset = DATASET_MAP[ss_name] source, _ = self.config.language_pair if dataset.get_manual_dl_files(source): logger.info(f"Skipping {dataset.name} for now. Incomplete dataset for {self.config.name}") continue # +++++++++++++++++++++
logger.info("Generating examples from: %s", ss_name) dataset = DATASET_MAP[ss_name] extract_dirs = extraction_map[ss_name] files = _get_local_paths(dataset, extract_dirs) filenames = _get_filenames(dataset)
sub_generator_args = tuple(files)
if ss_name.startswith("czeng"): if ss_name.endswith("16pre"): sub_generator = functools.partial(_parse_tsv, language_pair=("en", "cs")) sub_generator_args += tuple(filenames) elif ss_name.endswith("17"): filter_path = _get_local_paths(_CZENG17_FILTER, extraction_map[_CZENG17_FILTER.name])[0] sub_generator = functools.partial(_parse_czeng, filter_path=filter_path) else: sub_generator = _parse_czeng elif ss_name == "hindencorp_01": sub_generator = _parse_hindencorp elif len(files) == 2: if ss_name.endswith("_frde"): sub_generator = _parse_frde_bitext else: sub_generator = _parse_parallel_sentences sub_generator_args += tuple(filenames) elif len(files) == 1: fname = filenames[0] # Note: Due to formatting used by `download_manager`, the file # extension may not be at the end of the file path. if ".tsv" in fname: sub_generator = _parse_tsv sub_generator_args += tuple(filenames) elif ( ss_name.startswith("newscommentary_v14") or ss_name.startswith("europarl_v9") or ss_name.startswith("wikititles_v1") ): sub_generator = functools.partial(_parse_tsv, language_pair=self.config.language_pair) sub_generator_args += tuple(filenames) elif "tmx" in fname or ss_name.startswith("paracrawl_v3"): sub_generator = _parse_tmx elif ss_name.startswith("wikiheadlines"): sub_generator = _parse_wikiheadlines else: raise ValueError("Unsupported file format: %s" % fname) else: raise ValueError("Invalid number of files: %d" % len(files))
for sub_key, ex in sub_generator(*sub_generator_args): if not all(ex.values()): continue # TODO(adarob): Add subset feature. # ex["subset"] = subset key = f"{ss_name}/{sub_key}" if with_translation is True: ex = {"translation": ex} yield key, ex
def _parse_parallel_sentences(f1, f2, filename1, filename2): """Returns examples from parallel SGML or text files, which may be gzipped."""
def _parse_text(path, original_filename): """Returns the sentences from a single text file, which may be gzipped.""" split_path = original_filename.split(".")
if split_path[-1] == "gz": lang = split_path[-2]
def gen(): with open(path, "rb") as f, gzip.GzipFile(fileobj=f) as g: for line in g: yield line.decode("utf-8").rstrip()
return gen(), lang
if split_path[-1] == "txt": # CWMT lang = split_path[-2].split("_")[-1] lang = "zh" if lang in ("ch", "cn", "c[hn]") else lang else: lang = split_path[-1]
def gen(): with open(path, "rb") as f: for line in f: yield line.decode("utf-8").rstrip()
return gen(), lang
def _parse_sgm(path, original_filename): """Returns sentences from a single SGML file.""" lang = original_filename.split(".")[-2] # Note: We can't use the XML parser since some of the files are badly # formatted. seg_re = re.compile(r"<seg id=\"\d+\">(.*)</seg>")
def gen(): with open(path, encoding="utf-8") as f: for line in f: seg_match = re.match(seg_re, line) if seg_match: assert len(seg_match.groups()) == 1 yield seg_match.groups()[0]
return gen(), lang
parse_file = _parse_sgm if os.path.basename(f1).endswith(".sgm") else _parse_text
# Some datasets (e.g., CWMT) contain multiple parallel files specified with # a wildcard. We sort both sets to align them and parse them one by one. f1_files = sorted(glob.glob(f1)) f2_files = sorted(glob.glob(f2))
assert f1_files and f2_files, "No matching files found: %s, %s." % (f1, f2) assert len(f1_files) == len(f2_files), "Number of files do not match: %d vs %d for %s vs %s." % ( len(f1_files), len(f2_files), f1, f2, )
for f_id, (f1_i, f2_i) in enumerate(zip(sorted(f1_files), sorted(f2_files))): l1_sentences, l1 = parse_file(f1_i, filename1) l2_sentences, l2 = parse_file(f2_i, filename2)
for line_id, (s1, s2) in enumerate(zip(l1_sentences, l2_sentences)): key = f"{f_id}/{line_id}" yield key, {l1: s1, l2: s2}
def _parse_frde_bitext(fr_path, de_path): with open(fr_path, encoding="utf-8") as fr_f: with open(de_path, encoding="utf-8") as de_f: for line_id, (s1, s2) in enumerate(zip(fr_f, de_f)): yield line_id, {"fr": s1.rstrip(), "de": s2.rstrip()}
def _parse_tmx(path): """Generates examples from TMX file."""
def _get_tuv_lang(tuv): for k, v in tuv.items(): if k.endswith("}lang"): return v raise AssertionError("Language not found in `tuv` attributes.")
def _get_tuv_seg(tuv): segs = tuv.findall("seg") assert len(segs) == 1, "Invalid number of segments: %d" % len(segs) return segs[0].text
with open(path, "rb") as f: # Workaround due to: https://github.com/tensorflow/tensorflow/issues/33563 utf_f = codecs.getreader("utf-8")(f) for line_id, (_, elem) in enumerate(ElementTree.iterparse(utf_f)): if elem.tag == "tu": yield line_id, {_get_tuv_lang(tuv): _get_tuv_seg(tuv) for tuv in elem.iterfind("tuv")} elem.clear()
def _parse_tsv(path, filename, language_pair=None): """Generates examples from TSV file.""" if language_pair is None: lang_match = re.match(r".*\.([a-z][a-z])-([a-z][a-z])\.tsv", filename) assert lang_match is not None, "Invalid TSV filename: %s" % filename l1, l2 = lang_match.groups() else: l1, l2 = language_pair with open(path, encoding="utf-8") as f: for j, line in enumerate(f): cols = line.split("\t") if len(cols) != 2: logger.warning("Skipping line %d in TSV (%s) with %d != 2 columns.", j, path, len(cols)) continue s1, s2 = cols yield j, {l1: s1.strip(), l2: s2.strip()}
def _parse_wikiheadlines(path): """Generates examples from Wikiheadlines dataset file.""" lang_match = re.match(r".*\.([a-z][a-z])-([a-z][a-z])$", path) assert lang_match is not None, "Invalid Wikiheadlines filename: %s" % path l1, l2 = lang_match.groups() with open(path, encoding="utf-8") as f: for line_id, line in enumerate(f): s1, s2 = line.split("|||") yield line_id, {l1: s1.strip(), l2: s2.strip()}
def _parse_czeng(*paths, **kwargs): """Generates examples from CzEng v1.6, with optional filtering for v1.7.""" filter_path = kwargs.get("filter_path", None) if filter_path: re_block = re.compile(r"^[^-]+-b(\d+)-\d\d[tde]") with open(filter_path, encoding="utf-8") as f: bad_blocks = {blk for blk in re.search(r"qw{([\s\d]*)}", f.read()).groups()[0].split()} logger.info("Loaded %d bad blocks to filter from CzEng v1.6 to make v1.7.", len(bad_blocks))
for path in paths: for gz_path in sorted(glob.glob(path)): with open(gz_path, "rb") as g, gzip.GzipFile(fileobj=g) as f: filename = os.path.basename(gz_path) for line_id, line in enumerate(f): line = line.decode("utf-8") # required for py3 if not line.strip(): continue id_, unused_score, cs, en = line.split("\t") if filter_path: block_match = re.match(re_block, id_) if block_match and block_match.groups()[0] in bad_blocks: continue sub_key = f"{filename}/{line_id}" yield sub_key, { "cs": cs.strip(), "en": en.strip(), }
def _parse_hindencorp(path): with open(path, encoding="utf-8") as f: for line_id, line in enumerate(f): split_line = line.split("\t") if len(split_line) != 5: logger.warning("Skipping invalid HindEnCorp line: %s", line) continue yield line_id, {"translation": {"en": split_line[3].strip(), "hi": split_line[4].strip()}}README.md+80-31
cs-en/test-00000-of-00001.parquetAdded+3
cs-en/train-00000-of-00001.parquetAdded+3
cs-en/validation-00000-of-00001.parquetAdded+3
de-en/test-00000-of-00001.parquetAdded+3
de-en/train-00000-of-00003.parquetAdded+3
de-en/train-00001-of-00003.parquetAdded+3
de-en/train-00002-of-00003.parquetAdded+3
de-en/validation-00000-of-00001.parquetAdded+3
fi-en/test-00000-of-00001.parquetAdded+3
fi-en/train-00000-of-00002.parquetAdded+3
fi-en/train-00001-of-00002.parquetAdded+3
fi-en/validation-00000-of-00001.parquetAdded+3
ro-en/test-00000-of-00001.parquetAdded+3
ro-en/train-00000-of-00001.parquetAdded+3
ro-en/validation-00000-of-00001.parquetAdded+3
ru-en/test-00000-of-00001.parquetAdded+3
ru-en/train-00000-of-00001.parquetAdded+3
ru-en/validation-00000-of-00001.parquetAdded+3
tr-en/test-00000-of-00001.parquetAdded+3
tr-en/train-00000-of-00001.parquetAdded+3
tr-en/validation-00000-of-00001.parquetAdded+3
wmt16.pyDeleted-72
wmt_utils.pyDeleted-1025