Detecting Hate Speech in Social Media

Shervin Malmasi, Marcos Zampieri

Introduction

Research on safety and security in social media has grown substantially in the last decade. A particularly relevant aspect of this work is detecting and preventing the use of various forms of abusive language in blogs, micro-blogs, and social networks. A number of recent studies have been published on this issue such as the work by Xu et al. (2012) on identifying cyber-bullying, the detection of hate speech Burnap and Williams (2015) which was the topic of a recent survey Schmidt and Wiegand (2017), and the detection of racism Tulkens et al. (2016) in user generated content.

The growing interest in this topic within the research community is evidenced by several related studies presented in Section 2 and by two recent workshops: Text Analytics for Cybersecurity and Online Safety (TA-COS)http://www.ta-cos.org/home held in 2016 at LREC and Abusive Language Workshop (AWL)https://sites.google.com/site/abusivelanguageworkshop2017/ held in 2017 at ACL.

In this paper we address the problem of hate speech detection using a dataset which contains English tweets annotated with three labels: (1) hate speech (Hate); (2) offensive language but no hate speech (Offensive); and (3) no offensive content (Ok). Most studies on abusive language so far Burnap and Williams (2015); Djuric et al. (2015); Nobata et al. (2016) have been modeled as binary classification with only one positive and one negative classes (e.g. hate speech vs non-hate speech). As noted by Dinakar et al. (2011), systems trained on such data often rely on the frequency of offensive or non-socially acceptable words to distinguish between the two classes. Dinakar et al. (2011) stress that in some cases “the lack of profanity or negativity [can] mislead the classifier”.

Indeed, the presence of profane content does not in itself signify hate speech. General profanity is not necessarily targeted towards an individual and may be used for stylistic purposes or emphasis. On the other hand, hate speech may denigrate or threaten an individual or a group of people without the use of any profanities.

The main aim of this paper is to establish a lexical baseline for discriminating between hate speech and profanity on this standard dataset. The corpus used here provides us with an interesting opportunity to investigate how well a system can detect hate speech from other content that is generally profane. This baseline can be used to determine the difficulty of this task, and help highlight the most challenging aspects which must be addressed in future work.

The rest of this paper is organized as follows. In Section 2 we briefly outline some previous work on abusive language detection. The data is presented in Section 3, along with a description of our computational approach, features, and evaluation methodology. Results are presented in Section 4, followed by a conclusion and future perspectives in Section 5.

Related Work

There have been several studies on computational methods to detect abusive language published in the last few years. One example is the work by Xu et al. (2012) who apply sentiment analysis to detect bullying in tweets and use Latent Dirichlet Allocation (LDA) topic models Blei et al. (2003) to identify relevant topics in these texts.

A number of studies have been published on hate speech detection. As previously mentioned, to the best of our knowledge all of them rely on binary classification (e.g. hate speech vs non-hate speech). Examples of such studies include the work by Kwok and Wang (2013), Djuric et al. (2015), Burnap and Williams (2015), and by Nobata et al. (2016).

Due to the availability of suitable corpora, the overwhelming majority of studies on abusive language, including ours, have used English data. However, more recently a few studies have investigated abusive language detection in other languages. Mubarak et al. (2017) addresses abusive language detection on Arabic social media and Su et al. (2017) presents a system to detect and rephrase profanity in Chinese. Hate speech and abusive language datasets have been recently annotated for German Ross et al. (2016) and Slovene Fišer et al. (2017) opening avenues for future work in languages other than English.

Methods

Next we present the Hate Speech Detection dataset used in our experiments. We applied a linear Support Vector Machine (SVM) classifier and used three groups of features extracted for these experiments: surface nn-grams, word skip-grams, and Brown clusters. The classifier and features are described in more detail in Section 3.2 and Section 3.3 respectively. Finally, Section 3.4 discusses evaluation methods.

In these experiments we use the aforementioned Hate Speech Detection dataset created by Davidson et al. (2017) and distributed via CrowdFlower.https://data.world/crowdflower/hate-speech-identification The dataset features 14,50914{,}509 English tweets annotated by a minimum of three annotators.

Individuals in charge of the annotation of this dataset were asked to annotate each tweet and categorize them into one of three classes:

(Offensive): contains offensive language but no hate speech;

Each instance in this dataset contains the text of a tweet Each tweet is limited to a maximum of 140140 characters. along with one of the three aforementioned labels. The distribution of the texts across the three classes is shown in Table 1.

All the texts are preprocessed to lowercase all tokens and to remove URLs and emojis.

2 Classifier

We use a linear SVM to perform multi-class classification in our experiments. We use the LIBLINEARhttp://www.csie.ntu.edu.tw/%7Ecjlin/liblinear/ package Fan et al. (2008) which has been shown to be very efficient for similar text classification tasks. For example, the LIBLINEAR SVM implementation has been demonstrated to be a very effective classifier for Native Language Identification Malmasi and Dras (2015), temporal text classification Zampieri et al. (2016a), and language variety identification Zampieri et al. (2016b).

3 Features

We use two groups of surface features in our experiments as follows:

Surface nn-grams: These are our most basic features, consisting of character nn-grams (of order 22–88) and word nn-grams (of order 11–33). All tokens are lowercased before extraction of nn-grams; character nn-grams are extracted across word boundaries.

Word Skip-grams: Similar to the above features, we also extract 11-, 22- and 33-skip word bigrams. These features are were chosen to approximate longer distance dependencies between words, which would be hard to capture using bigrams alone.

4 Evaluation

To evaluate our methods we use 1010-fold cross-validation. For creating the folds, we employ stratified cross-validation aiming to ensure that the proportion of classes within each partition is equal Kohavi (1995).

We report our results in terms of accuracy. The results obtained by our methods are compared against a majority class baseline and an oracle classifier.

The oracle takes the predictions by all the classifiers in Table 2 into account. It assigns the correct class label for an instance if at least one of the the classifiers produces the correct label for that instance. This approach establishes the potential or theoretical upper limit performance for a given dataset. Similar analysis using oracle classifiers have been previously applied to estimate the theoretical upper bound of shared tasks datasets in Native Language Identification Malmasi et al. (2015) and similar language and language variety identification Goutte et al. (2016).

Results

We start by investigating the efficacy of our features for this task. We fist train a single classifier, with each of them using a type of feature. Subsequently we also train a single model combining all of our features into single space. These are compared against the majority class baseline, as well as the oracle. The results of these experiments are listed in Table 2.

The majority class baseline is quite high due to the class imbalance in the data. The oracle achieves an accuracy of 91.6%91.6\%, showing that none of our features are able to correctly classify a substantial portion of our samples.

We note that character nn-grams perform well here, with 44-grams achieving the best performance of all features. Word unigrams also perform well, while performance degrades with bigrams, trigrams and skip-grams. However, the skip-grams may be capturing longer distance dependencies which provide complementary information to the other feature types. In tasks relying on stylistic information, it has been shown that skip-grams capture information that is very similar to syntactic dependencies (Malmasi and Cahill, 2015, §5).

Finally, the combination of all features does not achieve the performance of a character 44-grams model and causes a large dimensionality increase, with a total of 5.55.5 million features. It is not clear if this model is able to correctly capture the diverse information provided by the three feature types since we include more character nn-gram models than word-based ones.

Next we analyze the rate of learning for these features. A learning curve for the classifier that yielded the best performance overall, character 4-grams, is shown in Figure 1.

We observe that accuracy increased continuously as the amount of training instances increased, and the standard deviation of the results between the cross-validation folds decreased. This suggests that the use of more training data is likely to provide even higher accuracy. It should be noted, however, that accuracy increases at a much slower rate after 15,00015,000 training instances.

Finally, we also examine a confusion matrix for the character 44-gram model, as shown in Figure 2. This demonstrates that the greatest degree of confusion lies between hate speech and generally offensive material, with hate speech more frequently being confused for offensive content. A substantial amount of offensive content is also misclassified as being non-offensive. The non-offensive class achieves the best result, with the vast majority of samples being correctly classified.

Conclusion

In this paper we applied text classification methods to distinguish between hate speech, profanity, and other texts. We applied standard lexical features and a linear SVM classifier to establish a baseline for this task. The best result was obtained by a character 4-gram model achieving 78%78\% accuracy. The results presented in this paper showed that distinguishing profanity from hate speech is a very challenging task.

This was to the best of our knowledge one of the first experiments to detect hate speech on social media in a scenario including non-hate speech profanity. Previous work so far (e.g. Burnap and Williams (2015) and Djuric et al. (2015)) dealt with the distinction between hate speech and socially acceptable texts in a binary classification setting. In binary classification, Dinakar et al. (2011) note that the frequency of offensive words helps classifiers to distinguish between hate speech and socially acceptable texts.

We see a few directions in which this work could be expanded such as the use of more robust ensemble classifiers, a linguistic analysis of the most informative features, and error analysis of the misclassified instances. These aspects are presented in more detail in the next section.

In future work we would like to investigate the performance of classifier ensembles and meta-learning for this task. Previous work has applied these techniques to a number of comparable text classification tasks, achieving success in competitive shared tasks. Examples of recent applications include automatic triage of posts in mental health forums Malmasi et al. (2016b), detection of lexical complexity Malmasi et al. (2016a), Native Language Identification Malmasi and Dras (2017), and dialect identification Malmasi and Zampieri (2017).

Another direction to pursue is the careful analysis of the most informative features for each class in this dataset. Our initial exploitation of the most informative words unigrams and bigrams suggests that coarse and obscene words are very informative for both Hate and Offensive words which confuses the classifiers. For Hate we observed a prominence of words targeting ethnic and social groups. Finally, an interesting outcome that should be investigated in more detail is that many of the most informative bigrams for the Ok feature grammatical words. A more detailed analysis of these features could lead to more robust feature engineering methods.

An error analysis could also help us better understand the challenges in this task. This could be used to provide insights about the classifiers’ performance as well as any underlying issues with the annotation of the Hate Speech Detection dataset which, as pointed out by Ross et al. (2016), is far from trivial. Figure 2 confirms that, as expected, most confusion occurs between Hate and Offensive texts. However, we also note that a substantial amount of offensive content is misclassified as being non-offensive. The aforementioned error analysis can provide insights about this.

Acknowledgments

We would like to thank the anonymous RANLP reviewers who provided us valuable feedback to increase the quality of this paper.

We further thank the developers and the annotators who worked on the Hate Speech Dataset for making this important resource available.

References