MLNLPCase Studies

Myanmar Hate Speech Analysis with XLM-RoBERTa

From Burmese text data to hate speech detection analysis.

GitHub
Myanmar Hate Speech Analysis with XLM-RoBERTa

Focus

NLP, Hate Speech Detection, Transformer Fine-Tuning

Scope

Burmese hate speech detection model comparison

Role

Data preparation, model training, evaluation, analysis

Summary

Overview

Myanmar Hate Speech Analysis with XLM-RoBERTa is an NLP project for Burmese hate speech detection and model comparison. Using the myHateSpeech corpus, the workflow cleans annotation tags, prepares binary and nine-label setups, trains character-level TF-IDF baselines, BiLSTM, and XLM-RoBERTa, and evaluates model behavior with accuracy, macro F1, weighted F1, and confusion matrix analysis.

Case Study

NLP model comparison workflow

01

Project overview

Burmese NLPhate speech analysismodel comparison

The project explores how different NLP approaches handle Burmese hate speech analysis across sparse features, sequence learning, and transformer fine-tuning.

  • Uses the myHateSpeech corpus to study sentence-level harmful language categories.
  • Moves beyond a simple hate versus non-hate setup to compare nine-label prediction.
  • Benchmarks sparse text features, sequence learning, and transformer fine-tuning in one workflow.
  • Evaluates overall performance and class-balanced behavior instead of relying on one metric.

02

Dataset and labels

myHateSpeech corpussentence-level labels9 classes

The myHateSpeech dataset contains Burmese/Myanmar sentences with sentence-level labels. The main task predicts one of nine categories: abusive, religious, racist, body-shaming, political, sexist, lethal, educational, and non-hate speech.

  • The raw dataset is kept outside the GitHub repository because of dataset licensing and redistribution rules.
  • The main experiment uses a nine-label hate speech setup.
  • A binary hate versus non-hate label is also created as an early pipeline check.
Label
Meaning
ab
Abusive Hate Speech
re
Religious Hate Speech
ra
Racist Hate Speech
bo
Body-Shaming Speech
po
Political Hate Speech
se
Sexist Speech
le
Lethal Speech
ed
Educational Hate Speech
no
No Hate Speech

03

Sample text format

Burmese textsafe exampleslabel mapping

The portfolio shows Burmese/Myanmar examples in a safe and non-offensive format so the input format is clear without repeating harmful content.

  • Original harmful text is not displayed on the public page.
  • The models still train on the labeled dataset used in the experiments.
  • Each sentence maps to one sentence-level label before training.
Input Text
Label
Model Task
ဒီနေ့ သတင်းတွေ ဖတ်ပြီး အမြင် မျှဝေချင်ပါတယ်
no
No hate speech
ဒီ နိုင်ငံရေး အခြေအနေကို ဆွေးနွေးသင့်တယ်
po
Political speech category
သူ့ပုံစံကို လှောင်ပြောင်တာ မသင့်တော်ပါ
bo
Body-shaming category

04

Data preparation

raw parsingtag removalclean textlabel mapping

The raw corpus includes word-level annotation tags such as /ab, /bo, and /ed|ab. These markers are removed from the model input while the sentence-level label is kept for training and evaluation.

  • Keeps Burmese/Myanmar text and emojis instead of over-cleaning the corpus.
  • Creates a processed CSV used by all training notebooks.
  • Uses one consistent preprocessing pipeline across all model families.
Step
Purpose
Raw parsing
Extracts tagged Myanmar sentences and sentence-level labels.
Tag removal
Removes word-level tags from the input text while preserving the original words.
Clean text creation
Creates model-ready text for TF-IDF, BiLSTM, and XLM-RoBERTa.
Label preparation
Creates both binary labels and nine-label targets for experiments.

05

TF-IDF baseline models

TF-IDFLogistic RegressionLinear SVM

The baseline setup uses character-level TF-IDF features with Logistic Regression and Linear SVM. Character n-grams help when Burmese spacing and tokenization are inconsistent.

  • The baseline is fast, practical, and effective for repeated character patterns.
  • It provides a realistic benchmark before moving to deeper architectures.
  • It produced the strongest macro F1 in the final comparison.
Component
Use in Project
Character-level TF-IDF
Converts text into character n-gram features without relying on perfect word tokenization.
Logistic Regression
Provides a simple traditional machine learning baseline.
Linear SVM
Provides a strong text baseline for sparse TF-IDF features.
Macro F1
Checks class-balanced performance across imbalanced categories.

06

BiLSTM sequence model

Embedding layerBiLSTMsequence modeling

The BiLSTM baseline treats each sentence as a token sequence and learns from word order before predicting one of the nine labels.

  • The BiLSTM provides a deep learning sequence baseline.
  • It reached moderate accuracy but weak macro F1.
  • The results suggest difficulty with minority labels.
Layer / Step
Purpose
Tokenizer
Converts clean Myanmar text into integer token sequences.
Padding
Converts variable-length text into fixed-length input sequences.
Embedding layer
Learns dense vector representations for tokens.
Bidirectional LSTM
Reads the sentence from both directions to capture sequence context.
Softmax output
Produces probabilities across the nine hate speech labels.

07

XLM-RoBERTa transformer fine-tuning

XLM-RoBERTaHugging FaceTransformer fine-tuning

The transformer experiment fine-tunes xlm-roberta-base, a pretrained multilingual transformer model, for Burmese hate speech analysis.

  • Uses pretrained multilingual knowledge instead of training from scratch.
  • Self-attention helps the model focus on informative parts of each sentence.
  • This model achieved the best overall accuracy and weighted F1.
Step
Purpose
XLM-R tokenizer
Converts Myanmar text into token IDs and attention masks.
MAX_LENGTH = 128
Limits each input to 128 tokens to balance context and training efficiency.
XLM-RoBERTa base
Provides pretrained multilingual language representations.
Classification head
Maps transformer output to the nine hate speech labels.
Fine-tuning
Updates the pretrained model on the myHateSpeech training split.

08

Model comparison results

78.2% accuracy77.2% weighted F157.9% TF-IDF macro F1

The final comparison shows a clear tradeoff: XLM-RoBERTa leads on overall performance with 78.2% accuracy and 77.2% weighted F1, while TF-IDF achieved the strongest macro F1.

  • XLM-RoBERTa delivered the strongest overall result.
  • TF-IDF stayed competitive and led on macro F1.
  • BiLSTM lagged on class-balanced performance.
  • The comparison shows why metric choice matters for imbalanced label sets.
Model
Accuracy
Macro F1
Weighted F1
TF-IDF Baseline
0.679
0.579
0.690
BiLSTM
0.659
0.220
0.606
XLM-RoBERTa
0.782
0.532
0.772
Myanmar hate speech model comparison chart
Model comparison across accuracy, macro F1, and weighted F1 for TF-IDF, BiLSTM, and XLM-RoBERTa.

09

Confusion matrix analysis

Class-level evaluationMinority labelsMisclassification patterns

The confusion matrix is used to inspect class-level prediction behavior and identify where the transformer confuses similar or underrepresented categories.

  • It shows which labels are predicted more reliably than others.
  • It helps locate overlap between similar or sparse categories.
  • This adds detail that summary metrics alone can miss.
XLM-RoBERTa confusion matrix for Myanmar hate speech analysis
Confusion matrix showing XLM-RoBERTa prediction behavior across the nine hate speech categories.

10

Build Stack

The stack combines Python data processing, traditional NLP baselines, deep learning sequence modeling, and Hugging Face transformer fine-tuning.

PythonPandasNumPyscikit-learnTF-IDFLogistic RegressionLinear SVMTensorFlowKerasBiLSTMPyTorchHugging Face TransformersXLM-RoBERTaNatural Language ProcessingMulti-Class NLPModel EvaluationMatplotlib

11

Limitations

class imbalancecontext sensitivitynot production moderation

This project is a portfolio case study, not a production moderation system.

  • Hate speech detection can be sensitive to sarcasm, slang, coded language, and social context.
  • Some labels have fewer examples, which affects macro F1 and minority-label reliability.
  • The model may confuse categories with overlapping wording or similar harmful expressions.
  • The dataset comes from a specific source and time period, so generalization should be tested further.
  • The model should not be used for automatic moderation without additional validation and human review.

12

Reflection

TF-IDFBiLSTMXLM-RoBERTamodel evaluation

This project shows how traditional NLP baselines, sequence models, and transformers behave differently on imbalanced Burmese text tasks.

  • Reinforced why strong baselines are important before using deeper models.
  • Improved evaluation around macro F1, weighted F1, and class imbalance.
  • Fine-tuned a pretrained multilingual transformer using Hugging Face Trainer.
  • Connected model results with the practical limits of automated content analysis.

More Projects

View all projects