# coding=utf-8 # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Lint as: python3 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")), } ), # No default supervised_keys (as we have to pass both question # and context as input). 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"], }