Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CARE

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:

  1. Medical-CoT synthesis: generate diagnostic reasoning from image, question, and ground-truth answer, then optionally verify the reasoning before keeping it.
  2. SFT cold start: fine-tune a VLM on structured <think>...</think><answer>...</answer> Medical-CoT data.
  3. 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.

Repository Layout

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.

Installation

cd CARE
python -m pip install -r requirements.txt
python -m pip install -e .[dev]

Data Formats

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.sh

Stage 0: Medical-CoT Synthesis

Set 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.sh

If VERIFIER_MODEL is empty, the script keeps generated reasoning without verifier filtering.

Stage 1: SFT Cold Start

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.sh

Stage 2: Confidence-Aware GRPO

NPROC_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.sh

The trainer computes token probabilities for each generated completion, averages valid completion-token probabilities into confidence, and passes it to confidence_aware_reward.

Tests

PYTHONPATH=src pytest -q

About

Official repository for “CARE: Confidence-Aware Reasoning for Reliable Medical VQA” (MICCAI 2026).

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages