File size: 2,882 Bytes
fb8e871
 
 
 
 
 
 
defe6dd
fb8e871
 
 
defe6dd
fb8e871
 
 
 
 
 
 
 
 
defe6dd
fb8e871
 
 
 
 
 
 
 
 
defe6dd
fb8e871
 
defe6dd
 
fb8e871
defe6dd
fb8e871
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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")),
                }