Datasets:
File size: 2,084 Bytes
77d6f7a |
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 |
from pathlib import Path
import datasets
import pandas as pd
_CITATION = """\
@InProceedings{AbusiveClauses:dataset,
title = {AbusiveClauses},
author={},
year={2022}
}
"""
_DESCRIPTION = "Binary Abusive Clauses in Polish"
_HOMEPAGE = ""
_LICENSE = ""
_LABELS = ["KLAUZULA_ABUZYWNA", "BEZPIECZNE_POSTANOWIENIE_UMOWNE"]
DATA_PATH = Path(".")
class AbusiveClausesConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(AbusiveClausesConfig, self).__init__(**kwargs)
class AbusiveClausesDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
TRAIN_FILE = DATA_PATH / "train.csv"
VAL_FILE = DATA_PATH / "dev.csv"
TEST_FILE = DATA_PATH / "test.csv"
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):
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN, gen_kwargs={"filepath": str(self.TRAIN_FILE)}
),
datasets.SplitGenerator(
name=datasets.Split.TEST, gen_kwargs={"filepath": str(self.TEST_FILE)}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": str(self.VAL_FILE)},
),
]
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}
|