korben99 commited on
Commit
29d996a
·
verified ·
1 Parent(s): 5f11c3d

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +52 -0
  2. binary_embedder_4096.pt +3 -0
  3. config.json +5 -0
README.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - embeddings
6
+ - binary
7
+ - bert
8
+ - efficient-inference
9
+ pipeline_tag: sentence-similarity
10
+ ---
11
+
12
+ # bne-binary-4096
13
+
14
+ Native **4096-bit binary** embedding model from the **Binary Native Embeddings** project.
15
+
16
+ - Backbone: `prajjwal1/bert-mini` (4L × 256d, ~11M params)
17
+ - Output: 4096-dim {-1,+1} binary via Linear(256→4096) + LayerNorm + STE
18
+ - Training: tanh contrastive loss on NLI 550k pairs, 3 epochs
19
+ - Key: differential LR (encoder 2e-5, projection 1e-3) + Straight-Through Estimator
20
+
21
+ | STS-B Spearman | Recall@10 (SciFact) | Memory / 1k vecs | Retrieval vs float (FAISS POPCNT) |
22
+ |---|---|---|---|
23
+ | 0.7275 | 0.2958 | 500 KB | 6.0x faster at 1M vecs (FAISS AVX2+POPCNT, Intel Core Ultra 7) |
24
+
25
+ Part of [binary-native-embeddings](https://github.com/korben99/binary-native-embeddings).
26
+
27
+ ## Why binary?
28
+
29
+ At 1M vectors with FAISS `IndexBinaryFlat` (AVX2 + POPCNT, Intel Core Ultra 7):
30
+ - float32 384-dim: 3 601 ms
31
+ - **binary 2048-dim: 293 ms (12.3x faster)**
32
+ - **binary 4096-dim: 596 ms (6.0x faster)**
33
+
34
+ POPCNT processes 64 bits/cycle; 2048-bit Hamming distance = 32 POPCNT instructions vs 384 multiply-accumulates, plus 6× better cache utilization (256 bytes/vector vs 1 536 bytes).
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ import torch
40
+ from transformers import BertTokenizer
41
+ from huggingface_hub import hf_hub_download
42
+
43
+ tokenizer = BertTokenizer.from_pretrained("prajjwal1/bert-mini")
44
+
45
+ from models.binary_embedder import BinaryEmbedder
46
+ model = BinaryEmbedder(binary_dim=4096)
47
+ weights = hf_hub_download("korben99/bne-binary-4096", "binary_embedder_4096.pt")
48
+ model.load_state_dict(torch.load(weights, map_location="cpu"))
49
+ model.eval()
50
+
51
+ vecs = model.encode(["hello world"], tokenizer) # (1, 4096), values in {-1, +1}
52
+ ```
binary_embedder_4096.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eba731dca210d7240c0d77f966dc207179b92d1766245ab2b9152ff581cc8d17
3
+ size 48956426
config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "model_type": "BinaryEmbedder",
3
+ "binary_dim": 4096,
4
+ "backbone": "prajjwal1/bert-mini"
5
+ }