NLRG at SemEval-2021 Task 5: Toxic Spans Detection Leveraging BERT-based Token Classification and Span Prediction Techniques

Gunjan Chhablani, Yash Bhartia, Abheesht Sharma, Harshit Pandey, Shan Suthaharan · DOI

Abstract

Toxicity detection in text has traditionally focused on sequence-level classification. However, the SemEval-2021 Task-5 (Toxic Spans Detection) shifts this focus toward identifying specific character-level spans within passages. This paper investigates the performance of BERT-based models—specifically BERT, RoBERTa, and SpanBERT—across two primary paradigms: Token Classification and Span Prediction. We further explore hybrid architectures, including Multi-Span prediction, joint Span+Token learning, and LSTM-CRF layers. Our findings indicate that Token Classification generally outperforms Span Prediction for this task. By intersecting predictions from multiple model checkpoints, we achieved a top post-evaluation F1 score of 0.6895, significantly outperforming baseline models.

Introduction

Automated content moderation often relies on binary labels (toxic vs. non-toxic) for entire comments. While useful, this approach lacks the granularity needed for human moderators to quickly identify problematic sections or for users to receive specific feedback. The Toxic Spans Detection task addresses this by requiring models to output the exact character offsets of offensive language. This task is inherently more complex than binary classification, as it requires the model to understand the precise boundaries of toxicity within diverse linguistic contexts.

Methodology

We evaluated several architectures based on Transformer models to determine the most effective strategy for span detection.

Overview of the investigated BERT-based architectures for toxic span detection, including (a) Token Classification, (b) Span+Token, (c) Span Prediction, (d) Multi-Spans, and (e) LSTM-CRF.

Core Architectures

  1. Token Classification (TC): A linear layer is applied to the output of each token embedding to predict a binary "toxic" or "non-toxic" label. This treats the problem as a sequence labeling task.
  2. Span Prediction (SP): Borrowing from extractive Question Answering (e.g., SQuAD), the model is prompted with a dummy question and tasked with predicting the start and end indices of a toxic span.

Hybrid and Advanced Approaches

  • Multi-Spans (MSP): A variation of span prediction designed to handle sentences with multiple, non-contiguous toxic segments using multi-label classification.
  • Spans+Token (SP-TC): A joint-learning approach where the model is trained simultaneously on both TC and SP objectives.
  • LSTM-CRF: A Bi-directional LSTM layer followed by a Conditional Random Field (CRF) is added on top of the BERT embeddings to better capture dependencies between neighboring token labels.
  • Ensembling Strategies: We utilized "Union" and "Intersection" methods to combine predictions from different architectures or different training checkpoints of the same model.

Key Insights and Results

Token Classification vs. Span Prediction

Our experiments consistently showed that Token Classification models outperform Span Prediction models. We hypothesize that BERT’s self-attention mechanism is better suited for representing individual token interactions than for defining span boundaries. The representation of a single token appears more robust than the representation of a span's start and end points, particularly when toxic spans are short or fragmented.

The Power of Intersection

A significant performance boost was observed when taking the intersection of predictions from the top three checkpoints of a model. This strategy effectively filters out "noise" or over-sensitive predictions where a model might flag non-toxic words as toxic. This approach led to our best post-evaluation F1 score of 0.6895 using RoBERTa-TC.

Model Size and Domain Pre-training

Interestingly, standard "BASE" models occasionally outperformed "LARGE" models or those pre-trained specifically on toxic data (like ToxicBERT). This suggests that for a dataset of 10,000 samples, larger models may be more prone to overfitting. However, the SBT-TC (SpanBERT Token Classification) model remained a strong contender, likely due to SpanBERT's pre-training objective which focuses on representing contiguous text spans.

Qualitative Challenges

Models often struggle with contextual ambiguity. For example, the word "ignorant" can be a neutral descriptor or a toxic slur depending on the surrounding text. Models frequently predicted such words as toxic even when they were not marked as such in the ground truth, highlighting the subjective nature of human annotation in this domain.

Conclusion

Our study demonstrates that treating toxic span detection as a token-level classification problem is currently the most effective approach. While hybrid models like Multi-Span were designed to address the limitations of standard span prediction, they did not consistently outperform simple Token Classification. Future work will focus on refining the integration of these architectures and exploring the "degree of toxicity" to better handle the inherent subjectivity of offensive language.

Summary updated

Abstract

Toxicity detection of text has been a popular NLP task in the recent years. In SemEval-2021 Task-5 Toxic Spans Detection, the focus is on detecting toxic spans within passages. Most state-of-the-art span detection approaches employ various techniques, each of which can be broadly classified into Token Classification or Span Prediction approaches. In our paper, we explore simple versions of both of these approaches and their performance on the task. Specifically, we use BERT-based models -- BERT, RoBERTa, and SpanBERT for both approaches. We also combine these approaches and modify them to bring improvements for Toxic Spans prediction. To this end, we investigate results on four hybrid approaches -- Multi-Span, Span+Token, LSTM-CRF, and a combination of predicted offsets using union/intersection. Additionally, we perform a thorough ablative analysis and analyze our observed results. Our best submission -- a combination of SpanBERT Span Predictor and RoBERTa Token Classifier predictions -- achieves an F1 score of 0.6753 on the test set. Our best post-eval F1 score is 0.6895 on intersection of predicted offsets from top-3 RoBERTa Token Classification checkpoints. These approaches improve the performance by 3% on average than those of the shared baseline models -- RNNSL and SpaCy NER.
BibTeX
@inproceedings{chhablani2021nlrg,
  author = {Gunjan Chhablani and Yash Bhartia and Abheesht Sharma and Harshit Pandey and Shan Suthaharan},
  title = {{NLRG at SemEval-2021 Task 5: Toxic Spans Detection Leveraging BERT-based Token Classification and Span Prediction Techniques}},
  booktitle = {SemEval @ ACL},
  year = {2021},
  url = {https://openreview.net/forum?id=Qay8ZJvXm4q},
}
Figure