Datasets:
Convert dataset to Parquet
#8
by albertvillanova HF Staff - opened
This view is limited to 50 files because it contains too many changes. See the raw diff here.
Files changed (50)
- README.md+67-26
- 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
- fr-en/test-00000-of-00001.parquetAdded+3
- fr-en/train-00000-of-00030.parquetAdded+3
- fr-en/train-00001-of-00030.parquetAdded+3
- fr-en/train-00002-of-00030.parquetAdded+3
- fr-en/train-00003-of-00030.parquetAdded+3
- fr-en/train-00004-of-00030.parquetAdded+3
- fr-en/train-00005-of-00030.parquetAdded+3
- fr-en/train-00006-of-00030.parquetAdded+3
- fr-en/train-00007-of-00030.parquetAdded+3
- fr-en/train-00008-of-00030.parquetAdded+3
- fr-en/train-00009-of-00030.parquetAdded+3
- fr-en/train-00010-of-00030.parquetAdded+3
- fr-en/train-00011-of-00030.parquetAdded+3
- fr-en/train-00012-of-00030.parquetAdded+3
- fr-en/train-00013-of-00030.parquetAdded+3
- fr-en/train-00014-of-00030.parquetAdded+3
- fr-en/train-00015-of-00030.parquetAdded+3
- fr-en/train-00016-of-00030.parquetAdded+3
- fr-en/train-00017-of-00030.parquetAdded+3
- fr-en/train-00018-of-00030.parquetAdded+3
- fr-en/train-00019-of-00030.parquetAdded+3
- fr-en/train-00020-of-00030.parquetAdded+3
- fr-en/train-00021-of-00030.parquetAdded+3
- fr-en/train-00022-of-00030.parquetAdded+3
- fr-en/train-00023-of-00030.parquetAdded+3
- fr-en/train-00024-of-00030.parquetAdded+3
- fr-en/train-00025-of-00030.parquetAdded+3
- fr-en/train-00026-of-00030.parquetAdded+3
- fr-en/train-00027-of-00030.parquetAdded+3
- fr-en/train-00028-of-00030.parquetAdded+3
- fr-en/train-00029-of-00030.parquetAdded+3
- fr-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
- wmt15.pyDeleted-78
- wmt_utils.pyDeleted-1025
23 unmodified lines24252627282930315 unmodified lines373839404142434445464748495051524 unmodified lines575859606162636465666768697071724 unmodified lines777879808182838485868788899091924 unmodified lines9798991001011021031041051061071081091101111124 unmodified lines11711811912012112212312412512612712812913013113223 unmodified linestask_categories:- translationtask_ids: []pretty_name: WMT15paperswithcode_id: wmt-2015dataset_info:- config_name: cs-enfeatures:5 unmodified lines- ensplits:- name: trainnum_bytes: 282996942num_examples: 959768- name: validationnum_bytes: 757817num_examples: 3003- name: testnum_bytes: 572203num_examples: 2656download_size: 1740666258dataset_size: 284326962- config_name: de-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 1364002869num_examples: 4522998- name: validationnum_bytes: 777334num_examples: 3003- name: testnum_bytes: 522989num_examples: 2169download_size: 1740666258dataset_size: 1365303192- config_name: fi-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 605146817num_examples: 2073394- name: validationnum_bytes: 363941num_examples: 1500- name: testnum_bytes: 306335num_examples: 1370download_size: 273390220dataset_size: 605817093- config_name: fr-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 14758986622num_examples: 40853137- name: validationnum_bytes: 1138737num_examples: 4503- name: testnum_bytes: 298771num_examples: 1500download_size: 6702781608dataset_size: 14760424130- config_name: ru-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 437752256num_examples: 1495081- name: validationnum_bytes: 1087746num_examples: 3003- name: testnum_bytes: 955972num_examples: 2818download_size: 1092059435dataset_size: 439795974---# Dataset Card for "wmt15"23 unmodified lines24252627282930315 unmodified lines373839404142434445464748495051524 unmodified lines575859606162636465666768697071724 unmodified lines777879808182838485868788899091924 unmodified lines9798991001011021031041051061071081091101111124 unmodified lines11711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217323 unmodified linestask_categories:- translationtask_ids: []paperswithcode_id: wmt-2015pretty_name: WMT15dataset_info:- config_name: cs-enfeatures:5 unmodified lines- ensplits:- name: trainnum_bytes: 282996174num_examples: 959768- name: validationnum_bytes: 757809num_examples: 3003- name: testnum_bytes: 572195num_examples: 2656download_size: 170092459dataset_size: 284326178- config_name: de-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 1363999245num_examples: 4522998- name: validationnum_bytes: 777326num_examples: 3003- name: testnum_bytes: 522981num_examples: 2169download_size: 821722473dataset_size: 1365299552- config_name: fi-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 605145153num_examples: 2073394- name: validationnum_bytes: 363933num_examples: 1500- name: testnum_bytes: 306327num_examples: 1370download_size: 347635272dataset_size: 605815413- config_name: fr-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 14758953934num_examples: 40853137- name: validationnum_bytes: 1138729num_examples: 4503- name: testnum_bytes: 298763num_examples: 1500download_size: 7781794388dataset_size: 14760391426- config_name: ru-enfeatures:- name: translation4 unmodified lines- ensplits:- name: trainnum_bytes: 437751056num_examples: 1495081- name: validationnum_bytes: 1087738num_examples: 3003- name: testnum_bytes: 955964num_examples: 2818download_size: 225905330dataset_size: 439794758configs:- 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: fr-endata_files:- split: trainpath: fr-en/train-*- split: validationpath: fr-en/validation-*- split: testpath: fr-en/test-*- config_name: ru-endata_files:- split: trainpath: ru-en/train-*- split: validationpath: ru-en/validation-*- split: testpath: ru-en/test-*---# Dataset Card for "wmt15"
123version https://git-lfs.github.com/spec/v1oid sha256:e5f3e29f5b49bc5c896e8fa9653a52cf2ad2b6b95d8b45dab793f8f15d06817asize 390311123version https://git-lfs.github.com/spec/v1oid sha256:8a36d1241bff8ad101f4d95c9e91e071d3d8e871c094b47cc65fae9230c7f554size 169195558123version https://git-lfs.github.com/spec/v1oid sha256:864967b2cb62dc7479aaa77d2a9acca602535af67a784b6779cea10b5cda0f72size 506590123version https://git-lfs.github.com/spec/v1oid sha256:dca6c5c1a432f7064665323555352e809b5c7e2ed620e61bbb6a27dcf2c9235esize 342691123version https://git-lfs.github.com/spec/v1oid sha256:e02f983e4da29b3f3146fce12efc4ce38b18cdde030a2469d48076d2de1bf678size 280410311123version https://git-lfs.github.com/spec/v1oid sha256:0d23f2a62ad56e80a830dc32b066aec9c69e7a8e494aa45b44600dd8a2ec12eesize 265799597123version https://git-lfs.github.com/spec/v1oid sha256:f78adeb0916b3eb857628d91b1c8e5100c5d7f55f0f9bebb16bdfd2994a70335size 274661121123version https://git-lfs.github.com/spec/v1oid sha256:a3baab716f14f8abfa63e54995e31f035bb78b20c7943de72f3e1110b7ff35bbsize 508753123version https://git-lfs.github.com/spec/v1oid sha256:2693bb05ad4d1c2739486a29a380696c88d8495eb6b55e7e7cacf96050cb0c1asize 203326123version 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:58d98b5d12c441a22d1f578014ebf21a6a8211a8760a8fe5dfe3207083ab8ef0size 233283123version https://git-lfs.github.com/spec/v1oid sha256:f828cbeb4629c394a78f7c08432a9624933c7437153f201cc05f441dc9d90390size 203322123version https://git-lfs.github.com/spec/v1oid sha256:29e6481a32def5da9b186de10e821a40f7e721b21da46fc6ba2a11737fe651ecsize 252521036123version https://git-lfs.github.com/spec/v1oid sha256:2945eecc27ed30a6d7a54fe6ecad3f6655fe0c4b56eca556012322f5f1ed144dsize 241043119123version https://git-lfs.github.com/spec/v1oid sha256:e5edaa2f4b41fc07342f198f6b84c3b0057af8fcb0faa7c72df19591a72448cdsize 243412633123version https://git-lfs.github.com/spec/v1oid sha256:6e353a54caae6426e63974d4cb948a36f087913da4e697f44a2904522dcb509dsize 247531966123version https://git-lfs.github.com/spec/v1oid sha256:f301322a64b0ba7fbb3c96d4de9889fc78c86efbc72f28d403bc48a742829e28size 241921185123version https://git-lfs.github.com/spec/v1oid sha256:005da64ea5624ea10f72143e67125d62ecf2814c96e308fc7896b78eed7f9d7esize 238610755123version https://git-lfs.github.com/spec/v1oid sha256:62a5f250c6df02b26a9c743351fbb60be272f01b8b461b378a77bdb8058775a8size 239751288123version https://git-lfs.github.com/spec/v1oid sha256:381439ab4fa98dcc3ac828e22e0239293ff6cc2ad745aa6bfc77e4932b0a2f41size 240634183123version https://git-lfs.github.com/spec/v1oid sha256:76809deb0788d8994b9f8c1c073b734cc641fca577c5023e548b92fbc2cbaba4size 242343417123version https://git-lfs.github.com/spec/v1oid sha256:ddfc36ddf68d9116fd8d67ed42bf2f43a337cd14b3ddd836ef8186fff5c7c32fsize 238870804123version https://git-lfs.github.com/spec/v1oid sha256:0215ed76222acac3b698f27a209511079e32e1e001a2aead2fdec40d39d4fee0size 239409582123version https://git-lfs.github.com/spec/v1oid sha256:6c14e2394a158b4578ad8e2be6a0a3ca910814bb41b6b380a310000196d0a19bsize 241468626123version https://git-lfs.github.com/spec/v1oid sha256:a6b43beef09c6f61f204a469ebc147bb5e252fd15f52482aa9684f5e3a7a17cdsize 241578607123version https://git-lfs.github.com/spec/v1oid sha256:2901adb38954d2d556d1870417e03641859d6bc1cf1762b7f393f5d7eeba35fesize 230826629123version https://git-lfs.github.com/spec/v1oid sha256:5951cf870978566d05fef8f9c1c5078e1f6738abbe0e7b41a04b594eb0e37f4esize 214465335123version https://git-lfs.github.com/spec/v1oid sha256:42e4b1cc88d983e51974bbe895be5f5b611e53660884089be6fa4aefb530bca2size 230800328123version https://git-lfs.github.com/spec/v1oid sha256:8e5046598a7c730e6a2da3251be34220cf6c91e3bb91b68fa53cd5025c3fa096size 227040323123version https://git-lfs.github.com/spec/v1oid sha256:0ac5deac642ab5ad5b0e0267d1321c77af9302d5b2d4c9dfcd2b4c76d6430f41size 226344855123version https://git-lfs.github.com/spec/v1oid sha256:b1c4d7d060fe9ec4e818862aec7abb725b77ac3b3cfbca100ae2cbc1d0bfb144size 260764742123version https://git-lfs.github.com/spec/v1oid sha256:67ae577c092ecdbf72eb750f549d502d9912754aa2615ce56e38d66505fd3862size 259089829123version https://git-lfs.github.com/spec/v1oid sha256:a30a96328798616e735399ffa3139c5be7e10cb445ded9897fc8694f73da132bsize 260776257123version https://git-lfs.github.com/spec/v1oid sha256:0eff0a4c1b56b25245ebc3ef9a08e4626e85830b19d7e7b2f02c6b00690d4567size 263760610123version https://git-lfs.github.com/spec/v1oid sha256:3aad438362d326adb99ceb99fb183eaa0e8e5d5643afdbca6cb423bf6684aa93size 267549707123version https://git-lfs.github.com/spec/v1oid sha256:96573de13bc5e6c0296aa25b05b76c957f8922518cb72f1c4d90dca011c3e1c9size 270207182123version https://git-lfs.github.com/spec/v1oid sha256:106a04661814791168b1e5a1bf6ee15f66c9fbe4f130d2ab2a9c1c04fb9eefb3size 274163568123version https://git-lfs.github.com/spec/v1oid sha256:dfde2300df74963f0a40b87dd47f570923c17328e713d8cfa96a5e6d176d2c2csize 277724876123version https://git-lfs.github.com/spec/v1oid sha256:0e902563ceddf13090d3b5c65a54e68aa622b9132922123be83b88c7abe1454fsize 364758089123version https://git-lfs.github.com/spec/v1oid sha256:71bf6b4d6c9af48e97e0136098f53427fe02eda871c82950f4dd3d0d79734866size 321905827123version https://git-lfs.github.com/spec/v1oid sha256:9fce7f570a8b694227524423850df0f7a2a52e9af77fe7d3393fafb6aa05961dsize 370310424123version https://git-lfs.github.com/spec/v1oid sha256:62696dcf29314fa7da58f74a61472fc5644133d4413371326fb90b1ae8cd13a8size 311268338123version https://git-lfs.github.com/spec/v1oid sha256:85478b397e7e17a7dfb0dfa869e365d6a2bc777efa70e2547bcaa841ef13e7bdsize 736946123version https://git-lfs.github.com/spec/v1oid sha256:80bd5e16b06852680fb6670d99e50bbe014a4fb8777722387a7558f775d98bf6size 538000123version https://git-lfs.github.com/spec/v1oid sha256:44a59b7ca7ea1c97aea82153024df7c549ea23d189d76a1e6654ccbb82ff0748size 224759711123version https://git-lfs.github.com/spec/v1oid sha256:fecb7d7b1c42bc162a2b530735dbf1eaa70f8504903426f6d43199019c0af55esize 607619123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778# 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"""WMT15: Translate dataset."""
import datasets
from .wmt_utils import Wmt, WmtConfig
_URL = "http://www.statmt.org/wmt15/translation-task.html"_CITATION = """@InProceedings{bojar-EtAl:2015:WMT, author = {Bojar, Ond\v{r}ej and Chatterjee, Rajen and Federmann, Christian and Haddow, Barry and Huck, Matthias and Hokamp, Chris and Koehn, Philipp and Logacheva, Varvara and Monz, Christof and Negri, Matteo and Post, Matt and Scarton, Carolina and Specia, Lucia and Turchi, Marco}, title = {Findings of the 2015 Workshop on Statistical Machine Translation}, booktitle = {Proceedings of the Tenth Workshop on Statistical Machine Translation}, month = {September}, year = {2015}, address = {Lisbon, Portugal}, publisher = {Association for Computational Linguistics}, pages = {1--46}, url = {http://aclweb.org/anthology/W15-3001}}"""
_LANGUAGE_PAIRS = [(lang, "en") for lang in ["cs", "de", "fi", "fr", "ru"]]
class Wmt15(Wmt): """WMT 15 translation datasets for all {xx, "en"} language pairs."""
BUILDER_CONFIGS = [ WmtConfig( # pylint:disable=g-complex-comprehension description="WMT 2015 %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 manual_download_instructions(self): if self.config.language_pair[1] in ["cs", "hi", "ru"]: return "Please download the data manually as explained. TODO(PVP)"
@property def _subsets(self): return { datasets.Split.TRAIN: [ "europarl_v7", "europarl_v8_16", "commoncrawl", "multiun", "newscommentary_v10", "gigafren", "czeng_10", "yandexcorpus", "wikiheadlines_fi", "wikiheadlines_ru", ], datasets.Split.VALIDATION: ["newsdev2015", "newsdiscussdev2015", "newstest2014"], datasets.Split.TEST: ["newstest2015", "newsdiscusstest2015"], }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("wmt15", "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 gzip 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 gzip 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(f"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+67-26
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
fr-en/test-00000-of-00001.parquetAdded+3
fr-en/train-00000-of-00030.parquetAdded+3
fr-en/train-00001-of-00030.parquetAdded+3
fr-en/train-00002-of-00030.parquetAdded+3
fr-en/train-00003-of-00030.parquetAdded+3
fr-en/train-00004-of-00030.parquetAdded+3
fr-en/train-00005-of-00030.parquetAdded+3
fr-en/train-00006-of-00030.parquetAdded+3
fr-en/train-00007-of-00030.parquetAdded+3
fr-en/train-00008-of-00030.parquetAdded+3
fr-en/train-00009-of-00030.parquetAdded+3
fr-en/train-00010-of-00030.parquetAdded+3
fr-en/train-00011-of-00030.parquetAdded+3
fr-en/train-00012-of-00030.parquetAdded+3
fr-en/train-00013-of-00030.parquetAdded+3
fr-en/train-00014-of-00030.parquetAdded+3
fr-en/train-00015-of-00030.parquetAdded+3
fr-en/train-00016-of-00030.parquetAdded+3
fr-en/train-00017-of-00030.parquetAdded+3
fr-en/train-00018-of-00030.parquetAdded+3
fr-en/train-00019-of-00030.parquetAdded+3
fr-en/train-00020-of-00030.parquetAdded+3
fr-en/train-00021-of-00030.parquetAdded+3
fr-en/train-00022-of-00030.parquetAdded+3
fr-en/train-00023-of-00030.parquetAdded+3
fr-en/train-00024-of-00030.parquetAdded+3
fr-en/train-00025-of-00030.parquetAdded+3
fr-en/train-00026-of-00030.parquetAdded+3
fr-en/train-00027-of-00030.parquetAdded+3
fr-en/train-00028-of-00030.parquetAdded+3
fr-en/train-00029-of-00030.parquetAdded+3
fr-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
wmt15.pyDeleted-78
wmt_utils.pyDeleted-1025