Unified Audio-Visual-Language Modeling › Modality Encoders

Michael BrenndoerferDecember 1, 20265 min read
Language AI HandbookAll chapters
Part 52 of 67Omni-Modal and Embodied Language Systems
Chapter 398Unified Audio-Visual-Language Modeling › Modality Encoders
Reading section 2 of 10 · Modality Encoders · 5 minSection 2 of 10 · 5 min

Section 2 of 10 · 5 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A model cannot use a waveform or a frame until it has a representation for it. A text tokenizer produces integer IDs, each associated with an embedding row. Audio and video encoders instead often produce real-valued feature vectors. In both cases the transformer receives vectors, but the audio and video positions do not need an ID in the text vocabulary.

Why not feed raw audio or pixels directly

At 16,000 samples per second, 30 seconds of audio gives 480,000 samples. A 30-second video at 30 frames per second gives 900 frames. If each 224×224224\times224 RGB frame contributes one sequence position per color value, the video has 135,475,200 positions. This is a deliberately inefficient raw encoding for comparison. An ordinary dense attention head computes pairwise scores for up to L2L^2 query-key positions before considering a mask. One head on the raw audio would therefore have about 2.3×10112.3\times10^{11} position pairs in one layer. A causal mask has fewer allowed pairs, with the same quadratic growth. An optimized kernel can avoid storing a dense score matrix while doing the underlying pairwise computation.

PythonIn [3]
CollapseExpand
# For a 30-second clip, compute raw sizes from the stated sampling and frame
# rates. Use one pooled video feature per frame. The 1,500 audio positions
# come from the Whisper large model configuration.
SAMPLE_RATE = 16_000  # Hz, speech
AUDIO_SECONDS = 30.0
VIDEO_FPS = 30
VIDEO_SECONDS = 30.0
FRAME_PIXELS = 224 * 224 * 3

raw_audio_samples = int(SAMPLE_RATE * AUDIO_SECONDS)
raw_video_values = int(VIDEO_FPS * VIDEO_SECONDS) * FRAME_PIXELS

# Compressed representations: Whisper-large (1500 vectors / 30s) and a
# per-frame ViT at 1 token per frame.
compressed_audio = 1500
compressed_video = int(VIDEO_FPS * VIDEO_SECONDS)  # 1 token per frame
compressed_total = compressed_audio + compressed_video

seq_lengths = {
    "Raw audio samples": raw_audio_samples,
    "Raw video values": raw_video_values,
    "Audio feature vectors": compressed_audio,
    "Video feature vectors": compressed_video,
}
print({k: f"{v:,}" for k, v in seq_lengths.items()})
print(f"Combined compressed length: {compressed_total:,}")
ConsoleOut [3]
CollapseExpand
{'Raw audio samples': '480,000', 'Raw video values': '135,475,200', 'Audio feature vectors': '1,500', 'Video feature vectors': '900'}
Combined compressed length: 2,400
VisualizationOut [4]
CollapseExpand
Log-scale bar chart comparing raw audio, raw video, and compressed feature sequence lengths.
Sequence lengths for a 30-second clip. The hypothetical raw inputs place each sample or color value at a position. The compressed examples use one pooled video vector per frame and the Whisper large audio feature length.

This figure compares counts of positions, not bytes or measured latency. Restricting video to one vector per frame is an illustrative pooling choice. A vision encoder can also preserve a patch sequence per frame, or keep multiple spatial regions. Pooling saves positions while making it harder to recover within-frame detail. Speech recognition features can also retain information about the speaker. Whisper-PMFA used features from Whisper encoder blocks for speaker verification.

Audio encoders

A common front end divides the waveform into overlapping windows, computes a spectrum for each window, and aggregates spectral energy into mel-filterbank bins. The resulting mel spectrogram has one axis for time and one for frequency bins. For an actual model, check the exact window, hop, padding and feature stride before converting a time span into a number of output positions.

If M∈RM×T\mathbf{M}\in\mathbb{R}^{M\times T} denotes a spectrogram with MM frequency bins and TT frames, the audio encoder EaE_a produces time-indexed vectors

Ha=Ea(M)∈RTa×da.\mathbf{H}_a = E_a(\mathbf{M})\in\mathbb{R}^{T_a\times d_a}.

Here TaT_a counts output positions, and dad_a counts components per position. A stride-two convolution can reduce the time resolution without changing the duration of the underlying clip. The Whisper paper uses 30-second input segments and a convolutional stem with stride two. The released large model configuration lists hidden width 1,280 and up to 1,500 source positions. Padding and trimming affect which positions represent the actual clip near its boundaries.

Video encoders

One option runs a vision encoder on each frame and preserves the time ordering of the frame features. A frame encoder can describe the frame at its own timestamp without encoding motion between frames. A later model can still infer motion by comparing the ordered outputs. Another option projects spatiotemporal patches across consecutive frames. For TT frames of height HH and width WW, with nonoverlapping patches of temporal extent ptp_t and spatial extent p×pp\times p, exactly divisible dimensions yield

Lv=TptHpWp.L_v = \frac{T}{p_t}\frac{H}{p}\frac{W}{p}.

This is a count before pooling or adding markers. At 300 frames of 224×224224\times224, with p=16p=16 and pt=2p_t=2, it is 150×14×14=29,400150\times14\times14=29{,}400. Real encoders may sample fewer frames or merge patches after encoding. Those are separate choices with separate effects on what timing or spatial detail reaches the language model.

Text tokenizer

A tokenizer such as byte-pair encoding maps input text to a sequence of vocabulary IDs. The embedding lookup maps each ID to a fixed-width vector. Token counts depend on the vocabulary and normalization rules. An encoder can retain continuous features at input positions while a generation head selects discrete IDs at its output.

Feature vectors and token IDs

A position filled by an audio or video encoder is sometimes called a token. This usage describes its place in the sequence. It does not mean the encoder emitted an ID from the text vocabulary.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy