BanhTrangPhoi-L20

A smaller, faster student of BAAI/bge-m3 that keeps all three bge-m3 heads (dense, sparse/lexical, ColBERT multi-vector).

  • 20 transformer layers (teacher layers 0, 1, 2, 3, 6, 8, 9, 10, 11, 12, 14, 15 and 16-23) instead of 24.
  • Vocabulary pruned from 250,002 to 125,000 tokens (about 128M parameters saved), 388M parameters in total.
  • Trained by knowledge distillation from bge-m3 (see "Training").
  • Same output space as bge-m3: 1024-d dense vectors (L2-normalised), per-token sparse weights, 1024-d ColBERT vectors.

Read this first: status and honest limits

This model did NOT pass our tier-1 release gate against the original bge-m3. The gate (our own, set 2026-11-18) requires non-inferiority on every tier-1 cell: delta >= -1.0 point AND 95% CI lower bound >= -2.5 on the ALL cell of vi/ja/en/zh/ko and on every sub-cell with n >= 250. The L20 fp16 model falls outside it on 15 cells, all of them Chinese/Korean cross-lingual MKQA cells (n = 250), Korean ALL recall@50 (dense), and Vietnamese ALL recall@50 (dense, delta -0.6 with a wide CI). Tier 2 (ar, es, fr, hi, id, ru, th) is within its limits in every mode for fp16, fp32 and Q8_0, and fails in the all mode for the int8 variant (see table). Full lists are in gate/.

Practical reading: Vietnamese, Japanese and English are on par with bge-m3 in our pools; Chinese and Korean are slightly weaker, mostly in the cross-lingual (query in zh/ko, English corpus) setting. If those matter to you, test on your own data.

Not measured: anything beyond 512 tokens (all gates use max_len 512), languages outside the list above, and retrieval domains outside our pools. Absolute scores are for our pools and our scoring code; do not compare them with numbers from other harnesses.

Results against bge-m3 (fp16, same scoring path)

Tier 1, ALL cells, mode all (dense + sparse + ColBERT), recall@20 in %, teacher -> student:

variant vi ja en zh ko tier-2 mean delta (all / dense)
gpu-fp16 94.6 -> 95.1 100 -> 100 98.9 -> 100 91.1 -> 90.2 89.9 -> 89.7 -0.91 / -0.57
cpu-fp32 (ONNX) 94.6 -> 95.1 100 -> 100 98.9 -> 100 91.1 -> 90.4 89.9 -> 89.7 -0.92 / -0.59
cpu-int8-hlf (ONNX int8) 94.6 -> 95.7 100 -> 100 98.9 -> 100 91.1 -> 90.4 89.9 -> 88.8 -1.12 (below the -1.0 limit) / -0.97
Q8_0 GGUF (separate repo) 94.6 -> 95.1 100 -> 100 98.9 -> 100 91.1 -> 90.4 89.9 -> 89.7 -0.95 / -0.61

Measurement: 4,631 queries over 20 pools (about 94k documents), max_len 512. Tier 1 = vi/ja/en/zh/ko (MIRACL, MKQA, MLDR and a few small in-house domain pools, labelled in the tables); tier 2 = ar/es/fr/hi/id/ru/th (MIRACL, MKQA, MLDR). Tier-2 delta is in points of 100 x metric (nDCG@10 for MIRACL/MLDR, recall@100 for MKQA), averaged over the gated cells. Confidence intervals: paired bootstrap over queries.

Variants (folders)

folder format size use it when
gpu-fp16/ safetensors fp16 (HF XLMRobertaModel) + head weights 0.78 GB GPU, or when you want to fine-tune / re-export. Reference quality.
cpu-fp32/ ONNX fp32 with all three heads 1.56 GB CPU when quality matters most (Korean, Chinese).
cpu-int8-hlf/ ONNX, dynamic per-channel int8 0.95 GB CPU, dense (+ BM25) retrieval where RAM and latency matter. About 1.7-2.1x faster and ~23% less RAM than fp32 on our CPU benchmark. Costs about 0.9 points Korean ALL recall@20 (mode all) vs the fp16 student; fails the tier-2 limit in the all mode (-1.12); dense-only tier 2 is -0.97. Prefer cpu-fp32 for Korean.
GGUF Q8_0 llama.cpp 0.44 GB in the separate repo EVOKA/BanhTrangPhoi-L20-GGUF

cpu-int8-hlf: onnxruntime dynamic int8 on MatMul weights; the sparse/ColBERT head MatMuls and layers 0, 1, 18, 19 stay fp32 ("hlf" = heads + last2 + first2). Each folder is self-contained (tokenizer, id_map_*.json, head weights, PRUNE_INFO.json, SURGERY.json).

Usage

ONNX (cpu-fp32/ or cpu-int8-hlf/), all three heads in one call

import numpy as np, onnxruntime as ort
from huggingface_hub import snapshot_download
from tokenizers import Tokenizer

folder = "cpu-int8-hlf"   # or "cpu-fp32"
p = snapshot_download("EVOKA/BanhTrangPhoi-L20", allow_patterns=[f"{folder}/*"]) + "/" + folder
tk = Tokenizer.from_file(f"{p}/tokenizer.json")
tk.enable_padding(pad_id=1, pad_token="<pad>"); tk.enable_truncation(512)
sess = ort.InferenceSession(f"{p}/model.onnx", providers=["CPUExecutionProvider"])

def encode(texts):
    e = tk.encode_batch(texts)
    ids = np.array([x.ids for x in e], dtype=np.int64)
    mask = np.array([x.attention_mask for x in e], dtype=np.int64)
    dense, sparse, colbert = sess.run(None, {"input_ids": ids, "attention_mask": mask})
    return dense, sparse, colbert, ids, mask

dense, sparse, colbert, ids, mask = encode(["Hà Nội là thủ đô của Việt Nam.", "Thủ đô nước Việt Nam là gì?"])
print(dense.shape, float(dense[0] @ dense[1]))   # (2, 1024); dense is already L2-normalised

Outputs: dense_vecs (b, 1024), sparse_vecs (b, t) = weight per input token, colbert_vecs (b, t-1, 1024) (position 0 / CLS excluded; use mask[:, 1:] to drop padding). Sparse: build the lexical dict per text as max weight per token id, skipping weights <= 0 and the special ids 0, 1, 2, 3 (see reference/m3.py, lex_dict). The token ids are the pruned vocabulary; to compare with bge-m3's sparse weights map them with id_map_new2old.json.

Recommended retrieval setup: dense + BM25

We suggest using the dense head together with a classic BM25 / keyword index (hybrid retrieval) instead of the sparse or ColBERT heads. This is the setup the cpu-int8-hlf variant targets. Use the sparse and ColBERT heads when you want bge-m3's full "all" scoring (dense + sparse + colbert, weights as in bge-m3); they are available from all folders.

PyTorch (gpu-fp16/)

reference/m3.py is a minimal loader of the three heads on top of XLMRobertaModel: dense = L2(CLS), sparse = relu(Linear(h)) per token, ColBERT = L2(Linear(h[1:])). Pass the gpu-fp16 folder as path.

Speed and memory (CPU, indicative)

Measured on one aarch64 box (Cortex-X925 / A725, 16 threads, onnxruntime 1.22.1), while other jobs were running (load average about 12), 3 heads computed. "b1" = batch-1 latency p50 in ms; "b64" = throughput in texts/s with batch 64; RSS in MB at 512 tokens. Query = 32 tokens, passages = 256 / 512 tokens. Numbers are noisy; measure on your hardware.

variant q32 b1 / b64 p256 b1 / b64 p512 b1 / b64 RSS (p512)
cpu-fp32 33.7 ms / 42.3 231.8 ms / 5.7 480.9 ms / 3.2 3.8 GB
cpu-int8-hlf 18.9 ms / 84.9 127.9 ms / 12.0 265.3 ms / 5.5 2.9 GB

GPU (RTX 3060, torch fp16, batch 128, shared machine, best of several runs, earlier measurement): passages of 256 tokens, 3 heads: bge-m3 118.5 texts/s vs L20 133.3 (about 1.12x); dense only: 134.5 vs 159.4 (about 1.2x). The GGUF variant is benchmarked in its own repo card.

Training

Teacher: BAAI/bge-m3. The student is initialised from the teacher by vocabulary pruning (keep-set of 125k ids) and layer selection, then trained by knowledge distillation: KL divergence on the dense / sparse / ColBERT / combined score matrices, a feature-matching loss, and a small InfoNCE term, with an online fp16 teacher and hard negatives from a precomputed teacher dense index. Final stage: 5k steps, lr 1e-5, about 147k rows.

Training data includes FineWeb-2 (ODC-By 1.0), C4 (ODC-By 1.0), Aya (Apache-2.0), OASST1 (Apache-2.0), TyDi QA questions (Apache-2.0), Wikidata (CC0). MIRACL, MKQA and MLDR were used for evaluation only, and near-duplicates of evaluation queries/passages were removed from the training mix. The licences of the individual sources apply to those sources; no claim is made here about the licence status of any other data.

License and citation

Model weights and code in this repository: MIT (the teacher, BAAI/bge-m3, is MIT-licensed). Please also credit the teacher:

@misc{bge-m3,
  title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation},
  author={Chen, Jianlv and Xiao, Shitao and Zhang, Peitian and Luo, Kun and Lian, Defu and Liu, Zheng},
  year={2024}, eprint={2402.03216}, archivePrefix={arXiv}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for EVOKA/BanhTrangPhoi-L20

Base model

BAAI/bge-m3
Quantized
(317)
this model

Paper for EVOKA/BanhTrangPhoi-L20