from __future__ import absolute_import, division, print_function import logging import datasets _CITATION = """ MiniNLP Data """ _DESCRIPTION = """ MiniNLP Data """ _URLS = { "train": "train.tsv", "dev": "dev.tsv", "test": "test.tsv", } class MiniNLPConfig(datasets.BuilderConfig): def __init__(self, **kwargs): """ Args: **kwargs: keyword arguments forwarded to super. """ super().__init__(**kwargs) class MiniNLP(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ MiniNLPConfig( name="MiniNLP", version=datasets.Version("1.0.0", ""), description="MiniNLP Dataset For Models", ), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("int32"), "num": datasets.Value("int32"), "query": datasets.Value("string"), "doc": datasets.Value("string"), "label": datasets.Value("string"), "score": datasets.Value("float32"), } ), # No default supervised_keys (as we have to pass both question # and context as input). supervised_keys=None, homepage="https://fuliucansheng.github.io/", citation=_CITATION, ) def _split_generators(self, dl_manager): downloaded_files = dl_manager.download_and_extract(_URLS) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}, ), ] def _generate_examples(self, filepath): """This function returns the examples in the raw (text) form.""" logging.info("generating examples from = %s", filepath) names = ["num", "query", "doc", "label", "score"] with open(filepath, encoding="utf-8") as f: for id_, line in enumerate(f): values = line.strip("\n").split("\t") row_dict = dict(zip(names, values)) yield id_, { "id": id_, "num": int(row_dict.get("num")), "query": row_dict.get("query"), "doc": row_dict.get("doc"), "label": row_dict.get("label"), "score": float(row_dict.get("score")), }