UHH-LT at SemEval-2020 Task 12: Fine-Tuning of Pre-Trained Transformer Networks for Offensive Language Detection

Fine-tuning of pre-trained transformer networks such as BERT yield state-of-the-art results for text classification tasks. Typically, fine-tuning is performed on task-specific training datasets in a supervised manner. One can also fine-tune in unsupervised manner beforehand by further pre-training the masked language modeling (MLM) task. Hereby, in-domain data for unsupervised MLM resembling the actual classification target dataset allows for domain adaptation of the model. In this paper, we compare current pre-trained transformer networks with and without MLM fine-tuning on their performance for offensive language detection. Our MLM fine-tuned RoBERTa-based classifier officially ranks 1st in the SemEval 2020 Shared Task 12 for the English language. Further experiments with the ALBERT model even surpass this result.


Offensive Language Detection
The automatic detection of hate-speech, cyber-bullying, or aggressive and offensive language became a vividly studied task in natural language processing (NLP) in recent years. The offensive language detection (OLD) shared Task 6 of 2019's International Workshop on Semantic Evaluation (SemEval) (Zampieri et al., 2019b) attracted submissions from more than 100 teams. The Offensive Language Identification Dataset (OLID) used in this shared task comprises three hierarchical classification sub-tasks: A) offensive language detection, B) categorization of offensive language, and C) offensive language target identification (Zampieri et al., 2019a). For Task A, 14,100 Twitter tweets were manually labeled as either offensive (OFF) or not offensive (NOT). Task B distinguishes the 4,640 offensive tweets from task A into targeted (TIN) or general, untargeted (UNT) offensive language. Task C, finally, separates targeted insults into the three categories: groups (GRP), individuals (IND), and others (OTH).
OffensEval 2020, the SemEval 2020 Offensive Language Detection Shared Task, does not provide an own manually labeled training set for the English language (Zampieri et al., 2020). Instead, a large 'weakly labeled' dataset was published by the organizers, containing roughly nine million tweets. Each tweet has been automatically classified by an ensemble of five different supervised classifiers trained on the OLID dataset. The weakly labeled dataset contains the raw tweet (with user mentions replaced by a special 'USER' token) along with the average label probability and the variance of the five classifier predictions. Since there is no way that such weak labels themselves carry more useful information to a machine learning system than the original dataset on which the five classifiers were trained, we decided not to use any of the weakly labeled information. Instead, for our classification systems, we rely on the 2019 OLID dataset only. However, the OffensEval 2020 dataset is an ample source to build models using unsupervised learning, particularly for domain-adaptation of a pre-trained language model such as BERT (Devlin et al., 2019) or its successors which are based on the transformer neural network architecture. Unfortunately, training a transformer-based language model in an unsupervised manner is incredibly resource-consuming, making it impractical to learn from large datasets without access to larger GPU clusters or TPU hardware. Regarding this, the contribution of our paper is two-fold: 1. We evaluate to what extent different pre-trained transformer-based neural network models can be fine-tuned to detect offensive language and its sub-categories. An ensemble based on the ALBERT (Lan et al., 2019) model achieves the best overall performance.
2. We study how an additional fine-tuning step with masked language modeling (MLM) of the best individual model RoBERTa (Liu et al., 2019b) conducted on in-domain data affects the model performance. An ensemble of models trained with this strategy was submitted as our official contribution to the OffensEval 2020 shared task for the English language and achieved first place in the competition.

Related Work
Offensive language detection: Nowadays, a number of public datasets are available to train machine classifiers for detecting English offensive language. Unfortunately, underlying data sources, category definitions, data sampling strategies, and annotation guidelines differ to a large extent between these datasets. Hence, results of different datasets are hardly comparable, and training sets usually cannot be combined to obtain a more robust classification system. Schmidt and Wiegand (2017), and Fortuna and Nunes (2018)  Although winning systems can achieve striking prediction accuracy, OLD is far from being a solved problem. Prediction performance usually drops severely if the target data comprises different characteristics than the training data. Gröndahl et al. (2018), for instance, show that many machine learning architectures can be fooled easily just by adding the word "love" to an offensive tweet to make it appear as non-offensive. Struß et al. (2019) highlight that linguistic information alone is not enough in many cases to decide whether a tweet is hateful or not. Also context information, e.g. about tweeting users themselves (Ribeiro et al., 2018), or mentioned users in tweets (Wiedemann et al., 2018) can be a useful feature for automatic OLD.
Pre-trained language models for text classification: Transfer learning with deep neural networks, in general, has proven to be superior over supervised learning for text classification, especially for small training data situations. This is illustrated exemplarily in our last year's approach (Wiedemann et al., 2019) to the OLD SemEval shared task which employed unsupervised pre-training of a recurrent neural network architecture with a topic cluster prediction task. Practically all winners of the aforementioned shared task competitions employ some form of a fine-tuned bidirectional transformer-based language model, a neural network architecture for which Devlin et al. (2019) published with BERT the seminal work. This architecture has been proven highly successful for transfer learning. A base model is pretrained with a MLM task and a next-sentence prediction (NSP) task in an unsupervised manner on very large datasets. The knowledge about language regularities and semantic coherence encoded in the network during this step can then be employed successfully in later training steps of fine-tuning the network weights to the actual classification task. Since BERT, a number of successor models improving the network architecture, the pre-training strategy, or the pre-training dataset have been published. A selection of these models will be evaluated in Section 3.

Fine-tuning Transformer Networks
We investigate two questions regarding the fine-tuning of pre-trained transformer networks for OLD. First, which pre-trained model performs best on the 2020 OLD shared task? Second, we investigate how much language model fine-tuning on in-domain data prior to classification fine-tuning improves the performance of the best model.

Model Selection of Transformer Networks
As we have indicated in Section 2, transformer networks have been successfully employed for several text classification tasks. We test the following transformer-based pre-trained models for the OffensEval 2020 OLD shared task.
BERT -Bidirectional Encoder Representations from Transformers: this seminal transformerbased language model employs an attention mechanism that enables to learn contextual relations between (sub-)words in a text sequence (Devlin et al., 2019). BERT uses two training strategies: 1) MLM where 15 % of the tokens in a sequence are replaced (masked) for which the model learns to predict the original tokens, and 2) NSP where the model receives pairs of sentences as input and learns to predict whether or not the second sentence is a successor of the first one in their original document context.

RoBERTa -A Robustly Optimized BERT Pretraining
Approach: this is a replication of BERT developed by Facebook (Liu et al., 2019b) with the following modifications 1) training the model longer with bigger batches as well as more and cleaner data, 2) discard the NSP objective, 3) training on longer sequences, and 4) dynamically change the masking patterns, e.g. taking care of masking complete multiword units. RoBERTa outperformed BERT on most tasks of the GLUE NLP benchmark (ibid.).
XLM-RoBERTa -XLM-R: this is a cross-lingual version of RoBERTa which is trained on several languages at once (Conneau et al., 2019). The model itself is equivalent to RoBERTa, but the training data consists of texts from more than 100 languages filtered from the CommonCrawl 1 dataset.
ALBERT -A Lite BERT for Self-supervised Learning of Language Representations: this is a modification on BERT especially to mitigate memory limitations and training time issues (Lan et al., 2019). The main contributions that ALBERT makes over the design choices of BERT are 1) decomposing the embedding parameters into smaller matrices that will be projected to the hidden space separately, 2) share parameters across layers to improve or stabilize the learned parameters, and 3) inter-sentence coherence loss, which is based on sentence order prediction (SOP), in contrast to BERT's simpler NSP objective.

Masked Language Model Fine-tuning
Sun et al. (2019) showed that further pre-training of BERT with the masked language model task can improve later results of supervised task-specific fine-tuning. The authors tested within-task, in-domain and cross-domain further pre-training. Evaluations show that the first strategy is susceptible to overfit the training set and, thus, may harm classification performance. The last strategy does not help since BERT is already trained on general-domain data. In-domain further pre-training, however, helps to improve later classification performance if there is a substantial overlap in language characteristics between further pre-training data and supervised training data. The 'weakly labeled' dataset of the 2020 OLD shared task most certainly is a valuable dataset for further in-domain pre-training. However, with ca. 9 million tweets it is also rather large. Pre-training on the complete dataset is not possible regarding our hardware limitations. 2 Therefore, we conduct MLM pre-training only on a small sample of the original data. We strip URLs and user mentions from tweets, remove duplicates and, finally, randomly sample 5 % of the original dataset size, i.e. 436.123 tweets for further pre-training. We further pre-train the presumably best model RoBERTa-large (Liu et al., 2019b) (cp. Section 4) for one epoch (batch size 4, and learning rate 2e-5).

Ensembling
For our official OffensEval 2020 test set submission as team UHH-LT, we aggregated predictions from classifiers with different ensemble approaches.

Ensemble of model variants:
We fine-tuned different transformer models with the OffensEval 2019 training data using the corresponding test data for validation. The following models were tested: BERTbase and BERT-large (uncased), RoBERTa-base and RoBERTa-large, XLM-RoBERTa, and four different ALBERT models (large-v1, large-v2, xxlarge-v1, and xxlarge-v2). Each model was fine-tuned for 6 epochs with a learning rate of 5e-6, maximum sequence length of 128, and batch size 4. After each epoch, the model was evaluated on the validation set. The best performing epoch was saved for the ensembling. We tested two ensemble approaches: 1) majority vote from all models, and 2) majority vote from one model type but with different parameter sizes such as BERT-base and BERT-large.

MLM RoBERTa ensemble:
To be able to learn from the entire 2019 OLID dataset (training and test set), as well as to smooth instabilities of predictions originating from random effects during model training, we also aggregated predictions using 10-fold cross-validation. For this, the further MLM pretrained RoBERTa-large model is fine-tuned 10 times, each time with 90 % of the OLID data for training and the remaining 10 % as validation set. The best model after 6 epochs of training with learning rate 5e-6 and batch size 8 is used to predict the OLD 2020 test data. The final predictions for submission were obtained via majority vote on the 10 predictions per test data instance. Table 1 shows results of binary offensive language detection for a naive baseline (assuming all tweets as either offensive or not), as well as for the individual fine-tuned transformer models and their corresponding ensembles. All transformer models largely outperform the naïve baseline, some of them (e.g. XLM-RoBERTa) even outperform most of the other system submissions in the competition. 3 Our best individual model is RoBERTa-large with an F1-score of 91.96 %. Hence, we select this model as the basis for further MLM pre-training. From Table 2, we can see that the MLM fine-tuned RoBERTa model achieved consistently better results in terms of Macro F1 than the single pre-trained transformer models (to lower random effects of neural network training, the table shows average values of 10 runs).   Regarding the ensembles of model variants, we see in Table 1 that all approaches consistently perform better than the individual models. Here, the ensemble averaging the predictions from the two ALBERTxxlarge models performed best with an F1-score of 92.25 %.

Results
For the OffensEval 2020 Shared Task, we decided to submit the results form the MLM pre-trained RoBERTa ensemble. 4 Table 3 presents the official results of our system in the sub-tasks A, B, and C together with their ranks achieved in the competition. While our ensemble reaches the top rank for task A, there are a handful of competing approaches achieving better results for offensive language categorization (B) and target identification (C). The post-submission experiments on the official test set as presented in this paper (cp. Table 1) show that the ALBERT-based ensembles would have even beat this first ranked submission. However, the MLM fine-tuned RoBERTa model was considerably more successful on task C than the best ALBERT-xxlarge ensemble, especially to detect the "OTH" class. Figure 2 shows the corresponding confusion matrices for the submitted predictions. One observation that can be revealed from the matrices is that the predictions for Tasks B and C are considerably biased towards the majority class. For Task A, however, we see more false positive cases for the offensive class which is underrepresented in the training data. A qualitative look into a sample of false predictions (cp. Fig. 1) reveals tweets wrongly predicted as offensive (false positives), some of which seem inconsistently annotated in the gold standard. Parts of expressions in Examples 1, and 2 qualified as offensive in many other training examples. Examples 3, and 4 contain some negative words that may have triggered a higher offensiveness prediction score. For the false negative samples, it is not really obvious why the models missed the correct class, since except for example 6, they actually contain strong offensive vocabulary.

Conclusion
After last year's SemEval shared task on offensive language detection was already dominated by the then newly published BERT model, for the year 2020 competition we were successful in fine-tuning BERT's successor models to create the best performing system. The predictions obtained from fine-tuning of the ALBERT model on the OLID dataset achieved 92.25 % macro F1-score as the best overall result (including our post-submission experiments) on the official test set of the Shared Task A for the English language. We also found the 'weak labels' distributed along with 9 million tweets by the shared task organizers not useful for training our classifiers. However, the tweets themselves provided useful indomain data for unsupervised pre-training. With 92.04 % macro-F1, our predictions based on further language model pre-training of the RoBERTa model on ca. 440.000 tweets, before fine-tuning on last year's OLID dataset achieved the first rank in the official SemEval competition for sub-task A, and also high ranks (6, and 3) for the other two sub-tasks. We conclude that further pre-training of a transformer 1. FP: @USER the gov and nyc mayor are the biggest joke except maybe for the idiots who elected them 2. FP: @USER What the fuck 3. FP: @USER I know it was bad but I used to love it 4. FP: men who voted yes are childish, sorry are you 17??Men, would you have a problem if a girl said if she's not receiving head she's not giving head?
5. FN: @USER It's as if every single one of her supporters are just as stupid as her. Wehdone..   model with in-domain data is useful for offensive language detection. However, for tasks B and C, our models are clearly biased towards the majority class resulting in somewhat lower ranks. Hence, taking the high class imbalance of the OLID dataset better into account could further improve our results.