Skip to main content
QUICK REVIEW

[Paper Review] Offensive Language and Hate Speech Detection with Deep Learning and Transfer Learning

Bencheng Wei, Jason Li|arXiv (Cornell University)|Aug 6, 2021
Hate Speech and Cyberbullying DetectionComputer Science1 references19 citations
TL;DR

This paper proposes a deep learning approach combining Bi-LSTM with transfer learning using BERT, DistilBERT, and GPT-2 for classifying tweets into hate speech, offensive language, or neither. Using a public dataset of 24,783 tweets, the authors achieve over 92% accuracy after hyperparameter tuning, with the ALBERT model outperforming other transfer learning architectures in classification performance.

ABSTRACT

Toxic online speech has become a crucial problem nowadays due to an exponential increase in the use of internet by people from different cultures and educational backgrounds. Differentiating if a text message belongs to hate speech and offensive language is a key challenge in automatic detection of toxic text content. In this paper, we propose an approach to automatically classify tweets into three classes: Hate, offensive and Neither. Using public tweet data set, we first perform experiments to build BI-LSTM models from empty embedding and then we also try the same neural network architecture with pre-trained Glove embedding. Next, we introduce a transfer learning approach for hate speech detection using an existing pre-trained language model BERT (Bidirectional Encoder Representations from Transformers), DistilBert (Distilled version of BERT) and GPT-2 (Generative Pre-Training). We perform hyper parameters tuning analysis of our best model (BI-LSTM) considering different neural network architectures, learn-ratings and normalization methods etc. After tuning the model and with the best combination of parameters, we achieve over 92 percent accuracy upon evaluating it on test data. We also create a class module which contains main functionality including text classification, sentiment checking and text data augmentation. This model could serve as an intermediate module between user and Twitter.

Motivation & Objective

  • To address the growing challenge of toxic online speech, particularly hate speech and offensive language in social media content.
  • To develop an automated, scalable solution for classifying tweets into three categories: hate speech, offensive language, or neither.
  • To improve classification accuracy by leveraging transfer learning with pre-trained language models such as BERT, DistilBERT, and GPT-2.
  • To optimize model performance through hyperparameter tuning using Keras Tuner, focusing on learning rate, dropout, and dense layer configurations.
  • To create a reusable, modular NLP pipeline for text classification, sentiment analysis, and data augmentation in brand safety applications.

Proposed method

  • The authors train a Bi-LSTM model using both random and pre-trained GloVe embeddings to establish a baseline for text classification.
  • They apply transfer learning using three pre-trained models: BERT, DistilBERT, and GPT-2, fine-tuning them for the three-class hate speech classification task.
  • Hyperparameter tuning is performed using the Keras Tuner library, optimizing hidden units, dropout rates, and learning rates across both LSTM and dense layers.
  • The model is trained with a batch size of 128 and 20 epochs, using the Adam optimizer and categorical cross-entropy loss.
  • A custom class module is developed to support text classification, sentiment analysis via TextBlob, and data augmentation for improved robustness.
  • Model evaluation is conducted using test data, with performance measured via accuracy, confusion matrices, and a cost-benefit analysis of false positives and false negatives.

Experimental results

Research questions

  • RQ1Can transfer learning models like BERT, DistilBERT, and GPT-2 outperform traditional Bi-LSTM models with random or GloVe embeddings in classifying offensive language and hate speech?
  • RQ2What is the optimal combination of hyperparameters (e.g., learning rate, dropout, hidden units) for maximizing classification accuracy in a Bi-LSTM architecture on this dataset?
  • RQ3How do false positive and false negative predictions impact brand safety, and how can model performance be optimized to minimize costly misclassifications?
  • RQ4To what extent does data imbalance affect model performance, and how can data augmentation and normalization techniques mitigate this?
  • RQ5Can a modular, reusable NLP pipeline be effectively built to support real-time offensive language detection in social media monitoring?

Key findings

  • The best-performing model, a fine-tuned ALBERT-based transfer learning model, achieved over 92% accuracy on the test set, outperforming both Bi-LSTM with random embeddings and other transfer learning models.
  • Hyperparameter tuning significantly improved model performance, with optimal settings including 352 and 320 LSTM units, 0.65 and 0.80 dropout rates, and 0.0001 learning rate.
  • Among the transfer learning models, the base ALBERT model showed the highest accuracy, followed by DistilBERT and GPT-2, indicating strong performance for smaller, distilled models in this task.
  • Sentiment analysis using TextBlob revealed that hate speech and offensive language tweets had similar subjectivity (≈0.4) but more negative polarity than neutral tweets (subjectivity ≈0.3).
  • The model demonstrated a strong ability to distinguish between offensive language and neutral content, though class 0 (hate speech) and class 1 (offensive language) shared overlapping vocabulary, increasing classification difficulty.
  • A public GitHub repository with a Jupyter notebook is provided to enable reproducibility and deployment of the ALBERT-based model for real-world brand safety applications.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.