IITK @Detox at S em E val-2021 Task 5: Semi-Supervised Learning and Dice Loss for Toxic Spans Detection (2021)

Abstract: In this work, we present our approach and findings for SemEval-2021 Task 5 - Toxic Spans Detection. The task’s main aim was to identify spans to which a given text’s toxicity could be attributed. The task is challenging mainly due to two constraints: the small training dataset and imbalanced class distribution. Our paper investigates two techniques, semi-supervised learning and learning with Self-Adjusting Dice Loss, for tackling these challenges. Our submitted system (ranked ninth on the leader board) consisted of an ensemble of various pre-trained Transformer Language Models trained using either of the above-proposed techniques.

## introduction content moderation has become the topic of most conversations regarding social media platforms. however, with over 4 billion active internet users, it is impossible to moderate each piece of message generated online manually. therefore, the focus is now shifting towards tackling the issue using machine learning methods. various toxicity detection datasets @xcite and models @xcite @xcite have been successfully developed over the years to tackle the issue of moderation. however, these have mostly focused on identifying whole comments or documents as either toxic or not. in semi-automated settings, a model merely generating a toxicity score for each comment, some of which can be very lengthy, is not of much help to human moderators. to tackle this issue, the se-meval 2021 task 5 : toxic spans detection is introduced @xcite . the task involves identifying text spans in a given toxic post that contributes towards the toxicity of that post. the task aims to promote the development of a system that would augment human moderators by giving them more insights into what actually contributes to the text's toxicity. the task is challenging mainly due to the following reasons: a) small size of the dataset b) characteristics of text samples extracted from social media leading to difficulties such as out-of-vocabulary words and ungrammatical sentences c) class imbalance in the dataset d) inconsistencies in data annotations. we approached this task as a subtoken level sequence labeling task. fine-tuned pretrained transformer language models (qiu et al., 2020) are the backbone of all our approaches. we investigated two main techniques to enhance the results of the fine-tuned transformer models, namely semi-supervised learning @xcite and fine-tuning with self-adjusting dice loss @xcite . this paper reports the results of our experiments with these different techniques and pre-trained transformer models. our submitted system consisted of an ensemble of different pre-trained transformer models and achieved an f1 score of 0.6895 on the test set and secured 9th position on the task leaderboard. all of our code is made publicly available on github foot_0 . the rest of this paper is organized as follows. section 2 discusses the previous works in the fields of offensive language detection and span identification. section 3 describes the dataset. section 4 explains the proposed approaches. section 5 reports the results of various experiments with the proposed approaches, and section 6 analyzes the proposed approaches via ablation studies. we conclude with an error analysis of our model performance in section 7 and concluding remarks in section 8. ## related work as the task involves detecting toxic spans in a text, we present the related work in two parts: (i) offensive language detection and (ii) span identification. offensive language detection: research work has been done on different abusive and offensive language identification problems, ranging from aggression @xcite to hate speech @xcite , and offensive language @xcite . recent contributions to offensive language detection came from the semeval-2019 task 6 offenseval @xcite . the task organizers concluded that most top-performing teams either used bert @xcite or an ensemble model to achieve sota results. interestingly, the task of locating toxic spans is relatively novel, and its successful completion can be groundbreaking. a recent approach with a narrower scope is by @xcite , who focused on the rationality of decision in the task of hate speech detection. ## experiments and results the competition used the span level f1 score, calculated individually for each text sample from its character offsets and averaged over all the text samples, as the metric to evaluate system performance. we decided to use this metric for hyperparameter tuning and reporting the final results. however, during the training process, the models were checked for overfitting using the token level f1 score, which was also a good indicator of model performance as our training approach was that of a sequence labeling task. the first set of experiments we performed were on the div-a dataset. our baseline model achieved an f1 score of 0.669 on the dev split on this set. the organizers also released a baseline model, consisting of a spacy statistical model trained on the competition training dataset and evaluated on the competition trial dataset. the organizer's baseline achieved an f1 score of 0.600 on the trial dataset. this score was significantly lower than that of our baseline model, and therefore we use our baseline model only to compare the performance of our subsequent models. we then fine-tuned a bert-base-cased model with the self-adjusting dice loss and adamw optimizer and tuned the loss function's two hyperparameters. the scores we obtained for the different hyperparameter values are reported in ## ablation study after the competition, we wanted to study the effect of our different preprocessing and postprocessing techniques. we employ three main data cleaning techniques during our preprocessing, expanding contractions, removing numbers, and removing full stops. to study each particular technique's impact, we created three new div-b datasets, each having the results show that removing numbers and expanding contractions both had contrasting effects on the two models. this shows that we could have yielded better results by trying different preprocessing techniques for the different transformer models. apart from that, we see that the most positive effect on model performance came from removing full stops from the training data in both cases. we also wanted to see the effect of our postprocessing step. for that, we compared the performance of the bert-base-cased model on the div-b dev split. as expected, the results showed minor improvement due to our postprocessing as the score increased from 0.6748 to 0.6754. ## error analysis the results we have obtained have brought to light some problems that need to be resolved. first of all, the data annotations have many issues, leading to a lower f1 score even though the predicted in some cases, the annotations are not uniform in what toxicity label they assign to the same word over different text samples. we have also observed that complete sentences were marked as toxic just because of the presence of a few toxic words in them. these irregularities in the annotations make it difficult for the model to generalize on the data. besides the incorrect annotations, we further try to analyze the type of mistakes our system is making. the dataset contains numerous examples where no toxic spans are annotated. such a case arose when the annotators had difficulty in attributing toxicity to a particular span. investigating our model performance shows that our model highly under-performs on such examples. in addition to the empty span examples, we also discover that our model fails to capture the full context in some cases. for e.g., in the phrase "no more chinese," our model only predicts the word chinese as toxic, whereas the complete phrase attributes to the toxicity of the sentence. another problem is our model's inconsistency in labeling the corresponding noun and adjective pairs in a sentence. however, similar types of inconsistencies were also found in the annotations and are therefore difficult to avoid [appendix d]. ## conclusion the task of detecting toxic spans in the text is a novel one, and there is no doubt about how impor-tant a model trained successfully for this task can turn out to be for online content moderation. however, the data gathered from online platforms tend to be noisy and corrupted. coupled with the limitations of generating large-scale annotated datasets in real life, they pose two daunting challenges. in conclusion, our final submission shows that transfer learning through pre-trained transformer models can achieve competitive results for this task. using modified loss functions and semi-supervised learning, even more can be extracted from limited annotated data. moreover, considering the subjectivity involved in span detection, the task can also be expanded to report severity scores of spans and classify the type of toxicity. this will further help simplify and rationalize online content moderation.