Datasets:
laugustyniak
commited on
Commit
•
77d6f7a
1
Parent(s):
e896385
Upload abusive_clauses_loader.py
Browse files- abusive_clauses_loader.py +75 -0
abusive_clauses_loader.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
|
3 |
+
import datasets
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
_CITATION = """\
|
7 |
+
@InProceedings{AbusiveClauses:dataset,
|
8 |
+
title = {AbusiveClauses},
|
9 |
+
author={},
|
10 |
+
year={2022}
|
11 |
+
}
|
12 |
+
"""
|
13 |
+
|
14 |
+
_DESCRIPTION = "Binary Abusive Clauses in Polish"
|
15 |
+
|
16 |
+
_HOMEPAGE = ""
|
17 |
+
_LICENSE = ""
|
18 |
+
_LABELS = ["KLAUZULA_ABUZYWNA", "BEZPIECZNE_POSTANOWIENIE_UMOWNE"]
|
19 |
+
|
20 |
+
DATA_PATH = Path(".")
|
21 |
+
|
22 |
+
|
23 |
+
class AbusiveClausesConfig(datasets.BuilderConfig):
|
24 |
+
def __init__(self, **kwargs):
|
25 |
+
super(AbusiveClausesConfig, self).__init__(**kwargs)
|
26 |
+
|
27 |
+
|
28 |
+
class AbusiveClausesDataset(datasets.GeneratorBasedBuilder):
|
29 |
+
VERSION = datasets.Version("1.0.0")
|
30 |
+
|
31 |
+
TRAIN_FILE = DATA_PATH / "train.csv"
|
32 |
+
VAL_FILE = DATA_PATH / "dev.csv"
|
33 |
+
TEST_FILE = DATA_PATH / "test.csv"
|
34 |
+
|
35 |
+
BUILDER_CONFIGS = [
|
36 |
+
datasets.BuilderConfig(name="abusive-clauses-pl", version=VERSION)
|
37 |
+
]
|
38 |
+
|
39 |
+
def _info(self):
|
40 |
+
features = datasets.Features(
|
41 |
+
{
|
42 |
+
"text": datasets.Value("string"),
|
43 |
+
"label": datasets.features.ClassLabel(
|
44 |
+
names=_LABELS, num_classes=len(_LABELS)
|
45 |
+
),
|
46 |
+
}
|
47 |
+
)
|
48 |
+
|
49 |
+
return datasets.DatasetInfo(
|
50 |
+
description=_DESCRIPTION,
|
51 |
+
features=features,
|
52 |
+
supervised_keys=None,
|
53 |
+
homepage=_HOMEPAGE,
|
54 |
+
license=_LICENSE,
|
55 |
+
citation=_CITATION,
|
56 |
+
)
|
57 |
+
|
58 |
+
def _split_generators(self, dl_manager):
|
59 |
+
return [
|
60 |
+
datasets.SplitGenerator(
|
61 |
+
name=datasets.Split.TRAIN, gen_kwargs={"filepath": str(self.TRAIN_FILE)}
|
62 |
+
),
|
63 |
+
datasets.SplitGenerator(
|
64 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": str(self.TEST_FILE)}
|
65 |
+
),
|
66 |
+
datasets.SplitGenerator(
|
67 |
+
name=datasets.Split.VALIDATION,
|
68 |
+
gen_kwargs={"filepath": str(self.VAL_FILE)},
|
69 |
+
),
|
70 |
+
]
|
71 |
+
|
72 |
+
def _generate_examples(self, filepath: str):
|
73 |
+
df = pd.read_csv(filepath)
|
74 |
+
for idx, example in enumerate(df.itertuples(index=False)):
|
75 |
+
yield idx, {"text": example.text, "label": example.label}
|