A deep learning-based system for detecting and classifying hate speech in Vietnamese social media content.
vn-hate-speech-detection/
├── data/ # Data directory
│ ├── raw/ # Raw datasets
│ ├── processed/ # Preprocessed data
│ └── sample/ # Sample data for testing
├── models/ # Saved model checkpoints
├── notebooks/ # Jupyter notebooks for exploration
├── src/
│ ├── data/ # Data loading and preprocessing
│ ├── models/ # Model architectures
│ ├── training/ # Training utilities
│ ├── evaluation/ # Evaluation metrics
│ ├── inference/ # Prediction interface
│ └── utils/ # Utility functions
├── scripts/ # Training and evaluation scripts
├── config/ # Configuration files
├── requirements.txt # Python dependencies
└── README.md # This file
git clone https://github.com/DHPh/vn-hate-speech-detection.git
cd vn-hate-speech-detection
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python scripts/download_dataset.py --output_dir data/raw --prepare
python -m pip install underthesea
Download the ViHSD dataset:
python scripts/download_dataset.py --prepare
Or use it in your code:
from src.data.dataset import HateSpeechDataset
from src.data.preprocessor import VietnamesePreprocessor
# Load and preprocess data
preprocessor = VietnamesePreprocessor()
dataset = HateSpeechDataset(data_path="data/processed/vihsd_processed.csv", preprocessor=preprocessor)
python scripts/train.py --data data/processed/vihsd_processed.csv --model phobert --epochs 10 --batch_size 16
from src.inference.predictor import HateSpeechPredictor
predictor = HateSpeechPredictor(model_path="models/best_model.pth")
text = "Your Vietnamese text here"
result = predictor.predict(text)
print(f"Label: {result['label']}, Confidence: {result['confidence']:.2f}")
python src/inference/api.py
Then access the API at http://localhost:8000/docs
This project uses the ViHSD (Vietnamese Hate Speech Detection) dataset from HuggingFace.
free_text (text content) and label (0: normal, 1: hate speech)python scripts/download_dataset.py --output_dir data/raw --prepare
This will:
You can also use your own CSV dataset with columns:
text: Vietnamese text contentlabel: Binary label (0: normal, 1: hate speech) or multi-class labelsExample:
text,label
"Văn bản tiếng Việt bình thường",0
"Văn bản chứa nội dung xúc phạm",1
Edit config/config.yaml to customize:
Results will be saved in:
models/: Trained model checkpointsresults/: Evaluation metrics and plotslogs/: Training logsContributions are welcome! Please feel free to submit a Pull Request.
MIT License
If you use this project, please cite:
@software{vn_hate_speech_detection,
title={Vietnamese Social Media Hate Speech Detection},
author={Your Name},
year={2025}
}
A deep learning-based system for detecting and classifying hate speech in Vietnamese social media content.
vn-hate-speech-detection/
├── data/ # Data directory
│ ├── raw/ # Raw datasets
│ ├── processed/ # Preprocessed data
│ └── sample/ # Sample data for testing
├── models/ # Saved model checkpoints
├── notebooks/ # Jupyter notebooks for exploration
├── src/
│ ├── data/ # Data loading and preprocessing
│ ├── models/ # Model architectures
│ ├── training/ # Training utilities
│ ├── evaluation/ # Evaluation metrics
│ ├── inference/ # Prediction interface
│ └── utils/ # Utility functions
├── scripts/ # Training and evaluation scripts
├── config/ # Configuration files
├── requirements.txt # Python dependencies
└── README.md # This file
git clone https://github.com/DHPh/vn-hate-speech-detection.git
cd vn-hate-speech-detection
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python scripts/download_dataset.py --output_dir data/raw --prepare
python -m pip install underthesea
Download the ViHSD dataset:
python scripts/download_dataset.py --prepare
Or use it in your code:
from src.data.dataset import HateSpeechDataset
from src.data.preprocessor import VietnamesePreprocessor
# Load and preprocess data
preprocessor = VietnamesePreprocessor()
dataset = HateSpeechDataset(data_path="data/processed/vihsd_processed.csv", preprocessor=preprocessor)
python scripts/train.py --data data/processed/vihsd_processed.csv --model phobert --epochs 10 --batch_size 16
from src.inference.predictor import HateSpeechPredictor
predictor = HateSpeechPredictor(model_path="models/best_model.pth")
text = "Your Vietnamese text here"
result = predictor.predict(text)
print(f"Label: {result['label']}, Confidence: {result['confidence']:.2f}")
python src/inference/api.py
Then access the API at http://localhost:8000/docs
This project uses the ViHSD (Vietnamese Hate Speech Detection) dataset from HuggingFace.
free_text (text content) and label (0: normal, 1: hate speech)python scripts/download_dataset.py --output_dir data/raw --prepare
This will:
You can also use your own CSV dataset with columns:
text: Vietnamese text contentlabel: Binary label (0: normal, 1: hate speech) or multi-class labelsExample:
text,label
"Văn bản tiếng Việt bình thường",0
"Văn bản chứa nội dung xúc phạm",1
Edit config/config.yaml to customize:
Results will be saved in:
models/: Trained model checkpointsresults/: Evaluation metrics and plotslogs/: Training logsContributions are welcome! Please feel free to submit a Pull Request.
MIT License
If you use this project, please cite:
@software{vn_hate_speech_detection,
title={Vietnamese Social Media Hate Speech Detection},
author={Your Name},
year={2025}
}