|
""" TweetTopicMultilingual Dataset """ |
|
import json |
|
import datasets |
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
_DESCRIPTION = """[TweetTopicMultilingual](TBA)""" |
|
_VERSION = "0.0.3" |
|
_CITATION = """TBA""" |
|
_HOME_PAGE = "https://cardiffnlp.github.io" |
|
_NAME = "tweet_topic_multilingual" |
|
_ROOT_URL = f'https://huggingface.co/datasets/cardiffnlp/{_NAME}/resolve/main/dataset' |
|
_LANGUAGES = ["en", "es", "ja", "gr"] |
|
_URL = {} |
|
|
|
|
|
for lan in _LANGUAGES: |
|
_URL[lan] = {split: f"{_ROOT_URL}/{lan}/{lan}_{split}.jsonl" for split in ["train", "test", "validation"]} |
|
_URL["en_2022"] = {split: f"{_ROOT_URL}/en_2022/{split}.jsonl" for split in ["train", "validation"]} |
|
|
|
for lan in _LANGUAGES: |
|
_URL.update({ |
|
f"{lan}_cross_validation_{n}": { |
|
split: f"{_ROOT_URL}/{lan}/cross_validation/{lan}_{split}_{n}.jsonl" |
|
for split in ["train", "test", "validation"] |
|
} for n in range(5) |
|
}) |
|
|
|
|
|
class Config(datasets.BuilderConfig): |
|
"""BuilderConfig""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(Config, self).__init__(**kwargs) |
|
|
|
|
|
class TweetTopicMultilingual(datasets.GeneratorBasedBuilder): |
|
"""Dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
Config(name=i, version=datasets.Version(_VERSION), description=_DESCRIPTION) for i in _URL.keys() |
|
] |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_file = dl_manager.download_and_extract(_URL[self.config.name]) |
|
splits = _URL[self.config.name].keys() |
|
return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_file[i]}) for i in splits] |
|
|
|
def _generate_examples(self, filepath): |
|
_key = 0 |
|
logger.info("generating examples from = %s", filepath) |
|
with open(filepath, encoding="utf-8") as f: |
|
_list = [json.loads(i) for i in f.read().split('\n') if len(i) > 0] |
|
for i in _list: |
|
yield _key, i |
|
_key += 1 |
|
|
|
def _info(self): |
|
names = [ |
|
"arts_&_culture", "business_&_entrepreneurs", "celebrity_&_pop_culture", "diaries_&_daily_life", "family", |
|
"fashion_&_style", "film_tv_&_video", "fitness_&_health", "food_&_dining", "gaming", |
|
"learning_&_educational", "music", "news_&_social_concern", "other_hobbies", "relationships", |
|
"science_&_technology", "sports", "travel_&_adventure", "youth_&_student_life" |
|
] |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"label": datasets.Sequence(datasets.features.ClassLabel(names=names)), |
|
"label_name": datasets.Sequence(datasets.Value("string")) |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOME_PAGE, |
|
citation=_CITATION, |
|
) |
|
|