IB

IBI-CAAI/Ker-VLJEPA-3B

Model

Ker-VLJEPA-3B

0

7 commits

1 linked in READMEs

updated Mar 25, 2026

See the code

README

Ker-VLJEPA-3B

A multi-modal vision-language model for automated Chest CT radiology report generation. Ker-VLJEPA-3B takes pre-computed 1024-d slice embeddings from Guided-Chest-CT-LeJEPA as input (not raw CT images) and generates free-text narrative findings reports in the style of a radiologist.

Dependency: This model requires IBI-CAAI/Guided-Chest-CT-LeJEPA to first extract per-slice embeddings from raw CT volumes. Ker-VLJEPA-3B does not process CT images directly.

New SOTA on CT-RATE: Macro F1 = 0.429, surpassing the previous state-of-the-art U-VLM (F1 = 0.414) by +3.6%.

Developed by the Institute for Biomedical Informatics Center for Applied AI (IBI-CAAI) at the University of Kentucky.

Model Details

PropertyValue
Model TypeMulti-modal Vision-Language Model (VLM) for Chest CT report generation
Language ModelLlama 3.2 3B with LoRA adapters (r=64, alpha=128)
Input EmbeddingsGuided-Chest-CT-LeJEPA (ViT-Large) β€” required dependency, provides 1024-d per-slice embeddings from raw CT
Visual EncoderZ-Zoned Perceiver β€” compresses variable-length slice embeddings into 32 fixed visual tokens (3072-d)
Visual GroundingFlamingo-style gated cross-attention adapters at LLM layers 7, 14, 21
InputPre-computed LeJEPA slice embeddings (num_slices x 1024) β€” not raw CT images
OutputFree-text narrative radiology findings report
Model Date03/2026
LicenseCC BY-NC-SA 4.0 (inherited from CT-RATE dataset terms)
Parameters~3.2B (Llama 3B base) + 1.7 GB LoRA + 320 MB bridge components

Architecture

Ker-VLJEPA-3B bridges vision and language through a 3-stage architecture:

Raw CT Volume
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Guided-Chest-CT-LeJEPA     β”‚  ViT-Large backbone (separate model)
β”‚  (per-slice feature extract) β”‚  Produces 1024-d embedding per slice
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚ (num_slices, 1024)
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Z-Zoned Perceiver          β”‚  32 anatomical zones, each with learned queries
β”‚  + Global Self-Attention    β”‚  Compresses variable-length slices β†’ 32 tokens
β”‚  + JEPA Predictor (β†’ 3072d) β”‚  Projects into LLM hidden space
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚ (32, 3072)
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Llama 3.2 3B + LoRA        β”‚  Embedding grafting: visual tokens replace
β”‚  + Cross-Attention Adapters  β”‚    <|visual_region|> placeholders in prompt
β”‚    @ layers 7, 14, 21       β”‚  Cross-attention: text attends to visual tokens
β”‚  + Additive Layer Projectors β”‚    at 3 intermediate LLM layers
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β–Ό
      Narrative Report

Key Architectural Innovations

  • Z-Zoned Cross-Attention: Divides the body axis into 32 spatial zones. Each zone's queries attend only to slices within their anatomical region, enforcing spatial specialization by construction.
  • Flamingo-style Cross-Attention Bridge: Rather than simple additive injection (which the LLM can trivially ignore), text hidden states explicitly attend to visual tokens via cross-attention at layers 7, 14, and 21.
  • Warm Bridge Technique: Bridge components (cross-attention adapters, layer projectors, LoRA) are initialized from a prior converged checkpoint rather than random, yielding +4.4% F1 improvement.
  • Frozen Cross-Attention + EWC: During narrative fine-tuning (Phase 4), cross-attention adapters are frozen to preserve visual grounding, while Elastic Weight Consolidation constrains LoRA drift.

Intended Uses

This model is intended for research purposes in medical imaging and radiology.

  • Automated generation of narrative chest CT findings reports
  • Research into vision-language architectures for medical imaging
  • Benchmarking on the CT-RATE evaluation protocol

Not intended for: Clinical diagnosis, treatment decisions, or any patient-facing application without proper clinical validation.

Training

Data

Trained exclusively on the train split of CT-RATE (~46,400 volumes), with guided cropping annotations from ReXGroundingCT.

Hardware

8x NVIDIA H200 GPUs with DDP via HuggingFace Accelerate, bf16 mixed precision.

4-Phase Training Pipeline

PhaseObjectiveTrainable ComponentsKey HyperparametersResult
Phase 1Visual encoder alignmentVisual encoder + JEPA headLR=5e-5, BS=32, 20 epochsF1=0.460, AUC=0.811
Phase 2Contrastive bridge (InfoNCE + MMD)Visual encoder + LoRA + JEPA headLR=3e-5, BS=64, 30 epochsF1=0.465, AUC=0.816
Phase 3Generative fine-tuning (positive-findings-only text)JEPA predictor + LoRA + cross-attn + layer projectorsLR=2e-5, BS=8, warm bridge initGen F1=0.422
Phase 4Raw narrative fine-tuningLoRA only (cross-attn frozen, EWC=100.0)LR=5e-7, BS=8, 14 epochsGen F1=0.429

Phase 3 β†’ Phase 4 innovation: In Phase 3, the model trains on positive-findings-only text to learn pathology detection without gradient domination from normal-text tokens (~90% of raw reports). Phase 4 then adapts to raw radiologist prose with frozen cross-attention + ultra-conservative LoRA updates.

Generation Configuration

ParameterValueRationale
Temperature0.6Optimal via sweep β€” balances diversity and accuracy
Top-p0.9Nucleus sampling
Repetition penalty1.1Prevents degenerate loops
No-repeat n-gram4Medical reports need some anatomical repetition
Max new tokens384Covers 95%+ of reports

Results

CT-RATE Benchmark (Cross-Method Comparison)

All methods evaluated on the CT-RATE validation set (2,984 volumes) using the official RadBERT classifier for 18-class binary label extraction.

MethodMacro F1Macro PrecMacro RecNotes
CT-CLIP (Hamamci et al.)0.194β€”β€”Zero-shot
CT-CHAT (Hamamci et al.)0.287β€”β€”Fine-tuned
BTB3D (Song et al.)0.354β€”β€”
U-VLM (Lee et al.)0.4140.4910.429Previous SOTA
Ker-VLJEPA-3B0.4290.3890.524

Per-Class Results (2,984 validation samples)

ClassPrecRecF1Support
Pleural effusion0.5740.7890.664370
Arterial wall calcification0.6420.6600.651849
Coronary artery wall calcification0.5800.5850.582752
Cardiomegaly0.4370.7430.550315
Lung nodule0.4910.5600.5231,344
Lung opacity0.5450.4530.4941,173
Emphysema0.3460.6670.456588
Lymphadenopathy0.3930.5320.452769
Pulmonary fibrotic sequela0.3840.5050.436819
Atelectasis0.3690.4960.423698
Consolidation0.4300.3890.408576
Pericardial effusion0.2380.6140.343215
Mosaic attenuation pattern0.2560.4940.337245
Hiatal hernia0.2570.3970.312413
Peribronchial thickening0.2710.3540.307347
Medical material0.1940.7220.305306
Bronchiectasis0.2380.3280.276326
Interlobular septal thickening0.3570.1420.203246

Macro (default 0.5 threshold): F1=0.429, Prec=0.389, Rec=0.524

Evaluation Protocol

Clinical accuracy follows the CT-RATE evaluation protocol, the same methodology used by CT-CLIP, CT-CHAT, BTB3D, and U-VLM:

  1. Generate free-text narrative reports from all validation CT volumes (temp=0.6, top_p=0.9)
  2. Clean degenerate text (truncate at onset of repeated chars/unicode)
  3. Strip negation suffixes before RadBERT (prevents false positive extraction)
  4. Extract 18 binary abnormality labels using the official CT-RATE RadBERT classifier with CT-RATE weights
  5. Compute macro-averaged F1, precision, recall against ground-truth labels

The RadBERT classifier achieves F1=0.982 on ground-truth reports, confirming it is a reliable extraction tool.

How to Use

Prerequisites

pip install torch transformers peft safetensors accelerate
pip install flash-attn --no-build-isolation  # recommended for fast generation

You will also need:

Repository Contents

Ker-VLJEPA-3B/
β”œβ”€β”€ README.md                           # This file
β”œβ”€β”€ model.py                            # Inference-only model class
β”œβ”€β”€ generate_report.py                  # CLI example
└── weights/
    β”œβ”€β”€ visual_encoder.safetensors      # Z-Zoned Perceiver + JEPA predictor (43 MB)
    β”œβ”€β”€ bridge_components.safetensors   # Cross-attn adapters, layer projectors, norms (277 MB)
    β”œβ”€β”€ lora_adapters/                  # LoRA adapter weights for Llama 3.2 3B (1.7 GB)
    β”‚   β”œβ”€β”€ adapter_config.json
    β”‚   └── adapter_model.safetensors
    └── tokenizer/                      # Tokenizer with <|visual_region|> special token
        β”œβ”€β”€ chat_template.jinja
        β”œβ”€β”€ tokenizer.json
        └── tokenizer_config.json

Python API

import numpy as np
import torch
from model import load_model

# 1. Load the model (requires local Llama 3.2 3B)
model = load_model(
    llm_path="/path/to/Llama-3.2-3B",
    weights_dir="weights",
    device="cuda",
)

# 2. Load pre-computed LeJEPA slice embeddings for a CT volume
#    Shape: (1, num_slices, 1024) β€” one 1024-d embedding per CT slice
#    See IBI-CAAI/Guided-Chest-CT-LeJEPA for how to extract these
embeddings = torch.from_numpy(np.load("volume_embeddings.npy")).unsqueeze(0).float()
mask = torch.ones(1, embeddings.shape[1])  # 1=valid, 0=padding

# 3. Generate a narrative report
report = model.generate(
    slice_embeddings=embeddings,
    mask=mask,
    temperature=0.6,
    max_new_tokens=384,
)
print(report)

CLI

python generate_report.py \
    --llm_path /path/to/Llama-3.2-3B \
    --embeddings volume_embeddings.npy \
    --temperature 0.6

End-to-End: Raw CT Volume β†’ Report

This example shows the full pipeline, from a raw NIfTI CT volume through LeJEPA embedding extraction to report generation.

import nibabel as nib
import numpy as np
import torch
import torch.nn.functional as F
import timm
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from model import load_model

# --- Step 1: Load the LeJEPA visual backbone ---
backbone = timm.create_model(
    "vit_large_patch14_dinov2", pretrained=False,
    num_classes=0, in_chans=1, img_size=518, dynamic_img_size=True,
)
ckpt = load_file(hf_hub_download("IBI-CAAI/Guided-Chest-CT-LeJEPA", "model.safetensors"))
backbone.load_state_dict(ckpt, strict=False)
backbone.eval().cuda()

# --- Step 2: Preprocess and extract slice embeddings ---
# HU clipping and normalization must match LeJEPA training exactly
CLIP_MIN, CLIP_MAX = -997.0, 888.0
MEAN_HU, STD_HU = -142.39, 360.97
RANGE = CLIP_MAX - CLIP_MIN
NORM_MEAN = (MEAN_HU - CLIP_MIN) / RANGE
NORM_STD = STD_HU / RANGE

vol = nib.load("chest_ct.nii.gz").get_fdata()  # (H, W, D) in Hounsfield Units

slice_embeddings = []
with torch.no_grad():
    for i in range(vol.shape[2]):
        s = torch.from_numpy(vol[:, :, i]).float().unsqueeze(0)  # (1, H, W)
        s = torch.clamp(s, CLIP_MIN, CLIP_MAX)
        s = (s - CLIP_MIN) / RANGE
        s = (s - NORM_MEAN) / NORM_STD
        # Align to patch size 14
        _, H, W = s.shape
        tH, tW = (H // 14) * 14, (W // 14) * 14
        if tH != H or tW != W:
            s = F.interpolate(s.unsqueeze(0), size=(tH, tW), mode='nearest').squeeze(0)
        emb = backbone(s.unsqueeze(0).cuda())  # (1, 1024)
        slice_embeddings.append(emb.cpu())

embeddings = torch.cat(slice_embeddings, dim=0).unsqueeze(0)  # (1, num_slices, 1024)
mask = torch.ones(1, embeddings.shape[1])

# --- Step 3: Generate the report ---
model = load_model("/path/to/Llama-3.2-3B", "weights", "cuda")
report = model.generate(slice_embeddings=embeddings, mask=mask)
print(report)

Prompt Format

The model uses the Llama 3.2 chat template with 32 <|visual_region|> tokens injected into the user message:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a radiology reporting assistant. Describe thoracic findings based on
the provided CT scan visual features. Report only what you observe.<|eot_id|>
<|start_header_id|>user<|end_header_id|>

Based on the visual features from this CT scan, describe the thoracic findings.
<|visual_region|> x 32<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Each <|visual_region|> placeholder is replaced at the embedding level with the corresponding visual token from the perceiver encoder. Cross-attention adapters at layers 7, 14, and 21 provide additional grounding throughout generation.

Limitations

  • Domain-specific: Trained exclusively on Chest CT from CT-RATE. Performance on other body regions, modalities, or datasets is unknown.
  • Not clinically validated: This is a research model. Generated reports should not be used for clinical decision-making.
  • Hallucination: Like all generative models, Ker-VLJEPA-3B can produce findings not present in the scan. The 0.389 precision indicates ~61% of generated positive findings are true positives.
  • Degeneration: At high token counts (>384), generation quality degrades. Reports should be truncated.
  • English only: All training text is in English.

Citation

If you use this model, please cite the CT-RATE dataset:

@misc{bumgardner2026curriculumdriven3dctreport,
      title={Curriculum-Driven 3D CT Report Generation via Language-Free Visual Grafting and Zone-Constrained Compression}, 
      author={V. K. Cody Bumgardner and Mitchell A. Klusty and Mahmut S. Gokmen and Evan W. Damron},
      year={2026},
      eprint={2603.23308},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2603.23308}, 
}
chest-ct
lejepa
llama
lora
medical
radiology
report-generation
safetensors
text-generation
university-of-kentucky
vision-language

Contributors

codybum

7 commits

IB

IBI-CAAI/Ker-VLJEPA-3B

Model

Ker-VLJEPA-3B

0

7 commits

1 linked in READMEs

updated Mar 25, 2026

See the code

README

Ker-VLJEPA-3B

A multi-modal vision-language model for automated Chest CT radiology report generation. Ker-VLJEPA-3B takes pre-computed 1024-d slice embeddings from Guided-Chest-CT-LeJEPA as input (not raw CT images) and generates free-text narrative findings reports in the style of a radiologist.

Dependency: This model requires IBI-CAAI/Guided-Chest-CT-LeJEPA to first extract per-slice embeddings from raw CT volumes. Ker-VLJEPA-3B does not process CT images directly.

New SOTA on CT-RATE: Macro F1 = 0.429, surpassing the previous state-of-the-art U-VLM (F1 = 0.414) by +3.6%.

Developed by the Institute for Biomedical Informatics Center for Applied AI (IBI-CAAI) at the University of Kentucky.

Model Details

PropertyValue
Model TypeMulti-modal Vision-Language Model (VLM) for Chest CT report generation
Language ModelLlama 3.2 3B with LoRA adapters (r=64, alpha=128)
Input EmbeddingsGuided-Chest-CT-LeJEPA (ViT-Large) β€” required dependency, provides 1024-d per-slice embeddings from raw CT
Visual EncoderZ-Zoned Perceiver β€” compresses variable-length slice embeddings into 32 fixed visual tokens (3072-d)
Visual GroundingFlamingo-style gated cross-attention adapters at LLM layers 7, 14, 21
InputPre-computed LeJEPA slice embeddings (num_slices x 1024) β€” not raw CT images
OutputFree-text narrative radiology findings report
Model Date03/2026
LicenseCC BY-NC-SA 4.0 (inherited from CT-RATE dataset terms)
Parameters~3.2B (Llama 3B base) + 1.7 GB LoRA + 320 MB bridge components

Architecture

Ker-VLJEPA-3B bridges vision and language through a 3-stage architecture:

Raw CT Volume
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Guided-Chest-CT-LeJEPA     β”‚  ViT-Large backbone (separate model)
β”‚  (per-slice feature extract) β”‚  Produces 1024-d embedding per slice
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚ (num_slices, 1024)
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Z-Zoned Perceiver          β”‚  32 anatomical zones, each with learned queries
β”‚  + Global Self-Attention    β”‚  Compresses variable-length slices β†’ 32 tokens
β”‚  + JEPA Predictor (β†’ 3072d) β”‚  Projects into LLM hidden space
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚ (32, 3072)
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Llama 3.2 3B + LoRA        β”‚  Embedding grafting: visual tokens replace
β”‚  + Cross-Attention Adapters  β”‚    <|visual_region|> placeholders in prompt
β”‚    @ layers 7, 14, 21       β”‚  Cross-attention: text attends to visual tokens
β”‚  + Additive Layer Projectors β”‚    at 3 intermediate LLM layers
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β–Ό
      Narrative Report

Key Architectural Innovations

  • Z-Zoned Cross-Attention: Divides the body axis into 32 spatial zones. Each zone's queries attend only to slices within their anatomical region, enforcing spatial specialization by construction.
  • Flamingo-style Cross-Attention Bridge: Rather than simple additive injection (which the LLM can trivially ignore), text hidden states explicitly attend to visual tokens via cross-attention at layers 7, 14, and 21.
  • Warm Bridge Technique: Bridge components (cross-attention adapters, layer projectors, LoRA) are initialized from a prior converged checkpoint rather than random, yielding +4.4% F1 improvement.
  • Frozen Cross-Attention + EWC: During narrative fine-tuning (Phase 4), cross-attention adapters are frozen to preserve visual grounding, while Elastic Weight Consolidation constrains LoRA drift.

Intended Uses

This model is intended for research purposes in medical imaging and radiology.

  • Automated generation of narrative chest CT findings reports
  • Research into vision-language architectures for medical imaging
  • Benchmarking on the CT-RATE evaluation protocol

Not intended for: Clinical diagnosis, treatment decisions, or any patient-facing application without proper clinical validation.

Training

Data

Trained exclusively on the train split of CT-RATE (~46,400 volumes), with guided cropping annotations from ReXGroundingCT.

Hardware

8x NVIDIA H200 GPUs with DDP via HuggingFace Accelerate, bf16 mixed precision.

4-Phase Training Pipeline

PhaseObjectiveTrainable ComponentsKey HyperparametersResult
Phase 1Visual encoder alignmentVisual encoder + JEPA headLR=5e-5, BS=32, 20 epochsF1=0.460, AUC=0.811
Phase 2Contrastive bridge (InfoNCE + MMD)Visual encoder + LoRA + JEPA headLR=3e-5, BS=64, 30 epochsF1=0.465, AUC=0.816
Phase 3Generative fine-tuning (positive-findings-only text)JEPA predictor + LoRA + cross-attn + layer projectorsLR=2e-5, BS=8, warm bridge initGen F1=0.422
Phase 4Raw narrative fine-tuningLoRA only (cross-attn frozen, EWC=100.0)LR=5e-7, BS=8, 14 epochsGen F1=0.429

Phase 3 β†’ Phase 4 innovation: In Phase 3, the model trains on positive-findings-only text to learn pathology detection without gradient domination from normal-text tokens (~90% of raw reports). Phase 4 then adapts to raw radiologist prose with frozen cross-attention + ultra-conservative LoRA updates.

Generation Configuration

ParameterValueRationale
Temperature0.6Optimal via sweep β€” balances diversity and accuracy
Top-p0.9Nucleus sampling
Repetition penalty1.1Prevents degenerate loops
No-repeat n-gram4Medical reports need some anatomical repetition
Max new tokens384Covers 95%+ of reports

Results

CT-RATE Benchmark (Cross-Method Comparison)

All methods evaluated on the CT-RATE validation set (2,984 volumes) using the official RadBERT classifier for 18-class binary label extraction.

MethodMacro F1Macro PrecMacro RecNotes
CT-CLIP (Hamamci et al.)0.194β€”β€”Zero-shot
CT-CHAT (Hamamci et al.)0.287β€”β€”Fine-tuned
BTB3D (Song et al.)0.354β€”β€”
U-VLM (Lee et al.)0.4140.4910.429Previous SOTA
Ker-VLJEPA-3B0.4290.3890.524

Per-Class Results (2,984 validation samples)

ClassPrecRecF1Support
Pleural effusion0.5740.7890.664370
Arterial wall calcification0.6420.6600.651849
Coronary artery wall calcification0.5800.5850.582752
Cardiomegaly0.4370.7430.550315
Lung nodule0.4910.5600.5231,344
Lung opacity0.5450.4530.4941,173
Emphysema0.3460.6670.456588
Lymphadenopathy0.3930.5320.452769
Pulmonary fibrotic sequela0.3840.5050.436819
Atelectasis0.3690.4960.423698
Consolidation0.4300.3890.408576
Pericardial effusion0.2380.6140.343215
Mosaic attenuation pattern0.2560.4940.337245
Hiatal hernia0.2570.3970.312413
Peribronchial thickening0.2710.3540.307347
Medical material0.1940.7220.305306
Bronchiectasis0.2380.3280.276326
Interlobular septal thickening0.3570.1420.203246

Macro (default 0.5 threshold): F1=0.429, Prec=0.389, Rec=0.524

Evaluation Protocol

Clinical accuracy follows the CT-RATE evaluation protocol, the same methodology used by CT-CLIP, CT-CHAT, BTB3D, and U-VLM:

  1. Generate free-text narrative reports from all validation CT volumes (temp=0.6, top_p=0.9)
  2. Clean degenerate text (truncate at onset of repeated chars/unicode)
  3. Strip negation suffixes before RadBERT (prevents false positive extraction)
  4. Extract 18 binary abnormality labels using the official CT-RATE RadBERT classifier with CT-RATE weights
  5. Compute macro-averaged F1, precision, recall against ground-truth labels

The RadBERT classifier achieves F1=0.982 on ground-truth reports, confirming it is a reliable extraction tool.

How to Use

Prerequisites

pip install torch transformers peft safetensors accelerate
pip install flash-attn --no-build-isolation  # recommended for fast generation

You will also need:

Repository Contents

Ker-VLJEPA-3B/
β”œβ”€β”€ README.md                           # This file
β”œβ”€β”€ model.py                            # Inference-only model class
β”œβ”€β”€ generate_report.py                  # CLI example
└── weights/
    β”œβ”€β”€ visual_encoder.safetensors      # Z-Zoned Perceiver + JEPA predictor (43 MB)
    β”œβ”€β”€ bridge_components.safetensors   # Cross-attn adapters, layer projectors, norms (277 MB)
    β”œβ”€β”€ lora_adapters/                  # LoRA adapter weights for Llama 3.2 3B (1.7 GB)
    β”‚   β”œβ”€β”€ adapter_config.json
    β”‚   └── adapter_model.safetensors
    └── tokenizer/                      # Tokenizer with <|visual_region|> special token
        β”œβ”€β”€ chat_template.jinja
        β”œβ”€β”€ tokenizer.json
        └── tokenizer_config.json

Python API

import numpy as np
import torch
from model import load_model

# 1. Load the model (requires local Llama 3.2 3B)
model = load_model(
    llm_path="/path/to/Llama-3.2-3B",
    weights_dir="weights",
    device="cuda",
)

# 2. Load pre-computed LeJEPA slice embeddings for a CT volume
#    Shape: (1, num_slices, 1024) β€” one 1024-d embedding per CT slice
#    See IBI-CAAI/Guided-Chest-CT-LeJEPA for how to extract these
embeddings = torch.from_numpy(np.load("volume_embeddings.npy")).unsqueeze(0).float()
mask = torch.ones(1, embeddings.shape[1])  # 1=valid, 0=padding

# 3. Generate a narrative report
report = model.generate(
    slice_embeddings=embeddings,
    mask=mask,
    temperature=0.6,
    max_new_tokens=384,
)
print(report)

CLI

python generate_report.py \
    --llm_path /path/to/Llama-3.2-3B \
    --embeddings volume_embeddings.npy \
    --temperature 0.6

End-to-End: Raw CT Volume β†’ Report

This example shows the full pipeline, from a raw NIfTI CT volume through LeJEPA embedding extraction to report generation.

import nibabel as nib
import numpy as np
import torch
import torch.nn.functional as F
import timm
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from model import load_model

# --- Step 1: Load the LeJEPA visual backbone ---
backbone = timm.create_model(
    "vit_large_patch14_dinov2", pretrained=False,
    num_classes=0, in_chans=1, img_size=518, dynamic_img_size=True,
)
ckpt = load_file(hf_hub_download("IBI-CAAI/Guided-Chest-CT-LeJEPA", "model.safetensors"))
backbone.load_state_dict(ckpt, strict=False)
backbone.eval().cuda()

# --- Step 2: Preprocess and extract slice embeddings ---
# HU clipping and normalization must match LeJEPA training exactly
CLIP_MIN, CLIP_MAX = -997.0, 888.0
MEAN_HU, STD_HU = -142.39, 360.97
RANGE = CLIP_MAX - CLIP_MIN
NORM_MEAN = (MEAN_HU - CLIP_MIN) / RANGE
NORM_STD = STD_HU / RANGE

vol = nib.load("chest_ct.nii.gz").get_fdata()  # (H, W, D) in Hounsfield Units

slice_embeddings = []
with torch.no_grad():
    for i in range(vol.shape[2]):
        s = torch.from_numpy(vol[:, :, i]).float().unsqueeze(0)  # (1, H, W)
        s = torch.clamp(s, CLIP_MIN, CLIP_MAX)
        s = (s - CLIP_MIN) / RANGE
        s = (s - NORM_MEAN) / NORM_STD
        # Align to patch size 14
        _, H, W = s.shape
        tH, tW = (H // 14) * 14, (W // 14) * 14
        if tH != H or tW != W:
            s = F.interpolate(s.unsqueeze(0), size=(tH, tW), mode='nearest').squeeze(0)
        emb = backbone(s.unsqueeze(0).cuda())  # (1, 1024)
        slice_embeddings.append(emb.cpu())

embeddings = torch.cat(slice_embeddings, dim=0).unsqueeze(0)  # (1, num_slices, 1024)
mask = torch.ones(1, embeddings.shape[1])

# --- Step 3: Generate the report ---
model = load_model("/path/to/Llama-3.2-3B", "weights", "cuda")
report = model.generate(slice_embeddings=embeddings, mask=mask)
print(report)

Prompt Format

The model uses the Llama 3.2 chat template with 32 <|visual_region|> tokens injected into the user message:

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

You are a radiology reporting assistant. Describe thoracic findings based on
the provided CT scan visual features. Report only what you observe.<|eot_id|>
<|start_header_id|>user<|end_header_id|>

Based on the visual features from this CT scan, describe the thoracic findings.
<|visual_region|> x 32<|eot_id|><|start_header_id|>assistant<|end_header_id|>

Each <|visual_region|> placeholder is replaced at the embedding level with the corresponding visual token from the perceiver encoder. Cross-attention adapters at layers 7, 14, and 21 provide additional grounding throughout generation.

Limitations

  • Domain-specific: Trained exclusively on Chest CT from CT-RATE. Performance on other body regions, modalities, or datasets is unknown.
  • Not clinically validated: This is a research model. Generated reports should not be used for clinical decision-making.
  • Hallucination: Like all generative models, Ker-VLJEPA-3B can produce findings not present in the scan. The 0.389 precision indicates ~61% of generated positive findings are true positives.
  • Degeneration: At high token counts (>384), generation quality degrades. Reports should be truncated.
  • English only: All training text is in English.

Citation

If you use this model, please cite the CT-RATE dataset:

@misc{bumgardner2026curriculumdriven3dctreport,
      title={Curriculum-Driven 3D CT Report Generation via Language-Free Visual Grafting and Zone-Constrained Compression}, 
      author={V. K. Cody Bumgardner and Mitchell A. Klusty and Mahmut S. Gokmen and Evan W. Damron},
      year={2026},
      eprint={2603.23308},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2603.23308}, 
}
chest-ct
lejepa
llama
lora
medical
radiology
report-generation
safetensors
text-generation
university-of-kentucky
vision-language

Contributors

codybum

7 commits