AI-based detection of suicidal ideation in text: model development and evaluation for a student mental health chatbot
Abstract
Background: Conversational digital mental health interventions (DMHIs) require mechanisms for recognizing expressions of suicidal ideation (SI) and initiating appropriate safety responses. Artificial intelligence (AI)-based detection approaches could provide a scalable safeguard; but systems designed for real world deployment must consider accuracy alongside computational efficiency, transparency, and appropriate response pathways. Methods: We developed a lightweight SI-detection system for integration into Minder, a mental health chatbot intervention for students. The detection pipeline combined a fine-tuned Sentence-BERT (SBERT) encoder with a nonparametric, anchor-based decision layer. The encoder was trained on 220,833 sentence-level text samples from public social media datasets. Fine-tuning used partial unfreezing and Batch-All Triplet Loss, with three configurations (Light, Medium, Heavy) compared on a development set. Each text input was encoded as 768-dimensional embeddings, then compared, using cosine similarity, against an expert-curated reference set of statements spanning suicidal ideation, intent, planning, and method. Inputs exceeding a development-set threshold were flagged as containing SI. The selected model was evaluated on a held-out test set and benchmarked against four open-weight generative language models under zero-shot prompting. Results: The Light fine-tuning configuration was selected for its strong performance and better preservation of the embedding space’s broader semantic structure. On the held-out test set, it achieved precision 0.91, recall 0.92, specificity 0.92, F1 0.91, and accuracy 0.92. A stricter threshold raised precision to 0.98 but lowered recall to 0.34. This trade-off informed a proposed workflow in which high-confidence detections trigger an immediate supportive response and crisis resources, while intermediate scores prompt clarification and re-evaluation. The system performed comparably to Phi-4 (accuracy 0.93, F1 0.92) while using roughly one-eighteenth of its storage and fewer than one-hundredth of its parameters. Conclusion: These findings demonstrate the technical feasibility of a computationally efficient, domain-grounded approach for SI detection in informal text. Keeping the decision logic separate from the encoder makes the system auditable and allows the flagging criteria to be inspected and iteratively refined. Prospective evaluation using contextually representative chatbot conversations is required before deployment, including assessment of missed disclosures, user acceptability, and clinical governance.