Datasets:

Languages:
English
Multilinguality:
monolingual
Size Categories:
1k<10K
ArXiv:
Tags:
License:
File size: 4,282 Bytes
29fd70e
 
 
 
 
 
f0150f2
29fd70e
87b7a0d
29fd70e
f0150f2
 
 
 
 
 
 
 
 
 
 
 
 
 
29fd70e
 
 
 
76366aa
29fd70e
f0150f2
 
 
 
 
 
 
 
 
 
 
 
 
29fd70e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00c2e2a
29fd70e
 
 
 
 
 
00c2e2a
29fd70e
 
 
 
 
 
 
 
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
""" TweetTopic Dataset """
import json
from itertools import chain
import datasets

logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """[TweetTopic](https://arxiv.org/abs/2209.09824)"""

_VERSION = "1.0.4"
_CITATION = """
@inproceedings{dimosthenis-etal-2022-twitter,
    title = "{T}witter {T}opic {C}lassification",
    author = "Antypas, Dimosthenis  and
    Ushio, Asahi  and
    Camacho-Collados, Jose  and
    Neves, Leonardo  and
    Silva, Vitor  and
    Barbieri, Francesco",
    booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
    month = oct,
    year = "2022",
    address = "Gyeongju, Republic of Korea",
    publisher = "International Committee on Computational Linguistics"
}
"""
_HOME_PAGE = "https://cardiffnlp.github.io"
_LABEL_TYPE = "single"
_NAME = f"tweet_topic_{_LABEL_TYPE}"
_URL = f'https://huggingface.co/datasets/cardiffnlp/{_NAME}/raw/main/dataset'
_URLS = {
    f"{str(datasets.Split.TEST)}_2020": [f'{_URL}/split_temporal/test_2020.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TEST)}_2021": [f'{_URL}/split_temporal/test_2021.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_2020": [f'{_URL}/split_temporal/train_2020.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_2021": [f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_all": [f'{_URL}/split_temporal/train_2020.{_LABEL_TYPE}.json', f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.VALIDATION)}_2020": [f'{_URL}/split_temporal/validation_2020.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.VALIDATION)}_2021": [f'{_URL}/split_temporal/validation_2021.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_random": [f'{_URL}/split_random/train_random.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.VALIDATION)}_random": [f'{_URL}/split_random/validation_random.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TEST)}_coling2022_random": [f'{_URL}/split_coling2022_random/test_random.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_coling2022_random": [f'{_URL}/split_coling2022_random/train_random.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TEST)}_coling2022": [f'{_URL}/split_coling2022_temporal/test_2021.{_LABEL_TYPE}.json'],
    f"{str(datasets.Split.TRAIN)}_coling2022": [f'{_URL}/split_coling2022_temporal/train_2020.{_LABEL_TYPE}.json'],
}

class TweetTopicSingleConfig(datasets.BuilderConfig):
    """BuilderConfig"""

    def __init__(self, **kwargs):
        """BuilderConfig.

        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(TweetTopicSingleConfig, self).__init__(**kwargs)


class TweetTopicSingle(datasets.GeneratorBasedBuilder):
    """Dataset."""

    BUILDER_CONFIGS = [
        TweetTopicSingleConfig(name=_NAME, version=datasets.Version(_VERSION), description=_DESCRIPTION),
    ]

    def _split_generators(self, dl_manager):
        downloaded_file = dl_manager.download_and_extract(_URLS)
        return [datasets.SplitGenerator(name=i, gen_kwargs={"filepaths": downloaded_file[i]}) for i in _URLS.keys()]

    def _generate_examples(self, filepaths):
        _key = 0
        for filepath in filepaths:
            logger.info(f"generating examples from = {filepath}")
            with open(filepath, encoding="utf-8") as f:
                _list = [i for i in f.read().split('\n') if len(i) > 0]
                for i in _list:
                    data = json.loads(i)
                    yield _key, data
                    _key += 1

    def _info(self):
        names = ["arts_&_culture", "business_&_entrepreneurs", "pop_culture", "daily_life", "sports_&_gaming", "science_&_technology"]
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "date": datasets.Value("string"),
                    "label": datasets.features.ClassLabel(names=names),
                    "label_name": datasets.Value("string"),
                    "id": datasets.Value("string")
                }
            ),
            supervised_keys=None,
            homepage=_HOME_PAGE,
            citation=_CITATION,
        )