Anxo/erisk26-task1-patient-07-adapter
eRisk 2026 Task 1 — Simulated Patient Adapter (PEFT/LoRA)
This repository contains a PEFT/LoRA adapter for a simulated patient persona intended for eRisk 2026 Task 1.
- What’s included: adapter weights + a reference conversation script.
- *What’s not included:* the base model weights (you must download them separately). ---
Base model requirement (important)
This adapter is designed to be used with:
- Base model:
meta-llama/Meta-Llama-3-8B-Instruct
⚠️ The base model is typically gated. Participants must have access to the base model on Hugging Face and be authenticate.
Mandatory system prompt (must be used verbatim)
For eRisk 2026 Task 1, participants must NOT modify the system prompt below. This is part of the task protocol to ensure comparable behavior across participants.
Use exactly:
"You are a simulated patient. Act realistically based on your internal training. Ensure contextual realism. Avoid overly detailed or formal speech. Keep natural speaking style (e.g., short answers, hesitations, casual expressions). Do not mention you are an AI."
Notes:
- Keep punctuation and wording identical.
- Do not add additional system instructions.
- Do not prepend safety messages, disclaimers, or extra persona constraints.
Repository contents
adapter_model.safetensors/adapter_config.jsonThe PEFT adapter to load withPeftModel.from_pretrained(...).conv_interact.pyMinimal interactive conversation runner (Doctor ↔ Patient). ---
Quickstart (recommended)
1) Install dependencies
~~~bash pip install -U "transformers>=4.40" peft accelerate torch hf auth login ~~~
2) Run the interactive demo
~~~bash python conv_interact.py ~~~
Minimal loading example (adapter-only)
Below is a minimal snippet showing how to load the base model + this adapter.
~~~python import torch from transformers import AutoTokenizer, AutoModelForCausalLM from peft import PeftModel
--- CONFIGURATION ---
BASEMODELID = "meta-llama/Meta-Llama-3-8B-Instruct"
ADAPTERPATH = "<REPLACEWITHTHISREPO_NAME>"
1. Load Tokenizer & Fix Padding
tokenizer = AutoTokenizer.frompretrained(BASEMODELID) tokenizer.padtokenid = tokenizer.eostokenid tokenizer.paddingside = 'left' # Crucial for generation
2. Load Base Model (Force float16 for compatibility)
basemodel = AutoModelForCausalLM.frompretrained( BASEMODELID, torchdtype=torch.float16, devicemap="auto", )
3. Load the Patient Adapter
print(f"Loading Adapter from {ADAPTERPATH}...") model = PeftModel.frompretrained(basemodel, ADAPTERPATH)
4. Initialize History with the "Generic" Prompt
DO NOT CHANGE SYSTEM PROMPT. It is crucial for ensuring the patient behaves as intended.
Important: IT WILL BE CONSIDERED AS CHEATING!!
messages = [ {"role": "system", "content": "You are a simulated patient. Act realistically based on your internal training. Ensure contextual realism. Avoid overly detailed or formal speech. Keep natural speaking style (e.g., short answers, hesitations, casual expressions). Do not mention you are an AI."}, ]
terminators = [ tokenizer.eostokenid, tokenizer.converttokenstoids("<|eotid|>") ]
print("--- Patient Loaded. Type 'quit' to exit. ---")
while True: userinput = input("Doctor: ") if userinput.lower() == 'quit': break
# 1. Update history messages.append({"role": "user", "content": user_input})
# 2. Format history & Create Attention Mask # returndict=True gives us the 'attentionmask' automatically inputs = tokenizer.applychattemplate( messages, addgenerationprompt=True, returntensors="pt", returndict=True ).to(model.device)
# 3. Generate response # explicitly passing attentionmask prevents the warning you saw earlier with torch.nograd(): outputs = model.generate( inputids=inputs.inputids, attentionmask=inputs.attentionmask, maxnewtokens=256, eostokenid=terminators, padtokenid=tokenizer.eostokenid, dosample=True, temperature=0.6, topp=0.9, )
# 4. Decode response # We slice [inputlen:] to ensure we don't print the prompt back to the user responsetokens = outputs[0][inputs.inputids.shape[-1]:] assistanttext = tokenizer.decode(responsetokens, skipspecial_tokens=True)
print(f"Patient: {assistant_text}")
# 5. Append assistant response to history messages.append({"role": "assistant", "content": assistant_text}) ~~~
Reproducibility guidance
To reduce run-to-run variability during development:
- set a fixed random seed (PyTorch + CUDA)
- consider
do_sample=Falsefor deterministic debugging (not necessarily for final experiments) - log:
- base model id + exact adapter repo id + commit hash
- transformers/peft versions
- decoding parameters (temperature, topp, maxnew_tokens)
Task rule reminder (prompt integrity)
This repo provides code that includes the official system prompt. For the eRisk 2026 Task 1 protocol, participants are required to keep the system prompt unchanged. ---
License & access
- The adapter weights in this repo are released under the license specified in this model card.
- Usage requires compliance with the base model’s license and access conditions for
meta-llama/Meta-Llama-3-8B-Instruct.
How to cite
If you use this adapter in academic work, please cite the eRisk overview paper and/or the task description as appropriate.
Maintainers / Contact
Maintained by IRLab-UDC (eRisk organizers). For issues, open a GitHub/HF issue in the corresponding repository or contact the task organizers.
