"""The SuperTweetEval benchmark.""" import json import os import datasets _SUPER_TWEET_EVAL_CITATION = """TBA""" _SUPER_TWEET_EVAL_DESCRIPTION = """TBA""" _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_QA_DESCRIPTION = """\ TweetQA is am abstractive question-answering dataset on Twitter. """ _TWEET_QA_CITATION = """\ @inproceedings{xiong2019tweetqa, title={TweetQA: A Social Media Focused Question Answering Dataset}, author={Xiong, Wenhan and Wu, Jiawei and Wang, Hong and Kulkarni, Vivek and Yu, Mo and Guo, Xiaoxiao and Chang, Shiyu and Wang, William Yang}, booktitle={Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics}, year={2019} } """ class SuperTweetEvalConfig(datasets.BuilderConfig): """BuilderConfig for SuperTweetEval.""" def __init__(self, features, data_url, citation, label_classes=("False", "True"), **kwargs): """BuilderConfig for SuperTweetEval. 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(SuperTweetEvalConfig, self).__init__(version=datasets.Version("1.0.3"), **kwargs) self.features = features self.label_classes = label_classes self.data_url = data_url self.citation = citation class SuperTweetEval(datasets.GeneratorBasedBuilder): """The SuperTweetEval benchmark.""" BUILDER_CONFIGS = [ SuperTweetEvalConfig( name="tweet_topic", description=_TWEET_TOPIC_DESCRIPTION, citation=_TWEET_TOPIC_CITATION, features=["text", "label_list", "id", "date"], data_url="https://dl.fbaipublicfiles.com/glue/SuperTweetEval/data/v2/BoolQ.zip", ), SuperTweetEvalConfig( name="tweet_ner7", description=_TWEET_NER7_DESCRIPTION, citation=_TWEET_NER7_CITATION, features=["text_tokenized", "label_sequence", "id", "date"], data_url="https://dl.fbaipublicfiles.com/glue/SuperTweetEval/data/v2/BoolQ.zip", ), SuperTweetEvalConfig( name="tweet_qa", description=_TWEET_QA_DESCRIPTION, citation=_TWEET_QA_CITATION, features=["text", "label_str", "paragraph", "question"], data_url="https://dl.fbaipublicfiles.com/glue/SuperTweetEval/data/v2/BoolQ.zip", ) ] def _info(self): features = {feature: datasets.Value("string") for feature in self.config.features} if self.config.name == "tweet_topic": 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["label_list"] = datasets.Sequence(datasets.features.ClassLabel(names=names)) if self.config.name == "tweet_ner7": 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["label_sequence"] = datasets.Sequence(datasets.features.ClassLabel(names=names)) return datasets.DatasetInfo( description=_SUPER_TWEET_EVAL_DESCRIPTION + "\n" + self.config.description, features=datasets.Features(features), citation=self.config.citation + "\n" + _SUPER_TWEET_EVAL_CITATION, ) def _split_generators(self, dl_manager): dl_dir = dl_manager.download_and_extract(self.config.data_url) or "" task_name = _get_task_name_from_data_url(self.config.data_url) dl_dir = os.path.join(dl_dir, task_name) if self.config.name in ["axb", "axg"]: return [ datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": os.path.join(dl_dir, f"{task_name}.jsonl"), "split": datasets.Split.TEST, }, ), ] return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": os.path.join(dl_dir, "train.jsonl"), "split": datasets.Split.TRAIN, }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": os.path.join(dl_dir, "val.jsonl"), "split": datasets.Split.VALIDATION, }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": os.path.join(dl_dir, "test.jsonl"), "split": datasets.Split.TEST, }, ), ] def _generate_examples(self, data_file, split): with open(data_file, encoding="utf-8") as f: for line in f: row = json.loads(line) if self.config.name == "multirc": paragraph = row["passage"] for question in paragraph["questions"]: for answer in question["answers"]: label = answer.get("label") key = "%s_%s_%s" % (row["idx"], question["idx"], answer["idx"]) yield key, { "paragraph": paragraph["text"], "question": question["question"], "answer": answer["text"], "label": -1 if label is None else _cast_label(bool(label)), "idx": {"paragraph": row["idx"], "question": question["idx"], "answer": answer["idx"]}, } elif self.config.name == "record": passage = row["passage"] entity_texts, entity_spans = _get_record_entities(passage) for qa in row["qas"]: yield qa["idx"], { "passage": passage["text"], "query": qa["query"], "entities": entity_texts, "entity_spans": entity_spans, "answers": _get_record_answers(qa), "idx": {"passage": row["idx"], "query": qa["idx"]}, } else: if self.config.name.startswith("wsc"): row.update(row["target"]) example = {feature: row[feature] for feature in self.config.features} if self.config.name == "wsc.fixed": example = _fix_wst(example) example["idx"] = row["idx"] if "label" in row: if self.config.name == "copa": example["label"] = "choice2" if row["label"] else "choice1" else: example["label"] = _cast_label(row["label"]) else: assert split == datasets.Split.TEST, row example["label"] = -1 yield example["idx"], example