Abstract
Self-harm is a critical risk factor for suicide and a vital outcome measure in mental healthcare. However, it is often recorded in unstructured, free-text clinical notes, making large-scale analysis difficult. While cloud-based Large Language Models (LLMs) offer powerful text analysis capabilities, they often conflict with strict healthcare data governance. This study evaluates whether a privacy-preserving LLM, running entirely within a secure National Health Service (NHS) infrastructure, can accurately identify self-harm and its timing. We compared a locally served 27-billion-parameter Gemma 3 model (Gemma3-27b) against a fine-tuned RoBERTa baseline. Gemma3-27b outperformed the baseline, achieving a global weighted F1-score of 0.88 and demonstrating superior performance in identifying the timing of events, all while requiring significantly less annotated data.
Introduction
Self-harm—defined as intentional self-injury or self-poisoning—is the strongest predictor of future suicide. In clinical settings, details regarding self-harm are frequently "trapped" within unstructured electronic health records (EHRs). Traditional methods to extract this data involve manual review, which is unscalable, or supervised Natural Language Processing (NLP), which requires massive amounts of high-fidelity labeled data.
While commercial cloud-based LLMs (e.g., GPT-4, Claude) have shown promise in clinical NLP, their use is often prohibited by data governance regulations like GDPR. Sending sensitive mental health records to third-party servers poses significant privacy risks. This research addresses the "privacy vs. performance" trade-off by deploying an open-weight LLM locally within a secure hospital firewall to determine if it can match or exceed the reasoning capabilities of traditional supervised models.
Methods
Model and Deployment
The researchers utilized Gemma3-27b, a decoder-only transformer model. To ensure the model could run on accessible, modest hardware, the team applied 4-bit quantization, reducing the model size to 10.6 GB. This allowed the model to be served via the Ollama framework on a single NVIDIA T4 GPU (16GB) within the Oxford Health NHS Foundation Trust’s secure infrastructure.
Prompt Engineering
Rather than traditional fine-tuning, which is computationally expensive and requires large datasets, the team used advanced prompting techniques:
- Chain-of-Thought (CoT): Guiding the model to "think" through its reasoning steps before providing a final classification.
- Panel-of-Experts (PoE): Simulating a consensus-based decision-making process within the prompt to improve accuracy.
Baseline Comparison
The LLM's performance was benchmarked against a RoBERTa (Robustly Optimized BERT Pretraining Approach) classifier. RoBERTa is a standard transformer-based model that was specifically fine-tuned on the study's annotated dataset for multi-label text classification.
Datasets
The study utilized a gold-standard dataset of 1,352 clinical notes from 628 unique patients, sourced from the Clinical Record Interactive Search (CRIS) database.
- Annotation: Two domain experts with decades of clinical experience manually labeled the notes for the presence of self-harm and its recency: recent (≤90 days), historical (>90 days), or unknown.
- Enrichment: To address the sparsity of self-harm mentions in general records, a smaller model (Gemma3-4b) was used to pre-filter notes, ensuring the final validation set contained a sufficient density of relevant events.
Results
Gemma3-27b demonstrated superior performance across nearly all metrics compared to the fine-tuned RoBERTa model.
- Overall Accuracy: Gemma3-27b achieved a global weighted F1-score of 0.88, compared to 0.85 for RoBERTa.
- Detection of Self-Harm: For the primary task of identifying the presence of self-harm, Gemma achieved a Precision of 0.92 and a Recall of 0.92.
- Temporal Identification: Identifying when self-harm occurred proved more challenging. For recent self-harm (≤90 days), Gemma achieved an F1-score of 0.79. Notably, in the "historical" category, Gemma’s F1-score of 0.51 significantly outperformed RoBERTa’s 0.18.
- Handling Ambiguity: In cases where the timing was "unknown," RoBERTa failed entirely (F1=0.00), whereas Gemma achieved an F1 of 0.39, leveraging its pre-trained reasoning to handle vague clinical documentation.
Discussion
The Advantage of Local LLMs
The study highlights several key advantages of using local LLMs in clinical settings. First, the "Long Tail" Advantage: Supervised models like RoBERTa struggle with rare categories because they lack sufficient training examples. In contrast, the LLM uses its broad pre-trained "world knowledge" to reason through edge cases and ambiguous language.
Second, the Zero-Shot Efficiency of the LLM suggests that the traditional bottleneck of clinical NLP—the need for thousands of manual annotations—can be mitigated. High performance was achieved through prompt engineering rather than gradient-based training.
Feasibility and "Green AI"
The ability to run a 27B parameter model on a single, relatively low-cost GPU is a significant milestone for resource-constrained healthcare settings. This "Green AI" approach demonstrates that hospitals do not need massive server farms or expensive cloud subscriptions to implement state-of-the-art AI for patient monitoring.
Limitations
The researchers noted that performance might vary across different NHS Trusts due to varying documentation styles. Furthermore, LLMs remain sensitive to prompt phrasing, and the "optimal" prompt for Gemma may not translate perfectly to other models like Llama or Mistral. Finally, temporal ambiguity remains a challenge, often reflecting the inherent vagueness of clinical notes rather than a failure of the model itself.
Conclusion
Local, privacy-preserving language models offer a practical and superior solution for identifying self-harm events in electronic health records. By outperforming traditional supervised models while adhering to strict data governance, these models have the potential to transform clinical monitoring and improve the response to critical public health challenges in mental health care.
Summary updated