Katkat

Multimodal Models: Images, Audio and Text

By the Katkat team · Updated · 9 min read

Quick overview

How multimodal LLMs turn images and audio into tokens: vision encoders, projectors, fusion designs, token cost, product uses and limits, for interviews.

Lesson 12 of 88 · AI Engineering Interview Course

After this lesson you should be able to explain how an LLM "sees" an image and "hears" audio: both are converted into sequences of vectors that the transformer treats much like text tokens. You should be able to compare the main ways of fusing modalities, estimate how many tokens an image or an audio clip costs, and say where multimodal models are reliable and where they are not.

The core idea: everything becomes a sequence of vectors

A transformer only needs a sequence of embedding vectors of the model's hidden size. Text gets there through a tokenizer and an embedding table. A multimodal model adds other front ends that produce vectors of the same size from pixels or sound. After that point, the decoder does not care where a vector came from.

The pipeline for a vision-language model usually looks like this:

  1. A modality encoder turns raw input into a sequence of feature vectors.
  2. A connector (a projection) maps those features into the LLM's embedding space.
  3. The resulting vectors are placed in the input sequence next to the text embeddings.
  4. The LLM runs as usual and generates text, one token at a time.

If you need a refresher on the decoder itself, see The Transformer, Explained for Engineers and Embeddings: Representing Text as Vectors.

Vision encoders and image tokens

Most vision encoders are Vision Transformers (ViT). The image is cut into fixed-size square patches, and each patch is flattened and linearly projected into a vector. Position information is added so the model knows where each patch came from, and a stack of transformer layers produces one feature vector per patch.

Many encoders are pretrained with a contrastive objective, as in CLIP: images and their captions are embedded, and training pulls matching pairs together and pushes mismatched pairs apart. The result is an encoder whose features already line up with language concepts, which makes the later connection to an LLM much easier.

Worked example: patch counts.

  • A 224 x 224 image with 16 x 16 patches gives (224 / 16) x (224 / 16) = 14 x 14 = 196 patches.
  • A 336 x 336 image with 14 x 14 patches gives 24 x 24 = 576 patches.

Patch count grows with the square of the side length. Doubling the resolution multiplies the number of patches by four, and attention cost grows faster still.

Real products handle large or oddly shaped images in different ways, and the details vary by vendor. Common strategies are resizing to a fixed size, splitting the image into tiles plus a low-resolution overview, and pooling or compressing patch features before they reach the LLM.

Here is an illustrative tiling scheme (not any specific product): a 1344 x 896 image is split into 448 x 448 tiles, which gives 3 x 2 = 6 tiles. If each tile is compressed to 256 tokens and one overview image adds another 256, the total is 6 x 256 + 256 = 1,792 tokens. That is roughly the same context budget as a long page of text, for one picture.

Audio: spectrograms, encoders and codec tokens

Sound is a waveform, for example 16,000 samples per second. Feeding raw samples to a transformer would create enormous sequences, so audio is compressed first. There are two common routes.

Continuous features for understanding. The waveform is converted into a log-mel spectrogram, which is a time-by-frequency picture of the signal with frequencies on a perceptual scale. An audio encoder (a convolutional front end plus transformer layers, as in Whisper-style speech models) reduces the frame rate and outputs one vector per short time step.

Worked example: audio token rate. Assume 16 kHz audio and a 10 ms hop between spectrogram frames.

  • 30 seconds = 480,000 samples.
  • Frames: 30 s / 0.01 s = 3,000 frames.
  • A front end that downsamples time by 2 gives 1,500 positions, which is 50 per second.
  • One minute is therefore 60 x 50 = 3,000 audio positions.

Rates differ between models, but the lesson is that audio costs context in proportion to its duration, whatever the content.

Discrete codec tokens for generation. To make a model speak, it helps to predict discrete tokens. A neural audio codec compresses sound into integer codes using vector quantization, often several codebooks per time step. The LLM predicts those codes, and a decoder turns them back into a waveform. This lets one model both listen and talk, at the price of more tokens per second and a more complex output format.

How the modalities are fused

"Fusion" is where the modality features meet the language model. The main designs are in this table.

DesignHow it worksStrengthsWeaknesses
Projector into the input sequenceEncoder features pass through a small MLP or linear layer and are inserted as extra tokensSimple, reuses a pretrained LLM, easy to train in stagesMany tokens per image, so context and compute cost grow
Cross-attention layersExtra layers let text hidden states attend to encoder features without adding them to the sequenceImage does not lengthen the text sequenceNew layers to train, more architecture change
Compressing connectorA learned module (for example, a set of query vectors) summarises many patches into a fixed small number of tokensPredictable token budgetCan lose fine detail such as small text
Native (early) fusionOne model is trained from scratch on interleaved text and discrete image or audio tokensFlexible, can generate images or audio tooExpensive pretraining, harder to build

The first design is the easiest to explain in an interview, and LLaVA-style models popularised it. Training is typically staged. First, only the connector is trained (encoder and LLM frozen) on image-caption pairs so the features land in the right space. Then the LLM, often with a parameter-efficient method such as the one in LoRA and QLoRA, is tuned on instruction data that mixes images and questions.

Inside the decoder, image tokens are ordinary positions. Text tokens attend to them through normal self-attention, so a question that comes after the image can read it directly. This is also why the image takes up space in the KV cache for the whole conversation.

Cost, latency and context

Because media becomes tokens, the usual LLM cost model applies. Take a hypothetical price of $3 per million input tokens (illustrative only).

  • One image at 1,792 tokens costs 1,792 x $3 / 1,000,000 = $0.005376, about half a cent.
  • 1,000 such images per day is 1.792 million tokens, or $5.376 per day of input.
  • One minute of audio at 3,000 positions costs 3,000 x $3 / 1,000,000 = $0.009.

Latency follows the same logic: more input tokens means a longer prefill phase and a worse time to first token. See Context Windows: Limits, Cost and Long-Context Behaviour for the budget side, and Streaming and Latency Metrics: TTFT and Tokens per Second for how prefill shows up in user-visible latency.

For voice products there is an architectural choice:

ApproachFlowTrade-off
CascadeSpeech-to-text, then LLM, then text-to-speechEach part is swappable and debuggable, but latencies add up and tone, emotion and interruptions are lost
Native audio modelAudio in, audio out in one modelLower latency potential and can use prosody, but harder to inspect, control and evaluate

Typical product uses and limits

Common uses include:

  • Document understanding: reading invoices, forms, charts and screenshots, often without a separate OCR step.
  • Visual question answering: product photos, accessibility descriptions, UI screenshots for support.
  • Speech: transcription, meeting summaries, voice assistants.
  • Agents: reading a screen to decide the next click (see Browser and Computer-Use Agents).

Known limits to state clearly:

  • Fine detail: small text, dense tables and tiny objects can be lost when images are downscaled or compressed.
  • Counting and spatial reasoning: "how many items" or "which is left of which" is less reliable than describing the scene.
  • Hallucination: the model may describe things that are not in the image, especially when the question presupposes them. See Why Language Models Hallucinate.
  • Audio nuance: accents, noise, overlapping speakers and domain jargon degrade transcripts. Cascades can also mis-hear names with no way to recover.
  • Security: instructions hidden inside an image or audio clip can act as prompt injection. See Prompt Injection and Guardrails.
  • Generation is not symmetric: many models accept images but output only text. Producing images or speech needs extra components or a natively multimodal model.

Practical mitigations are to crop or tile to the region of interest, send higher resolution only when needed, extract text with a dedicated OCR step for critical fields, and validate outputs against ground truth in an evaluation set.

How does this come up in interviews?

1. How does an LLM process an image? A vision encoder, usually a ViT, splits the image into patches and produces one feature vector per patch. A connector projects those into the LLM's embedding space, and they are inserted into the sequence like tokens. The decoder then attends to them with ordinary self-attention while generating text.

2. Why can a single image be expensive, and how would you reduce the cost? Patches grow with the square of the resolution, and each becomes a token that costs prefill compute, context space and KV cache memory. For example, a 336 x 336 image with 14 x 14 patches yields 576 tokens. Reduce cost by downscaling, cropping to the relevant region, sending fewer or lower-detail images, or using a model with a compressing connector.

3. Cascade or native audio for a voice assistant? A cascade (speech-to-text, LLM, text-to-speech) is easier to debug, swap and evaluate, and works well for transcription-style tasks. A native audio model can respond faster and use tone and interruptions but is harder to control and inspect. The answer depends on latency targets, the need for emotion or prosody, and how much observability the team requires.

4. A user uploads a photo of a receipt and the model returns a wrong total. How do you investigate? First check the input: resolution, compression and whether the text is legible after downscaling. Then compare the model's reading with OCR output or a human label, and test cropping or tiling the totals area. For a production system, add validation such as checking that line items sum to the total, and evaluate on a labelled receipt set.

5. How would you train a vision-language model from a pretrained LLM and encoder? Keep both frozen and train the connector on image-caption pairs so visual features align with the language space. Then fine-tune the LLM, possibly with LoRA, on mixed image-text instruction data. Evaluate for regressions in text-only ability, since fine-tuning can degrade it.

Common mistakes

  • Saying the model "reads pixels directly." There is always an encoder and a projection step before the LLM sees anything.
  • Treating an image as one token. It is hundreds or more, and it counts against context and cost.
  • Assuming higher resolution is always better, ignoring the quadratic growth in patches and the latency cost.
  • Trusting multimodal output for exact quantities, such as counts or totals, without validation.
  • Forgetting that images and audio are untrusted input that can carry injected instructions.
  • Mixing up continuous audio features (for understanding) with discrete codec tokens (for generation).
  • Presenting the cascade as outdated. It remains a sensible choice when control and debuggability matter.
  • Quoting token counts per image as universal. They depend on the model, the tiling scheme and the vendor.

Sources and further reading