Neural audio generators such as MusicGen don't predict raw waveform samples. An encoder first compresses each short audio frame into a continuous embedding z. That embedding is then turned into a handful of discrete integers by residual vector quantization (RVQ): a cascade of K codebooks, each one quantizing what the previous one couldn't represent.
e_0 = z (target embedding)
for k = 1..K:
p_k(i) = softmax( -‖e_{k-1} − C_k[i]‖ / T ) over codebook C_k
c_k = sample i ~ p_k (this level's token)
e_k = e_{k-1} − C_k[c_k] (residual passed down)
distortion = ‖e_K‖
Level 1 captures the coarse, high-energy structure of the sound; each deeper level quantizes the leftover residual, adding finer detail — coarse-to-fine, exactly like the rings stacked in this scene. The temperature T reshapes the softmax: low T is close to greedy nearest-codeword selection (argmin), high T flattens the distribution so rarer, more "creative" tokens get sampled.
A transformer is trained autoregressively over the resulting token stream, factorizing the joint probability as p(x₁…x_T) = ∏ₜ p(xₜ | x<ₜ), predicting each frame's K tokens from everything generated before it — that's the piano-roll grid growing to the right, one column per time step.
- Levels — how many residual codebooks stack (K). More levels lower the residual error but need more tokens per frame.
- Codewords per level — codebook size; a bigger codebook can represent finer nuances but is a harder search.
- Temperature — sampling randomness; watch perplexity rise as T increases.
- Perplexity = exp(entropy of the sampling distribution) — how many codewords were realistically "in play" for that choice.
The embedding and codewords here live in a reduced 2D feature plane so the quantization geometry stays visible in 3D — real models quantize in a few-hundred-dimensional space, but the residual cascade and coarse-to-fine logic are identical.