|
from pathlib import Path |
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
@inproceedings{augustyniak-etal-2020-political, |
|
title = "Political Advertising Dataset: the use case of the Polish 2020 Presidential Elections", |
|
author = "Augustyniak, Lukasz and |
|
Rajda, Krzysztof and |
|
Kajdanowicz, Tomasz and |
|
Bernaczyk, Micha{\l}", |
|
booktitle = "Proceedings of the The Fourth Widening Natural Language Processing Workshop", |
|
month = jul, |
|
year = "2020", |
|
address = "Seattle, USA", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://www.aclweb.org/anthology/2020.winlp-1.28", |
|
pages = "110--114" |
|
} |
|
""" |
|
|
|
_DESCRIPTION = "Polish Political Advertising Dataset" |
|
|
|
_HOMEPAGE = "https://github.com/laugustyniak/misinformation" |
|
|
|
DATA_PATH = Path(".") |
|
|
|
|
|
class PoliticalAdvertisingConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(PoliticalAdvertisingConfig, self).__init__(**kwargs) |
|
|
|
|
|
class PoliticalAdvertisingDataset(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.0.0") |
|
|
|
TRAIN_FILE = DATA_PATH / "train.json" |
|
VAL_FILE = DATA_PATH / "dev.json" |
|
TEST_FILE = DATA_PATH / "test.json" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="political-advertising-pl", version=VERSION) |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"tokens": datasets.Sequence(datasets.Value("string")), |
|
"tags": datasets.Sequence( |
|
datasets.features.ClassLabel( |
|
names=[ |
|
"O", |
|
"B-DEFENSE_AND_SECURITY", |
|
"I-DEFENSE_AND_SECURITY", |
|
"B-EDUCATION", |
|
"I-EDUCATION", |
|
"B-FOREIGN_POLICY", |
|
"I-FOREIGN_POLICY", |
|
"B-HEALHCARE", |
|
"I-HEALHCARE", |
|
"B-IMMIGRATION", |
|
"I-IMMIGRATION", |
|
"B-INFRASTRUCTURE_AND_ENVIROMENT", |
|
"I-INFRASTRUCTURE_AND_ENVIROMENT", |
|
"B-POLITICAL_AND_LEGAL_SYSTEM", |
|
"I-POLITICAL_AND_LEGAL_SYSTEM", |
|
"B-SOCIETY", |
|
"I-SOCIETY", |
|
"B-WELFARE", |
|
"I-WELFARE", |
|
] |
|
) |
|
), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
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_json(filepath) |
|
for row_id, row in df.iterrows(): |
|
yield row_id, { |
|
"id": row.id, |
|
"text": row.text, |
|
"tags": row.tags, |
|
"url": row.url, |
|
"tweet_id": row.tweet_id, |
|
} |
|
|