Mental Health Text Classification
This competition is hosted on Zindi, a machine learning platform for data science challenges.
TL;DR: In small-data NLP with noisy text, preprocessing quality determines the ceiling. Spelling correction, domain-specific whitelists, and problem decomposition produce more lift than model sophistication. When you have 600 samples, every token matters — treat vocabulary curation as a first-class engineering task.
The Problem
Classifying mental health text from university students in Kenya required understanding that the language used doesn't follow standard English NLP patterns. Students wrote short free-text responses to "What is on your mind?" and these needed to be classified into four categories: Depression, Alcohol, Suicide, and Drugs. The text was messy — spelling errors fragmented the vocabulary, Kenyan slang introduced words that standard dictionaries would flag as errors, and code-switching between English and Swahili meant no single language model could handle everything.
The dataset was small — approximately 600 training samples. This immediately ruled out large neural networks and pretrained language models that need thousands of examples to fine-tune effectively. With so few samples, every engineering decision had to extract maximum signal from minimal data. Overfitting was the constant threat, and any approach that added parameters without proportional signal would hurt rather than help.
The four categories have very different linguistic signatures. Depression is expressed in emotional language ("feeling worthless," "can't sleep"). Drug references use specific substance names, often in slang (bhang, miraa, muguka). Alcohol mentions drinking patterns and social contexts. Suicide uses direct or indirect references to self-harm. A single model treating all four equally would miss these structural differences.
My Approach
I started with the vocabulary problem. Standard TF-IDF treats "depressd," "deppressed," and "depressed" as three separate tokens — tripling the sparsity and diluting the signal. My pipeline applied UDPipe tokenization followed by hunspell spelling correction to unify variants before feature extraction. But I couldn't blindly correct everything — Kenyan slang terms like "bhang" (cannabis), "miraa" (khat), and "muguka" (a stimulant plant) are legitimate words that hunspell would try to "fix." I whitelisted these terms to preserve their signal while correcting genuine misspellings.
Rather than training a single multi-class model, I decomposed the problem into one-vs-rest binary classifiers. Each class gets its own model, specialized in detecting that specific category's language patterns. Depression language differs structurally from drug references — a model trained specifically for depression can learn emotional vocabulary patterns without being confused by substance names, and vice versa. The ensemble averages probabilities across these specialized classifiers independently per class.
For text representation, I built TF-IDF with sublinear scaling and L2 normalization to handle the short, variable-length statements. LSA (Latent Semantic Analysis) with exactly 4 latent dimensions — matching the 4 target classes — added semantic structure to the sparse matrix, giving gradient-boosted models a denser signal to work with alongside the sparse bag-of-words features.
Recognizing that no single representation would dominate on such small data, I tested multiple embedding strategies in parallel: TF-IDF + XGBoost (sparse bag-of-words with boosting), GLMNet Ridge (regularized logistic regression, historically strong on sparse text), Keras embedding (task-specific 16-dimensional learned embeddings), and StarSpace via ruimtehol (joint text-label embedding space). The final prediction was a simple average of all models' probabilities — deliberately avoiding a stacking meta-learner that would overfit on 600 samples.
Key Decisions
Spelling Correction with Slang Whitelist
Hunspell correction unifies misspelling variants, but Kenyan substance slang (bhang, miraa, muguka) must be preserved. The whitelist prevents false corrections that would destroy critical signal for the Drugs category — where these exact terms carry the most predictive power.
One-vs-Rest Decomposition
Each mental health category gets its own specialized binary classifier. Depression language patterns differ structurally from drug references. Specialized models learn category-specific vocabulary without interference from other classes' signals.
Multiple Representation Strategies
With only 600 training samples, no single text representation dominates. Testing sparse (TF-IDF), regularized linear (GLMNet), learned embeddings (Keras), and joint embedding (StarSpace) in parallel maximizes the chance that at least one captures the relevant signal for each class.
Simple Average Ensemble (No Meta-Learner)
With 600 samples, a stacking meta-learner would overfit immediately. Simple averaging of diverse model families reduces variance without adding parameters. The diversity comes from fundamentally different text representations, not from tuning blend weights.
Key Takeaway
The main lesson from this project: when data is small and text is noisy, preprocessing decisions matter more than model architecture. The spelling correction with domain-specific whitelist, the one-vs-rest decomposition, and the decision to avoid a meta-learner — these design choices collectively mattered more than which gradient boosting library I used. In small-data NLP, the engineer who understands the language and the domain will always outperform the one who throws more compute at the problem.
Design insight: In small-data NLP with noisy text, preprocessing quality determines the ceiling. Spelling correction, domain-specific whitelists, and problem decomposition produce more lift than model sophistication. When you have 600 samples, every token matters — treat vocabulary curation as a first-class engineering task.
Related Insights
NLP Classification in 2018 vs LLMs Today →LLM Image Classification →
FAQ
What is the key takeaway from "Mental Health NLP"?
In small-data NLP with noisy text, preprocessing quality determines the ceiling. Spelling correction, domain-specific whitelists, and problem decomposition produce more lift than model sophistication. When you have 600 samples, every token matters — treat vocabulary curation as a first-class engineering task.
Who wrote this and what is it about?
This was written by Mahmoud Trigui, Senior Data Scientist. Classifying university student text for a mental health chatbot using NLP techniques. Ranked Top 36% (492/900 competitors) on Zindi, July 2020.