Datasets:
Upload intoxicat.py
Browse files- intoxicat.py +112 -0
intoxicat.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Loading script for the IntoxiCat dataset.
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
logger = datasets.logging.get_logger(__name__)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
_CITATION = """ """
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
_DESCRIPTION = """ InToxiCat is a dataset for the detection of abusive language in Catalan. """
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
_HOMEPAGE = """ https://huggingface.co/datasets/projecte-aina/InToxiCat"""
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
_URL = "https://huggingface.co/datasets/projecte-aina/InToxicat/resolve/main/"
|
| 22 |
+
_FILE_TRAIN = "train.json"
|
| 23 |
+
_FILE_DEV = "dev.json"
|
| 24 |
+
_FILE_TEST = "test.json"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class InToxiCatConfig(datasets.BuilderConfig):
|
| 28 |
+
""" Builder config for the InToxiCat dataset """
|
| 29 |
+
|
| 30 |
+
def __init__(self, **kwargs):
|
| 31 |
+
"""BuilderConfig for InToxiCat.
|
| 32 |
+
Args:
|
| 33 |
+
**kwargs: keyword arguments forwarded to super.
|
| 34 |
+
"""
|
| 35 |
+
super(InToxiCatConfig, self).__init__(**kwargs)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class InToxiCat(datasets.GeneratorBasedBuilder):
|
| 39 |
+
""" InToxiCat Dataset """
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
BUILDER_CONFIGS = [
|
| 43 |
+
InToxiCatConfig(
|
| 44 |
+
name="InToxiCat",
|
| 45 |
+
version=datasets.Version("1.0.0"),
|
| 46 |
+
description="InToxiCat dataset",
|
| 47 |
+
),
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
def _info(self):
|
| 51 |
+
return datasets.DatasetInfo(
|
| 52 |
+
description=_DESCRIPTION,
|
| 53 |
+
features=datasets.Features(
|
| 54 |
+
{
|
| 55 |
+
"id": datasets.Value("string"),
|
| 56 |
+
"context": datasets.Value("string"),
|
| 57 |
+
"sentence": datasets.Value("string"),
|
| 58 |
+
"topic": datasets.Value("string"),
|
| 59 |
+
"keywords": datasets.Sequence(datasets.Value("string")),
|
| 60 |
+
"context_needed": datasets.Value("string"),
|
| 61 |
+
"is_abusive": datasets.features.ClassLabel(names=['abusive','not_abusive']),
|
| 62 |
+
"abusiveness_agreement": datasets.Value("string"),
|
| 63 |
+
"target_type": datasets.Sequence(datasets.features.ClassLabel(names=['INDIVIDUAL','GROUP','OTHERS'])),
|
| 64 |
+
"abusive_spans": datasets.Sequence(feature={'text': datasets.Value(dtype='string', id=None), 'index': datasets.Value(dtype='string', id=None)}, length=-1, id=None), #datasets.Sequence(feature=datasets.Sequence(datasets.Value(dtype='string', id=None))),
|
| 65 |
+
"target_spans": datasets.Sequence(feature={'text': datasets.Value(dtype='string', id=None), 'index': datasets.Value(dtype='string', id=None)}, length=-1, id=None),
|
| 66 |
+
"is_implicit": datasets.Value("string")
|
| 67 |
+
}
|
| 68 |
+
),
|
| 69 |
+
homepage=_HOMEPAGE,
|
| 70 |
+
citation=_CITATION,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
def _split_generators(self, dl_manager):
|
| 74 |
+
"""Returns SplitGenerators."""
|
| 75 |
+
urls_to_download = {
|
| 76 |
+
"train": f"{_FILE_TRAIN}",
|
| 77 |
+
"dev": f"{_FILE_DEV}",
|
| 78 |
+
"test": f"{_FILE_TEST}"
|
| 79 |
+
}
|
| 80 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 81 |
+
|
| 82 |
+
return [
|
| 83 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
| 84 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
| 85 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]})
|
| 86 |
+
]
|
| 87 |
+
|
| 88 |
+
def _generate_examples(self, filepath):
|
| 89 |
+
"""This function returns the examples in the raw (text) form."""
|
| 90 |
+
logger.info("generating examples from = %s", filepath)
|
| 91 |
+
data = json.load(open(filepath, 'r'))
|
| 92 |
+
for id_, example in enumerate(data):
|
| 93 |
+
yield id_, {
|
| 94 |
+
"id": example["id"],
|
| 95 |
+
"context": example["context"],
|
| 96 |
+
"sentence": example["sentence"],
|
| 97 |
+
"topic": example["topic"],
|
| 98 |
+
"keywords": example["key_words"],
|
| 99 |
+
"context_needed": example["annotation"]["context_needed"] if example["annotation"]["context_needed"] else None,
|
| 100 |
+
"is_abusive": example["annotation"]["is_abusive"] if example["annotation"]["is_abusive"] else None,
|
| 101 |
+
"abusiveness_agreement": example["annotation"]["abusiveness_agreement"],
|
| 102 |
+
"target_type": example["annotation"]["target_type"] if example["annotation"]["target_type"] else None,
|
| 103 |
+
"abusive_spans": {
|
| 104 |
+
"text": [text for text, _ in example["annotation"]["abusive_spans"]],
|
| 105 |
+
"index": [index for _, index in example["annotation"]["abusive_spans"]]
|
| 106 |
+
} if example["annotation"]["abusive_spans"] != [] else None,
|
| 107 |
+
"target_spans": {
|
| 108 |
+
"text": [text for text, _ in example["annotation"]["target_spans"]],
|
| 109 |
+
"index": [index for _, index in example["annotation"]["target_spans"]]
|
| 110 |
+
} if example["annotation"]["target_spans"] != [] else None,
|
| 111 |
+
"is_implicit": example["annotation"]["is_implicit"] if example["annotation"]["is_implicit"] != "" else None
|
| 112 |
+
}
|