sat / sat.py
albertvillanova's picture
Add dataset loading script
e7277de verified
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""SAT dataset."""
import json
import datasets
# TODO
_CITATION = """\
"""
_DESCRIPTION = """\
SAT (Style Augmented Translation) dataset contains roughly 3.3 million English-Vietnamese pairs of texts.
"""
_HOMEPAGE = "https://github.com/vietai/sat"
# TODO
_LICENSE = "Unknown"
_URL = {
"train": "https://storage.googleapis.com/vietai_public/best_vi_translation/v1/train.en-vi.json",
"test": "https://storage.googleapis.com/vietai_public/best_vi_translation/v1/test.en-vi.json",
}
class Sat(datasets.GeneratorBasedBuilder):
"""SAT dataset."""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({"translation": datasets.features.Translation(languages=["en", "vi"])}),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_path = dl_manager.download(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_path": data_path["train"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"data_path": data_path["test"],
},
),
]
def _generate_examples(self, data_path):
with open(data_path, encoding="utf-8") as f:
for key, line in enumerate(f):
yield key, json.loads(line)