蒸馏需额外安装 pip install model2vec[distill],微调需 pip install model2vec[train];使用预训练模型需从 HuggingFace hub 下载,首次运行需联网;微调依赖 datasets 等额外库。

pip install model2vecREADME 未说明显存要求;蒸馏与推理均可在 CPU 上完成,基础包主要依赖 numpy,无需 GPU。
把任意 Sentence Transformer 蒸馏成小而快的静态嵌入模型,体积最多缩小 50 倍、CPU 推理最多快 500 倍
把预训练句向量模型蒸馏成轻量静态词向量,推理速度极快、无需 GPU,适合大规模文本向量化和检索场景。
核心能力
- 将 Sentence Transformer 蒸馏为静态词嵌入模型
- 模型体积最多缩小 50 倍,最小模型仅约 8 MB
- CPU 推理速度最多提升 500 倍
- 无需数据集,在 CPU 上约 30 秒完成蒸馏
- 支持分类、相似度、回归等任务的微调,且不依赖 torch
容易踩的坑
- v0.10.0最新正式版2026-10-11 · 2026-10-11 08:09 UTC
What's Changed
- feat: disable progress bars, add hf hub as a direct dependency by @stephantul in https://github.com/MinishLab/model2vec/pull/345
- feat: Replace pca by @stephantul in https://github.com/MinishLab/model2vec/pull/344
- feat: export classifier and regressor pipelines to ONNX by @serhiizghama in https://github.com/MinishLab/model2vec/pull/346
- feat: make onnx export a function by @stephantul in https://github.com/MinishLab/model2vec/pull/347
- feat: add onnx model cards by @stephantul in https://github.com/MinishLab/model2vec/pull/349
- fix: add distillation duplicate guard by @stephantul in https://github.com/MinishLab/model2vec/pull/350
- fix: start of word tokens for added by @stephantul in https://github.com/MinishLab/model2vec/pull/351
- fix: trainer uses best checkpoint by @stephantul in https://github.com/MinishLab/model2vec/pull/352
- fix: onnx export correctly ignores unk by @stephantul in https://github.com/MinishLab/model2vec/pull/353
- fix: unk token for unigrams by @stephantul in https://github.com/MinishLab/model2vec/pull/354
- feat: new integration test by @stephantul in https://github.com/MinishLab/model2vec/pull/355
- feat: make setters for max_length by @stephantul in https://github.com/MinishLab/model2vec/pull/356
- chore: typing on loading should return a T, not a StaticModel by @stephantul in https://github.com/MinishLab/model2vec/pull/357
- fix(train): pad training batches with the model's pad id by @serhiizghama in https://github.com/MinishLab/model2vec/pull/358
- fix(train): drop unknown tokens during training and inference by @serhiizghama in https://github.com/MinishLab/model2vec/pull/359
- docs: Update main readme by @Pringled in https://github.com/MinishLab/model2vec/pull/361
- fix(inference): pass the token through when loading the encoder by @serhiizghama in https://github.com/MinishLab/model2vec/pull/362
- feat: max length behavior by @stephantul in https://github.com/MinishLab/model2vec/pull/363
- fix(onnx): export vocabulary-quantized models with their token mapping and weights by @serhiizghama in https://github.com/MinishLab/model2vec/pull/364
- feat: small helper method to reduce overlap by @stephantul in https://github.com/MinishLab/model2vec/pull/365
- docs: fix classifier docstring by @stephantul in https://github.com/MinishLab/model2vec/pull/366
- feat: higher speed encoding by @stephantul in https://github.com/MinishLab/model2vec/pull/367
- fix: norm underflow for float16 by @stephantul in https://github.com/MinishLab/model2vec/pull/369
- feat: add allow list for paths by @stephantul in https://github.com/MinishLab/model2vec/pull/370
- feat: remove loggit mapping from training by @stephantul in https://github.com/MinishLab/model2vec/pull/371
- feat: add token dropout to training pipeline by @stephantul in https://github.com/MinishLab/model2vec/pull/373
- feat: add pairwise trainer by @stephantul in https://github.com/MinishLab/model2vec/pull/372
- fix(train): keep the trainer's max_length independent of the static model's tokenizer truncation by @serhiizghama in https://github.com/MinishLab/model2vec/pull/374
- fix: disable padding during distill and inference by @stephantul in https://github.com/MinishLab/model2vec/pull/376
- docs: Add Greptile acknowledgement by @Pringled in https://github.com/MinishLab/model2vec/pull/377
- fix: divide by length 1 instead of 1e-16 by @stephantul in https://github.com/MinishLab/model2vec/pull/380
- fix: stop the trainer's tokenizer from padding by @stephantul in https://github.com/MinishLab/model2vec/pull/379
- feat: pair and similarity head with 0 layers have no layers by @stephantul in https://github.com/MinishLab/model2vec/pull/383
- feat: train pair models with InfoNCE by @stephantul in https://github.com/MinishLab/model2vec/pull/381
- feat: add other metrics to loop progress bar by @stephantul in https://github.com/MinishLab/model2vec/pull/384
- feat: add contribution guidelines by @stephantul in
- v0.9.02026-08-12 · 2026-08-12 14:22 UTC
查看更新说明
What's Changed
- feat: add regression by @stephantul in https://github.com/MinishLab/model2vec/pull/333
- feat: Integration or regression tests by @stephantul in https://github.com/MinishLab/model2vec/pull/336
- feat: remove lightning by @stephantul in https://github.com/MinishLab/model2vec/pull/337
- feat: refactor inference by @stephantul in https://github.com/MinishLab/model2vec/pull/338
- fix: guard against safetensors contiguity bug by @stephantul in https://github.com/MinishLab/model2vec/pull/341
- feat: bump skeletoken & update integration test results by @stephantul in https://github.com/MinishLab/model2vec/pull/342
- chore: bump version by @stephantul in https://github.com/MinishLab/model2vec/pull/343
Full Changelog: https://github.com/MinishLab/model2vec/compare/v0.8.2...v0.9.0
- v0.8.22026-05-29 · 2026-05-29 11:46 UTC
查看更新说明
What's Changed
- fix: multiword broken by @stephantul in https://github.com/MinishLab/model2vec/pull/317
- feat: refactor training by @stephantul in https://github.com/MinishLab/model2vec/pull/316
- fix: upgrade skeletoken by @stephantul in https://github.com/MinishLab/model2vec/pull/318
- fix: Incorrect added token can cause issues when adding token as multiword token by @stephantul in https://github.com/MinishLab/model2vec/pull/319
- fix: don't set weights for non-quantized models by @stephantul in https://github.com/MinishLab/model2vec/pull/321
- fix: correctly set weights when w is initialized by @stephantul in https://github.com/MinishLab/model2vec/pull/322
- feat: convert output to float in distill by @stephantul in https://github.com/MinishLab/model2vec/pull/320
- clean up post-processing code by @stephantul in https://github.com/MinishLab/model2vec/pull/323
- chore: fix pre-commit by @stephantul in https://github.com/MinishLab/model2vec/pull/326
- chore: add exclude-newer by @stephantul in https://github.com/MinishLab/model2vec/pull/328
- feat: add frozen-weights option to training by @stephantul in https://github.com/MinishLab/model2vec/pull/327
- fix: small typing issue by @stephantul in https://github.com/MinishLab/model2vec/pull/329
- chore: Update email by @Pringled in https://github.com/MinishLab/model2vec/pull/331
- feat: add trusted publisher by @stephantul in https://github.com/MinishLab/model2vec/pull/332
Full Changelog: https://github.com/MinishLab/model2vec/compare/v0.8.1...v0.8.2
- v0.8.12026-03-27 · 2026-03-27 13:39 UTC
查看更新说明
What's Changed
- fix: Use posix path for Windows compatibility by @stephantul in https://github.com/MinishLab/model2vec/pull/314
- increase version to 0.8.1 by @stephantul in https://github.com/MinishLab/model2vec/pull/315
Full Changelog: https://github.com/MinishLab/model2vec/compare/v0.8.0...v0.8.1
- v0.8.02026-03-26 · 2026-03-26 06:34 UTC
查看更新说明
What's Changed
- docs: Added CITATION.cff, updated citation info by @Pringled in https://github.com/MinishLab/model2vec/pull/293
- docs: Added modelcard logo by @Pringled in https://github.com/MinishLab/model2vec/pull/294
- docs: Update default model for example by @Pringled in https://github.com/MinishLab/model2vec/pull/299
- chore: Deprecated Python 3.9 support by @Pringled in https://github.com/MinishLab/model2vec/pull/301
- chore: Update CI to run on external PRs, fix test import by @Pringled in https://github.com/MinishLab/model2vec/pull/303
- feat: replace tokenizer code with skeletoken by @stephantul in https://github.com/MinishLab/model2vec/pull/302
- feat: refactor persistence, remove from_sentence_transformers by @stephantul in https://github.com/MinishLab/model2vec/pull/305
- fix: refix tokenizer with added token shenanigans by @stephantul in https://github.com/MinishLab/model2vec/pull/304
- fix: if layers == 0, layers were not initialized by @stephantul in https://github.com/MinishLab/model2vec/pull/306
- feat: expose random seed, small typing fix by @stephantul in https://github.com/MinishLab/model2vec/pull/308
- feat: add util for tokenizer pad id by @stephantul in https://github.com/MinishLab/model2vec/pull/310
- docs: Update results to MTEB V2 by @Pringled in https://github.com/MinishLab/model2vec/pull/311
- chore: Bump version by @Pringled in https://github.com/MinishLab/model2vec/pull/312
Full Changelog: https://github.com/MinishLab/model2vec/compare/v0.7.0...v0.8.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Quickstart • Main Features • Model List • Results
Model2Vec is a technique to turn any sentence transformer into a small, fast static embedding model. Model2Vec reduces model size by a factor up to 50 and makes models up to 500 times faster, with a small drop in performance. Our best model is the most performant static embedding model in the world. See our results, read our docs, or dive in to see how it works.
Quickstart
Install the lightweight base package with:
pip install model2vec
You can start using Model2Vec by loading one of our flagship models from the HuggingFace hub. These models are pre-trained and ready to use. The following code snippet shows how to load a model and make embeddings, which you can use for any task, such as text classification, retrieval, clustering, or building a RAG system:
from model2vec import StaticModel
# Load a model from the HuggingFace hub (in this case the potion-base-32M model)
model = StaticModel.from_pretrained("minishlab/potion-base-32M")
# Make embeddings
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
# Make sequences of token embeddings
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
For advanced usage, see our inference docs. Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the distill extra with:
pip install model2vec[distill]
Then, you can distill a model in ~30 seconds on a CPU with the following code snippet:
from model2vec.distill import distill
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
# Save the model
m2v_model.save_pretrained("m2v_model")
For advanced usage, see our distillation docs, which includes some distillation best practices. After distillation, you can also fine-tune the distilled model, or a pre-trained model, for classification, similarity, regression, or pair similarity (e.g. query-document retrieval). First, make sure you install the train extras with:
pip install model2vec[train]
Then, you can fine-tune a model as follows:
from datasets import load_dataset
from model2vec.train import StaticModelForClassification
# Initialize a classifier from a pre-trained model
classifier = StaticModelForClassification.from_pretrained(path="minishlab/potion-base-32M")
# Load a dataset. Note: both single and multi-label classification datasets are supported
ds = load_dataset("setfit/subj")
# Train the classifier on text (X) and labels (y)
classifier.fit(ds["train"]["text"], ds["train"]["label"])
# Evaluate the classifier
classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["label"])
For advanced usage, see our training docs.
Main Features
- State-of-the-Art Performance: Model2Vec models outperform any other static embeddings (such as GLoVe and BPEmb) by a large margin, as can be seen in our results.
- Small: Model2Vec reduces the size of a Sentence Transformer model by a factor of up to 50. Our best model is just ~30 MB on disk, and our smallest model just ~8 MB (making it the smallest model on MTEB!).
- Lightweight Dependencies: the base package's only major dependency is
numpy. - Lightning-fast Inference: up to 500 times faster on CPU than the original model.
- Fast, Dataset-free Distillation: distill your own model in 30 seconds on a CPU, without a dataset.
- Fine-tuning: fine-tune Model2Vec models for classification, similarity, regression, or pair similarity, and run them without
torch. - Integrated in many popular libraries: Model2Vec is integrated direclty into popular libraries such as Sentence Transformers and LangChain. For more information, see our integrations documentation.
- Tightly integrated with HuggingFace hub: easily share and load models from the HuggingFace hub, using the familiar
from_pretrainedandpush_to_hub. Our own models can be found here.
What is Model2Vec?
Model2vec creates a small, fast, and powerful model that outperforms other static embedding models by a large margin on all tasks we could find, while being much faster to create than traditional static embedding models such as GloVe. Like BPEmb, it can create subword embeddings, but with much better performance. Distillation doesn't need any data, just a vocabulary and a model.
The core idea is to forward pass a vocabulary through a sentence transformer model, creating static embeddings for the indiviudal tokens. After this, there are a number of post-processing steps we do that results in our best models, as well as an optional pre-training step to further boost performance. For a more extensive deepdive, please refer to our official documentation on how Model2Vec works.
Documentation
Our official documentation can be found here. This includes in-depth documentation on inference, distillation, training, and integrations.
Model List
We provide a number of models that can be used out of the box. These models are available on the HuggingFace hub and can be loaded using the from_pretrained method. The models are listed below.
| Model | Language | Sentence Transformer | Params | Task |
|---|---|---|---|---|
| potion-base-32M | English | bge-base-en-v1.5 | 32.3M | General |
| potion-multilingual-128M | Multilingual | bge-m3 | 128M | General |
| potion-retrieval-32M | English | bge-base-en-v1.5 | 32.3M | Retrieval |
| potion-base-8M | English | bge-base-en-v1.5 | 7.5M | General |
| potion-code-16M-v2 | Code | CodeRankEmbed | 16.2M | Code |
Results
We have performed extensive experiments to evaluate the performance of Model2Vec models. The results are documented in the results folder. The results are presented in the following sections:
Acknowledgements
Thanks to Greptile for providing free access to their AI code review platform.
License
MIT
Citing
If you use Model2Vec in your research, please cite the following:
@software{minishlab2024model2vec,
author = {Stephan Tulkens and {van Dongen}, Thomas},
title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
year = {2024},
publisher = {Zenodo},
doi = {10.5281/zenodo.17270888},
url = {https://github.com/MinishLab/model2vec},
license = {MIT}
}