abusive-clauses-pl / abusive-clauses-pl.py
laugustyniak's picture
Update dataset (#1)
8b2a7d2
raw
history blame
2.43 kB
import datasets
import pandas as pd
_CITATION = """\
@InProceedings{AbusiveClauses:dataset,
title = {AbusiveClauses},
author={},
year={2022}
}
"""
_DESCRIPTION = "Binary Abusive Clauses in Polish"
_HOMEPAGE = ""
_LICENSE = "Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)"
_LABELS = ["KLAUZULA_ABUZYWNA", "BEZPIECZNE_POSTANOWIENIE_UMOWNE"]
_URLS = {
"train": "https://huggingface.co/datasets/laugustyniak/abusive-clauses-pl/resolve/main/train.csv",
"dev": "https://huggingface.co/datasets/laugustyniak/abusive-clauses-pl/resolve/main/dev.csv",
"test": "https://huggingface.co/datasets/laugustyniak/abusive-clauses-pl/resolve/main/test.csv",
}
class AbusiveClausesConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(AbusiveClausesConfig, self).__init__(**kwargs)
class AbusiveClausesDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="abusive-clauses-pl", version=VERSION)
]
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"label": datasets.features.ClassLabel(
names=_LABELS, num_classes=len(_LABELS)
),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls_to_download = _URLS
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}
),
datasets.SplitGenerator(
name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": downloaded_files["dev"]},
),
]
def _generate_examples(self, filepath: str):
df = pd.read_csv(filepath)
for idx, example in enumerate(df.itertuples(index=False)):
yield idx, {"text": example.text, "label": example.label}