|
Download code/README.md from quocbao747/embedding-model-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 3.94 kB
-
https://huggingface.co/quocbao747/embedding-model-benchmark/resolve/main/code/README.md
- Command line
-
hf download hf://quocbao747/embedding-model-benchmark/code/README.md
-
curl -L -o README.md https://huggingface.co/quocbao747/embedding-model-benchmark/resolve/main/code/README.md
3.94 kB
Benchmark code
The scripts behind every number in this repository. Results land in results/ (see ../results/README.md); the method is in ../docs/methodology.md.
harness/: the current harness (all models in the README)harness-v1/: the first version, kept for reference (early Qwen3-Embedding-4B, BGE-M3 and EmbeddingGemma 2 runs)
How a score is produced
- Load the dataset (
data.py): MTEB / Hugging Face task → corpus, queries, relevance labels - Encode (
zoo.py): each model with its own card's input format (prefixes, instructions, pooling, word segmentation), bf16, 512-token window or the model's own lower limit - Search: cosine similarity, top-100 per query (
worker.py; exact fp32 search ingen_score.py/fp32_rescore.py) - Score: nDCG@10, P@1, MRR@10, Recall@10/100 with
pytrec_eval(worker.evaluate) - Save: one metrics line per model × dataset, plus the top-10 run per query
Files in harness/
| Step | File | What it does |
|---|---|---|
| Data | data.py |
loads a task (Name or Name:subset), builds document text (title + body) |
| Models | zoo.py |
model registry: Hugging Face id, input format (kind), window, batch size; the Enc encoder class |
m3.py |
BGE-M3 dense + sparse + multi-vector heads and their fusion | |
n35.py |
Nemotron-3.5 text encoder (card's Transformers path) and the NVFP4 checkpoint path | |
vintern.py |
Vintern-Embedding-1B text path (multi-vector, MaxSim) | |
| Run | worker.py |
claims (model, dataset) jobs from a shared queue, encodes, searches, scores, writes metrics |
plan_jobs.py |
builds the job queue from smoke-test time estimates | |
bm25_run.py |
BM25 keyword baseline on CPU: pyvi word segmentation, bm25s, k1 = 1.5, b = 0.75; same metrics and output files as the GPU workers |
|
| Checks | smoke.py, nm_smoke.py |
load each model, run 2 small datasets, check for NaN, unit norms and a sane score before the full run |
n35_test.py |
Nemotron-3.5 gate tests | |
simcse_pool.py |
compares 4 ways of pooling sup-SimCSE-VietNamese-phobert-base (mean, CLS, pooler, SimCSE head) | |
| Large models | shard8b.py, build8b.py, score8b.py |
Qwen3-Embedding-8B: encode in document shards, merge, exact search |
| Re-scoring | gen_score.py, fp32_rescore.py |
exact fp32 search over stored embeddings (+ Matryoshka dimensions) |
fp32_bf16_noise.py, tag_ranking.py |
measure the tie noise of bf16 ranking; tag each result with how it was ranked | |
| Speed | speed_u.py |
the published speed table: every model at batch 32 on 2,048 Zalo Legal documents + 818 queries, docs/s, queries/s, peak memory |
speed.py, speed_n35.py |
earlier speed runs (sequence-length × batch sweeps) | |
| Report | report_pro.py |
static HTML progress report |
Run one model
pip install torch transformers sentence-transformers mteb pytrec_eval pyvi
# score one model on one dataset; writes metrics + top-10 run under $RESULTS
mkdir -p out && echo [] > out/jobs.json # worker.py expects a (here empty) job queue
RESULTS=./out python - local <<'PY'
import worker
enc = worker.make_enc("halong")
print(worker.run_job(enc, {"model": "halong", "task": "ZacLegalTextRetrieval"})[0])
PY
# BM25 baseline (CPU), any list of tasks
pip install bm25s
RESULTS=./out python bm25_run.py ZacLegalTextRetrieval TVPLRetrieval
Adding a model
- Add one line to
MODELSinzoo.py:key: (hf_id, kind, max_len, batch)kindpicks the input format:plain(no prefix),e5(query:/passage:),pyvi(Vietnamese word segmentation, PhoBERT models),qwen/inst(instruction on queries), and the model-specific kinds
- Follow the model card: prefixes, pooling and window come from the card or its sentence-transformers config, never from test scores
- Run
nm_smoke.py <key>first, then queue all datasets