File size: 4,022 Bytes
53d011d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2df3320
53d011d
 
 
 
 
 
 
 
 
 
 
 
d3d716b
 
 
 
 
53d011d
 
 
 
 
 
 
 
 
 
d3d716b
53d011d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3d716b
 
 
 
 
 
 
53d011d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3d716b
 
53d011d
 
d3d716b
 
 
 
 
53d011d
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from typing import Dict

import datasets as ds
import pandas as pd

_CITATION = """\
@inproceedings{,
    author = "小谷通隆 and 柴田知秀 and 中田貴之 and 黒橋禎夫",
    title = "日本語Textual Entailmentのデータ構築と自動獲得した類義表現に基づく推論関係の認識",
    booktitle = "言語処理学会第14回年次大会",
    year = "2008",
    url = "https://nlp.ist.i.kyoto-u.ac.jp/?Textual+Entailment+%E8%A9%95%E4%BE%A1%E3%83%87%E3%83%BC%E3%82%BF",
    pages = "1140-1143"
}
"""

_DESCRIPTION = """\

"""

_HOMEPAGE = "https://nlp.ist.i.kyoto-u.ac.jp/?Textual+Entailment+%E8%A9%95%E4%BE%A1%E3%83%87%E3%83%BC%E3%82%BF"

_LICENSE = "unknown"

_URL = "http://nlp.ist.i.kyoto-u.ac.jp/DLcounter/lime.cgi?down=http://nlp.ist.i.kyoto-u.ac.jp/nl-resource/rte/entail_evaluation_set.txt&name=entail_evaluation_set.txt"


class KUTEDataset(ds.GeneratorBasedBuilder):
    VERSION = ds.Version("1.0.0")
    DEFAULT_CONFIG_NAME = "3way"

    BUILDER_CONFIGS = [
        ds.BuilderConfig(
            name="original",
            version=VERSION,
            description="hoge",
        ),
        ds.BuilderConfig(
            name="3way",
            version=VERSION,
            description="fuga",
        ),
        ds.BuilderConfig(
            name="3way-strict",
            version=VERSION,
            description="fuga",
        ),
        ds.BuilderConfig(
            name="2way",
            version=VERSION,
            description="fuga",
        ),
    ]

    def _info(self) -> ds.DatasetInfo:
        if self.config.name == "original":
            labels = ds.ClassLabel(names=["◎", "○", "△", "×"])
        elif self.config.name in ["3way", "3way-strict"]:
            labels = ds.ClassLabel(names=["entailment", "neutral", "contradiction"])
        elif self.config.name == "2way":
            labels = ds.ClassLabel(names=["entailment", "non-entailment"])

        features = ds.Features(
            {
                "id": ds.Value("int32"),
                "premise": ds.Value("string"),
                "hypothesis": ds.Value("string"),
                "label": labels,
                "category_subcategory": ds.Value("string"),
            }
        )
        return ds.DatasetInfo(
            description=_DESCRIPTION,
            citation=_CITATION,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            features=features,
        )

    def _split_generators(self, dl_manager: ds.DownloadManager):
        data_path = dl_manager.download_and_extract(_URL)
        df: pd.DataFrame = pd.read_table(data_path, sep=" ", header=None)
        df.columns = ["id", "category_subcategory", "label", "premise", "hypothesis"]

        if self.config.name == "original":
            mapping = None
        elif self.config.name == "3way":
            mapping = {
                "◎": "entailment",
                "○": "entailment",
                "△": "neutral",
                "×": "contradiction",
            }
        elif self.config.name == "3way-strict":
            mapping = {
                "◎": "entailment",
                "○": None,
                "△": "neutral",
                "×": "contradiction",
            }
        elif self.config.name == "2way":
            mapping = {
                "◎": "entailment",
                "○": "entailment",
                "△": "non-entailment",
                "×": "non-entailment",
            }

        return [
            ds.SplitGenerator(
                name=ds.Split.TEST,
                gen_kwargs={"df": df, "mapping": mapping},
            ),
        ]

    def _generate_examples(self, df: pd.DataFrame, mapping: Dict[str, str] = None):
        data = []
        for row in df.to_dict("records"):
            if mapping is not None:
                row["label"] = mapping[row["label"]]
            if row["label"] is None:
                continue
            data.append(row)

        for i, row in enumerate(data):
            yield i, row