← All models

image-text-to-text Β· vision-language Β· WebGPU Β· ~2.9 GB

PaliGemma 2 β€” one model, many vision tasks via prefixes

PaliGemma is Google's task-steerable VLM: instead of a chat, you give it a short prefix β€” caption en, ocr, detect car, segment dog, answer en … β€” and it captions, reads text, locates objects (with box coordinates), or answers a visual question. All streaming, on your GPU, nothing uploaded.

Made by Paul Kinlan Β· Model runs locally in your browser by πŸ€— Transformers.js Β· Source on GitHub

At a glance

Modelonnx-community/paligemma2-3b-pt-224 (ONNX build of google/paligemma2-3b-pt-224)
Taskimage-text-to-text (task-prefixed vision β†’ text)
ArchitectureSigLIP-So400m vision encoder + Gemma 2 text decoder (PaliGemma 2)
Params / dtype~3B Β· decoder q4f16, vision fp16, embeddings q8
BackendWebGPU (required β€” needs a GPU + shader-f16)
Download~2.9 GB, cached after first load
LicenseGemma license (see model card)
Web APIsWebGPU, Web Workers, FileReader

This is the pt (pretrained) checkpoint β€” it responds best to the documented task prefixes (caption, ocr, detect, segment, answer). Free-form questions work but are terser than an instruction-tuned VLM.

Run it

Two cats on a couch A busy street scene A riverside at golden hour A cozy bedroom
…or drop / choose your own image
Selected image
The output streams here.

See inside

PaliGemma has no chat template β€” the whole instruction is a short task prefix placed after the image tokens. Below is the exact prompt string the processor receives (the <image> marker expands into 256 vision tokens), and the live token stream with the time each token arrived. For detect the model emits <locNNNN> coordinate tokens β€” the Practical demo decodes those into boxes.

Constructed prompt

Run a task to see the constructed prompt.

Token stream (value Β· ms since start)

Tokens appear here as they're generated.

Why it matters

Most VLMs do one thing (chat about an image). PaliGemma is a Swiss-army vision model: the same weights caption, read, locate, and answer β€” you just change the prefix. Running that in a browser tab turns a stack of separate vision services into one on-device primitive.

Use cases

Basics

Caption an image β€” the caption en prefix, streamed.

Practical

Detect objects by name and draw the boxes decoded from the model's <loc> tokens.

Wild

Free-form prefix lab β€” type any task string and see how the model responds.

Multi-model

PaliGemma captions β†’ an OPUS-MT translator renders multilingual alt-text.

How the API works

PaliGemma in Transformers.js uses a dedicated model class. You pass the image and a task-prefix prompt to the processor, then generate β€” streaming tokens as they come:

import { AutoProcessor, PaliGemmaForConditionalGeneration, load_image, TextStreamer }
  from "@huggingface/transformers";

const model_id = "onnx-community/paligemma2-3b-pt-224";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await PaliGemmaForConditionalGeneration.from_pretrained(model_id, {
  dtype: { embed_tokens: "q8", vision_encoder: "fp16", decoder_model_merged: "q4f16" },
  device: "webgpu",                        // WebGPU required
});

const image = await load_image(imageURL);
const prompt = "<image>caption en";  // or "<image>ocr", "<image>detect car", "<image>answer en …"
const inputs = await processor(image, prompt);

const streamer = new TextStreamer(processor.tokenizer,
  { skip_prompt: true, skip_special_tokens: true, callback_function: (t) => append(t) });
await model.generate({ ...inputs, max_new_tokens: 100, do_sample: false, streamer });

This page runs exactly that, in a Web Worker, and gates on a real WebGPU adapter first β€” if none exists it shows a labelled needs-WebGPU state instead of a fake answer.

References