T weet NLP : Cutting-Edge Natural Language Processing for Social Media (2022)

Abstract: In this paper we present TweetNLP, an integrated platform for Natural Language Processing (NLP) in social media. TweetNLP supports a diverse set of NLP tasks, including generic focus areas such as sentiment analysis and named entity recognition, as well as social media-specific tasks such as emoji prediction and offensive language identification. Task-specific systems are powered by reasonably-sized Transformer-based language models specialized on social media text (in particular, Twitter) which can be run without the need for dedicated hardware or cloud services. The main contributions of TweetNLP are: (1) an integrated Python library for a modern toolkit supporting social media analysis using our various task-specific models adapted to the social domain; (2) an interactive online demo for codeless experimentation using our models; and (3) a tutorial covering a wide variety of typical social media applications.

## introduction today's society cannot be understood without the role of social media. online users connect more and more via platforms that enable content sharing, either generic or around specific topics, and do this by means of text-only messages, or augmenting them with multimedia content such as pictures, audio or video. as such, these platforms have been used to understand user, group and organizationwide behaviours @xcite . in particular, twitter, which is the main platform studied in this paper, has long been an important resource for understanding society at large @xcite . twitter is interesting for nlp because it embodies many features that are natural in spontaneous and ever-evolving fast-paced communication. however, the majority of nlp research focuses on optimizing model development against training data and evaluation benchmarks which are, at worst, reasonably clean (e.g., news articles, blog posts or wikipedia). consequently, when deployed in the wild, features such as noisiness, multilinguality, immediacy, slang, technical jargon, lack of context, platform-specific restrictions on message length, emoji and other modalities, etc. become core communicative variables that need to be factored in. indeed, even traditional nlp tasks such as normalization @xcite , pos tagging @xcite , sentiment analysis @xcite or named entity recognition @xcite have been shown to produce suboptimal results in the context of social media. given the above, we put forward tweetnlp (tweetnlp.org), which offers a full-fledged nlp platform specialized in twitter. the backbone of tweetnlp consists of transformer-based language models that have been trained on twitter @xcite @xcite . then, these specialized language models have been further fine-tuned for specific nlp tasks on twitter data. these models have already proved highly popular, with thousands of downloads from the hugging face model hub every month @xcite . 1 tweetnlp integrates all these resources into a single platform. with a simple python api, tweetnlp offers an easy-to-use way to leverage cutting-edge nlp models in a variety of social media tasks. despite the trend of ever-larger language models @xcite , tweetnlp is more focused on the general user and applicability, and therefore integrates base models which are easily run in standard computers or on free cloud services. finally, all models can be accessed from an interactive online demo, offering anyone the possibility to test models and perform real-time analysis on twitter. ## related work general-purpose nlp libraries have been available for many years. starting from the java-based corenlp @xcite to the more recent python-based library stanza @xcite . more recently, libraries such as spacy foot_2 have been ubiquitous in nlp, both in research and industry. finally, in the language models and transformers era, the hugging face transformer hub has become indispensable for state-of-the-art nlp @xcite , which is also leveraged for our library tweetnlp. however, none of these libraries is specialized in social media or twitter. as for libraries developed specifically for social media, these are more limited and mostly associated with low-level tasks such as tokenization, part-of-speech @xcite tagging or dependency parsing @xcite , and initially available for java. the most recent twitterspecific python library is tweebanknlp @xcite based on stanza. this library provides state-of-the-art models on tokenization and lemmatization, besides competitive models on ner, partof-speech tagging and dependency parsing. in contrast, tweetnlp focuses on specialized twitterspecific language models for downstream tasks such as sentiment analysis and offensive language identification. ## models and functionalities tweetnlp is versatile in that it covers a wide range of tasks and applications. the backbone of tweetnlp are transformer-based language models, which are covered in section 3.1. the concrete nlp tasks integrated in tweetnlp are presented in section 3.2. finally, in section 3.3 we present embeddings used to represent words and tweets. all tweetnlp model checkpoints are available in the appendix. ## tweetnlp python library the tweetnlp python library has been integrated into pypi foot_4 and therefore is easily accessible and can be installed from pip ("pip install tweetnlp"). all the details on how to use tweetnlp are in the associated github repository, which is released fully open-source: https://github. com/cardiffnlp/tweetnlp . once installed, loading and using a fine-tuned model on any specific task can be done as follows. with the load statement, the associated fine-tuned language models are loaded in the background. users can then get the predictions for any given sentence or tweet with a simple pre-defined function (e.g., .sentiment or .predict). custom loading of existing fine-tuned language models not included in tweetnlp is also possible. the same functionalities apply to all the other tasks described in section 3.2. ## tutorials in addition to the python library presented in the previous section, tweetnlp offers access to the underlying python code structured in instructive google colab notebooks with starter code and examples ( https://tweetnlp. org/get-started/ ). these notebooks are aimed at users with varying degrees of experience in nlp and social media processing. in the fol-lowing we list the currently existing tutorials and a brief description: introduction to tweetnlp. in this initial introduction, users learn how to use the tweetnlp python library to make use of specialized models in social media for a wide variety of tasks from sentiment analysis to named entity recognition. getting data from twitter. this notebook helps users understand the twitter api foot_5 and how to interact with it. more importantly, there are concrete examples on how to retrieve data (i.e. tweets) from twitter, usually given a hashtag or a keyword. custom fine-tuning. in this notebook users can learn to fine-tune any given language model on a specific task (e.g. sentiment analysis). for this, we will take advantage of the tweeteval task data and unified format @xcite . additionally, users can learn how to easily evaluate language models on tweeteval. word embeddings. with this notebook users can learn how to train their own word embeddings on custom data using gensim foot_6 @xcite . the notebook also includes examples on how to get similarity scores from twitter-specific word embeddings, or how to obtain the nearest neighbour words from a given input word. language models over time. this notebook leverages the timelms library @xcite . users can learn how to make use of language models that have been trained in short periods of time since 2019 until recently. tweet embeddings. this notebook contains examples on how to transform a tweet into a vector (embedding) and how these enable important applications such as tweet similarity and retrieval. ## demo in addition to the python-based library and tutorials, we developed a comprehensive web-based demo integrating all our models, available at https://tweetnlp.org/demo/ . the goal of the demo is for any user to be able to test our models and get predictions. in particular, the model includes the following five functionalities: sentence/tweet classification (figure 1 ). users can input a sentence or a tweet (including a tweet url) and the output is a plot display of the confidence of the model with respect to its predictions. this demo includes all tweet classification tasks supported in english (see section 3.2), as well as a multilingual sentiment analysis model based on xlm-t. hashtag analysis (figure 2 ). this demo directly interacts with the twitter api. users can type a hashtag (or any keyword), initial and end dates, task and language. the system will then retrieve tweets for the given time interval and compute an aggregated analysis of the results. languages supported for this demo are available in the appendix. word prediction (figure 3 ). masked language models utilized in tweetnlp are trained to predict unknown (or masked) words within a sentence. for this demo, users can input a sentence with a masked word and the system will show the most likely words as given by the masked language model, in order of confidence. tweet similarity (figure 4 ). given two short pieces of text (e.g., two sentences or two tweets), this demo displays their cosine similarity score on a 0-100 scale as provided by our default tweet embedding model. named entity recognition (figure 5 ). given a tweet or a sentence, this ner demo locates its named entities and infers their types. ## evaluation in this section, we provide experimental results of the default models integrated into tweetnlp. ## conclusion and future work in this demo paper we have presented tweetnlp, an all-round platform for nlp specialized in social media. the platform is powered by relatively lightweight language models trained on twitter, and adapted (fine-tuned) to various popular nlp tasks on social media, such as sentiment analysis and offensive language identification. in addition 9 baseline checkpoint links are included in the appendix. to sharing the models, tweetnlp provides an online demo, a python library, and a tutorial to make the most of the models, regardless of the expertise of the user. tweetnlp also enables easy inspection of the models by non-programmers, which can help identify harmful biases or errors, that in turn would help improve the models in the future. while this first release version of tweetnlp is self-contained and complete, our goal is to keep updating it with both new models and tasks. since social media data is at the core of tweetnlp, we are planning to develop new datasets and models for social media tasks. in particular, our idea is to go beyond tweet classification tasks, which are currently well covered in tweetnlp. for instance, low-level tasks such as syntactic parsing and part-of-speech tagging has been traditionally hard in noisy environments such as social media. finally, in the future we are also planning to extend tweetnlp to other social media platforms such as reddit, linkedin or instagram, and to provide support for languages other than english in a wider variety of tasks.