CaSET-catalan-stance-emotions-twitter / CaSET-catalan-stance-emotions-twitter.py
ibaucells's picture
Update CaSET-catalan-stance-emotions-twitter.py
3e3cdab
import json
import csv
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """ """
_DESCRIPTION = """ The CaSET dataset is a Catalan corpus of Tweets annotated with Emotions, Static Stance, and Dynamic Stance. The dataset contains 11k unique sentence on five polemical topics, grouped in 6k pairs of sentences, paired as original messages and answers to these messages. """
_HOMEPAGE = """ https://huggingface.co/datasets/projecte-aina/CaSET-catalan-stance-emotions-twitter/ """
_URL = "https://huggingface.co/datasets/projecte-aina/CaSET-catalan-stance-emotions-twitter/resolve/main/"
_FILE = "data.jsonl"
class CaSETConfig(datasets.BuilderConfig):
""" Builder config for the CaSET dataset """
def __init__(self, **kwargs):
"""BuilderConfig for CaSET.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(CaSETConfig, self).__init__(**kwargs)
class CaSET(datasets.GeneratorBasedBuilder):
""" CaSET Dataset """
BUILDER_CONFIGS = [
CaSETConfig(
name="CaSET",
version=datasets.Version("1.0.0"),
description="CaSET dataset",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{"id_parent": datasets.Value("string"),
"id_reply": datasets.Value("string"),
"parent_text": datasets.Value("string"),
"reply_text": datasets.Value("string"),
"topic": datasets.features.ClassLabel
(names=
['aeroport',
'vaccines',
'lloguer',
'benidormfest',
'subrogada'
]
),
"dynamic_stance": datasets.features.ClassLabel
(names=
['Agree', 'Disagree', 'Elaborate', 'Query', 'Neutral', 'Unrelated', 'NA'
]
),
"parent_stance": datasets.features.ClassLabel
(names=
['FAVOUR', 'AGAINST', 'NEUTRAL', 'NA'
]
),
"reply_stance": datasets.features.ClassLabel
(names=
['FAVOUR', 'AGAINST', 'NEUTRAL', 'NA'
]
),
"parent_emotion": datasets.Sequence(datasets.Value("string")),
"reply_emotion": datasets.Sequence(datasets.Value("string")),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"data": f"{_URL}{_FILE}",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["data"]}),
]
def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
logger.info("generating examples from = %s", filepath)
with open(filepath, encoding="utf-8") as f:
data = [json.loads(line) for line in f]
for id_, pair in enumerate(data):
yield id_, {
"id_parent": pair["id_parent"],
"id_reply": pair["id_reply"],
"parent_text":pair["parent_text"],
"reply_text": pair["reply_text"],
"topic": pair["topic"],
"dynamic_stance": pair["dynamic_stance"],
"parent_stance": pair["parent_stance"],
"reply_stance": pair["reply_stance"],
"parent_emotion": pair["parent_emotion"],
"reply_emotion": pair["reply_emotion"],
}