Datasets:

Languages:
English
ArXiv:
License:
File size: 7,772 Bytes
506b85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfced60
506b85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfced60
 
 
 
 
 
 
 
506b85f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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.
"""CivilComments WILDS"""


import csv

import datasets


_CITATION = """\
@inproceedings{wilds2021,
    title = {{WILDS}: A Benchmark of in-the-Wild Distribution Shifts},
    author = {Pang Wei Koh and Shiori Sagawa and Henrik Marklund and Sang Michael Xie and Marvin Zhang and
    Akshay Balsubramani and Weihua Hu and Michihiro Yasunaga and Richard Lanas Phillips and Irena Gao and
    Tony Lee and Etienne David and Ian Stavness and Wei Guo and Berton A. Earnshaw and Imran S. Haque and
    Sara Beery and Jure Leskovec and Anshul Kundaje and Emma Pierson and Sergey Levine and Chelsea Finn
    and Percy Liang},
    booktitle = {International Conference on Machine Learning (ICML)},
    year = {2021}
}

@inproceedings{borkan2019nuanced,
    title={Nuanced metrics for measuring unintended bias with real data for text classification},
    author={Borkan, Daniel and Dixon, Lucas and Sorensen, Jeffrey and Thain, Nithum and Vasserman, Lucy},
    booktitle={Companion Proceedings of The 2019 World Wide Web Conference},
    pages={491--500},
    year={2019}
}

@article{DBLP:journals/corr/abs-2211-09110,
  author       = {Percy Liang and
                  Rishi Bommasani and
                  Tony Lee and
                  Dimitris Tsipras and
                  Dilara Soylu and
                  Michihiro Yasunaga and
                  Yian Zhang and
                  Deepak Narayanan and
                  Yuhuai Wu and
                  Ananya Kumar and
                  Benjamin Newman and
                  Binhang Yuan and
                  Bobby Yan and
                  Ce Zhang and
                  Christian Cosgrove and
                  Christopher D. Manning and
                  Christopher R{\'{e}} and
                  Diana Acosta{-}Navas and
                  Drew A. Hudson and
                  Eric Zelikman and
                  Esin Durmus and
                  Faisal Ladhak and
                  Frieda Rong and
                  Hongyu Ren and
                  Huaxiu Yao and
                  Jue Wang and
                  Keshav Santhanam and
                  Laurel J. Orr and
                  Lucia Zheng and
                  Mert Y{\"{u}}ksekg{\"{o}}n{\"{u}}l and
                  Mirac Suzgun and
                  Nathan Kim and
                  Neel Guha and
                  Niladri S. Chatterji and
                  Omar Khattab and
                  Peter Henderson and
                  Qian Huang and
                  Ryan Chi and
                  Sang Michael Xie and
                  Shibani Santurkar and
                  Surya Ganguli and
                  Tatsunori Hashimoto and
                  Thomas Icard and
                  Tianyi Zhang and
                  Vishrav Chaudhary and
                  William Wang and
                  Xuechen Li and
                  Yifan Mai and
                  Yuhui Zhang and
                  Yuta Koreeda},
  title        = {Holistic Evaluation of Language Models},
  journal      = {CoRR},
  volume       = {abs/2211.09110},
  year         = {2022},
  url          = {https://doi.org/10.48550/arXiv.2211.09110},
  doi          = {10.48550/arXiv.2211.09110},
  eprinttype    = {arXiv},
  eprint       = {2211.09110},
  timestamp    = {Wed, 23 Nov 2022 18:03:56 +0100},
  biburl       = {https://dblp.org/rec/journals/corr/abs-2211-09110.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}
"""


_DESCRIPTION = """\
In this dataset, given a textual dialogue i.e. an utterance along with two previous turns of context, the goal was to infer the underlying emotion of the utterance by choosing from four emotion classes - Happy, Sad, Angry and Others.
"""


class CivilCommentsWILDSConfig(datasets.BuilderConfig):
    """BuilderConfig for CivilCommentsWILDS."""

    def __init__(self, name, **kwargs):
        """BuilderConfig for EmoContext.
        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(CivilCommentsWILDSConfig, self).__init__(**kwargs)
        self.name = name


# _URL =  (
#     "https://worksheets.codalab.org/rest/bundles/0x8cd3de0634154aeaad2ee6eb96723c6e/"
#     "contents/blob/all_data_with_identities.csv"
# )


_URL = "all_data_with_identities.csv"


class CivilCommentsWILDS(datasets.GeneratorBasedBuilder):
    """SemEval-2019 Task 3: EmoContext Contextual Emotion Detection in Text. Version 1.0.0"""

    VERSION = datasets.Version("1.0.0")

    ALL_DEMOGRAPHICS = "all"

    DEMOGRAPHICS = {"male", "female", "LGBTQ", "christian", "muslim", "other_religions", "black", "white"}

    DEMOGRAPHICS_COLUMN_INDEX = {
  "male": 21,
  "female": 22,
  "LGBTQ": 47,
  "christian": 29,
  "muslim": 31,
  "other_religions": 48,
  "black": 36,
  "white": 37
}

    BUILDER_CONFIGS = [
        CivilCommentsWILDSConfig(
            name=name,
            version=datasets.Version("1.0.0"),
            description="Plain text",
        )
        for name in DEMOGRAPHICS | {ALL_DEMOGRAPHICS}
    ]

    DEFAULT_CONFIG_NAME = ALL_DEMOGRAPHICS

    LABERLS = ["False", "True"]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "label": datasets.features.ClassLabel(names=CivilCommentsWILDS.LABERLS),
                }
            ),
            supervised_keys=None,
            homepage="https://wilds.stanford.edu/datasets/#civilcomments",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        downloaded_file = dl_manager.download_and_extract(_URL)
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": downloaded_file, "split": "train"},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={"filepath": downloaded_file, "split": "val"},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": downloaded_file, "split": "test"},
            ),
        ]

    def _generate_examples(self, filepath, split):
        """Yields examples."""
        # Based on HELM's code
        # https://github.com/stanford-crfm/helm/blob/abfdcd8acd23b5ef3ec7ec987f5c90fb9de81406/src/helm/benchmark/scenarios/civil_comments_scenario.py#L20
        demographic = self.config.name
        with open(filepath, "r") as f:
            data = csv.reader(f, delimiter=",")
            next(data, None)
            for id_, row in enumerate(data):
                if row[3] == split:
                    if (demographic == CivilCommentsWILDS.ALL_DEMOGRAPHICS
                    or float(row[CivilCommentsWILDS.DEMOGRAPHICS_COLUMN_INDEX[demographic]]) >= 0.5):
                        yield id_, {
                            "text": row[2],
                            "label": int(float(row[14]) >= 0.5),
                        }