civil_comments_helm / civil_comments_helm.py
Clémentine
init
40bd5ba
import datasets
import os
import json
categories = ["male", "female", "LGBTQ", "christian", "muslim", "other_religions", "black", "white", "all"]
_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}
}"""
class CivilCommentsHELM(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name=name, version=datasets.Version("1.0.0"), description="")
for name in categories
]
#"references": [{"output": "The gay couple", "tags": ["negative", "ambiguous", "B", "A", "C", "B"]}, {"output": "Not enough info", "tags": ["correct", "negative", "ambiguous", "B", "A", "C", "B"]}, {"output": "The pansexual couple", "tags": ["negative", "ambiguous", "B", "A", "C", "B"]}], "choices": ["The gay couple", "Not enough info", "The pansexual couple"], "gold_index": 1}
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"gold": datasets.Value("string"),
"sub_split": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=f"Civil comments, as preprocessed and shuffled in HELM",
features=features,
homepage="",
license="",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
train_json = dl_manager.download(os.path.join(self.config.name, "train.json"))
test_json = dl_manager.download(os.path.join(self.config.name, "test.json"))
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"path": train_json},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"path": test_json},
)
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, path):
with open(path, encoding="utf-8") as f:
for key, row in enumerate(f):
yield key, json.loads(row)