Datasets:

Modalities:
Text
Formats:
parquet
Languages:
English
ArXiv:
Libraries:
Datasets
pandas
License:
File size: 7,140 Bytes
d1591fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6b76b7
d1591fc
 
 
b6b76b7
d1591fc
 
 
7f908d2
d1591fc
b6b76b7
d1591fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6b76b7
d1591fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6b76b7
 
 
d1591fc
 
 
b6b76b7
d1591fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# 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.

# Lint as: python3
"""BLiMP dataset with minimal pairs of grammatical phenomena in English."""


import json

import datasets


_CITATION = """
@article{warstadt2019blimp,
  title={BLiMP: A Benchmark of Linguistic Minimal Pairs for English},
  author={Warstadt, Alex and Parrish, Alicia and Liu, Haokun and Mohananey, Anhad and Peng, Wei, and Wang, Sheng-Fu and Bowman, Samuel R},
  journal={arXiv preprint arXiv:1912.00582},
  year={2019}
}
"""

_DESCRIPTION = """
BLiMP is a challenge set for evaluating what language models (LMs) know about
major grammatical phenomena in English. BLiMP consists of 67 sub-datasets, each
containing 1000 minimal pairs isolating specific contrasts in syntax,
morphology, or semantics. The data is automatically generated according to
expert-crafted grammars.
"""

_PROJECT_URL = "https://github.com/alexwarstadt/blimp/tree/master/"
_DOWNLOAD_URL = "https://raw.githubusercontent.com/alexwarstadt/blimp/master/"


class BlimpConfig(datasets.BuilderConfig):
    """BuilderConfig for Blimp."""

    def __init__(self, name, version=datasets.Version("0.1.0"), **kwargs):
        """BuilderConfig for Blimp.

        Args:
          name (str): UID of the linguistic paradigm
          **kwargs: keyword arguments forwarded to super.
        """
        description = _DESCRIPTION
        description += f"This configuration includes the paradigm {name}."

        super().__init__(name=name, description=description, version=version, **kwargs)


class Blimp(datasets.GeneratorBasedBuilder):
    """Minimal grammatical and ungrammatical pairs of 67 linguistic paradigms."""

    all_paradigms = [
        "adjunct_island",
        "anaphor_gender_agreement",
        "anaphor_number_agreement",
        "animate_subject_passive",
        "animate_subject_trans",
        "causative",
        "complex_NP_island",
        "coordinate_structure_constraint_complex_left_branch",
        "coordinate_structure_constraint_object_extraction",
        "determiner_noun_agreement_1",
        "determiner_noun_agreement_2",
        "determiner_noun_agreement_irregular_1",
        "determiner_noun_agreement_irregular_2",
        "determiner_noun_agreement_with_adj_2",
        "determiner_noun_agreement_with_adj_irregular_1",
        "determiner_noun_agreement_with_adj_irregular_2",
        "determiner_noun_agreement_with_adjective_1",
        "distractor_agreement_relational_noun",
        "distractor_agreement_relative_clause",
        "drop_argument",
        "ellipsis_n_bar_1",
        "ellipsis_n_bar_2",
        "existential_there_object_raising",
        "existential_there_quantifiers_1",
        "existential_there_quantifiers_2",
        "existential_there_subject_raising",
        "expletive_it_object_raising",
        "inchoative",
        "intransitive",
        "irregular_past_participle_adjectives",
        "irregular_past_participle_verbs",
        "irregular_plural_subject_verb_agreement_1",
        "irregular_plural_subject_verb_agreement_2",
        "left_branch_island_echo_question",
        "left_branch_island_simple_question",
        "matrix_question_npi_licensor_present",
        "npi_present_1",
        "npi_present_2",
        "only_npi_licensor_present",
        "only_npi_scope",
        "passive_1",
        "passive_2",
        "principle_A_c_command",
        "principle_A_case_1",
        "principle_A_case_2",
        "principle_A_domain_1",
        "principle_A_domain_2",
        "principle_A_domain_3",
        "principle_A_reconstruction",
        "regular_plural_subject_verb_agreement_1",
        "regular_plural_subject_verb_agreement_2",
        "sentential_negation_npi_licensor_present",
        "sentential_negation_npi_scope",
        "sentential_subject_island",
        "superlative_quantifiers_1",
        "superlative_quantifiers_2",
        "tough_vs_raising_1",
        "tough_vs_raising_2",
        "transitive",
        "wh_island",
        "wh_questions_object_gap",
        "wh_questions_subject_gap",
        "wh_questions_subject_gap_long_distance",
        "wh_vs_that_no_gap",
        "wh_vs_that_no_gap_long_distance",
        "wh_vs_that_with_gap",
        "wh_vs_that_with_gap_long_distance",
    ]

    BUILDER_CONFIGS = [BlimpConfig(paradigm) for paradigm in all_paradigms]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "sentence_good": datasets.Value("string"),
                    "sentence_bad": datasets.Value("string"),
                    "field": datasets.Value("string"),
                    "linguistics_term": datasets.Value("string"),
                    "UID": datasets.Value("string"),
                    "simple_LM_method": datasets.Value("bool"),
                    "one_prefix_method": datasets.Value("bool"),
                    "two_prefix_method": datasets.Value("bool"),
                    "lexically_identical": datasets.Value("bool"),
                    "pair_id": datasets.Value("int32"),
                }
            ),
            homepage=_PROJECT_URL,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        download_urls = _DOWNLOAD_URL + f"data/{self.config.name}.jsonl"
        downloaded_file = dl_manager.download_and_extract(download_urls)
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file})]

    def _generate_examples(self, filepath):
        """Yields examples."""
        with open(filepath, "r", encoding="utf-8") as f:
            for line in f:
                line_dict = json.loads(line)
                id_ = line_dict["UID"] + "_" + line_dict["pairID"]
                feats = {
                    "sentence_good": line_dict["sentence_good"],
                    "sentence_bad": line_dict["sentence_bad"],
                    "field": line_dict["field"],
                    "linguistics_term": line_dict["linguistics_term"],
                    "UID": line_dict["UID"],
                    "simple_LM_method": line_dict["simple_LM_method"],
                    "one_prefix_method": line_dict["one_prefix_method"],
                    "two_prefix_method": line_dict["two_prefix_method"],
                    "lexically_identical": line_dict["lexically_identical"],
                    "pair_id": int(line_dict["pairID"]),
                }
                yield id_, feats