Neural Sound Synthesis · Part 10 of 12

Language-Model Music Generation

Once a neural codec has turned sound into a stream of discrete integers, a transformer can model audio exactly the way GPT models text — next-token prediction, cross-entropy, sampling with temperature. This part follows that single idea from AudioLM's semantic-plus-acoustic hierarchy to MusicGen's codebook-interleaving trick, and asks you to generate a melody token by token. Three live demos throughout.

AudioLM · MusicLM · MusicGen Jukebox · VALL-E Semantic · Acoustic tokens Temperature · Top-k · CFG

1Audio as a language — the paradigm that unlocked everything

Part 9 ended with a neural codec — SoundStream, EnCodec — that maps a second of audio to a few dozen frames, each frame a handful of integers drawn from small learned codebooks. That single change reframes the whole problem. Audio is no longer a forty-thousand-dimensional continuous object; it is a sequence of tokens over a finite vocabulary, and we already own the most successful sequence model ever built: the autoregressive transformer.

The recipe is now identical to language modelling. Let $z = (z_1,\dots,z_T)$ be the token stream a codec emits for a clip. A transformer factorises its joint distribution the same way GPT factorises a sentence — one conditional at a time, strictly left to right:

$$p_\theta(z) = \prod_{t=1}^{T} p_\theta\!\left(z_t \mid z_{1},\dots,z_{t-1}\right)$$

and we train it by minimising exactly the cross-entropy that trains a chatbot — the negative log-likelihood of each true next token given its history:

$$\mathcal{L}(\theta) = -\,\mathbb{E}_{z\sim\mathcal{D}}\sum_{t=1}^{T}\log p_\theta\!\left(z_t \mid z_{

Nothing in either equation knows or cares that the tokens denote sound rather than words. That is the entire conceptual leap of this part: generation becomes a vocabulary problem. Everything the NLP community discovered — scaling laws, temperature sampling, top-k / top-p truncation, classifier-free guidance for conditioning, KV-caching for fast decoding — transfers wholesale to audio the moment the codec exists.

Why this is not obvious. Text tokens are (mostly) semantically meaningful and there are ~50k of them. Codec tokens are perceptual fragments with no standalone meaning, there can be several parallel streams per frame, and a single wrong token is an audible glitch, not a typo. The models below are largely about taming those three differences.
The two-stage tax. The LM never touches a waveform. It predicts tokens; the codec's decoder renders them to sound. Quality is therefore capped by the codec (Part 9), and the decoder can hallucinate detail the LM never specified — the same tension every token-domain model inherits.

The rest of this part is the family tree that grew from that leaf. AudioLM split the stream into a semantic and an acoustic hierarchy for long-term coherence. MusicLM hung a text encoder in front of it. MusicGen collapsed the hierarchy into one transformer over parallel codebooks with a clever interleaving pattern. Jukebox did it at the scale of whole raw-audio songs with lyrics; VALL-E did it for zero-shot voice cloning. One idea, five landmark systems.

2Sampling the token stream — and a transformer you can play

Training gives a distribution; generation is repeatedly drawing from it and feeding the draw back in. The knob that governs the character of the output is temperature, applied to the logits before the softmax. It is the single most important control in this entire field, so the demo below lets you hear it directly.

Given logits $u_i$ over the vocabulary, temperature $\tau$ rescales them before normalising:

$$p_i = \frac{\exp(u_i/\tau)}{\sum_j \exp(u_j/\tau)}$$

As $\tau\to 0$ the distribution collapses onto its mode — greedy, deterministic, often repetitive. At $\tau = 1$ you sample the model's raw beliefs. As $\tau\to\infty$ it flattens to uniform — pure noise. Between them lies the usable band where music sounds intentional but not mechanical. On top of temperature, two truncation tricks discard the unreliable tail:

A real autoregressive melody generator

The demo is a genuine token-LM in miniature. It learns a bigram transition table from a couple of built-in seed melodies over a musical token vocabulary — pitch tokens on a chosen scale, plus a REST and a SUSTAIN (tie) token — then samples a new sequence one token at a time, each token conditioned on the last, with your temperature applied to the transition row. It maps the tokens to notes and plays them, and shows both the raw token stream and the resulting piano-roll. This is exactly the loop a codec-token LM runs, shrunk to something you can inspect.

Top: the sampled token stream (pitch · R = rest · ~ = sustain). Bottom: the piano-roll it renders to. Drag temperature from 0.05 (greedy) to 2 (chaos).

Try this: set temperature to 0.05 and hit Generate a few times — the sampler is near-greedy, so it keeps falling into the same short loop the seeds made most likely. Push to 0.9 and it improvises recognisable phrases in the scale. Push to 2.0 and it wanders atonally, resting and leaping at random. Same model, same seeds — only the sharpness of the draw changed.

Conditioning: classifier-free guidance

Text-to-music needs the distribution steered by a prompt $c$. The dominant trick, borrowed from diffusion, is classifier-free guidance: train the same model both with the condition and with it dropped (a null token $\varnothing$), then at inference push the logits away from the unconditional prediction and toward the conditional one by a guidance weight $w$:

$$\ell_{\text{cfg}} = \ell_\theta(z_t \mid z_{

Larger $w$ makes the output cling harder to the prompt at some cost to diversity and naturalness — the same quality/adherence dial you feel in any text-to-image system, now over audio tokens.

3AudioLM — the semantic + acoustic hierarchy

A single codec-token LM has a problem: EnCodec-style tokens are optimised for reconstruction fidelity, not linguistic structure, so a raw LM over them drifts — it keeps the timbre but loses the tune over a few seconds. AudioLM (Borsos et al., 2022) solved this by predicting audio in two kinds of token, in coarse-to-fine order.

Semantic tokens — the plan

Discretised (k-means) activations of a self-supervised model, w2v-BERT. They are sampled slowly (~25 Hz) and capture long-term structure: phonetics, melody, rhythm, prosody. They sound terrible if decoded alone — they carry the plan, not the audio.

Acoustic tokens — the render

The RVQ codes of a SoundStream codec, several per frame across quantiser levels. They carry fidelity: speaker identity, timbre, recording conditions, fine spectral detail — everything needed to reconstruct a convincing waveform.

Generation runs as a cascade of three transformer stages. First a semantic stage models $p(s_{1:T})$ — the long-horizon plan. Then a coarse acoustic stage predicts the first few RVQ levels conditioned on the full semantic sequence, and finally a fine acoustic stage fills the remaining RVQ levels. Coarse-to-fine, plan-then-render:

$$p(s,a) = \underbrace{p(s_{1:T})}_{\text{semantic}} \; \underbrace{p\!\left(a^{\le q_c}_{1:T}\mid s_{1:T}\right)}_{\text{coarse acoustic}} \; \underbrace{p\!\left(a^{> q_c}_{1:T}\mid a^{\le q_c}_{1:T}\right)}_{\text{fine acoustic}}$$

Because the slow semantic stream commits to the structure first, the acoustic stages only have to render it — and the result stays coherent for far longer than a flat codec-token LM. AudioLM could continue a piano piece or a spoken sentence for many seconds while keeping the melody, speaker and syntax intact, all trained with no transcripts or labels. Explore the two-stage stack below.

hover a cell →
Semantic tokens are generated first (whole row), then each acoustic RVQ level in turn, coarse to fine. Hover any cell to see what that level carries.
Read the order. The top row fills completely before any acoustic token appears — the model decides what happens across the whole clip before deciding how it sounds. Within the acoustic block, level 1 (coarsest, most perceptually significant) is committed before the fine levels refine it. That is the RVQ residual ordering of Part 9, now used as a generation schedule.

4MusicLM — text conditioning by borrowing an embedding

AudioLM is unconditional: it continues audio, it does not follow a prompt. MusicLM (Agostinelli et al., 2023) turned it into a text-to-music system with one addition — a joint text–audio embedding space that lets a caption stand in for the missing audio context.

That embedding is MuLan, a contrastive model (a CLIP for music) trained on millions of tracks paired with free-form text so that a caption and a matching clip land near each other. At training time MusicLM conditions on MuLan's audio embedding of the target; at inference it swaps in the MuLan text embedding of the prompt — the shared space makes the substitution nearly seamless, and no captioned music is needed to train the generative stages at all.

$$M_{\text{text}}(\text{"a calm violin melody"}) \;\approx\; M_{\text{audio}}(\text{matching clip}) \;\Rightarrow\; p\big(\text{semantic},\text{acoustic}\mid M\big)$$

The generative core is AudioLM's hierarchy, extended to a three-level conditioning cascade: the MuLan token conditions a semantic stage, which conditions a coarse acoustic stage, which conditions a fine acoustic stage. MusicLM also shipped MusicCaps, a benchmark of expert-written captions, and demonstrated melody conditioning — hum a tune, describe a style, get the tune rendered in that style.

SystemConditioningToken hierarchySignature idea
AudioLMnone (continuation)semantic → coarse → fineself-supervised semantic tokens for long-term coherence
MusicLMtext / melody via MuLanMuLan → semantic → coarse → finecontrastive text–audio embedding as the prompt bridge
MusicGentext (T5) + melodysingle stage, parallel codebookscodebook-interleaving pattern + classifier-free guidance
Notice the compression happening across these three rows. AudioLM needed three transformers and a hand-built semantic/acoustic split. MusicLM added a fourth conditioning stage. MusicGen — next — threw the hierarchy out and did it with one transformer. The field's arc in this part is the steady collapse of a cascade into a single model.

5MusicGen — one transformer over parallel codebooks

EnCodec emits $K$ codebook tokens per frame (the RVQ levels). A naive LM must somehow model these parallel streams. MusicGen (Copet et al., 2023) does it with a single autoregressive transformer and a codebook-interleaving pattern that decides the order in which the $K\times T$ tokens are unrolled into one sequence. The choice of pattern is the whole efficiency story.

Three ways to unroll a $K\times T$ grid

Formally, if $z_{k,t}$ is the token at codebook $k$, frame $t$, the pattern is just a schedule $s(k,t)$ giving the decoding step at which that token is produced:

$$s_{\text{flatten}}(k,t) = tK + k,\qquad s_{\text{parallel}}(k,t) = t,\qquad s_{\text{delay}}(k,t) = t + k$$

The delay pattern turns a $K{\times}T$ problem that "should" take $KT$ steps into one that takes $T{+}K{-}1$ — for $T=1500,\,K=4$ that is ~1503 steps instead of 6000, a near-$4\times$ speedup, with almost no quality loss because the diagonal schedule still lets each fine code see the coarse codes of its frame. Step through all three below.

Rows = RVQ codebooks, columns = frames. Bright cells are being predicted at this step; filled cells are already decoded. Watch the total step count change with the pattern.

MusicGen conditions on text through a frozen T5 encoder (cross-attention or prefix), supports melody conditioning via a chromagram, and uses the classifier-free guidance of §2 to trade prompt-adherence against diversity. One model, one stage, competitive with the cascades — which is why it became the default open text-to-music baseline.

6Jukebox and VALL-E — the extremes of the same idea

Two systems bracket the token-LM family: one that predated the codec era and paid dearly for it, and one that carried the recipe into speech and made voice cloning trivial.

Jukebox (Dhariwal et al., 2020) — the ambitious ancestor

Two years before AudioLM, OpenAI's Jukebox generated whole songs with singing directly in raw audio. It built its own tokens with a multi-scale VQ-VAE — three levels compressing raw audio by 8×, 32× and 128× — then trained sparse transformers as autoregressive priors over each level, upsampling coarse tokens to fine. It conditioned on artist, genre and even time-aligned lyrics, and it worked: recognisable songs in the style of named artists, with words. The cost was brutal — coherence wandered over a song's length, and rendering a minute of audio took hours, because its codec tokens were far less compressed and less structured than the semantic/acoustic split that came later. Jukebox is the proof-of-concept whose pain motivated everything in §§3–5.

VALL-E (Wang et al., 2023) — the speech cousin

VALL-E applied the MusicGen-shaped recipe to text-to-speech: an EnCodec token LM, with a text prompt and a 3-second enrolment clip of a target speaker as acoustic context. Because the acoustic tokens carry timbre and the model does in-context learning, it reproduces an unseen speaker's voice, prosody and even acoustic environment from those three seconds — zero-shot voice cloning. It uses a hybrid schedule: an autoregressive model for the coarse codebook and a non-autoregressive model for the rest, a close relative of MusicGen's interleaving. VALL-E is the clearest evidence that "audio is a language" is a claim about all audio, not just music.

The dual-use edge. Zero-shot cloning from three seconds of audio is also a deepfake engine. Every serious release in this line now ships with a watermarking or detection plan; the capability and its misuse are the same model read two ways.

7From Jukebox to MusicGen in three years

The token-LM approach to music went from a compute-devouring curiosity to an open, single-model baseline in the span of three years — the moment good neural codecs (Part 9) arrived.

2020
Jukebox generates raw-audio songs with lyrics via a multi-scale VQ-VAE and sparse-transformer priors — proof that a token LM can sing, at ruinous cost. Part 10
2021–22
SoundStream & EnCodec deliver compact, structured RVQ tokens; AudioLM introduces the semantic + acoustic hierarchy for long-term-coherent, label-free continuation. Part 9 · 10
Jan 2023
MusicLM adds MuLan text–audio embeddings for text-to-music; VALL-E ports the recipe to zero-shot text-to-speech voice cloning. Part 10
Jun 2023
MusicGen collapses the cascade into a single transformer over EnCodec's parallel codebooks using the delay interleaving pattern, T5 text and melody conditioning, classifier-free guidance — open-sourced. Part 10
2023→
Attention turns to the diffusion alternative for text-to-audio — continuous latents instead of discrete tokens, non-autoregressive, faster at length. Part 11

→Where to go next

You have seen the second great paradigm of neural audio: once a codec discretises sound, a transformer models it exactly like language — factorised left to right, trained by cross-entropy, sampled with temperature, steered by guidance. AudioLM's hierarchy bought coherence, MusicLM bought prompts, MusicGen bought a single efficient model. But discrete tokens are not the only game. Part 11 takes the other road entirely: diffusion in a continuous latent, generating audio in parallel rather than one token at a time.

Series hubAll twelve parts · the interactive map Part 9 ←Neural Audio Codecs · where the tokens come from Part 11 →Latent Diffusion for Text-to-Audio CollectionDSP & Music

References

  1. Dhariwal, P., Jun, H., Payne, C., Kim, J. W., Radford, A., Sutskever, I. (2020). Jukebox: A Generative Model for Music. arXiv:2005.00341.
  2. Borsos, Z. et al. (2022). AudioLM: A Language Modeling Approach to Audio Generation. arXiv:2209.03143.
  3. Agostinelli, A. et al. (2023). MusicLM: Generating Music From Text. arXiv:2301.11325.
  4. Copet, J. et al. (2023). Simple and Controllable Music Generation (MusicGen). arXiv:2306.05284.
  5. Wang, C. et al. (2023). Neural Codec Language Models are Zero-Shot Text to Speech Synthesizers (VALL-E). arXiv:2301.02111.
  6. Défossez, A. et al. (2022). High Fidelity Neural Audio Compression (EnCodec). arXiv:2210.13438.
  7. Ho, J. & Salimans, T. (2022). Classifier-Free Diffusion Guidance. arXiv:2207.12598.
  8. Holtzman, A. et al. (2020). The Curious Case of Neural Text Degeneration. ICLR. (top-p / nucleus sampling.)