Lunar Boom Learning

1.3 · Audio Embeddings

Section 1.3 of 1.4

Audio Embeddings

Turning sound into coordinates a model can compare

Learn how models turn audio into vectors, compare sounds inside an embedding space, and connect music with written descriptions.

About 10 minutes

Guiding question

How can a model compare two sounds without comparing every audio sample?

By the end, you’ll be able to
  • Define an audio embedding and explain how it differs from the original recording.
  • Explain what closeness means inside an embedding space.
  • Describe how audio and text can be placed in a shared space.

Imagine trying to organise thousands of songs. Comparing every waveform sample would be slow and not very helpful. You might care more about whether two clips share an instrument, mood, rhythm, genre, or type of sound.

An audio embedding gives a model a more useful summary. An encoder turns a sound into a list of numbers called a vector. Those numbers act like coordinates inside an embedding space. The original recording may contain hundreds of thousands of audio samples, while the embedding can have a fixed size that is much easier to compare.

The embedding is not a tiny audio file. You cannot normally press play on it or use it to recreate every detail of the recording. It keeps the information that the model learned to treat as useful for its task.

From a sound clip to an embedding

  1. The model receives audio

    The input may be a waveform or a representation derived from it, such as a log-mel spectrogram.

  2. An encoder finds patterns

    Layers inside the model respond to useful features such as frequency patterns, timing, texture, instruments, voices, or sound events.

  3. The features are combined

    The model turns its internal activations into a fixed-size vector.

  4. The vector is compared

    The system can compare the new embedding with other audio embeddings, text embeddings, labels, or examples from a dataset.

Embedding, waveform, and codec representation

Swipe sideways to view the full comparison

RepresentationMain purposeCan it normally recreate the exact audio?Typical use
WaveformStore the changing audio signalYes, when the samples and format are preservedPlayback, editing, and direct audio generation
EmbeddingRepresent features useful for a learned taskNoSimilarity, search, tagging, classification, and conditioning
Neural codec representationCompress audio while keeping enough detail for reconstructionApproximately, through a decoderAudio compression and token-based generation

What does closeness mean?

Once two sounds have been turned into vectors, the model can compare them mathematically. A common method is cosine similarity, which compares the direction of two vectors. Vectors pointing in a similar direction receive a higher similarity score.

If two clips are close in the space, it means the model has learned to treat them as related. That relationship could come from shared instruments, genre, sound events, mood, recording texture, or another pattern learned during training.

Close does not mean identical. Two tracks can sound different while sharing a useful high-level feature. A jazz saxophone solo and a jazz piano trio may be placed near each other because both match the idea of jazz, even though their waveforms are very different.

In practice

Audio-only example: YAMNet

YAMNet is trained to recognise 521 audio event classes from AudioSet. It also produces a 1,024-value embedding for each short audio frame. TensorFlow shows how those embeddings can be reused to train a smaller classifier for a new task, such as separating cat and dog sounds, without training the full audio model again.

Putting audio and text in the same space

An audio-only embedding model compares sounds with other sounds. A joint audio-text model goes one step further. It uses one encoder for audio and another for text, then places both outputs in the same embedding space.

During training, matching pairs are pulled closer together. For example, a clip of soft piano and the caption soft solo piano with a slow melody should receive similar embeddings. Mismatched pairs are pushed further apart.

This approach is called contrastive learning. It teaches the model which audio and text belong together without requiring every possible concept to be turned into a fixed label.

Examples in practice

Audio and language example: CLAP

CLAP stands for Contrastive Language-Audio Pretraining. It uses separate audio and text encoders and trains them to place matching audio and descriptions close together in one space. The original researchers tested the learned representations across sound events, music, and speech tasks. The shared space also supports zero-shot classification, where a model compares audio with new text labels without training a separate classifier for each label.

Music-focused example: MuLan

MuLan applies the same broad idea specifically to music and natural language. It was trained to connect music recordings with free-form descriptions. The resulting space can support music search, tagging, and matching text with tracks. A search for 'bright dance music with a strong beat' can be turned into a text embedding and compared with music embeddings from a catalogue.

How embeddings can guide generation

MusicLM used MuLan embeddings to connect text prompts with generated music. During training, MusicLM used embeddings created from music audio. During generation, it used an embedding created from the user's text. Because MuLan placed related music and descriptions in the same space, the text embedding could act as a high-level guide for the music model.

What can audio embeddings be used for?

Swipe sideways to view the full comparison

TaskHow the embedding helpsExample
Similarity searchFinds nearby vectorsShow tracks related to a selected clip
Text-to-music searchCompares text and audio in a shared spaceFind music matching 'slow cinematic strings'
Tagging and classificationFeeds learned features into labels or a smaller modelDetect speech, drums, or environmental sounds
Transfer learningReuses features from a pretrained encoderTrain a new classifier with less labelled data
Generation controlProvides a high-level conditioning signalGuide a model toward music matching a prompt
EvaluationCompares generated audio with a requested descriptionEstimate how well a result follows its prompt

Why does an embedding map fit on a screen?

Real embeddings often contain hundreds or thousands of values, so they cannot be displayed directly on a flat screen. A method such as UMAP can reduce those vectors to two dimensions and give each item a visible position.

The map is useful for exploring clusters and nearby examples, but it is only a simplified projection. Some distances change when many dimensions are squeezed into two. A reliable interactive should therefore show the original similarity score as well as the point's position on the map.

Interactive lesson

Explore an Audio Embedding Space

Try it: Select a simulated sound to reveal its closest neighbours. Then choose a text description and compare the results. Use the colour controls to see whether clusters follow instrument, genre, mood, or sound type. Remember that the map is a two-dimensional projection of a larger space.

An audio embedding is a vector of learned features. Similarity is measured in the original high-dimensional space. A two-dimensional map can make clusters easier to explore, but it cannot preserve every distance perfectly.

Check your understanding

Ready for a quick check?

Test whether you can explain what embeddings contain, how similarity works, and how audio can be connected with text.

Ready to continue?

Save this section to your account and continue from any device.

Checking your account…
Sources for this lesson (7)