Skip to main content

NLP Mental Health

A cross-domain NLP study evaluating how depression detection models transfer to suicidal ideation content on social media.

  • Natural Language Processing
  • Machine Learning
  • Transformer Embeddings
  • Cross-Domain Evaluation
  • Research
NLP Mental Health project cover.

Project overview

This research investigates whether a model trained to detect depression in Twitter text can generalize to a related but linguistically different domain: suicidal ideation.

Three representations—TF-IDF, RoBERTa, and MentalBERT—were tested across six traditional classifiers under the same cross-domain conditions to isolate the impact of feature quality.

257K+Training tweets
9,119Out-of-domain posts
3Feature representations
6Classifiers evaluated

The research question

Depression and suicidal ideation are clinically related, but the language people use to describe them can differ considerably. Models that perform well within one dataset may therefore fail when applied to another condition.

The central question was whether contextual transformer embeddings could preserve meaning across this topical domain shift better than sparse lexical features.

Experimental workflow

The workflow keeps training and out-of-domain evaluation strictly separated, allowing transfer performance to be measured without retraining on suicidal-intention labels.

01Clean social textURLs · mentions · punctuation · casing · lemmatization
02ATF-IDFSparse lexical representation
02BRoBERTaGeneral contextual embeddings
02CMentalBERTMental-health-domain embeddings
03Train six classifiersNB · RF · DT · SVM · Logistic Regression · KNN
04AIn-domain testMDDL held-out data
04BCross-domain testSuicidal intention dataset

Datasets

Both datasets contain Twitter content, keeping the platform consistent while changing the mental-health condition being detected.

Training and in-domain evaluation

MDDL Depression Dataset

Size
257,178 tweets
Labels
Depressed / non-depressed
Out-of-domain evaluation

Twitter Suicidal Intention Dataset

Size
9,119 posts
Labels
Suicidal / non-suicidal

Vocabulary shift

Only 20 of the top 50 words were shared between the two datasets. Depression content was dominated by clinical language, while the suicidal-intention dataset contained more direct, action-oriented distress expressions.

This 60% non-overlap explains why models depending on exact word frequency struggled to transfer, even though both datasets came from the same social platform.

Clinical terms

disorder · diagnosed · bipolar · PTSD

Distress terms

die · kill · suicide · want · can’t

Cross-domain results

Contextual embeddings produced a dramatic improvement over TF-IDF. KNN showed the clearest reversal, moving from the worst result with TF-IDF to the strongest result with RoBERTa.

TF-IDFRoBERTaMentalBERT
Naive Bayes
Random Forest
Decision Tree
SVM
Logistic Regression
KNN

Cross-domain F1 score (%)

ClassifierTF-IDF F1RoBERTa F1MentalBERT F1
Naive Bayes0.20280.43470.4845
Random Forest0.09980.35170.3660
Decision Tree0.09640.39740.3703
SVM (Linear)0.01460.48420.2764
Logistic Regression0.01190.51050.4249
KNN0.00090.64470.6280

The KNN reversal

With TF-IDF, KNN achieved an F1 score of only 0.0009. Sparse lexical vectors placed linguistically different but semantically related tweets far apart.

With RoBERTa embeddings, KNN reached the best cross-domain F1 score of 0.6447 and recall of 0.5429. Dense contextual representations made nearest neighbours genuinely meaningful.

TF-IDF + KNN0.0009Worst cross-domain F1
RoBERTa + KNN0.6447Best cross-domain F1

Key findings

01

Representation dominates

Feature quality affected transfer performance more strongly than classifier choice.

02

TF-IDF does not generalize

Vocabulary mismatch caused F1 drops of up to 99.7% under domain shift.

03

RoBERTa wins

General-purpose RoBERTa outperformed MentalBERT across every evaluated classifier.

Limitations and next steps

The transformers were used as frozen feature extractors, and the best recall remained approximately 0.54. The current system is a research prototype and must not be treated as a deployment-ready mental-health screening tool.

Future work includes end-to-end fine-tuning, domain adaptation, ensemble approaches, and stronger recall-focused evaluation while preserving ethical safeguards.