Depression is the leading cause of disability-adjusted life years in the 15–44 age group globally, yet the median delay between symptom onset and first clinical contact remains approximately 11 years. The widespread adoption of social media platforms has created an unprecedented longitudinal corpus of self-expressed psychological states — one that, if properly modelled, could enable proactive identification of individuals approaching a depressive episode weeks before they reach clinical severity. This paper introduces MentalRoBERTa-EW (Early-Warning), the first transformer-based framework to frame depression detection explicitly as an early-warning timeline prediction problem. Rather than classifying a user's current mental state from a static text snapshot, MentalRoBERTa-EW outputs both a binary risk classification and a calibrated temporal estimate of days until episode onset. The architecture combines two innovations: (1) domain-adaptive masked language model pre-training of RoBERTa-base on a 1.2-billion-token mental health community corpus, and (2) an Early-Warning Timeline Head — a Temporal Convolutional Network trained jointly with the classification objective to predict days-to-onset from longitudinal post sequences. We construct a 76,158-post dataset spanning Reddit and Twitter/X, including a novel 14,820-post Timeline-Probe partition with verifiable episode-onset anchors — the first longitudinal mental health NLP resource of its kind. A rigorous five-vector leakage prevention protocol eliminates user-level contamination, near-duplicate inflation, temporal leakage, subreddit signal bleed, and metadata exposure — directly addressing methodological gaps identified in prior work. MentalRoBERTa-EW achieves 74.3% macro F1 at T−30 days before episode onset, 86.9% at T−7, and 91.4% at T−3, with a mean absolute error of 3.2 days on episode timing prediction. On the static classification task it achieves 94.5% macro F1 and AUC-ROC of 0.983 — outperforming BERT-base by 5.5 F1 points and vanilla RoBERTa-base by 3.0 F1 points. Cross-platform evaluation on Twitter/X yields 90.1% macro F1, demonstrating strong domain generalisation. Longitudinal Integrated Gradients analysis confirms the model learns clinically meaningful linguistic trajectories aligned with DSM-5 symptom clusters, with token attribution patterns shifting from future-tense hopelessness (T−30) toward present-state helplessness and cognitive slowing markers (T−7). We discuss clinical deployment scenarios, the distinction between screening and diagnosis, the five-vector leakage protocol as a reusable community methodology, and a structured ethics framework covering privacy, false-positive risk, dual-use concerns, and the boundaries of responsible automated mental health screening. Keywords: depression detection, early-warning systems, timeline prediction, RoBERTa, domain-adaptive pre-training, mental health NLP, longitudinal social media analysis, transformer fine-tuning, clinical NLP, Integrated Gradients, digital mental health screening, dataset leakage prevention.
Devashish Soan (Fri,) studied this question.