|
|
|
"""dataset.ipynb |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1sNXmgV-J4w6JSdtXK-0TckTP5SFkGPtz |
|
|
|
###Create a file.py |
|
""" |
|
|
|
import datasets |
|
import csv |
|
import pandas as pd |
|
|
|
_URLS = { |
|
"zh-en": { |
|
"TRAIN_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=1bGzmCXre__7mY7DhGFTWH2tJS4ZtTm5L&export=download", |
|
"VALIDATION_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=15xUzB1fj2U7eWDZIjEUWkgVKjv14r43_&export=download", |
|
"TEST_DOWNLOAD_URL": "https://drive.google.com/u/0/uc?id=18r8dCsLazDyliRoEDtbt3aOcPh8d_baJ&export=download" |
|
} |
|
} |
|
|
|
class NewDataset(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name = "zh-en", |
|
version = VERSION, |
|
description = "The translation dataset between Traditional Chinese and English" |
|
) |
|
] |
|
|
|
def _info(self): |
|
|
|
if self.config.name == "zh-en": |
|
features = datasets.Features( |
|
{ "translation": datasets.features.Translation( languages=["en", "zh"] ) } |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
|
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
|
|
|
|
|
|
|
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
""" Returns SplitGenerators""" |
|
|
|
my_urls = _URLS[self.config.name] |
|
|
|
train_path = dl_manager.download_and_extract(my_urls["TRAIN_DOWNLOAD_URL"]) |
|
validation_path = dl_manager.download_and_extract(my_urls["VALIDATION_DOWNLOAD_URL"]) |
|
test_path = dl_manager.download_and_extract(my_urls["TEST_DOWNLOAD_URL"]) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs = { "filepath" : train_path, "split" : "train" } |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs = { "filepath" : validation_path, "split" : "validation" } |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs = { "filepath" : test_path, "split" : "test"}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
""" Generate Dravidian MT examples""" |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f) |
|
for idx, row in enumerate(reader): |
|
|
|
if self.config.name == "zh-en": |
|
result = { "translation" : { "en" : row["en"], "zh" : row["zh"] } } |
|
|
|
yield idx, result |