Sentence Similarity
Model2Vec
English
embeddings
static-embeddings
feature-extraction
quantization
1-bit
littlebit
Instructions to use MisasAI/LittleLittlePotion-164kb with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Model2Vec
How to use MisasAI/LittleLittlePotion-164kb with Model2Vec:
from model2vec import StaticModel model = StaticModel.from_pretrained("MisasAI/LittleLittlePotion-164kb") embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."]) print(embeddings.shape) - Notebooks
- Google Colab
- Kaggle
Download scripts/lbit_decode.py from MisasAI/LittleLittlePotion-164kb: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/MisasAI/LittleLittlePotion-164kb/resolve/main/scripts/lbit_decode.py
- Command line
-
hf download hf://MisasAI/LittleLittlePotion-164kb/scripts/lbit_decode.py
-
curl -L -o lbit_decode.py https://huggingface.co/MisasAI/LittleLittlePotion-164kb/resolve/main/scripts/lbit_decode.py
1.36 kB
| """Decode a micro700kb-style model to a dense [vocab, 256] numpy table. | |
| Accepts either the original Model2Vec safetensors (embeddings/mapping/weights) | |
| or a LittleBit .lbit written by micro_lb.py.""" | |
| import torch | |
| from safetensors import safe_open | |
| from safetensors.torch import load_file | |
| _SH = torch.tensor([7, 6, 5, 4, 3, 2, 1, 0], dtype=torch.uint8) | |
| def _signs(pk, r): | |
| return ((pk.unsqueeze(-1) >> _SH) & 1).view(pk.shape[0], -1)[:, :r].float() * 2 - 1 | |
| def _ints(b, nbits, n): | |
| bits = ((b.long().unsqueeze(1) >> torch.arange(8)) & 1).view(-1)[: n * nbits].view(n, nbits) | |
| return (bits << torch.arange(nbits)).sum(-1) | |
| def decode(path): | |
| x = load_file(path) | |
| if "embeddings" in x: # original vocab-quantized Model2Vec | |
| return (x["weights"].float()[:, None] * x["embeddings"].float()[x["mapping"].long()]).numpy() | |
| with safe_open(path, "pt") as f: | |
| m = f.metadata() | |
| r, n, nb = int(m["rank"]), int(m["vocab"]), int(m["map_bits"]) | |
| C = 0 | |
| for p in ("pri", "res"): | |
| if f"centroids.{p}.U_bits" not in x: | |
| continue | |
| h, g, l = (x[f"centroids.{p}.{s}"].float() for s in "hgl") | |
| C = C + (h[:, None] * _signs(x[f"centroids.{p}.U_bits"], r) * l) @ (_signs(x[f"centroids.{p}.V_bits"], r) * g[:, None]).T | |
| return (x["weights"].float()[:, None] * C[_ints(x["mapping_bits"], nb, n)]).numpy() | |