Paper · 2023-09-24 · cs.CL
MentaLLaMA: Interpretable Mental Health Analysis on Social Media with Large Language Models
Builds IMHI, a 105K-sample instruction dataset for interpretable mental health analysis on social media. ChatGPT writes explanations from expert few-shot prompts and dataset labels, then is checked for correctness, consistency and quality. LLaMA2 models tuned on it (MentaLLaMA) approach fine-tuned discriminative baselines on several of 10 test sets (author-reported).
Instruction tuningLikelihood-based text evaluationLLM evaluationmental-healthinstruction-tuningexplanation-generationdataset
arXivPDFCodeMarkdown14 min read
AI-compiled by claude-haiku-5-5 on 2026-11-08, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Automatic systems that look at social media posts for signs of mental health problems usually return only a label, such as "yes" or a category, with no reasons. Large chatbots can give reasons, but they are not reliable at the label, even when shown examples. Training a model to do both well needs data where each label comes with a written explanation, and such data was scarce.
The authors take posts that already carry labels from ten existing datasets. They ask ChatGPT to write an explanation for each label, guided by a few examples that experts wrote by hand. They then check the explanations for correctness, internal consistency and quality, partly with automatic tools and partly with human raters. The result is a training and test collection, which they use to tune open LLaMA 2 models into a family they call MentaLLaMA. The models are judged on whether they pick the right label and on how good their explanations read. The authors stress that outputs are for non-clinical research only.
TL;DR
The paper formalises interpretable mental health analysis as text generation and releases the IMHI dataset, with about 105K instruction samples built from ChatGPT explanations and checked for correctness, consistency and quality §1 §3. It fine-tunes LLaMA2-7B, LLaMA2-chat-7B and LLaMA2-chat-13B on it §4. On the IMHI benchmark, MentaLLaMA-chat-13B is reported to reach or approach fine-tuned MentalRoBERTa on several test sets, with explanation quality close to ChatGPT §1 §6.2. All numbers are author-reported.
Problem
Mental health analysis on social media has mostly been framed as classification with pre-trained encoders, which generalise poorly to new tasks and give little explanation for their decisions §1. Zero-shot and few-shot prompting of general LLMs gives weak classification results, and the authors report that this also degrades the explanations §1. Fine-tuning would help, but two obstacles stand in the way: no high-quality training data with explanations is openly available, and no open-source LLM tuned for this task had been released §1.
Method
The method has four parts: a task formulation, a dataset built with ChatGPT and expert prompts, a training recipe for LLaMA2 models, and a benchmark with two metrics.
-
Task formulation. The task is a generation problem. Each training pair holds a query (post plus question) and a response that gives the answer and a rationale. The model maximises the conditional log-likelihood of the response tokens given the query and earlier response tokens §2 eq. 1.
-
Raw data. Ten datasets from Reddit, Twitter and SMS, covering eight mental health analysis tasks, are collected with their existing annotations. Split sizes and label sets are in tab. 1 §3.1.
-
Gold explanations. Domain experts write one task instruction and 35 explanation examples for each of the ten datasets, giving a gold set of 350 posts. Each explanation follows the template "[label] Reasoning: [explanation]" §3.2.
-
Generating explanations with ChatGPT. For each post the prompt contains the task instruction, two gold explanations per class sampled from the gold set, and the dataset's annotated label. ChatGPT then writes the explanation §3.2 fig. 2. Example ChatGPT prompts per dataset are in tab. 6 app. C.
-
Automatic evaluation of generated data §3.3.1.
- Correctness: where ChatGPT disagrees with the annotated label, experts check the prompt and response and rewrite the label or explanation. Per-dataset agreement is shown in fig. 3 (a) §3.3.1.
- Consistency: a MentalBERT classifier is trained on (explanation, label) pairs from ChatGPT responses and predicts the label from the explanation eq. 2. Its weighted F1 on held-out ChatGPT responses is above 93.5% for every dataset, per fig. 3 (b) §3.3.1.
- Quality: BART-score compares responses with the expert gold explanations. Zero-shot, few-shot and label-included prompts are compared on the 350 gold posts fig. 3 (c) §3.3.1.
-
Human evaluation of generated data. 200 explanations are rated by three domain experts on four aspects (consistency, reliability, professionality, overall), each on a 0 to 3 scale. Scores are averaged per sample §3.3.2 app. B fig. 4.
-
Instruction construction. Posts and their evaluated explanations are turned into question and response pairs by fixed rules. This gives 72,095 training and 14,346 validation samples §3.4. A completion-style variant (IMHI-completion) uses other templates for models without instruction ability §3.4 tab. 4.
-
Training MentaLLaMA. LLaMA2-7B is trained on the IMHI training split for 10 epochs and the best checkpoint on the validation split is kept. The chat variants (LLaMA2-chat-7B and -13B) use the same settings. A LLaMA2-7B model is also trained on IMHI-completion for comparison §4. Hyperparameters are in the table below.
-
IMHI benchmark. Test splits from the ten datasets are grouped into ten test sets §5. Correctness is weighted F1 on labels, where each free-text response is mapped to a label by a MentalBERT-based classifier because outputs are not in one template §5 tab. 2. Quality is the BART-score of each response §5.
-
Generalisation test. Four tasks (Dreaddit, T-SID, CAMS, IRF) are removed from the training data to form IMHI-general. T5, BART and MentaLLaMA-chat models are retrained on it and tested on those four tasks §6.3 tab. 3.
Key equations:
\max_{\phi} \sum_{(q,r)\in\mathcal{D}} \sum_{j=1}^{|r|} \log P_{\phi}(r_j \mid q, r_{<j}) eq. 1
[\mathrm{label}]^{p}_{i} = \mathrm{MentalBERT}\big([\mathrm{explanation}]_i\big) eq. 2
Dataset construction (steps 2 to 7) §3:
# IMHI construction [§3.2] [§3.3.1] [§3.4]
# Input: labelled posts per dataset; gold set G (350 expert explanations)
# Output: (question, answer) pairs, split by the raw train and valid splits
def build_imhi(datasets, gold_set, instructions):
# Two gold explanations per class, used as few-shot examples [§3.2]
shots = two_per_class(gold_set)
pairs = []
for dataset in datasets:
for post, label in dataset.items():
# Prompt ChatGPT with instruction, shots, post and label [§3.2]
prompt = make_prompt(instructions[dataset.name], shots, post, label)
explanation = chatgpt(prompt)
# Experts rewrite label or explanation after disagreement [§3.3.1]
if disagrees(explanation, label):
explanation = expert_rewrite(post, label, explanation)
# Rule-based question; the explanation is the answer [§3.4]
question = rule_question(dataset.name, post)
pairs.append((question, explanation))
return pairsTraining (step 8) §4:
# MentaLLaMA supervised fine-tuning [§4]
# Input: base LLaMA2 model; IMHI train and validation pairs
# Output: checkpoint chosen on the validation split
def finetune(model, train_pairs, valid_pairs):
# AdamW with maximum learning rate 1e-5 [§4]
optimizer = AdamW(model.parameters(), lr=1e-5)
# Warm-up over 3% of steps; the later decay is not stated [§4]
scheduler = warmup_then_decay(optimizer, warmup_ratio=0.03)
best_score = None
for epoch in range(10): # 10 epochs [§4]
step = 0
for batch in batches(train_pairs, size=32): # 32 per step [§4]
# Negative log-likelihood of response tokens only [eq. 1]
# Input limited to 2048 tokens [§4]
loss = response_nll(model, batch, max_len=2048)
# Accumulate 8 steps, so the effective batch is 256 [§4]
(loss / 8).backward()
step += 1
if step % 8 == 0:
optimizer.step()
scheduler.step()
optimizer.zero_grad()
# Keep the best checkpoint; the selection metric is not stated [§4]
score = evaluate(model, valid_pairs)
if best_score is None or score > best_score:
best_score = score
save(model)
return best_scoreBenchmark scoring (step 9) §5:
# IMHI benchmark scoring [§5] [§3.3.1]
# Input: responses and references for one test set; gold labels
# Output: weighted F1 (correctness) and mean BART-score (quality)
def score_test_set(responses, gold_labels, references):
# Map each free-text response to a label with MentalBERT [§5]
predicted = [classify(response) for response in responses]
correctness = weighted_f1(gold_labels, predicted)
# BART-score of each response against its reference [§5]
scores = [bart_score(r, ref) for r, ref in zip(responses, references)]
quality = sum(scores) / len(scores)
return correctness, qualityHyperparameters
| Name | Value | Where | Notes |
|---|---|---|---|
| base models | LLaMA2-7B; LLaMA2-chat-7B; LLaMA2-chat-13B | §4 | MentaLLaMA-7B, -chat-7B, -chat-13B |
| training data | IMHI train split, 72,095 samples | §3.4 §4 | validation split 14,346 samples |
| epochs | 10 | §4 | best checkpoint on IMHI validation set |
| optimiser | AdamW | §4 | betas, epsilon, weight decay: not stated |
| max learning rate | 1e-5 | §4 | |
| warm-up | 3% (warm-up ratio) | §4 | decay schedule after warm-up: not stated |
| batch size | 32 with gradient accumulation 8, "actual batch size 256" | §4 | whether 32 is per GPU or in total across 4 GPUs: not stated |
| max input length | 2048 | §4 | tokenisation and truncation rules: not stated |
| attention | FlashAttention | §4 | |
| hardware | 4 × NVIDIA A100 80GB | §4 | training time: not stated |
| precision | not stated | §4 | |
| LoRA or other PEFT | not used for the paper's models | §4 | the README's 33B LoRA model is not in the paper README.md |
| random seed | not stated | single run per model implied; variance not reported | |
| decoding (response generation) | not stated in paper | IMHI.py | code passes max_length=2048 and no sampling arguments |
| classifier input length | not stated in paper | label_inference.py | 512 tokens with truncation |
| classifier batch size | not stated in paper | label_inference.py | default 8 |
| BART-score model | not stated in paper | score.py | facebook/bart-large-cnn |
| eval batch size | not stated in paper | IMHI.py | default 24; the README uses 8 README.md |
Results
Author-reported. Setup: ten test sets (IMHI benchmark, 19,353 instruction test samples in total, derived from the Instruction column of tab. 1), weighted F1 for correctness tab. 2, BART-score for quality fig. 5. Baselines: BERT-base, RoBERTa-base, MentalBERT and MentalRoBERTa (110M); LLaMA2-7B and -13B zero-shot; ChatGPT zero-shot and few-shot (175B); GPT-4 few-shot (1.76T, as stated in tab. 2); T5-large and BART-large and LLaMA2-7B fine-tuned on IMHI-completion §6.1.
Correctness, IMHI test set tab. 2. Values are weighted F1 (%). The table uses "--" for entries it does not report; the paper does not explain these entries. Bold marks in the paper are not reproduced.
| Method | Size | CAMS | CLP | DR | Dreaddit | IRF | loneliness | MultiWD | SAD | SWMH | T-SID |
|---|---|---|---|---|---|---|---|---|---|---|---|
| BERT-base | 110M | 34.92 | 62.75 | 90.90 | 78.26 | 72.30 | 83.92 | 76.69 | 62.72 | 70.76 | 88.51 |
| RoBERTa-base | 110M | 36.54 | 66.07 | 95.11 | 80.56 | 71.35 | 83.95 | -- | 67.53 | 72.03 | 88.76 |
| MentalBERT | 110M | 39.73 | 62.63 | 94.62 | 80.04 | 76.73 | 82.97 | 76.19 | 67.34 | 71.11 | 88.61 |
| MentalRoBERTa | 110M | 47.62 | 69.71 | 94.23 | 81.76 | -- | 85.33 | -- | 68.44 | 72.16 | 89.01 |
| LLaMA2-7B (zero-shot) | 7B | 16.34 | 36.26 | 58.91 | 53.51 | 38.02 | 58.32 | 40.1 | 11.04 | 37.33 | 25.55 |
| LLaMA2-13B (zero-shot) | 13B | 14.64 | 39.29 | 54.07 | 36.28 | 38.89 | 55.48 | 53.65 | 13.2 | 40.5 | 25.27 |
| ChatGPT (zero-shot) | 175B | 33.85 | 56.31 | 82.41 | 71.79 | 41.33 | 58.40 | 62.72 | 54.05 | 49.32 | 33.30 |
| ChatGPT (few-shot) | 175B | 44.46 | 61.63 | 84.22 | 75.38 | 43.31 | 58.78 | 64.93 | 63.56 | 60.19 | 43.95 |
| GPT-4 (few-shot) | 1.76T | 42.37 | 62.0 | 82.0 | 78.18 | 51.75 | 72.85 | 62.58 | 55.68 | 62.94 | 40.48 |
| T5-Large (completion FT) | 770M | 40.2 | 48.6 | 84.9 | 77.7 | 74.0 | 80.8 | 76.4 | 58.1 | 70.0 | 77.1 |
| BART-Large (completion FT) | 406M | 43.8 | 50.3 | 84.6 | 80.0 | 76.2 | 83.3 | 77.2 | 59.6 | 71.5 | 77.9 |
| LLaMA2-7B (completion FT) | 7B | 30.47 | 51.17 | 84.94 | 61.59 | 73.5 | 81.25 | 65.52 | 49.6 | 63.08 | 68.93 |
| MentaLLaMA-7B | 7B | 32.52 | 59.86 | 76.14 | 71.65 | 67.53 | 83.52 | 68.44 | 49.93 | 72.51 | 72.64 |
| MentaLLaMA-chat-7B | 7B | 44.8 | 51.84 | 83.95 | 62.2 | 72.88 | 83.71 | 75.79 | 62.18 | 75.58 | 77.74 |
| MentaLLaMA-chat-13B | 13B | 45.52 | 52.61 | 85.68 | 75.79 | 76.49 | 85.1 | 75.11 | 63.62 | 71.7 | 75.31 |
Author statements about tab. 2:
- MentalBERT and MentalRoBERTa are best among the four discriminative models on 8 of 10 sets §6.2.1. This matches the table.
- ChatGPT zero-shot beats both zero-shot LLaMA2 models on all 10 sets §6.2.1. This matches the table.
- MentaLLaMA-chat-13B "surpasses or approaches" the discriminative state of the art on 7 of 10 sets §1, and is within "less than 5%" of MentalRoBERTa on 7 of 10 §6.2.1. See Pitfalls for how the table supports this.
- MentaLLaMA-7B beats completion-tuned LLaMA2-7B on 8 of 10 sets; the chat variants beat MentaLLaMA-7B on 9 of 10 §6.2.1.
Generalisation, unseen tasks tab. 3. Correctness, weighted F1 (%).
| Model | CAMS | Dreaddit | IRF | T-SID |
|---|---|---|---|---|
| LLaMA2-13B (zero-shot) | 14.64 | 36.28 | 38.89 | 25.27 |
| ChatGPT (zero-shot) | 33.85 | 71.79 | 41.33 | 33.30 |
| MentaLLaMA-chat-7B | 20.19 | 67.42 | 54.6 | 64.76 |
| MentaLLaMA-chat-13B | 27.22 | 71.98 | 65.51 | 70.7 |
The paper states that MentaLLaMA beats zero-shot LLaMA2-13B on all four and beats zero-shot ChatGPT on three §6.3. Both match the table. The source has T5-large and BART-large rows for this table commented out, so the paper's table shows only the four rows above.
Explanation quality: reported as BART-score in fig. 5. The values are in the figures only and are not given in the text, so this card does not transcribe them. The text states: LLaMA2-7B fine-tuned on IMHI-completion beats zero-shot LLaMA2-7B on all 10 sets §6.2.2. It also beats BART-large on 9 of 10 sets, but only MultiWD and IRF improve by more than 0.2 BART-score §6.2.2. MentaLLaMA beats zero-shot LLaMA2-7B on all 10 sets; the chat variants improve further, with MentaLLaMA-chat-13B over 0.2 above chat-7B on 8 of 10 §6.2.2. On the expert gold set, MentaLLaMA models are described as comparable to ChatGPT and GPT-4 on most sets §6.2.2 fig. 5 (c).
Human evaluation §6.4 fig. 6: 200 MentaLLaMA-chat-13B explanations, same protocol as §3.3.2. The authors report averages above 2.2 on all four aspects, comparable to ChatGPT for consistency and reliability, and clearly below ChatGPT on professionality §6.4.
Data-generation checks §3.3: 7 of 10 raw datasets reach over 90% agreement between annotation and ChatGPT; T-SID is below 70% and loneliness and IRF are below 80% §3.3.1 fig. 3 (a). Consistency classifiers reach over 94% on 9 of 10 gold sets and 86.6% on SAD §3.3.1.
Paper vs code
The official repository is SteveKGYang/MentaLLaMA (MIT, copyright NaCTeM). The paper's abstract links it, which is the basis for treating it as official. I checked it at commit 42cd29dfb91092843daae53ec162c75605d753ff. It contains three evaluation scripts, a README, data and released examples. It has no training script and no training configuration, so the training recipe in §4 cannot be checked against code.
- No training code. The only scripts are
src/IMHI.py(response generation and rule-based scoring),src/label_inference.py(MentalBERT label inference) andsrc/score.py(BART-score and other metrics) README.md. The README says that the MentalBERT classifiers are released on Hugging Face, not in the repository README.md. - 33B LoRA model. The README adds a MentaLLaMA-33B-lora model based on Vicuna-33B, trained with LoRA README.md README.md. The paper does not describe it.
- BART-score checkpoint. The code loads
facebook/bart-large-cnnscore.py. The paper does not name a checkpoint. - Direction of BART-score. The code passes the model's response as the first argument and the reference as the second score.py. The paper does not state the direction. The BARTScore library, which is not in this repo, decides what is scored; check its convention before porting.
- Quality averages. The code reports the mean of per-response scores per dataset score.py. The paper does not state the aggregation.
- Reference for IMHI quality. Test CSVs carry the reference explanation in a column named
gpt-3.5-turbo, which the code loads as the gold text IMHI.py. The BART-score on the IMHI test set therefore compares to ChatGPT-written references. The paper's §5 says it follows §3.3.1, which used the expert gold set. The expert set is only run through--test_dataset expertREADME.md. - Expert gold set size. The paper says 35 posts for each of ten datasets, 350 in total §3.2. The README lists nine datasets (no CLP) with 35 samples each README.md, and the folder
human_evaluation/test_instruction_expertholds nine files. The count of ten is not reproduced in the release. - T-SID label name. The paper's Table 1 lists the T-SID class as "None" tab. 1. The released classifier calls it
controllabel_inference.py, while the rule-based gold check looks for "no mental disorders" IMHI.py. - Classifier truncation and batch. The label classifier truncates input to 512 tokens and uses a default batch size of 8 label_inference.py label_inference.py. The paper does not state either.
- Generation settings.
generategetsmax_length=2048and no sampling arguments IMHI.py. The tokenizer uses left padding with the unknown token as pad IMHI.py IMHI.py. The paper does not state decoding settings. - Rule-based scoring. The code includes a keyword rule-based labeller, switched on by
--rule_calculate. It matches substrings such as "no" inside "none" or "not" for binary tasks, and counts unmatched outputs as label 0 IMHI.py. The paper says rule-based label determination is difficult for these outputs §5.
Pitfalls
- No training code. The paper gives the main hyperparameters §4, but the scheduler's shape, weight decay, precision, seed, loss masking and the padding and packing scheme are not stated. Eq. 1 implies that only response tokens are scored, but the paper does not say so explicitly. Reproduce with a standard recipe and report the differences.
- Batch arithmetic is ambiguous. The paper gives batch size 32, accumulation 8 and an "actual batch size" of 256 §4, on 4 GPUs. Whether 32 is per GPU is not stated. An implementation that multiplies by 4 gets an effective batch of 1,024.
- Max length counts differently. The paper's 2048 is a model-input limit for training §4. The released inference script passes 2048 as
max_lengthtogenerateIMHI.py. Whether that bounds the prompt plus the response depends on the Transformers version. Check it when reproducing. - Correctness depends on a second model. Free-text responses are mapped to labels by MentalBERT classifiers, which were trained on ChatGPT explanations §3.3.1 §5. Their accuracy is reported as above 95% on the IMHI test data README.md. Results cannot be compared across papers without the same classifiers, and the training code for those classifiers is not released.
- Rule-based fallback is lossy. Keyword matching can assign the wrong label, and unmatched outputs fall back to label 0 IMHI.py. Do not use the rule-based number as the benchmark score.
- The "7 of 10" claim. The paper says MentaLLaMA-chat-13B is within "less than 5%" of MentalRoBERTa on 7 of 10 sets §6.2.1. The paper does not define "gap" as absolute points or relative change. Reading the table with absolute points and the best of the four discriminative models per set, I count six sets within 5 points (CAMS, IRF, loneliness, MultiWD, SAD, SWMH) and none surpassed. This is my arithmetic from tab. 2, not a value the paper reports.
- Ambiguous "approaches". "Surpasses or approaches" in §1 is not defined. Use the table, not the phrase.
- Gold labels from ChatGPT in the release. The IMHI test references are ChatGPT explanations, not expert text IMHI.py. A BART-score computed against them measures agreement with ChatGPT's wording, not with experts. Use the expert set for that claim.
- Human rewrites are not traceable. Where ChatGPT disagreed with the annotations, experts rewrote labels or explanations §3.3.1. The paper does not say how many items this covered, and the release does not mark them. The IMHI data cannot be rebuilt from the paper alone.
- Quality metric is weak. The authors say BART-score correlates only moderately with human judgement §6.4 §7. Treat quality gains as indicative only.
- Professionality gap. Human raters find MentaLLaMA clearly below ChatGPT on professionality §6.4. The authors suggest continued pre-training on mental health text as a remedy §6.4. The paper reports no such experiment; it lists it as future work §7.
- Generalisation details. The IMHI-general retraining is described only as re-fine-tuning on the reduced data §6.3. Epochs and hyperparameters are not stated.
- Use limits. The authors say the outputs are for non-clinical research only. Bias and over-generalisation are noted as risks §8.
- Version. The LaTeX source's booktitle is WWW '24, and the arXiv metadata used here is v3 [raw metadata]. Figures are PDFs and PNGs in the source; this card does not reproduce them.
Lineage
- Builds on: BARTScore for the quality metric §3.3.1 §5. MentalBERT (arXiv 2110.15621, as cited in the repository README) for the consistency and label classifiers §3.3.1 §5. LLaMA 2 and its chat variants as base models §4. Instruction tuning and RLHF as background §1 app. A (no cards in this wiki).
- Earlier evaluation: Yang et al., arXiv 2304.03347 (cited in the repository README), a human evaluation of ChatGPT's explanations for mental health classification §1 §3.2. The explanation quality criteria are taken from that line of work §3.3.1.
- Compared against: ChatGPT and GPT-4 (zero-shot and few-shot), BERT, RoBERTa, MentalBERT, MentalRoBERTa, T5-large and BART-large, all as baselines in tab. 2 and tab. 3.
- Superseded by: not known from content in this wiki.
Source and license
Adapted from “MentaLLaMA: Interpretable Mental Health Analysis on Social Media with Large Language Models” by Kailai Yang, Tianlin Zhang, Ziyan Kuang, Qianqian Xie, Jimin Huang, Sophia Ananiadou (arXiv:2309.13567), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/SteveKGYang/MentaLLaMA at commit 42cd29dfb910 (MIT). Any quoted code is shown under that license.