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
- Decode to 48 kHz mono.
- 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.
- Drop a trailing partial window;
repeatpada track shorter than one window. - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cc6515abae798f6c220fb62d2c3ba709f6acaba3b8a4e8256e51a8121545ac6
|
|
| MD5 |
d81f953cd84778b1033b8dab6dcab34a
|
|
| BLAKE2b-256 |
de4dd46c8eb16dcfa7481c07def9125af4373966afb151691cd1ca9f6d2c8af9
|
Provenance
The following attestation bundles were made for clapback_embed-0.1.0.tar.gz:
Publisher:
embed-release.yml on seethroughlab/clapback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clapback_embed-0.1.0.tar.gz -
Subject digest:
7cc6515abae798f6c220fb62d2c3ba709f6acaba3b8a4e8256e51a8121545ac6 - Sigstore transparency entry: 2706050277
- Sigstore integration time:
-
Permalink:
seethroughlab/clapback@acc549f11273c4161d211253e9c15b39f217e21a -
Branch / Tag:
refs/tags/embed-v0.1.0 - Owner: https://github.com/seethroughlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
embed-release.yml@acc549f11273c4161d211253e9c15b39f217e21a -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf27e314162c28ac93fc88b61c9a0ac83346f564e94a755d1435ef7546f901e1
|
|
| MD5 |
cf723a323e88a05147a7426f59782321
|
|
| BLAKE2b-256 |
d0e90537e6244965c634764863575e659ce47108bf53c35b72819e56ed51c358
|
Provenance
The following attestation bundles were made for clapback_embed-0.1.0-py3-none-any.whl:
Publisher:
embed-release.yml on seethroughlab/clapback
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clapback_embed-0.1.0-py3-none-any.whl -
Subject digest:
bf27e314162c28ac93fc88b61c9a0ac83346f564e94a755d1435ef7546f901e1 - Sigstore transparency entry: 2706050298
- Sigstore integration time:
-
Permalink:
seethroughlab/clapback@acc549f11273c4161d211253e9c15b39f217e21a -
Branch / Tag:
refs/tags/embed-v0.1.0 - Owner: https://github.com/seethroughlab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
embed-release.yml@acc549f11273c4161d211253e9c15b39f217e21a -
Trigger Event:
push
-
Statement type: