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.

Metadata

Release files for clapback-embed 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clapback-embed 0.1.0
File Size Uploaded Provenance Actions
clapback_embed-0.1.0.tar.gz 24.0 kB With provenance Details for clapback_embed-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clapback-embed 0.1.0
File Interpreter ABI Platform Actions
clapback_embed-0.1.0-py3-none-any.whl Python 3 none any Details for clapback_embed-0.1.0-py3-none-any.whl

Total release size: 38.9 kB

Release files / clapback_embed-0.1.0.tar.gz

Download URL clapback_embed-0.1.0.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7cc6515abae798f6c220fb62d2c3ba709f6acaba3b8a4e8256e51a8121545ac6
BLAKE2b-256 checksum
How to use checksums
de4dd46c8eb16dcfa7481c07def9125af4373966afb151691cd1ca9f6d2c8af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Release files / clapback_embed-0.1.0-py3-none-any.whl

Download URL clapback_embed-0.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf27e314162c28ac93fc88b61c9a0ac83346f564e94a755d1435ef7546f901e1
BLAKE2b-256 checksum
How to use checksums
d0e90537e6244965c634764863575e659ce47108bf53c35b72819e56ed51c358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

Security for clapback-embed 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for clapback_embed-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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