tweet_generation / tweet_generation.py
asahi417's picture
init
db30823
"""Tweet Generation Dataset."""
import json
import datasets
_VERSION = "0.0.0"
_TWEET_GENERATION_DESCRIPTION = """"""
_TWEET_GENERATION_CITATION = """"""
_TWEET_CORPUS_DESCRIPTION = """Unlabeled tweet corpus ranging from 2018 to 2022."""
_TWEET_CORPUS_CITATION = """\
@inproceedings{loureiro-etal-2022-timelms,
title = "{T}ime{LM}s: Diachronic Language Models from {T}witter",
author = "Loureiro, Daniel and
Barbieri, Francesco and
Neves, Leonardo and
Espinosa Anke, Luis and
Camacho-collados, Jose",
editor = "Basile, Valerio and
Kozareva, Zornitsa and
Stajner, Sanja",
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics: System Demonstrations",
month = may,
year = "2022",
address = "Dublin, Ireland",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.acl-demo.25",
doi = "10.18653/v1/2022.acl-demo.25",
pages = "251--260",
abstract = "Despite its importance, the time variable has been largely neglected in the NLP and language model literature. In this paper, we present TimeLMs, a set of language models specialized on diachronic Twitter data. We show that a continual learning strategy contributes to enhancing Twitter-based language models{'} capacity to deal with future and out-of-distribution tweets, while making them competitive with standardized and more monolithic benchmarks. We also perform a number of qualitative analyses showing how they cope with trends and peaks in activity involving specific named entities or concept drift. TimeLMs is available at github.com/cardiffnlp/timelms.",
}
"""
_TWEET_TOPIC_DESCRIPTION = """
TweetTopic is a multi-label twitter topic classification task, where each example consists of a tweet
and a set of topics. One tweet can be associated with multiple topics, and the training/validation tweets are taken
from September 2019 to August 2020, while the test tweets are taken from September 2020 to August 2021.
Following the original work, we evaluate with macro F1 score."""
_TWEET_TOPIC_CITATION = """\
@inproceedings{antypas-etal-2022-twitter,
title = "{T}witter Topic Classification",
author = "Antypas, Dimosthenis and
Ushio, Asahi and
Camacho-Collados, Jose and
Silva, Vitor and
Neves, Leonardo 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",
url = "https://aclanthology.org/2022.coling-1.299",
pages = "3386--3400",
abstract = "Social media platforms host discussions about a wide variety of topics that arise everyday. Making sense of all the content and organising it into categories is an arduous task. A common way to deal with this issue is relying on topic modeling, but topics discovered using this technique are difficult to interpret and can differ from corpus to corpus. In this paper, we present a new task based on tweet topic classification and release two associated datasets. Given a wide range of topics covering the most important discussion points in social media, we provide training and testing data from recent time periods that can be used to evaluate tweet classification models. Moreover, we perform a quantitative evaluation and analysis of current general- and domain-specific language models on the task, which provide more insights on the challenges and nature of the task.",
}
"""
_TWEET_NER7_DESCRIPTION = """
TweetNER is a named-entity recognition dataset on Twitter. The training/validation tweets are taken
from September 2019 to August 2020, while the test tweets are taken from September 2020 to August 2021.
Following the original work, we evaluate with span F1 score.
"""
_TWEET_NER7_CITATION = """\
@inproceedings{ushio-etal-2022-named,
title = "Named Entity Recognition in {T}witter: A Dataset and Analysis on Short-Term Temporal Shifts",
author = "Ushio, Asahi and
Barbieri, Francesco and
Sousa, Vitor and
Neves, Leonardo and
Camacho-Collados, Jose",
booktitle = "Proceedings of the 2nd Conference of the Asia-Pacific Chapter of the Association for Computational Linguistics and the 12th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
month = nov,
year = "2022",
address = "Online only",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.aacl-main.25",
pages = "309--319",
abstract = "Recent progress in language model pre-training has led to important improvements in Named Entity Recognition (NER). Nonetheless, this progress has been mainly tested in well-formatted documents such as news, Wikipedia, or scientific articles. In social media the landscape is different, in which it adds another layer of complexity due to its noisy and dynamic nature. In this paper, we focus on NER in Twitter, one of the largest social media platforms, and construct a new NER dataset, TweetNER7, which contains seven entity types annotated over 11,382 tweets from September 2019 to August 2021. The dataset was constructed by carefully distributing the tweets over time and taking representative trends as a basis. Along with the dataset, we provide a set of language model baselines and perform an analysis on the language model performance on the task, especially analyzing the impact of different time periods. In particular, we focus on three important temporal aspects in our analysis: short-term degradation of NER models over time, strategies to fine-tune a language model over different periods, and self-labeling as an alternative to lack of recently-labeled data. TweetNER7 is released publicly (https://huggingface.co/datasets/tner/tweetner7) along with the models fine-tuned on it (NER models have been integrated into TweetNLP and can be found at https://github.com/asahi417/tner/tree/master/examples/tweetner7{\_}paper).",
}
"""
_TWEET_NERD_DESCRIPTION = """TBA"""
_TWEET_NERD_CITATION = """\
@article{mishra2022tweetnerd,
title={TweetNERD--End to End Entity Linking Benchmark for Tweets},
author={Mishra, Shubhanshu and Saini, Aman and Makki, Raheleh and Mehta, Sneha and Haghighi, Aria and Mollahosseini, Ali},
journal={arXiv preprint arXiv:2210.08129},
year={2022}
}
"""
_TWEET_SENTIMENT_DESCRIPTION = """TBA"""
_TWEET_SENTIMENT_CITATION = """\
TBA
"""
_ROOT_URL = "https://huggingface.co/datasets/cardiffnlp/tweet_generation/resolve/main/dataset"
class TweetGenerationConfig(datasets.BuilderConfig):
"""BuilderConfig for TweetGeneration."""
def __init__(self, features, data_url, citation, label_classes=("False", "True"), **kwargs):
"""BuilderConfig for TweetGeneration.
Args:
features: `list[string]`, list of the features that will appear in the
feature dict. Should not include "label".
data_url: `string`, url to download the zip file from.
citation: `string`, citation for the data set.
url: `string`, url for information about the data set.
label_classes: `list[string]`, the list of classes for the label if the
label is present as a string. Non-string labels will be cast to either
"False" or "True".
**kwargs: keyword arguments forwarded to super.
"""
super(TweetGenerationConfig, self).__init__(version=datasets.Version(_VERSION), **kwargs)
self.features = features
self.label_classes = label_classes
self.data_url = data_url
self.citation = citation
class TweetGeneration(datasets.GeneratorBasedBuilder):
"""The TweetGeneration benchmark."""
BUILDER_CONFIGS = [
TweetGenerationConfig(
name="tweet_corpus",
description=_TWEET_CORPUS_DESCRIPTION,
citation=_TWEET_CORPUS_CITATION,
features=["id", "text", "date"],
data_url=f"{_ROOT_URL}/tweet",
)
]
def _info(self):
features = {feature: datasets.Value("string") for feature in self.config.features}
if "topic" in self.config.name:
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"]
features["gold_label_list"] = datasets.Sequence(
datasets.features.ClassLabel(names=names))
elif "sentiment" in self.config.name:
features["text"] = datasets.Value("string")
features["gold_label_binary"] = datasets.Value("int32")
features["date"] = datasets.Value("string")
elif "nerd" in self.config.name:
features["target"] = datasets.Value("string")
features["text"] = datasets.Value("string")
features["definition"] = datasets.Value("string")
features["text_start"] = datasets.Value("int32")
features["text_end"] = datasets.Value("int32")
features["gold_label_binary"] = datasets.Value("int32")
features["date"] = datasets.Value("string")
elif "ner" in self.config.name:
names = [
"B-corporation", "B-creative_work", "B-event", "B-group", "B-location", "B-person", "B-product",
"I-corporation", "I-creative_work", "I-event", "I-group", "I-location", "I-person", "I-product", "O"]
features["gold_label_sequence"] = datasets.Sequence(datasets.features.ClassLabel(names=names))
features["text_tokenized"] = datasets.Sequence(datasets.Value("string"))
features["entities"] = datasets.features.Sequence(
{"entity": datasets.Value("string"), "type": datasets.Value("string")}
)
return datasets.DatasetInfo(
description=_TWEET_GENERATION_DESCRIPTION + "\n" + self.config.description,
features=datasets.Features(features),
citation=self.config.citation + "\n" + _TWEET_GENERATION_CITATION,
)
def _split_generators(self, dl_manager):
splits = ["train", "test", "validation"]
if "temporal" in self.config.name:
splits += ["test_1", "test_2", "test_3", "test_4"]
downloaded_file = dl_manager.download_and_extract(
{s: f"{self.config.data_url}/{s}.jsonl" for s in splits})
return [datasets.SplitGenerator(name=s, gen_kwargs={"filepath": downloaded_file[s]}) for s in splits]
def _generate_examples(self, filepath):
_key = 0
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