A Dataset for Investigating the Impact of Context for Offensive Language Detection in Tweets (2023)

Abstract: Offensive language detection is crucial in natural language processing (NLP). We investigated the importance of context for detecting such language in reply tweets on Twitter, where the use of offensive language is widespread. We collected a Turkish tweet dataset where the target group was unvaccinated people during the Covid period. Tweets in the dataset were enriched with contextual information by adding the original tweet to which a particular tweet was posted as a reply. The dataset, which includes over 28,000 tweet-reply pairs, was manually labeled by human annotators and made publicly available. In addition, we compared the performance of different machine learning models with and without contextual information. Our results show that this type of contextual information was not very useful in improving the performance of the models in general, although it slightly increased the macro-averaged F1-score of certain models.

## introduction humans can communicate through language, which enables them to engage in many useful activities, yet language might also be used for destructive purposes. one of the most critical examples of this is offensive language, which can be defined as "any utterance which is blasphemous, obscene, indecent, insulting, hurtful, disgusting, morally repugnant, or which breaches commonly accepted standards of decent and proper speech" @xcite . the use of offensive language can occur on a variety of platforms, but is particularly common on online platforms such as twitter. in recent years, several approaches have been proposed to automatically detect offensive language in tweets. finetuning language models pre-trained with extensive data is considered the current state-of-the-art for detecting offensive language. bert @xcite is one of the most prominent transformerbased pre-trained language models for english and has also been shown to be very effective in detecting offensive language @xcite @xcite . a similar trend can be observed for other languages. for example, @xcite used @xcite , the arabic version of bert, for arabic. similarly, berturk @xcite has been successfully used to detect offensive language in turkish tweets @xcite @xcite . annotated datasets are needed to train or finetune machine learning models for offensive language detection. a number of datasets have been prepared for different languages and domains and made publicly available @xcite @xcite . a limitation of these datasets is that generally each tweet is labeled individually without considering contextual information. there are few studies that consider contextual information. @xcite investigate the relative contribution of user information features in machine learning models by using explainability techniques. @xcite propose a graph-based approach to represent dialog data from chat logs of an online game and use this representation for abusive language detection. @xcite define context as the previous comment in a reddit conversation thread and show that such contextual information is useful for detecting hate speech. we hypothesize that similar contextual information may be useful for offensive language detection in tweets. as a motivating example, consider a reply tweet that states, "i fully agree." the category of this reply tweet (i.e., whether it is offensive or not) depends on the previous context, i.e., the tweet to which it was posted as a reply. to investigate the impact of such contextual information on commonly used machine learning-based offensive language detection models, we collected and manually annotated tweet-reply pairs in turkish, a 1 1543 low-resource language with limited datasets. one of the first tweet datasets for detecting offensive language in turkish was developed by @xcite . recently, @xcite and toraman et al. (2022) also released tweet datasets for turkish. however, none of these datasets consider contextual information. we chose our domain as the covid-19 pandemic, which affected our lives in a number of different ways. pandemics trigger fear and anger in most people, leading to increased use of offensive language. @xcite studied the detection of hostile statements in the context of the covid-19 pandemic, and @xcite showed that such offensive language occurred against unvaccinated people during this period. therefore, we selected unvaccinated people as our target group. the main contributions of this paper are twofold: (i) we collect and manually annotate a turkish tweet dataset specific to the covid-19 period and containing contextual information in the form of the replied tweet. (ii) we investigate the impact of such contextual information on the performance of commonly used machine learning-based models for offensive language detection. the dataset and source code are made publicly available for future studies. 1 the rest of the paper is organized as follows. while section 2 examines the collection and annotation of the dataset, section 3 focuses on the experiments conducted to compare the machine learning models with and without contextual information. finally, section 4 discusses the lessons learned. ## dataset we collected a dataset containing replied and reply tweet pairs. a reply tweet is a tweet written in response to another tweet, while a replied tweet is a tweet to which another tweet has replied. suppose a tweet t 1 is posted and then another tweet t 2 is posted in response to t 1. in this case, t 1 is called a replied tweet and t 2 is called a reply tweet. our goal was to create a target group-specific dataset to enable the development of models capable of detecting offensive language towards a specific target group. we selected unvaccinated people in the covid 19 pandemic as the target group for offensive language. we examined the period from march 2020, when the virus reached türkiye, to september 2022, when the pandemic was no longer on the agenda for most people on the planet. we used search by keyword with 16 different queries such as "aşısız" (unvaccinated) and "aşı olmak istemeyen" (those who do not want to be vaccinated) to identify relevant tweets. the keywords are phrases meaning "aşısız" (unvaccinated) with different singular/plural forms or spellings due to the turkish character related issues. the list of all keywords used in this study can be found in the appendix. there were different options to search for the replied and reply tweet pairs. the first one was getting pairs where at least one of the 16 search keywords occurred in the reply tweet. we call this dataset 1. another possibility is that these keywords occur in the replied tweet. this case contains two subcases. the first case is to have at least one of these keywords in a replied tweet, which itself is a reply to another tweet. we refer to this case as dataset 2. finally, the last case is to have at least one of these keywords in a replied tweet that is not itself a reply to another tweet. this case is called dataset 3. all three of these datasets were merged to obtain the final dataset. although conversations on twitter could be arbitrarily long, we only looked at the previous tweet (replied tweet) to avoid unnecessarily complicated data format. in other words, all of the samples in our dataset are a pair. yet, we could capture any replied-reply couple related to unvaccinated people as long as at least one of the tweets contains one or more of the pre-determined keywords. during the search, we collected tweet id and tweet text information for both the replied and reply tweets. once the collection process was completed, we proceeded with labeling. the objective of the annotation was to obtain a binary label indicating whether or not the reply tweet contains offensive language against unvaccinated people. making explanations about specific points is essential for this part. first of all, we decided to keep the task clear so that we could understand the impact of the context better, so using a binary label looked like the best option, and we only looked at offensive language against unvaccinated people; in other words, even if a reply tweet was offensive, against immigrants for instance, we labeled that as "not offensive against unvaccinated people" instead of "offensive against unvaccinated people". this was not because such offensive language was accep which cases to consider as offensive language is another crucial point to explain. situations like swearing and insulting were the most obvious ones. in addition, provocative words like stating that there should be a punishment, such as not being able to go outside or get into closed areas, without stating any exception or an alternative option, for unvaccinated people are included in this label. also, we want to express that quotations or simply stating an idea without using harmful language, like saying that "not getting vaccinated is a wrong behavior," are not perceived as offensive language. even if we determine criteria, as we mentioned, for when to consider a tweet as offensive, this field is inevitably subjective for specific examples. this is why at least two people annotated each pair in our dataset. the annotation process was carried out as follows. a general guideline for annotation was established and provided to the annotators (i.e., three of the authors of the paper) and a training was performed by using sample examples. each tweet pair was annotated independently by two annotators and a third annotator was used to resolve inconsistencies. for each tweet pair, there were three label options, namely "not offensive against unvaccinated people", "ambiguous", and "offensive against unvaccinated people". although it is stated that the goal was obtaining binary labels, three options were given in order to provide more flexibility to the annotators; however, the pairs whose final label is "ambiguous" were removed from the final dataset since this would make the primary goal of the study more difficult to interpret which was examining the effect of taking the replied tweet into account. while doing the annotation, totally unrelated cases in the dataset, such as unvaccinated fruits and vegetables owing to chosen keywords, were mostly cleaned even though a limited number of such cases might be still existing in the dataset. we wanted to measure inter-annotator agreement for these labels, so we used the f1 and cohen kappa scores. we obtained 55.22% and 46.26%, respectively, for these metrics. after obtaining the annotations by two annotators for each pair of tweets, the annotations were examined. if there is consistency, then this was chosen as the ultimate label. if the ultimate label is "ambiguous", it is removed; otherwise, it is added to the final dataset. if there is inconsistency in the form of one annotator choosing "not offensive" and the other choosing "offensive", these cases are ambiguous; consequently, these were removed as well. for the inconsistencies where one annotator chose "ambiguous", the third annotator looked at the tweet pair and determined the final decision. if a label other than "ambiguous" was chosen, then it is selected as the last label. if not, it was removed. after several hours of this procedure, pairs with binary labels were obtained. in total, we obtained 28808 pairs. while 13478 of them came from dataset 1, datasets 2 and 3 contributed with 1515 and 13815 pairs, respectively. the final binary dataset has 27219 examples that are not offensive against unvaccinated people, denoted with 0, and 1589 examples which are offensive against unvaccinated people which are denoted with 2 since 1 was representing the ambiguous case. the dataset is inevitably imbalanced since 94.48% of the pairs are labeled as 0. inter-annotator agreement for the dataset's last version was measured using the f1 score and cohen kappa score. this time they were calculated as 95.21% and 88.97%, which is significantly better than the initial version of the dataset. the final version of the dataset containing the replied and reply tweet ids as well as the manual annotations is made publicly available for future studies. foot_1 ## experiments and results after completing the annotation of the dataset, we used it to train and evaluate various machine learning models to detect offensive language against unvaccinated people. we randomly selected 20% of the dataset as the test set. for each algorithm we used, we examined two different scenarios. in the first, we used only the reply tweet, while in the second, we studied the impact of using the replied tweet in addition to the reply tweet on our models. ## 1546 conclusion we prepared an offensive language dataset for turkish, where the number of such datasets is very limited. unlike most other tweet datasets where each tweet is considered individually, we included the replied tweet as contextual information and investigated how this information affects the performance of commonly used machine learning models. contrary to our expectation, our results showed that this resulted in only a slight improvement in the f1-score for some models and did not significantly improve the performance of the studied models for offensive language detection in general. in theory, the previous tweet appears to contain important information. however, in analyzing our dataset, we found that most reply tweets have only a weak relationship to the replied tweet in terms of meaning. moreover, interaction with other tweets is dominated by the use of other features on twitter, such as "like" or "retweet." consequently, the use of information about previous tweets did not provide much contribution for offensive language detection in this study. nonetheless, attempting to develop models specifically designed to consider information about previous tweets could lead to better performance and represents a promising future research direction.