[Paper Review] Offensive Language Detection with BERT-based models, By Customizing Attention Probabilities
This paper proposes a method to enhance BERT-based models for offensive language detection by customizing attention masks using offensive scores derived from Multinomial Naive Bayes probabilities. By reweighting attention probabilities to focus more on offensive phrases, the approach improves F1-macro scores by up to 10% on Persian and 2% on English datasets, demonstrating effectiveness across languages and model architectures.
This paper describes a novel study on using `Attention Mask' input in transformers and using this approach for detecting offensive content in both English and Persian languages. The paper's principal focus is to suggest a methodology to enhance the performance of the BERT-based models on the `Offensive Language Detection' task. Therefore, we customize attention probabilities by changing the `Attention Mask' input to create more efficacious word embeddings. To do this, we firstly tokenize the training set of the exploited datasets (by BERT tokenizer). Then, we apply Multinomial Naive Bayes to map these tokens to two probabilities. These probabilities indicate the likelihood of making a text non-offensive or offensive, provided that it contains that token. Afterwards, we use these probabilities to define a new term, namely Offensive Score. Next, we create two separate (because of the differences in the types of the employed datasets) equations based on Offensive Scores for each language to re-distribute the `Attention Mask' input for paying more attention to more offensive phrases. Eventually, we put the F1-macro score as our evaluation metric and fine-tune several combinations of BERT with ANNs, CNNs and RNNs to examine the effect of using this methodology on various combinations. The results indicate that all models will enhance with this methodology. The most improvement was 2% and 10% for English and Persian languages, respectively.
Motivation & Objective
- To improve the performance of BERT-based models in detecting offensive language by dynamically adjusting attention mechanisms.
- To address the limitation of standard attention in missing subtle offensive cues by focusing more on high-impact offensive phrases.
- To develop a language-agnostic methodology applicable to both English and Persian, validated on distinct datasets.
- To explore the impact of attention mask customization using statistical probability estimation for offensive content.
- To demonstrate consistent performance gains across diverse architectures (CNN, RNN, ANN) fine-tuned with the proposed attention reweighting.
Proposed method
- Tokenize training data using BERT’s tokenizer and compute offensive scores via Multinomial Naive Bayes on token-level probabilities of offensive vs. non-offensive labels.
- Define language-specific equations to re-distribute attention mask values based on offensive scores, increasing attention on high-scoring tokens.
- Integrate the modified attention mask into BERT-based models, replacing standard attention input to guide attention toward offensive phrases.
- Fine-tune various combinations of BERT with feedforward networks, CNNs, RNNs (BiLSTM, BiGRU), and hybrid architectures on both OLID (English) and POLID (Persian) datasets.
- Use F1-macro as the primary evaluation metric to assess model performance across folds in 5-fold cross-validation.
- Apply error analysis to identify cases where the enhanced model corrects misclassifications made by standard models, particularly involving idiomatic or contextually offensive expressions.
Experimental results
Research questions
- RQ1Can reweighting attention masks using offensive scores improve the F1-macro performance of BERT-based models in offensive language detection?
- RQ2How does the proposed attention customization affect model performance across different neural architectures (e.g., CNN, RNN, feedforward networks)?
- RQ3To what extent does the method generalize across languages, particularly between English and Persian, given differing linguistic structures?
- RQ4What are the failure cases of the enhanced model, and what limitations exist in offensive score estimation for rare or ambiguous offensive terms?
- RQ5Can statistical estimation of offensive probabilities via Multinomial Naive Bayes effectively guide attention reweighting without requiring manual annotation per token?
Key findings
- The proposed method improved F1-macro scores by up to 10% on the Persian POLID dataset, with the best-performing model achieving an average F1 of 0.8630 using CNN2D with equation 6.
- On the English OLID dataset, the method yielded a maximum improvement of 2% in F1-macro, with the best model (CNN2D + equation 6) reaching an average F1 of 0.8630.
- All tested model architectures (BiLSTM, BiGRU, CNN2D, CNN-BiLSTM, KUISAIL) showed consistent performance gains when using the customized attention mask.
- Error analysis confirmed that the enhanced model correctly classified instances involving idiomatic or contextually offensive expressions—such as Persian idioms like 'muzmaars'—that standard models misclassified.
- The model failed on certain cases involving low-offensive-score tokens (e.g., offensive word with score ~0.53) due to insufficient probability estimation by Multinomial Naive Bayes, indicating a limitation in score calibration.
- The method demonstrated robustness across diverse architectures, suggesting that attention mask customization is a generalizable enhancement for offensive language detection.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.