# 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. """Dataset loading script for QQQ Historical Data Max. By Eu Jin Marcus Yatim""" import json import os import datasets _DESCRIPTION = """\ This dataset contains the specially modified QQQ Historical Data Max to act as A translation task. """ _HOMEPAGE = "https://huggingface.co/datasets/marcusy/qqq" _LICENSE = "mit" _URL = "https://huggingface.co/datasets/marcusy/qqq/raw/main/" _URLS = { "train": _URL + "train.jsonl", "dev": _URL + "dev.jsonl", } class QQQDataset(datasets.GeneratorBasedBuilder): """The dataset for QQQ.""" VERSION = datasets.Version("1.1.0") def _info(self): return datasets.DatasetInfo( # This is the description that will appear on the datasets page. description=_DESCRIPTION, # This defines the different columns of the dataset and their types features=datasets.Features( { "translation": datasets.features.Translation( languages=("query", "output") ) } ), # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and # specify them. They'll be used if as_supervised=True in builder.as_dataset. supervised_keys=None, # Homepage of the dataset for documentation homepage=_HOMEPAGE, # License for the dataset if available license=_LICENSE, ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download_and_extract(_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(downloaded_files["train"]), "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(downloaded_files["dev"]), "split": "dev", }, ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, filepath, split): # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. with open(filepath, encoding="utf-8") as f: for key, row in enumerate(f): data = json.loads(row) yield key, { "translation": data["translation"], }