Research
A Machine Learning Approach for Detection of Mental Health Conditions and Cyberbullying from Social Media
Overview Research area: Natural Language Processing for computational mental health and online safety, specifically multi-class text classification of social media posts. Technical level: Intermediate

- arXiv
- 2511.20001
- Published
- 2025-11-25
- Authors
- Edward Ajayi, Martha Kachweka, Mawuli Deku, Emily Aiken
AI summary
Overview
Research area: Natural Language Processing for computational mental health and online safety, specifically multi-class text classification of social media posts.
Technical level: Intermediate. The paper assumes familiarity with TF-IDF features, BERT-family transformers, fine-tuning, and macro-averaged classification metrics, but the task framing and pipeline are described concretely enough to follow.
Scope: The paper builds and evaluates a unified 10-class classifier for mental health conditions and cyberbullying drawn from aggregated Twitter and Reddit data, and pairs it with an ethically framed human-in-the-loop explainability prototype.
What This Paper Is About
Most prior work predicts mental health conditions from social media using binary labels (for example, depression versus not depression) and treats cyberbullying as a separate, narrow problem. This paper instead merges ten categories of mental health conditions and cyberbullying behaviors into a single multiclass classification task, trained on combined Twitter and Reddit datasets. Its goal is to establish a strong methodological baseline and to package the model not as a diagnostic tool but as a screening aid for trained human moderators.
Key Contributions
- A unified 10-class classification framework spanning both mental health conditions (suicide, depression, anxiety, stress, bipolar disorder, personality disorder) and cyberbullying types (age, gender, ethnicity, religion), trained on data aggregated from Twitter and Reddit via Kaggle.
- A "split-then-balance" data pipeline that deduplicates at the post level, splits 80/20 with stratification, then balances only the training pool using downsampling, deduplication, and EDA-based oversampling — while keeping the held-out test set realistic and imbalanced.
- A comprehensive model comparison across lexical baselines (TF-IDF with logistic regression and SVM), static BERT embedding hybrids (logistic regression, RNN, DNN), four end-to-end fine-tuned transformers (BERT-base, MentalBERT, MentalRoBERTa, ModernBERT), and a zero-shot LLM baseline (GPT-OSS 120B).
- A hybrid SHAP-LLM explainability framework and a prototype "Social Media Screener" dashboard that renders SHAP token importance as red highlights and uses an LLM (GPT-OSS 20B) to produce a plain-language rationale, alongside an ethical analysis framing the system as a human-in-the-loop aid.
Main Findings
- End-to-end fine-tuning is decisive: Finetuned MentalBERT was the top model with accuracy 0.92, Macro F1 0.76, weighted F1 0.93, precision 0.70, and recall 0.89. The other fine-tuned variants were close behind, with Macro F1 scores ranging from 0.70 to 0.71 (BERT 0.70, RoBERTa 0.70, ModernBERT 0.71).
- Hybrid static-embedding models underperform: BERT embedding-based classifiers (BERT_LogReg, BERT_RNN, BERT_DNN) scored Macro F1 between 0.53 and 0.58, the weakest group. The best traditional model, TF-IDF_LogReg, reached Macro F1 0.67 (accuracy 0.82); TF-IDF_SVM reached 0.64.
- Zero-shot LLM baseline was surpassed: The paper states MentalBERT outperformed both a generic counterpart and the zero-shot GPT-OSS 120B baseline; approximately 31.6% of the LLM's responses did not map to a valid label and were excluded from its performance calculation. The LLM's numeric scores are not reported in the provided content.
- Strong per-class results on high-signal classes: MentalBERT achieved F1 of 0.95 (Age CB), 0.96 (Religion CB), 0.93 (Non-Suicide), and 0.96 (Suicide). Its weakest classes were Personality Disorder (0.32), Stress (0.46), and Bipolar (0.70).
- Excellent suicide detection discrimination: All fine-tuned models achieved AUPRC of at least 0.992 on the Suicide class, with MentalBERT and ModernBERT both reaching 0.994. Calibration analysis identified MentalBERT as best calibrated, in contrast to under-confident BERT and over-confident ModernBERT.
- Balancing strategy helps specific rare classes: For MentalBERT, Macro F1 rose from 0.73 to 0.76 and accuracy from 0.90 to 0.92 after balancing. Bipolar F1 rose from 0.49 to 0.70, Anxiety from 0.59 to 0.65, and Personality Disorder from 0.28 to 0.32. Stress F1 was unchanged, which the authors attribute to lexical ambiguity that oversampling cannot resolve.
- Errors reflect semantics, not platform artifacts: Only 2.3% (123 of 5,311) of mental health posts were misclassified as cyberbullying, and 1.5% (10 of 689) of cyberbullying posts were misclassified as mental health. Errors concentrated between semantically related classes such as Anxiety and Stress.
- Weak labels appear reasonably reliable: A manual annotation study on 300 randomly selected posts (1% of the dataset), balanced across all ten classes, produced inter-annotator Cohen's Kappa of 0.76, and agreement with the original labels of 0.71 and 0.94 for the two annotators.
Methodology in Plain English
The authors pooled several existing Kaggle datasets into one master collection of 274,150 posts. The mental health portion covered four conditions (anxiety, stress, bipolar disorder, personality disorder) across 53,043 posts; the cyberbullying portion came from the SOSNet dataset with 47,692 posts labeled as gender, religion, ethnicity, age, "other," or not cyberbullying; and a third dataset of 232,074 posts covered suicidal versus non-suicidal content from the SuicideWatch, depression, and teenagers subreddits.
Text was lowercased and stripped of URLs, user mentions, non-alphanumeric characters, and extra whitespace. To avoid leakage, they deduplicated posts and then split 80/20 with stratification, keeping the test pool in its original imbalanced distribution to reflect reality. Only the training pool was balanced: large classes such as Suicide and Non-Suicide were downsampled, while small classes such as Personality Disorder and Stress were deduplicated and oversampled using EDA techniques that generate synthetic text through synonym replacement, random insertion, random swap, or random deletion.
Three model families were compared. Lexical models used TF-IDF with the top 5,000 features (unigrams and bigrams) fed into logistic regression and a linear SVM, both tuned with 5-fold cross-validation. Hybrid models used frozen CLS embeddings from bert-base-uncased (maximum length 128 tokens) fed into logistic regression, a 128-unit RNN, and a two-layer DNN (256 and 128 units). End-to-end models fine-tuned BERT-base, MentalBERT, MentalRoBERTa, and ModernBERT using AdamW at a learning rate of 2e-5, batch size 16, and a 90/10 train-validation split. A zero-shot GPT-OSS 120B baseline completed the comparison.
Evaluation used accuracy, Macro F1, weighted F1, per-class precision/recall/F1, plus AUPRC and calibration curves for the Suicide class. Explanations were produced by combining SHAP's per-word contribution values with an LLM (GPT-OSS 20B) that writes a narrative rationale, surfaced in a "Social Media Screener" dashboard where a moderator must confirm, dismiss, or re-categorize every flag.
Why This Matters
Impact on research: The paper argues that the field's reliance on weakly labeled, single-label, single-condition datasets is a fundamental bottleneck. By reporting results on a realistically imbalanced test set, it sets a cautious baseline and calls for multi-label benchmarks drawn from consented, clinically assessed cohorts.
Real-world applications:
- Flagging acute-risk content such as suicidal ideation for urgent human review by platform moderators.
- Supporting longitudinal analysis of linguistic shifts in conditions like bipolar disorder, where single posts carry limited signal.
- Helping trained clinicians or moderators triage high volumes of patient- or user-generated text rather than replace their judgment.
- Providing transparent per-word explanations so a moderator can see why a post was flagged before acting on it.
Industry relevance: Content moderation teams, trust-and-safety organizations, and digital mental health platforms can use the pipeline as a template for combining domain-adapted transformer fine-tuning with explainability tooling. The domain-adaptation result, where MentalBERT (accuracy 0.92) beats generic fine-tuned BERT (0.87) and hybrid static-embedding approaches, is directly transferable guidance for teams deciding how far to fine-tune versus how much to fine-tune versus freezing an encoder.
Future Directions
- Build a multi-label, clinically validated benchmark: The authors call this the most critical next step, since their single-label framework cannot capture co-occurring conditions such as suicidal ideation expressed within a bipolar narrative.
- Run formal human-in-the-loop user studies: The "Social Media Screener" prototype has not been tested with real moderators; HCI studies are needed to measure its effect on decision accuracy, efficiency, and trust.
- Explore multi-task architectures: With multi-label data, a shared encoder with separate classification heads could explicitly model interactions between mental health and cyberbullying phenomena.
- Test robustness and expand modalities: Cross-domain and temporal generalization remain untested, and the current work is limited to English text, excluding multilingual and multimodal signals such as images and video.
Target Audience
Researchers and practitioners working at the intersection of NLP, computational mental health, and online safety. It is most useful to applied machine learning engineers building moderation or screening systems, to clinical and public health researchers interested in what social-media classifiers can and cannot support, and to ethics-focused readers looking for a concrete example of framing an AI screening tool as a non-diagnostic, human-in-the-loop aid.
Authors’ abstract
Mental health challenges and cyberbullying are increasingly prevalent in digital spaces, necessitating scalable and interpretable detection systems. This paper introduces a unified multiclass classification framework for detecting ten distinct mental health and cyberbullying categories from social media data. We curate datasets from Twitter and Reddit, implementing a rigorous "split-then-balance" pipeline to train on balanced data while evaluating on a realistic, held-out imbalanced test set. We conducted a comprehensive evaluation comparing traditional lexical models, hybrid approaches, and several end-to-end fine-tuned transformers. Our results demonstrate that end-to-end fine-tuning is critical for performance, with the domain-adapted MentalBERT emerging as the top model, achieving an accuracy of 0.92 and a Macro F1 score of 0.76, surpassing both its generic counterpart and a zero-shot LLM baseline. Grounded in a comprehensive ethical analysis, we frame the system as a human-in-the-loop screening aid, not a diagnostic tool. To support this, we introduce a hybrid SHAPLLM explainability framework and present a prototype dashboard ("Social Media Screener") designed to integrate model predictions and their explanations into a practical workflow for moderators. Our work provides a robust baseline, highlighting future needs for multi-label, clinically-validated datasets at the critical intersection of online safety and computational mental health.