Datasets:
File size: 3,800 Bytes
6e80c25 a6cefe1 6e80c25 2dbac05 6e80c25 a6cefe1 6e80c25 2dbac05 6e80c25 2dbac05 6e80c25 |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
from pathlib import Path
import datasets
import pandas as pd
logger = datasets.logging.get_logger(__name__)
_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):
logger.info("⏳ Generating examples from = %s", filepath)
df = pd.read_json(filepath)
for row_id, row in df.iterrows():
yield row_id, {
"id": str(row_id),
"tokens": [str(token) for token in row.tokens],
"tags": [str(tag) for tag in row.tags],
}
|