Datasets:

Languages:
English
Multilinguality:
monolingual
Size Categories:
1K<n<10K
Language Creators:
expert-generated
Annotations Creators:
expert-generated
Source Datasets:
original
ArXiv:
Tags:
License:
File size: 16,054 Bytes
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
 
 
 
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
 
 
 
 
 
6515582
aac70a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
6515582
 
 
 
aac70a7
6515582
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
6515582
 
aac70a7
 
 
 
 
 
6515582
aac70a7
 
6515582
 
 
08aa36f
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
6515582
aac70a7
6515582
 
 
 
 
 
 
 
 
 
aac70a7
 
 
6515582
aac70a7
6515582
 
 
 
 
 
 
 
 
 
 
 
aac70a7
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
 
 
 
 
 
 
 
 
 
 
 
 
 
6515582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aac70a7
6515582
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""WinoBias: Winograd-schema dataset for detecting gender bias"""


import collections

import datasets


_CITATION = """\
@article{DBLP:journals/corr/abs-1804-06876,
  author    = {Jieyu Zhao and
               Tianlu Wang and
               Mark Yatskar and
               Vicente Ordonez and
               Kai{-}Wei Chang},
  title     = {Gender Bias in Coreference Resolution: Evaluation and Debiasing Methods},
  journal   = {CoRR},
  volume    = {abs/1804.06876},
  year      = {2018},
  url       = {http://arxiv.org/abs/1804.06876},
  archivePrefix = {arXiv},
  eprint    = {1804.06876},
  timestamp = {Mon, 13 Aug 2018 16:47:01 +0200},
  biburl    = {https://dblp.org/rec/journals/corr/abs-1804-06876.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
"""

_DESCRIPTION = """\
WinoBias, a Winograd-schema dataset for coreference resolution focused on gender bias.
The corpus contains Winograd-schema style sentences with entities corresponding to people
referred by their occupation (e.g. the nurse, the doctor, the carpenter).
"""

_HOMEPAGE = "https://uclanlp.github.io/corefBias/overview"

_LICENSE = "MIT License (https://github.com/uclanlp/corefBias/blob/master/LICENSE)"

_URL = "https://raw.githubusercontent.com/uclanlp/corefBias/master/WinoBias/wino/data/conll_format"


class WinoBiasConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super(WinoBiasConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)


class WinoBias(datasets.GeneratorBasedBuilder):
    """WinoBias: Winograd-schema dataset for detecting gender bias"""

    # This is an example of a dataset with multiple configurations.
    # If you don't want/need to define several sub-sets in your dataset,
    # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

    # If you need to make complex sub-parts in the datasets with configurable options
    # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
    # BUILDER_CONFIG_CLASS = MyBuilderConfig

    # You will be able to load one or the other configurations in the following list with
    # data = datasets.load_dataset('my_dataset', 'first_domain')
    # data = datasets.load_dataset('my_dataset', 'second_domain')
    def __init__(self, *args, writer_batch_size=None, **kwargs):
        super(WinoBias, self).__init__(*args, **kwargs)
        # Batch size used by the ArrowWriter
        # It defines the number of samples that are kept in memory before writing them
        # and also the length of the arrow chunks
        # None means that the ArrowWriter will use its default value
        self._writer_batch_size = writer_batch_size or 100

    BUILDER_CONFIGS = [
        WinoBiasConfig(
            name="type1_pro",
            description="winoBias type1_pro_stereotype data in cornll format",
        ),
        WinoBiasConfig(
            name="type1_anti",
            description="winoBias type1_anti_stereotype data in cornll format",
        ),
        WinoBiasConfig(
            name="type2_pro",
            description="winoBias type2_pro_stereotype data in cornll format",
        ),
        WinoBiasConfig(
            name="type2_anti",
            description="winoBias type2_anti_stereotype data in cornll format",
        ),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            # Info about features for this: http://cemantix.org/data/ontonotes.html
            features=datasets.Features(
                {
                    "document_id": datasets.Value("string"),
                    "part_number": datasets.Value("string"),
                    "word_number": datasets.Sequence(datasets.Value("int32")),
                    "tokens": datasets.Sequence(datasets.Value("string")),
                    "pos_tags": datasets.Sequence(
                        datasets.features.ClassLabel(
                            names=[
                                '"',
                                "''",
                                "#",
                                "$",
                                "(",
                                ")",
                                ",",
                                ".",
                                ":",
                                "``",
                                "CC",
                                "CD",
                                "DT",
                                "EX",
                                "FW",
                                "IN",
                                "JJ",
                                "JJR",
                                "JJS",
                                "LS",
                                "MD",
                                "NN",
                                "NNP",
                                "NNPS",
                                "NNS",
                                "NN|SYM",
                                "PDT",
                                "POS",
                                "PRP",
                                "PRP$",
                                "RB",
                                "RBR",
                                "RBS",
                                "RP",
                                "SYM",
                                "TO",
                                "UH",
                                "VB",
                                "VBD",
                                "VBG",
                                "VBN",
                                "VBP",
                                "VBZ",
                                "WDT",
                                "WP",
                                "WP$",
                                "WRB",
                                "HYPH",
                                "XX",
                                "NFP",
                                "AFX",
                                "ADD",
                                "-LRB-",
                                "-RRB-",
                                "-",
                            ]
                        )
                    ),
                    "parse_bit": datasets.Sequence(datasets.Value("string")),
                    "predicate_lemma": datasets.Sequence(datasets.Value("string")),
                    "predicate_framenet_id": datasets.Sequence(datasets.Value("string")),
                    "word_sense": datasets.Sequence(datasets.Value("string")),
                    "speaker": datasets.Sequence(datasets.Value("string")),
                    "ner_tags": datasets.Sequence(
                        datasets.features.ClassLabel(
                            names=[
                                "B-PERSON",
                                "I-PERSON",
                                "B-NORP",
                                "I-NORP",
                                "B-FAC",
                                "I-FAC",
                                "B-ORG",
                                "I-ORG",
                                "B-GPE",
                                "I-GPE",
                                "B-LOC",
                                "I-LOC",
                                "B-PRODUCT",
                                "I-PRODUCT",
                                "B-EVENT",
                                "I-EVENT",
                                "B-WORK_OF_ART",
                                "I-WORK_OF_ART",
                                "B-LAW",
                                "I-LAW",
                                "B-LANGUAGE",
                                "I-LANGUAGE",
                                "B-DATE",
                                "I-DATE",
                                "B-TIME",
                                "I-TIME",
                                "B-PERCENT",
                                "I-PERCENT",
                                "B-MONEY",
                                "I-MONEY",
                                "B-QUANTITY",
                                "I-QUANTITY",
                                "B-ORDINAL",
                                "I-ORDINAL",
                                "B-CARDINAL",
                                "I-CARDINAL",
                                "*",
                                "0",
                                "-",
                            ]
                        )
                    ),
                    "verbal_predicates": datasets.Sequence(datasets.Value("string")),
                    "coreference_clusters": datasets.Sequence(datasets.Value("string")),
                }
            ),
            supervised_keys=None,
            # Homepage of the dataset for documentation
            homepage=_HOMEPAGE,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""

        dev_data_dir = dl_manager.download(_URL + "/dev_" + self.config.name + "_stereotype.v4_auto_conll")
        test_data_dir = dl_manager.download(_URL + "/test_" + self.config.name + "_stereotype.v4_auto_conll")
        return [
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"filepath": dev_data_dir},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"filepath": test_data_dir},
            ),
        ]

    def _generate_examples(self, filepath):
        """Yields examples."""
        with open(filepath, encoding="utf-8") as f:
            id_ = 0
            document_id = None
            part_number = 0
            word_num = []
            tokens = []
            pos_tags = []
            parse_bit = []
            predicate_lemma = []
            predicate_framenet_id = []
            word_sense = []
            speaker = []
            ner_tags = []
            ner_start = False
            verbal_predicates = []
            coreference = []
            clusters = collections.defaultdict(list)
            coref_stacks = collections.defaultdict(list)
            for line in f:
                if line.startswith("#begin") or line.startswith("#end"):
                    continue
                elif not line.strip():
                    id_ += 1
                    yield str(id_), {
                        "document_id": document_id,
                        "part_number": part_number,
                        "word_number": word_num,
                        "tokens": tokens,
                        "pos_tags": pos_tags,
                        "parse_bit": parse_bit,
                        "predicate_lemma": predicate_lemma,
                        "predicate_framenet_id": predicate_framenet_id,
                        "word_sense": word_sense,
                        "speaker": speaker,
                        "ner_tags": ner_tags,
                        "verbal_predicates": verbal_predicates,
                        "coreference_clusters": sum(
                            clusters[1], []
                        ),  # flatten the list as writing the exmaples needs an array.
                    }

                    word_num = []
                    tokens = []
                    pos_tags = []
                    parse_bit = []
                    predicate_lemma = []
                    predicate_framenet_id = []
                    word_sense = []
                    speaker = []
                    ner_tags = []
                    verbal_predicates = []
                    coreference = []
                    clusters = collections.defaultdict(list)
                    coref_stacks = collections.defaultdict(list)
                else:
                    splits = [s for s in line.split() if s]
                    if len(splits) > 7:
                        document_id = splits[0]
                        part_number = splits[1]
                        word_num.append(splits[2])
                        tokens.append(splits[3])
                        pos_tags.append(splits[4])
                        parse_bit.append(splits[5])
                        predicate_lemma.append(splits[6])
                        predicate_framenet_id.append(splits[7])
                        word_sense.append(splits[8])
                        speaker.append(splits[9])
                        ner_word = splits[10]
                        coreference = splits[-1]
                        if ")" in ner_word and ner_start:
                            ner_start = False
                            ner_word = "0"
                        if "(" in ner_word:
                            ner_start = True
                            ner_word = ner_word.strip(" ").replace("(", "B-").replace("*", "").replace(")", "")
                            start_word = ner_word.strip(" ").replace("B-", "")
                        if ner_start:
                            if ner_word.strip(" ") == "*":
                                ner_word = "I-" + start_word
                        ner_tags.append(ner_word)
                        word_is_verbal_predicate = any(["(V" in x for x in splits[11:-1]])
                        if word_is_verbal_predicate:
                            verbal_predicates.append(splits[3])
                        if coreference != "-":
                            for segment in coreference.split("|"):
                                if segment[0] == "(":
                                    if segment[-1] == ")":
                                        cluster_id = int(segment[1:-1])
                                        clusters[cluster_id].append([splits[2], splits[2]])
                                    else:
                                        cluster_id = int(segment[1:])
                                        coref_stacks[cluster_id].append(splits[2])
                                else:
                                    cluster_id = int(segment[:-1])
                                    start = coref_stacks[cluster_id].pop()
                                    clusters[cluster_id].append([start, splits[2]])

            if tokens:
                # add the last one
                id_ += 1
                yield str(id_), {
                    "document_id": document_id,
                    "part_number": part_number,
                    "word_number": word_num,
                    "tokens": tokens,
                    "pos_tags": pos_tags,
                    "parse_bit": parse_bit,
                    "predicate_lemma": predicate_lemma,
                    "predicate_framenet_id": predicate_framenet_id,
                    "word_sense": word_sense,
                    "speaker": speaker,
                    "ner_tags": ner_tags,
                    "verbal_predicates": verbal_predicates,
                    "coreference_clusters": sum(clusters[1], []),
                }