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.
Core Architectures
- 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.
- 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