Classify text from university students in Kenya towards a mental health chatbot
# Mental Health Text Classification
This competition is hosted on Zindi, a machine learning platform for data science challenges.
Here is the link to the competition: Basic Needs Basic Rights Kenya - Tech4MentalHealth 🌾 - $4 200 USD
Ranked in the TOP 35%
---
**Competition**: Zindi – AI4D iCompass Social Media Sentiment Analysis for Mental Health
**Date**: Late 2021
**Language**: R
## Task
Classify short free-text statements from Kenyan university students into four mental health categories: Depression, Alcohol, Suicide, Drugs. Statements respond to "What is on your mind?" and contain spelling errors, slang, and code-switching.
## Engineering Decisions
### 1. Spelling Correction Before Tokenization
Student text is noisy—misspellings fragment the vocabulary ("depressd", "deppressed", "depressed" → three separate tokens in TF-IDF). The pipeline applies UDPipe tokenization followed by hunspell correction, unifying variants before feature extraction. Kenyan slang terms (bhang, miraa) are whitelisted to avoid false corrections.
```r
tokens$is_correct <- hunspell_check(tokens$token)
slang_terms <- c("bhang", "miraa", "muguka", "shisha", "weed", "meth")
tokens$is_correct[tokens$token %in% slang_terms] <- TRUE
```
### 2. One-vs-Rest Decomposition
Rather than training a single multi-class model, each class gets its own binary classifier. This lets different models specialize—depression language patterns differ structurally from drug references. The ensemble averages probabilities across models independently per class.
### 3. TF-IDF + LSA (4 latent topics)
Sublinear TF-IDF with L2 normalization handles the short, variable-length statements. LSA with exactly 4 latent dimensions (matching the 4 classes) adds semantic structure to the sparse matrix, giving gradient-boosted models a denser signal.
### 4. Multiple Representation Strategies
The pipeline tests multiple embedding approaches in parallel:
- **TF-IDF + XGBoost**: sparse bag-of-words with boosting
- **GLMNe …