Dependency-light pure-numpy CPU inference for CLIP embeddings, inference-free SPLADE, and BERT fill-mask — a drop-in replacement for the transformers / sentence-transformers models in a RAG stack (no PyTorch, no ONNX).
Project description
faster-clip
Dependency-light, pure-numpy CPU inference for the models a multilingual RAG
stack typically needs — with no PyTorch, no transformers, no sentence-transformers,
no ONNX. Just numpy + tokenizers (+ safetensors / huggingface_hub for
weights, pillow for images).
pip install faster-clip
It provides three drop-in replacements, each numerically matching the original HuggingFace pipeline:
| Class | Replaces | Output |
|---|---|---|
ClipModel |
SentenceTransformer('clip-ViT-B-32') + clip-ViT-B-32-multilingual-v1 |
512-d CLIP image / text embeddings (cosine ≈ 1.0) |
SparseEncoder |
SparseEncoder('…inference-free-splade…') |
{token_id: weight} sparse dicts (bit-identical) |
FillMask |
pipeline('fill-mask', 'bert-base-uncased' / 'bert-base-portuguese-cased') |
top-k {token_str, sequence, score} (identical strings) |
Model weights are downloaded from HuggingFace and cached on first use (the SPLADE weights, ~120 KB, ship inside the wheel).
CLIP embeddings
from faster_clip import ClipModel
from PIL import Image
clip = ClipModel() # lazily downloads image / text weights on first use
text_emb = clip.encode_text(["um carro vermelho", "a red car"]) # (2, 512)
img_emb = clip.encode_image(Image.open("photo.jpg")) # (1, 512)
Image and multilingual text land in the same 512-d CLIP space, so you can do cross-modal search. (Normalize yourself if you need unit vectors.)
SPLADE sparse encoding (no sparse tensor materialized)
The model is an inference-free SPLADE: encoding is a pure token→weight lookup, so the result is just a dict of the active dimensions — no dense/sparse vector is ever built.
from faster_clip import SparseEncoder
sparse = SparseEncoder()
sparse.encode("banco de dados vetorial")
# -> {'15060': 1.09, '2951': 1.11, '2078': 1.04, ...} # {token_id: weight}
encode, encode_query, and encode_document are equivalent (the model's query
route is the default) and accept a string or a list of strings.
Fill-mask autocomplete
from faster_clip import FillMask
fm = FillMask()
fm.predict("the weather is very [MASK]", lang="en")
# -> [{'token_str': '.', 'sequence': 'the weather is very.', 'score': 0.30}, ...]
fm.predict("o brasil é um [MASK]", lang="pt")
# -> [{'token_str': 'lixo', 'sequence': 'o brasil é um lixo', ...}, ...]
lang is "en" (bert-base-uncased) or "pt" (neuralmind/bert-base-portuguese-cased).
Model cache
Weights are cached by huggingface_hub under ~/.cache/huggingface. To run
offline, pre-download the models once (or set HF_HOME). CLIP vision/text and the
BERT MLMs are fetched on first use of each capability.
License
MIT. Model weights belong to their respective authors (OpenAI / Microsoft / sentence-transformers / neuralmind), used under their original licenses.
Project details
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 faster_clip-0.1.0.tar.gz.
File metadata
- Download URL: faster_clip-0.1.0.tar.gz
- Upload date:
- Size: 289.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e0e0f138ba0f17fe1c15cbff6602c3b06d04392b9c5284be152605c92a766de
|
|
| MD5 |
620d8e25139f43b7e3a89ac368df1d1c
|
|
| BLAKE2b-256 |
6c05fc01ee781fdd5bc40a8d7931a7fe0062f785710eac80e3335a459bd507af
|
File details
Details for the file faster_clip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: faster_clip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 289.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
705ee9e7221c1d877476e49540cb9c7366c6eb0b99b01a1166d8d708cb4904fa
|
|
| MD5 |
f3a8283b116ff516fd086ce31dccc019
|
|
| BLAKE2b-256 |
a9719ef6a1fec6fbae7172180c54d317caec4894f7e591e5d1ab61bf079c2149
|