Skip to content

Image-language and multimodal models · Image-language and multimodal models · MM013 · Model

LLaVA: image-based visual instruction tuning

Connects a pretrained vision encoder to a language model and trains on visual instruction examples. It illustrates how alignment pretraining and instruction tuning can produce an image-grounded assistant with a…

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Connects a pretrained vision encoder to a language model and trains on visual instruction examples. It illustrates how alignment pretraining and instruction tuning can produce an image-grounded assistant with a relatively simple multimodal connector.

Question / objective

Can instruction data teach a language model to use image features when following user questions and requests? The learning target replaces a null/alternative hypothesis formulation; benchmark evaluation is a separate statistical task.

Method type and supervision

Model/system family. Image-language or broader multimodal learning using the paired, generated or task-specific supervision described below. This is not a classical significance test.

Architecture / computational structure

A vision encoder maps an image to visual features; a learned projection maps them into the language-model embedding space, where they condition autoregressive answer generation. Later family variants change connectors and processing, so identify the specific design.

Assumptions

Instruction answers must be supported by the image. Synthetic teacher data can carry hallucinations and language bias. A language model may infer plausible context instead of using visible evidence, especially when image resolution removes text or small objects.

Formula / computational definition

Hv=Pϕ(Ev(I))H_v=P_\phi(E_v(I)) and L=−∑t∈answerlog⁡pθ(yt∣y<t,Hv,q)L=-\sum_{t\in answer}\log p_\theta(y_t\mid y_{<t},H_v,q) describe visual projection and answer-token instruction loss. Prompt tokens may be masked from the loss. This captures the central mechanism; consult the primary source for all masks, stages, normalizations and loss terms.

Parameters and notation

Learned/estimated quantities: Projection and selected LM/vision weights are trainable according to the stage. Image processor, token packing and answer masks are interface choices; not every LLaVA release uses the same projection or patch budget. Hyperparameters and design choices: Alignment versus instruction stages, image resolution, token budget, data mixture, loss masking and decoding affect performance.

Fitting, fine-tuning, and adaptation

Train the visual connector first, then selectively tune the language model or supported LoRA adapters. Unfreeze vision layers only when data support it. Retain text-only and grounding tests to detect language forgetting and increased visual hallucination. Save the exact trainable-module selection, data split, loss, optimizer and processor configuration; distinguish parameter adaptation from inference-time prompt tuning.

How to use and calibrate

Choose a specific model/processor and task protocol, validate preprocessing on known examples, tune only on a held-out development set and freeze the final evaluation. Use grounded QA, OCR/relationship subsets, object hallucination tests and image-swapping controls. Language-model judges need calibration against human-reviewed answers.

Example application

Answer a user’s question about the contents or relationships in a supplied image.

Interpretation / pitfalls

Watch out

Reported capability is conditional on available visual evidence, data coverage and the chosen task. Use grounded QA, OCR/relationship subsets, object hallucination tests and image-swapping controls. Language-model judges need calibration against human-reviewed answers. A successful numeric component example is not evidence that a complete system achieves a published benchmark score.

Python and R code examples

Component: Project visual features into a language-compatible embedding width. Dependencies: shared NumPy/base-R setup above. Python: executed successfully. R: unexecuted. Complete model training/inference: not run.

Full implementation routes: Python: use the authors’ model and matching processor/prompt template; R: call inference through reticulate and score structured answers natively. A toy projection does not implement a trained LLaVA assistant.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Project visual features into a language-compatible embedding width.

Shared setup for this chapter
import numpy as np
def softmax(x):
    z = np.asarray(x, dtype=float)
    e = np.exp(z-z.max())
    return e/e.sum()
visual=np.array([[1.,0.],[.2,.8]])
projection=np.array([[1.,0.,.5],[0.,1.,-.5]])
language_width_features=visual@projection
print(language_width_features,language_width_features.shape)
R

Component demo, not a trained model — Project visual features into a language-compatible embedding width.

visual <- rbind(c(1,0),c(.2,.8))
projection <- rbind(c(1,0,.5),c(0,1,-.5))
print(visual%*%projection); print(dim(visual%*%projection))

Sources

From the CodeSplash reference, entry MM013.