The Silent Signals in the Feed
Social media platforms are frequently where people voice severe emotional distress long before reaching out to hotlines or counselors. However, manual content moderation cannot read through millions of daily posts in time to flag urgent crisis signals.
For an Artificial Intelligence course project at Telkom University, my team and I explored automated text triage.
The objective was to build an NLP classification pipeline capable of sorting Twitter/X posts into two categories: Not Suicide (standard everyday expression) and Potential Suicide (posts containing self-harm risk markers), surfacing high-risk content for human review.
Raw Twitter / X Posts
│
▼
Regex & NLTK Text Cleaning
(Strip @mentions, URLs, hashtags, lowercase)
│
▼
The High-Dimensional Trap
(Decision Trees memorize rare words
and overfit on sparse vocabulary)
│
▼
TF-IDF Feature Representation
│
▼
GridSearchCV Hyperparameter Search
(1,760 Combinations, 8,800 5-Fold Fits)
├── min_samples_split = 15
└── max_leaf_nodes = 35
│
▼
Holdout Evaluation (90.0% Accuracy)
├── Not Suicide: Recall 0.94
└── Potential Suicide: Recall 0.85
│
▼
Streamlit Triage Simulator
The High-Dimensional Overfitting Trap
Our baseline classifier was a standard Scikit-learn DecisionTreeClassifier trained on a TF-IDF word matrix.
On the initial training run, the unconstrained tree scored a flawless 99.4% training accuracy. But when evaluated on holdout validation data, accuracy plunged below 78%.
Text data represented as TF-IDF is sparse and high-dimensional. A Decision Tree left to its own devices will branch down to individual unique words, creating deep leaves that memorize idiosyncratic phrases from specific training posts (such as a specific band lyric or username typo) rather than learning generalized sentiment patterns.
Unconstrained Tree:
Split 1 (word_A) -> Split 2 (word_B) -> ... -> Leaf (1 sample, 100% pure)
Result: Flawless training score, broken generalization on unseen posts.
How do we force a Decision Tree to only split on patterns supported by meaningful sample clusters?
Systematic Tuning Across 8,800 Model Fits
To curb this overfitting, we constrained the tree’s growth parameters using 5-fold cross-validation.
We ran a comprehensive grid search exploring 1,760 hyperparameter combinations, resulting in 8,800 individual model fits:
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import GridSearchCV
param_grid = {
'criterion': ['gini', 'entropy'],
'min_samples_split': [2, 5, 10, 15, 20],
'max_leaf_nodes': [15, 25, 35, 50],
'max_depth': [10, 20, 30, None]
}
grid_search = GridSearchCV(
estimator=DecisionTreeClassifier(random_state=42),
param_grid=param_grid,
cv=5,
n_jobs=-1,
scoring='f1_weighted'
)
grid_search.fit(X_train_tfidf, y_train)
The optimal configuration converged on:
- Splitting criterion:
gini - Minimum samples to split:
min_samples_split = 15 - Maximum leaf nodes:
max_leaf_nodes = 35
Setting min_samples_split = 15 forced the algorithm to require at least fifteen supporting examples before carving out a decision branch. Capping max_leaf_nodes = 35 stopped the tree from sprawling into thousands of micro-rules.
Evaluation Results and Asymmetric Risk
With the pruned tree, the model achieved 90.0% accuracy on the holdout test set, outperforming our Multinomial Naive Bayes baseline:
| Post Category | Precision | Recall | F1-Score |
|---|---|---|---|
| Not Suicide | 0.91 | 0.94 | 0.93 |
| Potential Suicide | 0.89 | 0.85 | 0.87 |
Looking at the class breakdown reveals an important trade-off. The model achieved 0.94 recall on standard posts, but 0.85 recall on at-risk posts, meaning roughly 15% of distressing messages slipped through undetected.
In mental health triage, this asymmetry carries weight. A false positive flags an ordinary sad post for a human moderator to double-check. A false negative leaves someone in distress without timely support. In a production deployment, the decision boundary would need to be shifted aggressively toward recall, accepting lower precision in exchange for catching more at-risk posts.
Interactive Reviewer App in Streamlit
To test the pipeline interactively, I wrapped the preprocessing steps and serialized vectorizer in a lightweight Streamlit interface:
Moderator Inputs Post Text
│
▼
Regex Clean & Tokenize
│
▼
TF-IDF Sparse Transform
│
▼
Constrained Decision Tree
│
▼
Color-Coded Triage Classification
A reviewer can type or paste a post snippet, and the app cleans the text, runs TF-IDF vectorization, and displays the risk category alongside confidence metrics.
What I Learned
This capstone showed me that tree-based algorithms on text require strict structural limits. Without pruning, decision trees memorize vocabulary noise rather than learning semantic signals.
It also highlighted the ethical reality of building automated moderation tools. Machine learning can serve as an efficient first-pass filter, but algorithms should never be final decision-makers when human well-being is at stake.