|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """ |
|
""" |
|
|
|
_DESCRIPTION = """ |
|
""" |
|
_URL = "https://raw.githubusercontent.com/kubotaissei/defamation_japanese_twitter/master/input/" |
|
_URLS = {"dataset": _URL + "data_twitter.json"} |
|
|
|
|
|
class DefamationJapaneseTwitterConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for DefamationJapaneseTwitterConfig.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for DefamationJapaneseTwitterConfig. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(DefamationJapaneseTwitterConfig, self).__init__(**kwargs) |
|
|
|
|
|
class DefamationJapaneseTwitter(datasets.GeneratorBasedBuilder): |
|
"""DefamationJapaneseTwitterConfig: Japanese Defamation Detection Twitter Dataset. Version 1.0.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
DefamationJapaneseTwitterConfig( |
|
name="plain_text", |
|
version=datasets.Version("1.0.0", ""), |
|
description="Plain text", |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"target": datasets.features.Sequence( |
|
datasets.ClassLabel(names=["C", "A1", "A2", "A3"]) |
|
), |
|
"label": datasets.features.Sequence( |
|
datasets.ClassLabel(names=["C", "B1", "B2", "B3", "B4"]) |
|
), |
|
"user_id_list": datasets.features.Sequence(datasets.Value("int32")), |
|
} |
|
), |
|
|
|
|
|
supervised_keys=None, |
|
homepage="", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": downloaded_files}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples depending on split""" |
|
|
|
with open(filepath["dataset"], encoding="utf-8") as f: |
|
data = json.load(f) |
|
|
|
for i, (id, v) in enumerate(data.items()): |
|
yield i, { |
|
"id": id, |
|
"target": v["target"], |
|
"label": v["label"], |
|
"user_id_list": v["user_id_list"], |
|
} |
|
|