Official repository for CARE: Confidence-Aware Reasoning for Reliable Medical VQA, accepted to MICCAI 2026.
This repository provides a minimal open-source implementation of the CARE training pipeline for reliable medical visual question answering.
The method has three parts:
- Medical-CoT synthesis: generate diagnostic reasoning from image, question, and ground-truth answer, then optionally verify the reasoning before keeping it.
- SFT cold start: fine-tune a VLM on structured
<think>...</think><answer>...</answer>Medical-CoT data. - Confidence-aware GRPO: optimize with format reward, answer reward, and Confidence-Aware Reward (CAR):
R_calib = R_out * C - lambda * (1 - R_out) * C
where C is the average token probability of the generated answer sequence.
CARE/
src/care/
cot_synthesis.py # Medical-CoT generation and optional verification
sft/format_sharegpt.py # Convert CoT records to LLaMA-Factory ShareGPT format
rl/train_grpo.py # CARE GRPO entry point
rl/trainer.py # Multimodal GRPO trainer with confidence extraction
rewards.py # R_form, R_out, and CAR reward functions
metrics.py # ECE utility
configs/ # Example training configs, no data
scripts/ # Runnable wrappers using environment variables
tests/ # Synthetic unit tests only
No dataset, checkpoint, wandb run, evaluation output, or local absolute path is included.
cd CARE
python -m pip install -r requirements.txt
python -m pip install -e .[dev]Raw Medical VQA records should contain a question, answer, and image path:
{
"id": "sample-1",
"image": "relative/path/to/image.png",
"problem": "What abnormality is shown?",
"answer": "pneumonia",
"answer_type": "OPEN"
}For GRPO, local JSON/JSONL records may use the same schema. answer_type can be OPEN or CLOSED.
For SFT, convert synthesized CoT records to LLaMA-Factory ShareGPT format:
INPUT_JSON=data/care_cot.json \
OUTPUT_JSON=data/care_cot_sft.json \
IMAGE_ROOT=data/images \
bash scripts/prepare_sft_data.shSet an OpenAI-compatible key in OPENAI_API_KEY. Use OPENAI_BASE_URL if your endpoint is not the default.
INPUT_JSON=data/raw_train.json \
OUTPUT_JSON=data/care_cot.json \
IMAGE_ROOT=data/images \
SYNTHESIS_MODEL=gpt-4o \
VERIFIER_MODEL=gpt-4o \
bash scripts/synthesize_cot.shIf VERIFIER_MODEL is empty, the script keeps generated reasoning without verifier filtering.
Copy configs/dataset_info.example.json to your LLaMA-Factory dataset directory as dataset_info.json, then edit the relative file_name.
NPROC_PER_NODE=4 \
CONFIG=configs/sft_qwen2_5vl_lora.yaml \
bash scripts/train_sft.shNPROC_PER_NODE=4 \
MODEL_NAME_OR_PATH=outputs/care-sft \
DATASET_NAME=data/care_grpo.json \
IMAGE_ROOT=data/images \
OUTPUT_DIR=outputs/care-grpo \
bash scripts/train_grpo.shThe trainer computes token probabilities for each generated completion, averages valid completion-token probabilities into confidence, and passes it to confidence_aware_reward.
PYTHONPATH=src pytest -q