Type "enchanting jazz song with a memorable saxophone solo" and get back minutes of coherent 24 kHz music — with no paired music-text data at training time, by stacking three frozen tokenizers and three autoregressive Transformers into a coarse-to-fine token hierarchy.
By 2022, you could type "a teddy bear riding a skateboard in Times Square" and a model would paint it. Text-to-image had exploded. So the obvious next question: type a sentence and get back a song. "Berlin 90s techno with a low bass and strong kick." A few minutes of music, at full fidelity, that actually sounds like what you asked for.
It turns out music is much harder than images, for three concrete reasons that this whole paper is built to defeat.
24 kHz audio is 24,000 numbers per second. Five minutes is 7.2 million samples. An autoregressive model that predicts raw samples one at a time (think WaveNet) would need a context window of millions of tokens to stay coherent over a song. That is hopeless. We need a compressed token representation — far fewer tokens per second — that still reconstructs to clean audio.
Here is the cruel trade-off. Compress hard (few tokens/sec) and you lose fidelity — the reconstruction sounds muddy. Keep fidelity (many tokens/sec) and the sequences get so long the model can't remember what it played 30 seconds ago, so it loses long-term structure. Earlier systems lived on one horn of this dilemma: Jukebox was coherent but artifact-ridden; PerceiverAR sounded great but drifted. You cannot get both with a single flat token stream.
Text-to-image rode on billions of (image, caption) pairs scraped from the web with their alt-text. Music has almost none. And describing music in words is genuinely hard: how do you capture timbre, groove, the interplay of a saxophone and a singer in a few words? The total paired audio-text data available (AudioSet + AudioCaps) is under 5,000 hours — tiny. Meanwhile there are millions of hours of music with no captions at all.
| Constraint | Number | Why it hurts |
|---|---|---|
| Raw audio rate | 24,000 samples/sec | 5 min = 7.2M samples — impossible context length |
| Coherence horizon needed | minutes | melody/key must survive thousands of tokens |
| Paired music-text data | < 5k hours | too little to learn text→music directly |
| Unlabeled music available | ~280k hours | huge — if only we could use it without captions |
That last row is the seed of the whole trick. There is a mountain of music with no labels, and a molehill of captioned music. MusicLM finds a way to train almost entirely on the mountain. The rest of this lesson is how.
MusicLM solves all three hardnesses with one architectural move: cast text-to-music as a hierarchical sequence-to-sequence problem over discrete tokens, using three independently-pretrained-and-frozen models to produce those tokens. No single network learns audio + semantics + text alignment all at once. Each job gets its own specialist.
Each defeats one of the three hardnesses from Chapter 0.
All three models are pretrained separately and then frozen — their weights never update while MusicLM trains. This is a deliberate engineering decision, not laziness:
MusicLM is, in the authors' words, AudioLM extended with text conditioning. So we need two prior ideas firmly in hand: quantization (turning continuous audio into discrete tokens) and AudioLM's coarse-to-fine hierarchy.
Transformers predict from a finite vocabulary via softmax — the same machinery that picks the next word. To reuse that machinery for audio, you must turn audio into a sequence of integers drawn from a fixed codebook. That's quantization. A VQ-VAE learns a codebook of K vectors; an encoder maps each chunk of audio to its nearest codebook vector and emits that vector's index. The decoder turns indices back into audio.
AudioLM's key realization (which MusicLM inherits) is that one token type can't do everything, so it uses two, each from a different model:
| Token type | From | Captures | Rate |
|---|---|---|---|
| Semantic (S) | w2v-BERT (self-supervised) | long-term structure: phonetics, melody, rhythm | low (25 Hz) |
| Acoustic (A) | SoundStream codec | fine detail: timbre, reverb, recording quality | high (600/sec) |
The generation order is coarse-to-fine: first generate the slow semantic tokens (they fix the "what" — the structure), then generate the fast acoustic tokens conditioned on the semantics (they fill in the "how it sounds"). This is the move that resolves Hardness #2: structure lives in a short, learnable sequence; detail lives in a longer sequence that only needs local context because the structure is already pinned down.
The acoustic tokens come from SoundStream, a neural audio codec. Its encoder strides over 24 kHz audio with a factor of 480, producing one embedding every 480 samples → 50 embeddings per second. Each of those embeddings then has to be turned into discrete tokens. The naive way fails badly — and fixing it is the heart of this chapter.
Suppose you want 6 kbps of audio quality. The bitrate of one codebook is rate × log2K bits/sec. To hit 6 kbps at 50 Hz you'd need log2K = 120 bits per embedding → a codebook of K = 2120 vectors. That's astronomically, unstorably large. A single codebook hits an exponential blowup as you demand more fidelity.
MusicLM's SoundStream uses 12 quantizers, each with a vocabulary of 1024. So the cost is linear in fidelity:
Each embedding becomes 12 token IDs (one per quantizer level). The bitrate:
And the token count that the generative model must produce:
That 600/sec figure is the number to remember — it's the firehose from Hardness #1, now compressed from 24,000 samples/sec down to 600 tokens/sec, a 40× reduction, while still reconstructing crisp 24 kHz music.
The orange dot is the target embedding we want to encode. Drag RVQ levels up. Each level snaps the remaining residual to its nearest small-codebook vector (the teal dots) and adds it to the running reconstruction (blue). Watch the reconstruction crawl toward the target and the residual shrink — fidelity grows by adding levels, never by one huge codebook.
# Residual vector quantization: the core insight in ~10 lines import torch def rvq_encode(x, codebooks): """x: [D] target embedding. codebooks: list of [K, D] tensors.""" residual = x.clone() tokens, recon = [], torch.zeros_like(x) for cb in codebooks: # 12 levels, each K=1024 d = ((cb - residual) ** 2).sum(-1) # dist to every codeword idx = d.argmin() # nearest codeword index = the TOKEN tokens.append(idx.item()) recon += cb[idx] # reconstruction = SUM of chosen codewords residual = x - recon # quantize the LEFTOVER next return tokens, recon # 12 ints; recon -> SoundStream decoder -> audio
Acoustic tokens are detail-rich but structure-poor: 600/sec, mostly local. To carry long-term musical structure — the melody, the groove, where the song is going — MusicLM uses a second, much slower token type: semantic tokens, denoted S, derived from w2v-BERT.
w2v-BERT is a 600M-parameter model pretrained with masked language modeling (MLM) on audio — it learns to fill in masked chunks of an audio sequence, with no labels. Exactly like BERT for text, its intermediate layers learn abstract, structure-bearing representations. MusicLM extracts embeddings from the 7th layer specifically.
Unlike SoundStream's RVQ, the semantic embeddings are quantized with a single k-means codebook: cluster the layer-7 embeddings into 1024 centroids, and each embedding becomes the ID of its nearest centroid. One token per frame — no residual stack — because we want a compact structural sketch, not high-fidelity reconstruction.
Semantic tokens come out at 25 Hz: just 25 tokens per second of audio. Contrast that with 600 acoustic tokens/sec. The ratio matters:
| Token type | Source | Quantizer | Tokens / second | Role |
|---|---|---|---|---|
| Semantic (S) | w2v-BERT layer 7 | k-means, 1024 centroids | 25 | long-term structure (the "what") |
| Acoustic (A) | SoundStream | RVQ, 12×1024 | 600 | fine detail (the "how it sounds") |
So a 10-second clip is just 250 semantic tokens but 6,000 acoustic tokens. The semantic sequence is 24× shorter — short enough for a Transformer to plan a coherent minute of music over. That length asymmetry IS the resolution of the coherence-vs-fidelity dilemma: plan in the short sequence, render in the long one.
Each gray dot is a w2v-BERT layer-7 embedding (shown in 2-D). The big colored dots are the k-means centroids (the codebook). A line connects each embedding to its nearest centroid — that centroid's index is the semantic token. Increase K to see finer structure captured; the stream of token IDs along the bottom is exactly what the semantic Transformer learns to model.
Now the masterstroke. We have great audio tokens (acoustic + semantic) but they all come from audio. How do we steer generation with text, given we have almost no paired data (Hardness #3)? Answer: MuLan, a joint music-text embedding model.
MuLan has two encoders — two "towers." A text tower (a BERT) maps a caption to a 128-d vector. An audio tower (a ResNet-50) maps a music clip to a 128-d vector. They are trained with a contrastive loss: pull the embeddings of a matching (music, text) pair together, push mismatched pairs apart. The result is a single shared 128-d space where "a song about it" and the actual song sit close.
Symbol by symbol: a is the audio embedding, t+ its true caption's embedding, tj ranges over all captions in the batch (the true one plus mismatched "negatives"), sim is cosine similarity, and τ is a temperature. Minimizing this makes the matching pair the most similar — i.e., it aligns the two towers into one space. (Same recipe as CLIP for images.)
DALL·E 2 also uses a CLIP joint space — but it trains a separate "prior" model to map text embeddings → image embeddings before decoding. MusicLM omits that prior entirely. Because MuLan's two towers are already so well aligned, the text embedding can be used directly as a stand-in for the audio embedding. Simpler pipeline, and it lets the decoder train on audio-only data.
The 128-d MuLan vector is continuous, but MusicLM wants everything as tokens for a homogeneous interface. So it applies another RVQ — 12 quantizers × 1024 — to the MuLan embedding, yielding 12 MuLan tokens. Since MuLan operates on 10-second windows, longer clips are handled by sliding a 10-s window with 1-s stride and averaging the embeddings before quantizing. Same RVQ is used for audio-derived MA (training) and text-derived MT (inference) — critical, so the token distributions match.
Each pair of dots (a music note ♪ and its caption ✎) starts scattered. Hit Run contrastive training: matching pairs are pulled together, mismatched ones repelled, until each caption sits on top of its song. Then hit Swap: we generate using the music embedding (training), then replace it with the nearby text embedding (inference) — and because they coincide, the generator can't tell the difference. That coincidence is the whole paired-data-free trick.
Now we assemble everything. MusicLM generates music as a cascade of three autoregressive stages, each a separate decoder-only Transformer (24 layers, 16 heads, 430M params each). Each stage predicts one token type, conditioned on the tokens above it. This is the reconstruction of the paper's Figure 2 — and the payoff of the whole lesson.
Let's trace exactly how many tokens flow through each stage for 1 second of generated audio. This is the single most clarifying calculation in the paper:
| Stage | Conditioning (input) | Output tokens / sec | Arithmetic |
|---|---|---|---|
| 1. Semantic | 12 MuLan tokens MA | 25 | 25 Hz × 1 level |
| 2. Coarse acoustic | MA + 25 semantic tokens | 200 | 50 Hz × 4 levels |
| 3. Fine acoustic | 200 coarse acoustic tokens | 400 | 50 Hz × 8 levels |
| Total acoustic | — | 600 | 50 Hz × 12 levels → SoundStream decode |
Read the progression: the conditioning gets richer and the output rate gets higher as we descend. The model plans with 25 cheap tokens, then commits to 200, then renders 400 more — a coarse-to-fine waterfall. Each stage only has to model a sequence short enough to stay coherent given what's above it.
The four rows are MuLan → Semantic → Coarse acoustic → Fine acoustic. Each row's token count scales with the seconds slider so you can see the budget grow. Step a stage generates the next row, conditioned (dashed arrows) on the rows above — watch the per-second counts (12, 25, 200, 400) light up. Run full cascade animates the whole waterfall, ending at the SoundStream decoder. This IS MusicLM, end to end.
Everything hinges on one swap. At training time MusicLM conditions on MA (MuLan tokens from the audio). At inference time it conditions on MT (MuLan tokens from the text prompt). Nothing else changes. Let's make the asymmetry precise because it's easy to misread.
The paper uses different temperatures per stage, tuned by listening: 1.0 for semantic, 0.95 for coarse acoustic, 0.4 for fine acoustic. Why the descending schedule?
| Stage | Temp | Reasoning |
|---|---|---|
| Semantic | 1.0 | We want diversity in structure/melody — full sampling explores musical ideas |
| Coarse acoustic | 0.95 | Mostly diverse, slightly tempered for stability |
| Fine acoustic | 0.4 | Near-greedy: fine detail should be consistent, not random — high temp here would add hiss/artifacts |
The paper's own probe experiment. Fix text only → re-sample semantics + acoustics: samples vary a lot in melody and rhythm, all still on-genre (high diversity). Fix text + semantics → re-sample only acoustics: samples share melody/rhythm but differ in reverb, distortion, instrument timbre (low diversity, same structure). Each bar shows how much that musical attribute varies — proving semantic tokens own structure and acoustic tokens own detail.
How do you even measure "good text-to-music"? You need two axes: audio quality (does it sound like real music?) and faithfulness (does it match the words?). MusicLM uses three metrics, evaluated on MusicCaps — a new 5.5k-example dataset of expert musician captions the authors released.
| Model | FADTrill ↓ | FADVGG ↓ | KLD ↓ | MCC ↑ | Human Wins ↑ |
|---|---|---|---|---|---|
| Riffusion | 0.76 | 13.4 | 1.19 | 0.34 | 158 |
| Mubert | 0.45 | 9.6 | 1.58 | 0.32 | 97 |
| MusicLM | 0.44 | 4.0 | 1.01 | 0.51 | 312 |
| MusicCaps (real) | — | — | — | — | 472 |
Read it: MusicLM wins on FADVGG by a wide margin (4.0 vs 9.6), ties Mubert on FADTrill, and dominates on both faithfulness metrics (KLD 1.01, MCC 0.51). In human A/B listening it was preferred 312 times vs 158 (Riffusion) and 97 (Mubert) — though the real reference music still won more (472), so a gap to ground truth remains. Notably, MusicLM matches Mubert on quality despite Mubert stitching pre-recorded sounds made by humans.
Toggle the metric. Bars rescale; the arrow tells you whether lower or higher is better, and the winning bar is highlighted. Flip between quality (FAD) and faithfulness (KLD/MCC/Wins) to see that MusicLM's biggest edge is faithfulness — it captures the text best.
The authors trained a stripped model that predicts coarse acoustic tokens directly from MuLan tokens — skipping the semantic stage: p(At | A<t, MA). Result:
When humans preferred the real music over MusicLM, three patterns recurred — worth knowing as the system's edges:
Two parts of the paper round out the story: an extension that adds melody conditioning, and a memorization study driven by the risks of generative music.
Words can't capture a melody you have in your head. So MusicLM adds a second conditioning signal: you hum, sing, or whistle a tune, and the model renders it in the style your text describes ("...as an electronic synth lead").
The mechanism reuses the joint-embedding playbook: build a melody embedding model trained so that two clips with the same melody but different acoustics (covers, instrumentals, vocals, hummed versions) land close together. The synthetic training pairs are made from different versions of the same song. Quantize the melody embedding with RVQ, and concatenate its tokens with the MuLan text tokens as a richer conditioning. Now the semantic stage sees both "what melody" and "what style."
Because the semantic sequence is short, MusicLM can generate up to 5-minute clips. It can also change the MuLan conditioning every 15 seconds to produce smooth, tempo-consistent transitions between described sections — a primitive "story mode."
Generative music raises a real risk: regurgitating copyrighted training audio. The authors adapt the LLM memorization methodology to the semantic stage. They prompt with MA plus the first T semantic tokens of a real clip (T from 0 to 250 = up to 10 s), greedily generate a 5-s continuation, and check for matches.
MusicLM is a synthesis paper: it takes AudioLM's hierarchy, SoundStream's codec, w2v-BERT's semantics, and MuLan's joint space, and shows the combination unlocks text-to-music with no paired data. Let's pin down the whiteboard summary and the symbol table.
MusicLM generates music as a coarse-to-fine token cascade. Three frozen tokenizers turn audio into tokens: SoundStream's RVQ gives 600 acoustic tokens/sec (fine detail), w2v-BERT + k-means gives 25 semantic tokens/sec (long-term structure), and MuLan's contrastively-trained joint space gives 12 conditioning tokens that are interchangeable between audio (MA, training) and text (MT, inference). Three autoregressive Transformers then model p(S | MA), p(Acoarse | S, MA), and p(Afine | Acoarse) in sequence; SoundStream decodes the acoustic tokens to 24 kHz audio. Because MuLan aligns audio and text, the model trains on audio-only data and is prompted with text — sidestepping the scarcity of paired music-text data, which is the paper's central contribution.
| Symbol / term | Meaning | Number to remember |
|---|---|---|
| A | Acoustic tokens (SoundStream RVQ) | 600 / sec = 50 Hz × 12 levels |
| S | Semantic tokens (w2v-BERT L7, k-means) | 25 / sec, 1024 centroids |
| MA | MuLan tokens from audio (training cond.) | 12 tokens, RVQ 12×1024 |
| MT | MuLan tokens from text (inference cond.) | swapped in for MA |
| RVQ | Residual vector quantization | quantize residual at each level; recon = Σ codewords |
| p(S|MA) | Stage 1: semantic modeling | temp 1.0 |
| p(Ac|S,MA) | Stage 2: coarse acoustic (RVQ levels 1–4) | temp 0.95, 200/sec |
| p(Af|Ac) | Stage 3: fine acoustic (RVQ levels 5–12) | temp 0.4, 400/sec |
| MuLan | Joint music-text embedding (contrastive) | 128-d shared space |
| FAD / KLD / MCC | quality / faithfulness / cycle-consistency | MusicLM: 4.0 / 1.01 / 0.51 |