Skip to main content

clapback-embed

Deterministic CLAP audio and text embeddings, without torch or transformers.

from clapback_embed import embed_file, embed_text

vector = embed_file("track.flac")          # 512 floats, unit length
query  = embed_text("dreamy ambient with piano")   # same space

Why this exists

Two machines running this produce the same vector. That is the whole point: a corpus built from many contributors can only tell disagreement about audio from disagreement about implementations if there is one implementation.

So everything that could vary is pinned and versioned — the mel front-end, the windowing rule, the pooling, the checkpoint, and the precision. PIPELINE_VERSION is the identity of all of it together.

It is not the checkpoint. A change to windowing or pooling moves every vector while laion/clap-htsat-unfused stays fixed. That is not hypothetical: Familiar changed every embedding it held by moving from middle-ten-seconds to a whole-track mean, without touching the checkpoint.

What it does

  1. Decode to 48 kHz mono.
  2. Split into consecutive, non-overlapping 10-second windows. CLAP cannot see more than ten seconds — HTSAT's positional embeddings are sized for a 1001×64 mel, and both ONNX and PyTorch reject anything else. A long track is several observations no matter what.
  3. Drop a trailing partial window; repeatpad a track shorter than one window.
  4. Embed each window, mean-pool the raw outputs, then L2-normalise.

Step 4 is deliberately not a mean of already-normalised vectors. The two differ.

Precision

Measured against a full chunked mean, as cosine distance from 1.0:

difference distance
float4 storage round-trip 6.0e-08
mel implementation (this vs transformers) 1.2e-07
runtime (torch vs ONNX fp32) 1.2e-07
fp32 vs fp16 1.5e-06
different rip of the same recording 3e-04 – 3e-03

fp16 is the first entry that leaves the corpus's identical band, so anything contributed must be fp32. Precision.FP16 exists for vectors that never leave your machine.

Models

The encoders are 112 MB (audio) and 502 MB (text) and are not vendored. Produce them from the pinned checkpoint:

uv pip install -e '.[export]'
python scripts/export_models.py --out ~/.cache/clapback/models

Exporting needs torch and transformers; using the result needs neither. Every export verifies itself against PyTorch before writing — an artifact that disagrees is worse than a missing one, because it produces plausible vectors that are comparable with nothing.

Override the location with CLAPBACK_MODEL_DIR.

One trap worth knowing

ClapFeatureExtractor selects a different filter bank when truncation="fusion" — torchaudio/HTK rather than slaney. Nothing about the resulting vectors looks wrong and they are comparable with nothing. This package implements the slaney path only, which is what the checkpoint's default (rand_trunc) uses, and asserts it rather than trusting a default.

Relatedly, rand_trunc takes a random crop of anything longer than one window. Reproducibility here rests on every window being exactly 480,000 samples, which is checked rather than assumed.

Tests

uv pip install -e '.[dev]'
pytest                      # windowing, front-end arithmetic, pooling
pytest -m artifacts         # adds determinism against the real encoders

The comparison against transformers is the drift guard for the whole corpus. It skips when the reference is not installed rather than being deleted.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clapback_embed-0.1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clapback_embed-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file clapback_embed-0.1.0.tar.gz.

File metadata

  • Download URL: clapback_embed-0.1.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for clapback_embed-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7cc6515abae798f6c220fb62d2c3ba709f6acaba3b8a4e8256e51a8121545ac6
MD5 d81f953cd84778b1033b8dab6dcab34a
BLAKE2b-256 de4dd46c8eb16dcfa7481c07def9125af4373966afb151691cd1ca9f6d2c8af9

See more details on using hashes here.

Provenance

The following attestation bundles were made for clapback_embed-0.1.0.tar.gz:

Publisher: embed-release.yml on seethroughlab/clapback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clapback_embed-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: clapback_embed-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for clapback_embed-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf27e314162c28ac93fc88b61c9a0ac83346f564e94a755d1435ef7546f901e1
MD5 cf723a323e88a05147a7426f59782321
BLAKE2b-256 d0e90537e6244965c634764863575e659ce47108bf53c35b72819e56ed51c358

See more details on using hashes here.

Provenance

The following attestation bundles were made for clapback_embed-0.1.0-py3-none-any.whl:

Publisher: embed-release.yml on seethroughlab/clapback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page