Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Understanding images and sound

Audio inputs: how can a language model listen?

A recording is a stream of measurements, not words. What should an audio position contain so a language model can use it?

We want a language model to answer a question about a recording. A microphone gives us thousands of measurements per second, but what could a position in that sequence tell us?

Follow the data through the mechanismWe want to ask a question about a recording16,000 measurements in one secondOne measurement: amplitude at one instantA single point misses the pattern of change
A recording has many measurements, but one instant’s amplitude does not describe the pattern that makes a sound.

Let a position describe a short sound

One instant’s amplitude tells us little; a stretch reveals repeated changes. Could we describe that stretch by measuring energy across frequency bands?

Follow the data through the mechanismA short piece of sound120 ms of audio32 ms window · 10 ms hopMeasure energy by frequencyTime frames128 mel bands
A moving 32 ms analysis window produces a new 128-band feature frame every 10 ms. These overlapping frames describe how frequency energy changes with time.

A 32 ms window, moved 10 ms at a time, gives us 128 mel-frequency measurements per frame. Overlap keeps a sound crossing a window boundary in view. These are local descriptions, rather than words.

Give attention fewer positions to connect

A frame is still ambiguous without its surroundings, but we now have roughly 100 frames per second. Could convolution learn useful local combinations at a lower time resolution before we ask attention to connect them?

Follow the data through the mechanismMel features · about 100 frames / secondEarlier context is dimmed; outlined columns are current.Current token computation.128F time frames3 × 3 convolution · stride 2 × 2Cumulative group norm → ReLU3 × 3 convolution · stride 2 × 2Cumulative group norm → ReLUEarlier context is dimmed; outlined columns are current.Current token computation.1,024About F / 4 positionsInput projection1,0241,536Earlier context is dimmed; outlined columns are current.Current token computation.1,536About 25 positions / second
Two convolutions halve time resolution twice; 32 frequency bands × 32 channels flatten to 1,024 coordinates before projection to 1,536.

Two stride-two stages leave about 25 positions per second. A learned projection gives each position 1,536 coordinates; the time axis gets shorter while the representations get wider.

Ask earlier frames for more information

Could the familiar attention operation let these positions request missing context? How far back a sound occurred could help too, alongside what it contains.

Follow the data through the mechanismAudio representations after subsamplingEarlier context is dimmed; outlined columns are current.Current token computation.1,536Encoder time positionsClip → RMSNorm8 attention headsWq1,536192Wk1,536192Wv1,536192Shared scale θ192softplus(θ)÷ (√192 · softplus(0))×QEarlier context is dimmed; outlined columns are current.Current token computation.19212 positionsKEarlier context is dimmed; outlined columns are current.Current token computation.19224 positionsVEarlier context is dimmed; outlined columns are current.Current token computation.19224 positions×QKᵀRelative time ΔSin / cos of ΔPosition projection1,5361,536Split 8 headsEarlier context is dimmed; outlined columns are current.Current token computation.19213 offsets×+Content + timing scoresSoft-cap 50 → mask → softmaxAttention map24 context slots12 queries×Combine valuesEarlier context is dimmed; outlined columns are current.Current token computation.19212 head resultsJoin 8 × 192 coordinatesEarlier context is dimmed; outlined columns are current.Current token computation.1,53612 positionsOutput projection1,5361,536Clip → RMSNormEarlier context is dimmed; outlined columns are current.Current token computation.1,536Attention branch output
Gemma 3n attention uses 8 heads of width 192, relative timing scores and a causal 13-position window; 12-query chunks organise the calculation, and padding slots are masked.

The query contributes both content scores and relative timing scores before masking and softmax. In this worked encoder, each position can read itself and 12 earlier positions, with no future positions; it uses eight heads of width 192.

The 12-query chunks organise computation, rather than fixing recording length. Relative sinusoidal timing features avoid a learned table of absolute recording slots; padding and processor limits remain separate considerations.

Combine requests with local patterns

Attention can request information from earlier sound, while a short convolution can recognise nearby patterns directly. Could we use both, with feed-forward layers to transform their results?

Follow the data through the mechanismMel features · about 100 frames / secondEarlier context is dimmed; outlined columns are current.Current token computation.128F time framesConvolution · time stride 4Earlier context is dimmed; outlined columns are current.Current token computation.1,536About 25 positions / secondConformer encoder12 layers1,536Keep one position in fourEarlier context is dimmed; outlined columns are current.Current token computation.1,536About 6.25 positions / second
Gemma 3n reduces the number of time positions before the language model sees them. Convolution and the Conformer encoder also turn local measurements into contextual audio features.

This combination is a Conformer. After 12 such blocks, keeping one position in four leaves about 6.25 outputs per second, trading some temporal detail for less language-model work.

Inside a Conformer block

The attention branch above sits between two feed-forward branches, alongside a gated causal convolution. Each branch adds to the downward residual stream; the feed-forward contributions are scaled by one half.

Follow the data through the mechanismContextual audio representationsEarlier context is dimmed; outlined columns are current.Current token computation.1,536Encoder time positions12 Conformer blocksFeed-forward 1Clip → RMSNorm → W₁ → SiLU → W₂W₁1,5366,144W₂6,1441,536Clip → RMSNorm → × 0.5+Feed-forward 2Clip → RMSNorm → W₁ → SiLU → W₂W₁1,5366,144W₂6,1441,536Clip → RMSNorm → × 0.5+Attention branch · expanded above8 heads · relative positions · 13-position causal window+Local convolution branchRMSNorm → input projection → GLUInput weights1,5363,0725 steps1,536Depthwise kernelGLU: 3,072 → 1,536 coordinatesCausal depthwise convolution · 5 positionsClip → RMSNorm → SiLU → output projectionOutput weights1,5361,536+Clip → RMSNormEarlier context is dimmed; outlined columns are current.Current token computation.1,536Same number of time positions
Each Conformer block has two 1,536 → 6,144 → 1,536 SiLU feed-forward branches, local attention and a gated causal convolution; each branch adds to the stream, and the block ends with RMSNorm.

The convolution’s GLU splits its projection into content and a sigmoid gate, then a five-position depthwise kernel processes each channel over time. This diagram follows Gemma 3n’s RMSNorm and SiLU choices; other Conformers can arrange their normalisation and operations differently.

Give the audio vectors the text width

Our audio vectors are now 1,536 coordinates wide, while the text vectors need 2,048. Could a learned projection make them fit together?

Follow the data through the mechanismAudio representationsText embeddingsEarlier context is dimmed; outlined columns are current.Current token computation.1,536A audio positionsEarlier context is dimmed; outlined columns are current.Current token computation.2,048Text positionsRMSNormAudio-to-text projection1,5362,048RMSNormEarlier context is dimmed; outlined columns are current.Current token computation.2,048A audio positionsSame sequenceEarlier context is dimmed; outlined columns are current.Current token computation.2,048Audio + text positions
Gemma 3n · E2B: projection changes each audio vector from 1,536 to 2,048 coordinates. It keeps the number of audio positions; normalisation sits before and after the learned matrix.

The position count stays the same. Changing vector width is separate from reducing time resolution.

Follow sound into the language model

Local frequency measurements gave us a manageable starting point. Attention and convolution added context; time reduction shortened the sequence; projection made it fit beside the text.

Follow the data through the mechanism16,000 samples / second128-band mel featuresEarlier context is dimmed; outlined columns are current.Current token computation.128F time framesConvolution · time stride 4Conformer encoder12 layers1,536Time reduction · factor 4Earlier context is dimmed; outlined columns are current.Current token computation.1,536A audio positionsRMSNormAudio-to-text projection1,5362,048RMSNormEarlier context is dimmed; outlined columns are current.Current token computation.2,048A audio positionsText embeddingsEarlier context is dimmed; outlined columns are current.Current token computation.2,048Text positionsPlace vectors in the sequenceEarlier context is dimmed; outlined columns are current.Current token computation.2,048Audio positions + text positionsLanguage model30 layers2,048Predict the next text token
Gemma 3n · E2B: the audio encoder produces 1,536-coordinate vectors. A learned 1,536 → 2,048 projection and normalisation put them at the text width. A counts valid audio positions; padding positions are masked.

This is the input path used by Gemma 3n, with 12 Conformer blocks combining local attention and convolution. The language model can use the recording alongside text, without discarding tone and other sounds in a transcription first. How would we give it a path for producing sound too?

Choose a different audio encoder

The goal is useful audio vectors, rather than one particular encoder. The model catalogue contains several choices:

PathWhat changesExamples
ConformerAttention and convolution build context together; widths and normalisation vary.Gemma 3n uses width 1,536; Gemma 4 E2B and E4B use width 1,024.
Whisper-based transformerA speech encoder prepares features, with frame stacking and a learned connector into the language model.Apriel Voice
Other convolution/attention stacksThe layer layout, time reduction and receptive field differ from our worked Conformer.LFM3, Liquid D1 and Nemotron 3 Nano Omni
Convolutional pyramidA hierarchy of convolutions prepares audio features.Muse Spark
Audio tokenizer and patch encoderAudio passes through a different two-stage representation path.MiMo-V2

The full diagram expands one worked attention design, rather than assigning its causal mask, relative positions or eight heads to every audio encoder. Audio generation also needs its own output path; an input encoder alone does not provide one.

Sources and worked example
  • Conformer, Gulati et al., 2020, and Universal Speech Model, Zhang et al., 2023.
  • Gemma 3n documentation.
  • Gemma 3n feature extractor: 16 kHz input, 32 ms windows, 10 ms hops and 128 mel bands.
  • Audio configuration: 12 Conformer blocks of width 1,536, eight attention heads, a 12-query chunk, left-context setting 13 (12 past positions plus the current one), right context zero, five-position convolution, half-scaled feed-forward branches and final reduction factor 4.
  • Model implementation: learned per-coordinate query scaling, projected relative sinusoidal positions, logit soft-cap 50, causal/padding masks, the Conformer residual paths and multimodal embedding projection.

F labels feature-frame count and A valid audio-output positions. Sampling-rate conversions, pre-emphasis, framing boundaries and padding affect exact lengths. Gemma 3n’s formatter pads audio soft-token slots separately from valid audio content. The waveform and feature cells are illustrations, not a measured recording. The shared picker covers Gemma 3n E2B and E4B; their audio tower is the same. The attention drawing shows a full 12-query chunk with 24 gathered context slots; each row reads 13 slots before sequence-boundary and padding masks. Queries are scaled by softplus(θ) / (√192 × softplus(0)), with one learned 192-coordinate scale shared across heads. The relative-position projection maps 1,536 sinusoidal coordinates to eight 192-coordinate heads. “Clip” denotes the implementation’s activation clamp at ±10¹⁰. Subsampling convolutions can use a short forward receptive field; the no-future attention mask does not imply zero audio-front-end lookahead. The optional block diagram labels operation order and representative weight shapes; masks also zero padded inputs to its local convolution. Other encoders in the comparison follow their own sourced architecture records.

← Browse all subjectsBack to the beginning ↑