U o B at S em E val-2021 Task 5: Extending Pre-Trained Language Models to Include Task and Domain-Specific Information for Toxic Span Prediction (2021)

Abstract: Toxicity is pervasive in social media and poses a major threat to the health of online communities. The recent introduction of pre-trained language models, which have achieved state-of-the-art results in many NLP tasks, has transformed the way in which we approach natural language processing. However, the inherent nature of pre-training means that they are unlikely to capture task-specific statistical information or learn domain-specific knowledge. Additionally, most implementations of these models typically do not employ conditional random fields, a method for simultaneous token classification. We show that these modifications can improve model performance on the Toxic Spans Detection task at SemEval-2021 to achieve a score within 4 percentage points of the top performing team.

## introduction and motivation moderation is crucial to promoting healthy online discussions. the anonymity afforded by computermediated communication enables individuals to engage in toxic behaviour which they would otherwise not consider. although many datasets and models focusing on toxicity detection have been released, most of them classify entire sequences of text, and do not highlight the individual words that make a text toxic. the toxic spans detection task at semeval-2021 @xcite focuses on the evaluation of systems that can accurately identify toxic spans within text. highlighting such spans can provide more information to human moderators in the form of attribution, instead of an unexplained toxicity score per post, and is thus a crucial step towards successful semi-automated moderation. in this paper we focus on the shared task, wherein systems are expected to extract a list of toxic spans, or an empty list, per text. a toxic span is defined as a sequence of words that contributes to a text's toxicity. since 2018, nlp models have adopted the concept of generative pre-training on a diverse corpus of unlabelled text, followed by supervised finetuning on specific tasks @xcite . pretrained models are built to simulate anthropomorphic learning, wherein existing knowledge can be adapted to new tasks without the need to train on these tasks from scratch -a requirement of traditional machine learning models. this idea of transfer learning, whilst powerful, leads to models being fine-tuned on target tasks using significantly fewer epochs than was previously standard. this reduced training on the target task means that taskspecific statistical information or domain-specific knowledge may not be learned by these models. such task-specific data may include count-based information, which has been shown to improve the performance of pre-trained models in sequence classification tasks (lim and madabushi, 2020; prakash and madabushi, 2020), or domain-specific knowledge, such as information pertaining to word toxicity, which has been shown to be one of the most predictive features of offensive commentary @xcite . additionally, pre-trained models tend to use a fully connected layer for classification tasks. this classification layer, however, makes an individual localised prediction for each token without accounting for predictions made on other tokens. a crf @xcite , on the other hand, maximises the probability of the entire sequence of predictions. this makes it more effective for cases where neighbouring predictions may influence each other. ner is one such application, where the decision to assign a certain label to a token may be influenced by the labels assigned to neighbouring tokens. @xcite combined the transfer capabilities of bert @xcite with the structured predictions of a crf, with the addition of a crf yielding performance improvements in several token-level tasks. thus, this work aims to test the following hypotheses: hypothesis 1 count-based information can aid pre-trained models in token classification tasks. hypothesis 2 pre-trained models are unlikely to capture domain-specific information. such information is likely to improve their performance in token classification tasks. hypothesis 3 adding a crf, which affords a sentence-level predictive scope, will improve pretrained model performance in token classification tasks. to ensure reproducibility, our program code, including hyperparameters, is made available online foot_0 . ## related work count-based information has been shown to improve the performance of pre-trained models in sequence classification tasks. lim and madabushi (2020) proposed an ensemble model of bert and tf-idf, which combined the sentence-level information captured by bert with the corpus-level information provided by tf-idf. the ensemble model performed 5 percentage points better than a standard bert model on subtask a at offenseval-2020 @xcite , achieving a score within 2 percentage points of the top performing team. similarly, prakash and madabushi (2020) employed an ensemble model of roberta @xcite with a multilayer perceptron using tf-idf features as input. the ensemble model improved upon the base roberta model by 7 percentage points to achieve state-of-the-art results on the rumoureval-2019 dataset @xcite . we use these studies as a basis for our first hypothesis described in section 1, and employ a similar method for incorporating tf-idf features described in section 3. domain-specific information has been shown to be an effective measure of toxicity. noever (2018) evaluated the relative predictive value of 28 features of syntax, sentiment, emotion, and outlier word dictionaries for online toxicity detection. by rank-ordering features through feature selection, the most predictive feature of offensive commentary was shown to be a simple bad word list. peder-sen (2019) compared two logistic regression classifiers against a simple word list model on subtask a at offenseval @xcite , with the rule-based model performing 4 percentage points better than either logistic regression model. section 3 discusses our methodology for adding word list features, which capture key word information in the offensive language domain, to pre-trained models. as discussed in section 1, a crf is a method for simultaneous token classification which is not commonly employed by pre-trained models. @xcite proposed a bert-crf model architecture composed of a token-level classifier on top of a bert model followed by a linear-chain crf. models with a crf improved upon or performed similarly to models without one on ner tasks in the portuguese language. this study is, to the best of our knowledge, one of the few that directly compares the performance of a base bert model against a bert-crf model. the improvements arising from adding a crf supports our third hypothesis described in section 1, which aims to explore whether similar improvements will arise in the context of toxic span detection. submissions to past toxicity detection tasks at semeval, such as offenseval and offenseval-2020, highlight how effective bert can be for toxicity detection. @xcite used a fine-tuned bert model to achieve state-of-the-art results on subtask a at offenseval, and seven of the top ten teams used bert. similarly, the top ten teams on subtask a at offenseval-2020 all used bert, roberta, or xlm-roberta @xcite , sometimes as part of ensemble models with cnns and lstms. @xcite submitted the best performing model, which used an ensemble of albert @xcite ) models of different sizes. the success of these models in toxicity detection tasks led us to choose to use a bert-based model for this work. ## methodology our pre-trained model of choice was distilbert @xcite ), which we used as a baseline measure of performance. we explore and present four models in addition to the baseline distilbert model in this paper: in section 1, we hypothesised that adding countbased information to pre-trained models would improve model performance in token classification tasks. tf-idf is a count-based statistical measure that captures corpus-level information, accounting for global correlations and associations between words. use of tf-idf captures word importance, enabling the identification of key words. this word importance could contribute to the identification of a text's toxicity, as shown by lim and madabushi (2020); @xcite . thus, we tested our first hypothesis by integrating tf-idf with the distilbert model. one of the most straightforward approaches for toxicity detection is to use a word list, whereby the toxicity of a sequence is determined by comparing the words it contains against a list of known toxic words. such domain-specific information has been shown to be effective for toxicity detection @xcite . we tested our second hypothesis by adapting a word list feature for token classification and integrating it with the distilbert model. we incorporated the tf-idf and word list features by modifying the distilbert model. first, we removed the token classification layer on top of the baseline distilbert model. then, for the tf-idf feature, we appended each token's tf-idf weight to its hidden state output vector. for the word list feature, we appended a value of 0 or 1. a value of 1 was used if the token appeared in the word list, whilst a value of 0 was used if it did not. these vectors were then pushed through a fully connected layer for classification. we tested our third hypothesis by adding a crf, a method for simultaneous token classification, to the distilbert model. we followed the more successful fine-tuning approach used by @xcite , which uses a linear classification layer and updates all weights, including bert's, during training. the crf takes the output scores from the classification layer as input and computes the loglikelihood of the given sequence of tags. the model was trained to maximise the log-likelihood of the correct tag sequence. as model performance on the validation dataset was very similar, all models were submitted to the task evaluation stage. it is clear that the f1 scores achieved by all models were very similar when tested against the test dataset, with the distilbert+tf-idf model improving upon the baseline distilbert model the most. it is worth noting, however, that whilst this difference is only 0.00672, that same difference would have increased our ranking by 6 ranks had it been added to our final f1 score. section 5 analyses the significance of the results achieved and studies the differences between the predictions of the distilbert and distilbert+tf-idf models in greater detail. ## discussion and analysis it is difficult to conclude with any certainty whether the addition of our proposed features improved model performance, as the scores achieved are very similar. whilst the increase in performance observed may indeed be due to our additions to the model, we also propose two alternative theories. the similarity in results may be due to the relative length of the token vectors compared to the length of the additional features. the hidden output from distilbert represents each token as a vector of length 768; the addition of one or two elements to each token vector may not be significant enough to discernibly impact model predictions. that being said, there are still small variations in performance between the models. whilst this may be due to the addition of new features, it may also be due to variations in the random seed used during fine-tuning. our most improved model performed 0.00672 f1 points better than the baseline distil-bert model -a figure within the performance variation range observed during tests involving the random seed (the distilbert+tf-idf model ranged by 0.00922 from 0.58008 to 0.58930, for example). despite our efforts to counteract this, time and resource limitations meant we were only able to train each model five times instead of the more rigorous ten. we conduct a more detailed analysis into the predictions of the baseline distilbert model and our best performing (distilbert+tf-idf) model. tables 4 and 5 show the confusion matrix of each model, respectively. these matrices are constructed using a subset of the test dataset from which the tokens correctly predicted by both models to be non-toxic have been removed. we subset the dataset in this way to significantly reduce the size of the data and to remove less interesting tokens. ## conclusion and future work this work explored the possibility of improving pre-trained model performance on the token classification task of toxic span detection. as discussed in section 1, we hypothesised that adding 1) countbased information, 2) domain-specific knowledge, and 3) a crf can aid pre-trained models in token classification tasks. whilst our experimental results (section 4) seem to suggest that all three of these features improve the performance of distilbert, we note that they do so only marginally (section 5). further analysis, however, showed that, whilst the overall f1 improvement from adding tf-idf was small, the addition of a count-based feature helped to reduce distilbert's overprediction of toxic tokens. we believe that these improvements, whilst small, provide an interesting avenue of exploration. we intend to further explore how these and other similar features interact with pre-trained models in the task of token classification.