# 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), }