File size: 4,784 Bytes
cfb895b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
128
129
130
131
132
133
134
135
136
137
138
import datasets as ds
import pandas as pd

_CITATION = """\
@article{yanaka-mineshima-2022-compositional,
    title = "Compositional Evaluation on {J}apanese Textual Entailment and Similarity",
    author = "Yanaka, Hitomi and Mineshima, Koji",
    journal = "Transactions of the Association for Computational Linguistics",
    volume = "10",
    year = "2022",
    address = "Cambridge, MA",
    publisher = "MIT Press",
    url = "https://aclanthology.org/2022.tacl-1.73",
    doi = "10.1162/tacl_a_00518",
    pages = "1266--1284",
}
"""

_DESCRIPTION = """\

"""

_HOMEPAGE = "https://github.com/verypluming/JSICK"

_LICENSE = "CC BY-SA 4.0"

_URLS = {
    "base": "https://raw.githubusercontent.com/verypluming/JSICK/main/jsick/jsick.tsv",
    "stress": "https://raw.githubusercontent.com/verypluming/JSICK/main/jsick-stress/jsick-stress-all-annotations.tsv",
}


class JSICKDataset(ds.GeneratorBasedBuilder):
    VERSION = ds.Version("1.0.0")
    DEFAULT_CONFIG_NAME = "base"

    BUILDER_CONFIGS = [
        ds.BuilderConfig(
            name="base",
            version=VERSION,
            description="hoge",
        ),
        ds.BuilderConfig(
            name="stress",
            version=VERSION,
            description="fuga",
        ),
    ]

    def _info(self) -> ds.DatasetInfo:
        labels = ds.ClassLabel(names=["entailment", "neutral", "contradiction"])
        if self.config.name == "base":
            features = ds.Features(
                {
                    "pair_ID": ds.Value("int32"),
                    "sentence_A_Ja": ds.Value("string"),
                    "sentence_B_Ja": ds.Value("string"),
                    "entailment_label_Ja": labels,
                    "relatedness_score_Ja": ds.Value("float32"),
                    "sentence_A_En": ds.Value("string"),
                    "sentence_B_En": ds.Value("string"),
                    "entailment_label_En": labels,
                    "relatedness_score_En": ds.Value("float32"),
                    "corr_entailment_labelAB_En": ds.Value("string"),
                    "corr_entailment_labelBA_En": ds.Value("string"),
                    "image_ID": ds.Value("string"),
                    "original_caption": ds.Value("string"),
                    "semtag_short": ds.Value("string"),
                    "semtag_long": ds.Value("string"),
                }
            )

        elif self.config.name == "stress":
            features = ds.Features(
                {
                    "pair_ID": ds.Value("string"),
                    "sentence_A_Ja": ds.Value("string"),
                    "sentence_B_Ja": ds.Value("string"),
                    "entailment_label_Ja": labels,
                    "relatedness_score_Ja": ds.Value("float32"),
                    "sentence_A_Ja_origin": ds.Value("string"),
                    "entailment_label_origin": labels,
                    "relatedness_score_Ja_origin": ds.Value("float32"),
                    "rephrase_type": ds.Value("string"),
                    "case_particles": 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(_URLS[self.config.name])
        df: pd.DataFrame = pd.read_table(data_path, sep="\t", header=0)

        if self.config.name == "base":
            return [
                ds.SplitGenerator(
                    name=ds.Split.TRAIN,
                    gen_kwargs={"df": df[df["data"] == "train"].drop("data", axis=1)},
                ),
                ds.SplitGenerator(
                    name=ds.Split.TEST,
                    gen_kwargs={"df": df[df["data"] == "test"].drop("data", axis=1)},
                ),
            ]

        elif self.config.name == "stress":
            df = df[
                [
                    "pair_ID",
                    "sentence_A_Ja",
                    "sentence_B_Ja",
                    "entailment_label_Ja",
                    "relatedness_score_Ja",
                    "sentence_A_Ja_origin",
                    "entailment_label_origin",
                    "relatedness_score_Ja_origin",
                    "rephrase_type",
                    "case_particles",
                ]
            ]
            return [
                ds.SplitGenerator(
                    name=ds.Split.TEST,
                    gen_kwargs={"df": df},
                ),
            ]

    def _generate_examples(self, df: pd.DataFrame):
        for i, row in enumerate(df.to_dict("records")):
            yield i, row