Kinds of AI model

An LLM, a vision model, speech-to-text, text-to-speech, a reasoning model and a multimodal one look like six different things. Inside they share one skeleton: cut what goes in into pieces, predict the pieces that come out. Watch each one, then pick the kind, or the chain, for a job.

Level: BasicWatch: 13 steps · ~1 minutePick a model for a jobRecall: 3 questions · 8 cardsCompare all 6Python

What you'll take away

  • Explain the one skeleton every kind shares: cut into pieces, predict the pieces out
  • Know why an LLM's answer comes out one token at a time, each one scored and picked
  • Tell speech-to-text from text-to-speech by which way the spectrogram goes
  • Pick the kind, or the chain, for a job, and when a reasoning model is worth its time

The 1-minute version

Tap a point and the picture below plays that step.

4Compare them all
LLMText in, text out, one next token at a time
Write a short poem about rain
LLM
Vision
Speech-to-text
Text-to-speech
Reasoning
Multimodal
the prompt goes to the LLM → …
Step 1 / 13 · step by step

The picture: the AI quarter's main street, one hall for each kind of model. Each example goes to its hall and is cut into pieces on the roof: a prompt into tokens (small tiles), a photo into 14 × 14 patches, sound into a spectrogram; the answer comes out a piece at a time. The piece counts are the published shapes named in the code. The tokenizer is a toy, and the next-token and label scores, the spectrogram patterns and the reasoning model's 120 thinking tokens are made up for the picture.

Step 4 · Every option at once, on one clock

Compare them all: Kinds of AI model

Six models, each with its own example, on one clock. Count how many pieces each cuts its input into and how many it makes. Every one works on pieces; only what a piece is differs.

cutting the input
LLMText in, text out, one next token at a time0 tokens → 0 tokens

Use it when Writing, summing up, translating, answering, code: anything that is text at both ends

Skip it when Exact sums or recent facts with no source to read: it predicts likely words, it doesn't look anything up

Numbers from the papers named: ViT gets 196 patches from 224 pixels, Whisper a frame every 10 ms, LLaVA-1.5 576 image vectors; audio at 24 kHz is 24,000 samples a second. Token counts come from this page's toy tokenizer, and the reasoning tile's thinking length is made up for the picture: real ones vary a lot. Press any tile to see it large above, with when it fits.

Six kinds: in, cut into, out

KindTakesCut intoGives
LLMWrite a short poem about raintokens (words and bits of words)Soft rain on the roof, the city slows to listen.
Visiona 224 × 224 photo of a cat16 × 16 pixel patchescat 93%
Speech-to-text3 seconds of speechspectrogram frames, one every 10 msMeet you at the station at six
Text-to-speechYour order ships todaysounds (phonemes) or tokens2 seconds of speech at 24 kHz
Reasoning3 pens cost 45 baht. What do 7 cost?tokens, like an LLM7 pens cost 105 baht.
Multimodala photo of a price tag + how much is it?image patches + text tokensIt says 249 baht.

One skeleton

Every kind cuts what comes in into pieces, turns each piece into a vector of numbers, predicts the pieces that go out, and turns those back into text, a label or sound. Text becomes tokens, an image becomes patches, speech becomes spectrogram frames. Only the two ends change; the middle is the same kind of network reading a sequence.

Picking one

Start from what you have and what you want. When no single kind does it, chain them: a voice assistant has long been speech-to-text, then an LLM, then text-to-speech, and each hand-off adds waiting. Some newer models take speech in and give speech out in one. Use a reasoning model only when the problem has several steps: its thinking costs time.

Look at what goes in and out

Product names don't say which kind a model is, and one model may take several kinds of input. The provider's own documentation says what it accepts and returns; that, not the name, tells you where it sits among these six.

In real code

pieces.py
# What each kind of model cuts its input into before it sees anything: tokens, image patches, spectrogram frames, and
# the samples a text-to-speech model has to make. No model and no download: only the cutting, with the published shapes.
# - ViT: 16 x 16 pixel patches (arXiv:2010.11929). LLaVA-1.5: CLIP ViT-L/14 at 336 px (arXiv:2310.03744).
# - Whisper: 16 kHz audio, a 400-sample (25 ms) window every 160 samples (10 ms); the signal is padded by half a window
#   at each end and the last frame dropped, as whisper/audio.py does (torch.stft center=True, then stft[..., :-1]).
# The tokenizer is a toy one (words and punctuation, a long word split in two); real ones are learned (BPE).
# Run: python3 pieces.py
import math
import re


def toy_tokens(text):
    out = []
    for w in re.findall(r"[A-Za-z0-9']+|[^\sA-Za-z0-9']", text):
        out += [w[:5], w[5:]] if len(w) > 7 else [w]
    return out


def patches(image, size):
    """Cut an image (rows of [r, g, b] pixels) into size x size squares, each flattened to one list of numbers."""
    h, w = len(image), len(image[0])
    return [[c for row in image[y:y + size] for px in row[x:x + size] for c in px]
            for y in range(0, h, size) for x in range(0, w, size)]


def frames(audio, window=400, hop=160):
    """Whisper's framing: pad half a window each side, a window every hop, drop the last frame."""
    half = window // 2
    padded = audio[half:0:-1] + audio + audio[-2:-half - 2:-1]  # reflect padding, as torch.stft does
    n = 1 + (len(padded) - window) // hop
    return [padded[i * hop:i * hop + window] for i in range(n)][:-1]


def loudest_hz(frame, rate):
    """One column of a spectrogram: how loud each frequency is in this frame (a plain DFT), and the loudest one."""
    n = len(frame)
    power = [abs(sum(frame[t] * complex(math.cos(2 * math.pi * k * t / n), -math.sin(2 * math.pi * k * t / n))
                     for t in range(n))) ** 2 for k in range(n // 2 + 1)]
    return power.index(max(power)) * rate / n


# Text: an LLM's prompt as tokens.
prompt = toy_tokens("Write a short poem about rain")
assert prompt == ["Write", "a", "short", "poem", "about", "rain"]

# An image: 224 x 224 pixels, 3 colours each, cut into 16 x 16 patches.
cat = [[[(x * 7 + y) % 256, (x * y) % 256, 128] for x in range(224)] for y in range(224)]
p = patches(cat, 16)
assert len(p) == (224 // 16) ** 2 == 196 and all(len(v) == 16 * 16 * 3 == 768 for v in p)

# Speech: 3 seconds of a 440 Hz tone at 16 kHz, as frames every 10 ms.
rate = 16_000
audio = [math.sin(2 * math.pi * 440 * t / rate) for t in range(3 * rate)]
f = frames(audio)
assert len(f) == 300 and all(len(x) == 400 for x in f)  # 100 frames a second
assert loudest_hz(f[150], rate) == 440.0  # the spectrogram's loudest band in the middle frame is the tone

# Text-to-speech, the other way: 2 seconds at 24 kHz is the number of samples the vocoder must make.
speech = [0.0] * (2 * 24_000)
assert len(speech) == 48_000

# Multimodal: a 336 px image through a ViT with 14 px patches, then the question's tokens, in one sequence.
image_vectors = (336 // 14) ** 2
question = toy_tokens("how much is it?")
assert image_vectors == 576 and len(question) == 5

print(f"text {len(prompt)} tokens, image {len(p)} patches of {len(p[0])} numbers, 3 s of speech {len(f)} frames"
      f" (loudest {loudest_hz(f[150], rate):.0f} Hz), 2 s of speech out {len(speech):,} samples,"
      f" image + question {image_vectors + len(question)} in one sequence")
Run: python3 pieces.pyIt printed: text 6 tokens, image 196 patches of 768 numbers, 3 s of speech 300 frames (loudest 440 Hz), 2 s of speech out 48,000 samples, image + question 581 in one sequence

Only the cutting, with the published shapes: a prompt into tokens (a toy tokenizer), a 224 px image into 196 patches of 16 × 16 pixels, 3 seconds of 16 kHz audio into 300 frames the way Whisper's code frames it (and the loudest band of one frame, found with a plain DFT), the 48,000 samples 2 seconds of 24 kHz speech need, and LLaVA-1.5's 576 image vectors plus the question's tokens. No model is downloaded. Really run.

Common questions

Why does an LLM's answer appear a bit at a time?

Because it makes one token at a time: it scores every token in its vocabulary as the next one, picks one, appends it and goes round again. Apps show each token as it comes instead of waiting for the end.

Read: one skeleton

What is a token, and how are they counted?

A piece of text the model reads and writes: a word, part of a word or a punctuation mark. Tokenizers learn the common pieces from data, so a common word is one token and a rare one several. This page's tokenizer is a toy; each real model counts differently.

How is a vision model different from a multimodal one?

A vision model gives scores for the labels it was trained on (or boxes around objects). It can't answer in sentences, but it's small and fast: right for millions of images and a fixed set of labels. A multimodal model reads the picture with your question and answers in text.

Why does speech-to-text turn the sound into a spectrogram?

Audio at 16 kHz is 16,000 numbers a second, each saying little on its own. A spectrogram says how loud each pitch band is every 10 ms, 100 frames a second. Many speech models read one; Whisper uses 80 log-Mel channels.

Table: in, cut into, out

Is a reasoning model always better than a plain LLM?

No. It writes thinking tokens before the answer, which cost time and compute. That pays off on problems with several steps, like maths, logic or debugging; on a short task like translating one sentence you get much the same answer, later.

How does a voice assistant work?

The long-standing way is a chain of three: speech-to-text listens, an LLM works out the answer, text-to-speech speaks. Each hand-off adds waiting; some models take speech in and give speech out in one. Build the chain yourself in the play tab.

Read: picking one

Does a product's model name tell you which kind it is?

Not always. Names are the provider's business, and one model may take several kinds of input. Check the provider's own docs for what it takes in (text, images, audio) and what it gives out, then match it to the six kinds here.

Next lesson

The algorithms inside AILevel: Deep

Every model shares one skeleton; next, the algorithms inside it: gradient descent, attention and how the next word is picked.