MIPT - NSU - UTMN at S em E val-2021 Task 5: Ensembling Learning with Pre-trained Language Models for Toxic Spans Detection (2021)

Abstract: This paper describes our system for SemEval-2021 Task 5 on Toxic Spans Detection. We developed ensemble models using BERT-based neural architectures and post-processing to combine tokens into spans. We evaluated several pre-trained language models using various ensemble techniques for toxic span identification and achieved sizable improvements over our baseline fine-tuned BERT models. Finally, our system obtained a F1-score of 67.55% on test data.

## introduction toxic speech has become a rising issue for social media communities. abusive content is very diverse and therefore offensive language and toxic speech detection is not a trivial issue. besides, social media moderation of lengthy comments and posts is often a time-consuming process. in this regard, the task of detecting toxic spans in social media texts deserves close attention. this work is based on the participation of our team, named mipt-nsu-utmn, in semeval 2021 task 5, "toxic spans detection" @xcite . organizers of the shared task provided participants with the trial, train, and test sets of english social media comments annotated at the span level indicating the presence or absence of text toxicity. we formulated the task as a token classification problem and investigated several bertbased models using two-step knowledge transfer. we found that preliminary fine-tuning of the model on data that is close to the target domain improves the quality of the token classification. the source code of our models is available at https: //github.com/morozowdmitry/semeval21. the paper is organized as follows. a brief review of related work is given in section 2. the definition of the task has been summarized in section 3. the proposed methods and experimental settings have been elaborated in section 4. section 5 contains the results and error analysis respectively. section 6 is a conclusion. ## related work computational approaches to tackle text toxicity have recently gained a lot of interest due to the widespread use of social media. since moderation is crucial to promoting healthy online discussions, research on toxicity detection has been attracting much attention. our work is also related to hate speech and abusive language detection @xcite . the toxic speech detection task is usually framed as a supervised learning problem. moreover, fairly generic features, such as bag of words @xcite or word embeddings @xcite , systematically yield reasonable classification performance @xcite . to better understand the mechanisms of toxic speech detection, some scholars @xcite @xcite compared different techniques for abusive language analysis. neural architectures and deep learning methods achieved high results in this domain. thus, @xcite explored the possibilities of deep learning and deep attention mechanisms for abusive comment moderation. @xcite proposed an approach to performing classification on abusive language based on convolutional neural networks (cnn). @xcite used bidirectional long-short term memory network. castelle (2018) experimented with cnn and gated recurrent units. some recent studies @xcite @xcite utilized pre-trained language models such as bidirec-tional encoder representations from transformers (bert) @xcite to detect offensive or abusive language. in recent years, the task of detecting and analyzing abusive, toxic, or offensive language has attracted the attention of more and more researchers. the shared tasks based on carefully curated resources, such as those organized at the semeval @xcite , germeval @xcite , evalita @xcite , and osact @xcite events, have significantly contributed to the progress of the field and to the enrichment of linguistic resources. in addition to the corpora collected for these shared tasks, @xcite released a large-scale dataset for offensive language identification. ibrohim and budi (2018); leite et al. (2020); pitenis et al. (2020); komalova et al. (2021) presented various datasets for abusive speech detection in non-english languages. most of these datasets classify whole texts or documents, and do not identify the spans that make a text toxic. ## shared task the task focuses on the evaluation of systems that detect the spans that make a text toxic, when detecting such spans is possible. the goal of the task is to define a sequence of words (character offsets) that attribute to the toxicity of the text, for example: the sources of data were various posts (comments) from publicly available datasets. the provided dataset contains 10,629 posts split into training (7939), trial (690), and test (2000) subsets. inspired by @xcite , the organizers proposed to employ the f1-score for evaluating the responses of a system participating in the shared task. let system a i return a set s t a i of character offsets, for parts of the post found to be toxic. let g t be the character offsets of the ground truth annotations of t. the f1-score of system a i is calculated with respect to the ground truth g for post t as follows, where | • | denotes set cardinality. the final f1-score is an average f t 1 (a i , g) over all the posts t of an evaluation dataset t to obtain a single score for system a i . ## methodology the stated problem was modified from char-level to token-level binary-classification. the proposed solution utilizes a pre-trained language model with a classification head to classify tokens. different configurations of bert pre-trained as masked language models were considered as a backbone. due to the lack of available token-level labeled public datasets for toxic comment and the relatively small size and sparsity of dataset provided by the competition, the following training pipeline was proposed to enhance knowledge transfer. first, fine-tune pre-trained bert on a larger-scale task of toxic comment classification, using the jigsaw dataset foot_0 from which the competition data were constructed. second, fine-tune obtained model to solve the actual toxic tokens classification problem. the exact training parameters are to be found below. for the first step: for the second step: the final solution contains n ×k models, where n is the number of different backbone bert architectures, k is the number of folds (5 in the current experiments). obtained models are further to be ensembled using different strategies with validation on the single hold-out dataset: ## experiments and results three pre-trained backbone bert architectures were considered: bert-base-uncased, bert-largeuncased @xcite , and bert-base pretrained for hate speech detection (dehate-bert) @xcite . first step setup and results: so as models except bert-base-uncased did not show compatible performance for token classification (and later for tests on the fold 0 did not show good f1-score for the actual task as well), later experiments were continued only for bertbase-uncased pre-trained model fine-tuned on token classification. for step two results are following: the experiments were conducted with huggingface transformers library @xcite . many patterns in our results are expected, but some stand out. in general, our model is good at detecting obscene language and utterances that demean honor and dignity or denote low moral character. we noticed that our model is not very good at identifying the posts that have no toxic span annotations. according to the corpus description, in some toxic posts, the core message is conveyed may be inherently toxic. thus, a sarcastic post can indirectly claim that people of a particular origin are inferior. hence, it was difficult to attribute the toxicity of those posts to particular spans. in such cases, the corresponding posts were labeled as not containing toxic spans. among our results, there are many examples where the model detected spans in not annotated posts, for example: in addition, some texts in the dataset raise questions of the annotation credibility, for example: the final result of our model is presented in ## conclusion this paper introduces our bert-based model for toxic spans detection. as expected, pre-training of the bert model using an additional domainspecific dataset improves further toxic spans detection performance. experimenting with different fine-tuning approaches has shown that our bertbased model benefits from the two-step knowledge transfer technique. an ensemble with spans intersection obtained our best result on the test data. in our future work, we will evaluate various language models, such as distilled versions of bert @xcite and roberta @xcite .