Extended LSTM: Adaptive Feature Gating for Toxic Comment Classification

Noor Islam S. MohammadarXiv 2025 · OpenReview

TL;DR

This paper introduces xLSTM, a lightweight and efficient model for detecting toxic comments, especially those from rare but high-risk categories. By using a novel "cosine-similarity feature gating" mechanism, xLSTM effectively amplifies minority toxic signals while suppressing benign ones, achieving state-of-the-art performance with significantly fewer parameters and faster inference than large transformer models like BERT.

What Problem Does This Paper Address?

Online platforms are flooded with user-generated content, making automated moderation of toxic comments a critical necessity. However, this task is plagued by extreme class imbalance: genuinely harmful comments (like threats or severe toxicity) are rare, making them hard for models to learn. Traditional models like BERT, while powerful, struggle with this imbalance, leading to poor recall on these crucial minority classes. They also come with a hefty computational cost for inference. Simpler models, on the other hand, lack the semantic understanding to catch subtle or context-dependent toxicity. The authors aim to bridge this gap by developing a model that is both semantically aware and highly efficient, with a particular focus on improving the detection of these hard-to-find toxic comments.

Methods

The core innovation of xLSTM is its cosine-similarity feature gating mechanism. Instead of just re-weighting token positions (like standard attention), this method operates at the feature dimension level. It uses a learned "toxicity prototype" vector (v) and calculates the cosine similarity between token embeddings and this prototype. This similarity score is then used to scale the token embeddings, effectively amplifying features that align with toxicity and downplaying those that don't. This is crucial for combating "gradient dilution," where the gradients from rare toxic examples get overwhelmed by those from common benign examples.

Beyond this, xLSTM combines several other techniques:

  • Multi-Source Embeddings: It fuses embeddings from GloVe, FastText, and BERT-CLS to capture diverse linguistic signals.
  • Character-Level BiLSTM: This component handles subword variations and obfuscation tactics used to evade detection.
  • Embedding-Space SMOTE: This data augmentation technique generates synthetic minority class examples in the embedding space to further balance the dataset.
  • Weighted Focal Loss: This loss function assigns higher importance to misclassified toxic examples, helping the model focus on learning them.

Datasets

The primary dataset used is the Jigsaw Toxic Comment Classification dataset. This is a well-known benchmark for toxic comment detection, containing over 159,000 Wikipedia talk-page comments annotated with six binary toxicity labels. The dataset is characterized by severe class imbalance, with the "toxic" class being only about 10.2% of the data, and even rarer labels like "threat" and "severe_toxic" appearing much less frequently.

The paper also mentions evaluating zero-shot transfer on the Contextual Abuse Dataset (CAD), which includes comments from Reddit, Twitter, and news sources, to assess cross-domain generalization.

Key Insights and Ideas

  • Feature-level gating is key: The paper strongly suggests that operating at the feature dimension (cosine similarity) is more effective than position-level attention for handling severe class imbalance. It directly addresses how minority class variance gets compressed.
  • Cosine similarity as a toxicity indicator: Using cosine similarity with a learned prototype provides a principled way to identify and amplify toxicity-aligned features, even when they are subtle.
  • Efficiency doesn't mean sacrificing performance: xLSTM demonstrates that a lightweight, theoretically grounded architecture can outperform massive models like BERT on challenging, imbalanced tasks.
  • Component synergy: While cosine gating is the main driver, the combination of multi-source embeddings, character-level processing, SMOTE, and weighted loss creates a robust system.

Key Results

  • State-of-the-art performance: xLSTM achieved a macro-F1 score of 0.881 on the Jigsaw dataset, outperforming fine-tuned BERT by 6.9 macro-F1 points.
  • Significant minority class improvement: Gains were particularly pronounced on rare labels: +71% for "severe_toxic", +33% for "threat", and +28% for "identity_hate" compared to fine-tuned BERT.
  • Drastic parameter reduction: xLSTM uses only 7.3 million parameters, which is about 15 times fewer than BERT (110 million parameters).
  • Fast inference: The model achieves 48 ms CPU inference latency (classifier-only), making it highly suitable for real-time moderation.
  • Ablation studies confirm effectiveness: Removing cosine gating alone resulted in a -4.8% macro-F1 drop, highlighting its critical contribution.

Limitations and Future Work

  • English-centric: The current model is trained and evaluated on English text. Generalization to other languages and domains is unverified.
  • Noisy annotations: The authors acknowledge that dataset annotations can be noisy and socially contingent.
  • Contextual limitations: The model processes comments in isolation, ignoring broader conversational context.
  • Deployment calibration: Deployment requires careful threshold calibration for specific precision-recall trade-offs.

Future work suggested includes:

  • Multilingual transfer.
  • Incorporating conversational context.
  • Developing fairness-aware training methods.
  • Investigating adversarial robustness.

Summary updated

Abstract

Toxic comment detection remains a challenging task, where transformer-based models (e.g., BERT) incur high computational costs and degrade on minority toxicity classes, while classical ensembles lack semantic adaptability. We propose xLSTM, a parameter-efficient and theoretically grounded framework that unifies cosine-similarity gating, adaptive feature prioritization, and principled class rebalancing. A learnable reference vector {v} in {R}^d modulates contextual embeddings via cosine similarity, amplifying toxic cues and attenuating benign signals to yield stronger gradients under severe class imbalance. xLSTM integrates multi-source embeddings (GloVe, FastText, BERT CLS) through a projection layer, a character-level BiLSTM for morphological cues, embedding-space SMOTE for minority augmentation, and adaptive focal loss with dynamic class weighting. On the Jigsaw Toxic Comment benchmark, xLSTM attains 96.0% accuracy and 0.88 macro-F1, outperforming BERT by 33% on threat and 28% on identity_hate categories, with 15 times fewer parameters and 50ms inference latency. Cosine gating contributes a +4.8% F1 gain in ablations. The results establish a new efficiency adaptability frontier, demonstrating that lightweight, theoretically informed architectures can surpass large pretrained models on imbalanced, domain-specific NLP tasks.
BibTeX
@misc{mohammad2025extended,
  author = {Noor Islam S. Mohammad},
  title = {{Extended LSTM: Adaptive Feature Gating for Toxic Comment Classification}},
  year = {2025},
  eprint = {2510.17018},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.17018},
}
Figure