model2vec 0.5.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {model2vec-0.5.0 → model2vec-0.7.0}/.github/workflows/ci.yaml +3 -22
- {model2vec-0.5.0 → model2vec-0.7.0}/.pre-commit-config.yaml +1 -1
- {model2vec-0.5.0 → model2vec-0.7.0}/Makefile +0 -1
- {model2vec-0.5.0 → model2vec-0.7.0}/PKG-INFO +37 -39
- {model2vec-0.5.0 → model2vec-0.7.0}/README.md +31 -36
- model2vec-0.7.0/assets/images/model2vec_logo.png +0 -0
- model2vec-0.7.0/docs/README.md +8 -0
- model2vec-0.7.0/model2vec/__init__.py +4 -0
- model2vec-0.7.0/model2vec/distill/distillation.py +260 -0
- model2vec-0.7.0/model2vec/distill/inference.py +254 -0
- model2vec-0.7.0/model2vec/distill/utils.py +49 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/hf_utils.py +84 -31
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/inference/model.py +19 -10
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/model.py +179 -65
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/quantization.py +29 -7
- model2vec-0.7.0/model2vec/tokenizer/__init__.py +12 -0
- model2vec-0.7.0/model2vec/tokenizer/datamodels.py +14 -0
- model2vec-0.7.0/model2vec/tokenizer/model.py +43 -0
- model2vec-0.7.0/model2vec/tokenizer/normalizer.py +42 -0
- model2vec-0.7.0/model2vec/tokenizer/pretokenizer.py +57 -0
- model2vec-0.7.0/model2vec/tokenizer/tokenizer.py +398 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/train/README.md +1 -1
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/train/base.py +43 -11
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/train/classifier.py +63 -12
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/utils.py +1 -29
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/version.py +1 -1
- model2vec-0.7.0/model2vec/vocabulary_quantization.py +45 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec.egg-info/PKG-INFO +37 -39
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec.egg-info/SOURCES.txt +9 -16
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec.egg-info/requires.txt +6 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/pyproject.toml +7 -1
- {model2vec-0.5.0 → model2vec-0.7.0}/results/README.md +31 -1
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/conftest.py +32 -25
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/test_distillation.py +98 -98
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/test_model.py +47 -25
- model2vec-0.7.0/tests/test_quantization.py +76 -0
- model2vec-0.7.0/tests/test_tokenizer.py +123 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/test_trainable.py +65 -2
- model2vec-0.7.0/tests/test_utils.py +84 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tutorials/README.md +1 -1
- model2vec-0.7.0/uv.lock +2931 -0
- model2vec-0.5.0/assets/images/logo.png +0 -0
- model2vec-0.5.0/assets/images/logo_v2.png +0 -0
- model2vec-0.5.0/assets/images/model2vec_model_diagram.png +0 -0
- model2vec-0.5.0/assets/images/model2vec_model_diagram_transparant_dark.png +0 -0
- model2vec-0.5.0/assets/images/model2vec_model_diagram_transparant_light.png +0 -0
- model2vec-0.5.0/assets/images/sentences_per_second_vs_average_score.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_accuracy.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_accuracy_v2.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_accuracy_v3.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_accuracy_v4.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_mteb_score.png +0 -0
- model2vec-0.5.0/assets/images/speed_vs_mteb_score_v2.png +0 -0
- model2vec-0.5.0/docs/README.md +0 -6
- model2vec-0.5.0/docs/integrations.md +0 -155
- model2vec-0.5.0/docs/usage.md +0 -250
- model2vec-0.5.0/docs/what_is_model2vec.md +0 -11
- model2vec-0.5.0/model2vec/__init__.py +0 -4
- model2vec-0.5.0/model2vec/distill/distillation.py +0 -344
- model2vec-0.5.0/model2vec/distill/inference.py +0 -149
- model2vec-0.5.0/model2vec/distill/tokenizer.py +0 -197
- model2vec-0.5.0/model2vec/distill/utils.py +0 -58
- model2vec-0.5.0/tests/test_quantization.py +0 -30
- model2vec-0.5.0/tests/test_utils.py +0 -121
- model2vec-0.5.0/uv.lock +0 -2360
- {model2vec-0.5.0 → model2vec-0.7.0}/.gitignore +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/LICENSE +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/assets/images/speed_vs_mteb_score_v3.png +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/assets/images/training_speed_vs_score.png +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/assets/images/tutorial_ezlo.png +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/distill/__init__.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/inference/README.md +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/inference/__init__.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/modelcards/classifier_template.md +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/modelcards/model_card_template.md +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/py.typed +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec/train/__init__.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec.egg-info/dependency_links.txt +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/model2vec.egg-info/top_level.txt +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/results/make_speed_vs_mteb_plot.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/scripts/export_to_onnx.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/setup.cfg +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/__init__.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/data/test_tokenizer/special_tokens_map.json +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/data/test_tokenizer/tokenizer.json +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/data/test_tokenizer/tokenizer_config.json +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tests/test_inference.py +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tutorials/recipe_search.ipynb +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tutorials/semantic_chunking.ipynb +0 -0
- {model2vec-0.5.0 → model2vec-0.7.0}/tutorials/train_classifier.ipynb +0 -0
|
@@ -9,15 +9,8 @@ jobs:
|
|
|
9
9
|
runs-on: ${{ matrix.os }}
|
|
10
10
|
strategy:
|
|
11
11
|
matrix:
|
|
12
|
-
os: ["ubuntu-latest"
|
|
13
|
-
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
14
|
-
exclude:
|
|
15
|
-
- os: windows-latest
|
|
16
|
-
python-version: "3.9"
|
|
17
|
-
- os: windows-latest
|
|
18
|
-
python-version: "3.11"
|
|
19
|
-
- os: windows-latest
|
|
20
|
-
python-version: "3.12"
|
|
12
|
+
os: ["ubuntu-latest"]
|
|
13
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
21
14
|
fail-fast: false
|
|
22
15
|
|
|
23
16
|
steps:
|
|
@@ -29,19 +22,7 @@ jobs:
|
|
|
29
22
|
python-version: ${{ matrix.python-version }}
|
|
30
23
|
allow-prereleases: true
|
|
31
24
|
|
|
32
|
-
# Step for Windows: Create and activate a virtual environment
|
|
33
|
-
- name: Create and activate a virtual environment (Windows)
|
|
34
|
-
if: ${{ runner.os == 'Windows' }}
|
|
35
|
-
run: |
|
|
36
|
-
irm https://astral.sh/uv/install.ps1 | iex
|
|
37
|
-
$env:Path = "C:\Users\runneradmin\.local\bin;$env:Path"
|
|
38
|
-
uv venv .venv
|
|
39
|
-
"VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append
|
|
40
|
-
"$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append
|
|
41
|
-
|
|
42
|
-
# Step for Unix: Create and activate a virtual environment
|
|
43
25
|
- name: Create and activate a virtual environment (Unix)
|
|
44
|
-
if: ${{ runner.os != 'Windows' }}
|
|
45
26
|
run: |
|
|
46
27
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
47
28
|
uv venv .venv
|
|
@@ -55,7 +36,7 @@ jobs:
|
|
|
55
36
|
# Run tests with coverage
|
|
56
37
|
- name: Run tests under coverage
|
|
57
38
|
run: |
|
|
58
|
-
coverage run -m pytest
|
|
39
|
+
coverage run --source=model2vec -m pytest
|
|
59
40
|
coverage report
|
|
60
41
|
|
|
61
42
|
# Upload results to Codecov
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: model2vec
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Fast State-of-the-Art Static Embeddings
|
|
5
5
|
Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
|
|
6
6
|
License: MIT License
|
|
@@ -39,10 +39,10 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
39
39
|
Classifier: Programming Language :: Python :: 3.10
|
|
40
40
|
Classifier: Programming Language :: Python :: 3.11
|
|
41
41
|
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
43
|
Classifier: Natural Language :: English
|
|
43
44
|
Requires-Python: >=3.9
|
|
44
45
|
Description-Content-Type: text/markdown
|
|
45
|
-
License-File: LICENSE
|
|
46
46
|
Requires-Dist: jinja2
|
|
47
47
|
Requires-Dist: joblib
|
|
48
48
|
Requires-Dist: numpy
|
|
@@ -74,34 +74,32 @@ Requires-Dist: skops; extra == "train"
|
|
|
74
74
|
Provides-Extra: inference
|
|
75
75
|
Requires-Dist: scikit-learn; extra == "inference"
|
|
76
76
|
Requires-Dist: skops; extra == "inference"
|
|
77
|
-
|
|
77
|
+
Provides-Extra: tokenizer
|
|
78
|
+
Requires-Dist: transformers; extra == "tokenizer"
|
|
79
|
+
Provides-Extra: quantization
|
|
80
|
+
Requires-Dist: scikit-learn; extra == "quantization"
|
|
78
81
|
|
|
79
82
|
|
|
80
|
-
<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</div>
|
|
83
|
+
<h2 align="center">
|
|
84
|
+
<img width="35%" alt="Model2Vec logo" src="assets/images/model2vec_logo.png"><br/>
|
|
85
|
+
Fast State-of-the-Art Static Embeddings
|
|
86
|
+
</h2>
|
|
87
|
+
|
|
86
88
|
|
|
87
|
-
<div align="center">
|
|
88
|
-
<h2>Fast State-of-the-Art Static Embeddings</h2>
|
|
89
|
-
</div>
|
|
90
89
|
|
|
91
90
|
<div align="center">
|
|
92
91
|
<h2>
|
|
93
92
|
<a href="https://huggingface.co/minishlab"><strong>🤗 Models</strong></a> |
|
|
94
|
-
<a href="https://
|
|
95
|
-
<a href="https://minishlab.github.io/"><strong>🌐 Blog</strong></a> |
|
|
93
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><strong>📖 Docs</strong></a> |
|
|
96
94
|
<a href="https://github.com/MinishLab/model2vec/blob/main/results/README.md"><strong>🏆 Results</strong></a> |
|
|
97
|
-
<a href="https://github.com/MinishLab/model2vec/
|
|
98
|
-
|
|
95
|
+
<a href="https://github.com/MinishLab/model2vec/tree/main/tutorials"><strong>📚 Tutorials</strong></a> |
|
|
96
|
+
<a href="https://minish.ai/blog"><strong>🌐 Blog</strong></a>
|
|
99
97
|
</div>
|
|
100
98
|
|
|
101
99
|
<div align="center">
|
|
102
100
|
<h2>
|
|
103
101
|
<a href="https://pypi.org/project/model2vec/"><img src="https://img.shields.io/pypi/v/model2vec?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
|
|
104
|
-
<a href="https://
|
|
102
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><img src="https://img.shields.io/badge/docs-minish.ai-blue.svg" alt="Docs"></a>
|
|
105
103
|
<a href="https://pepy.tech/project/model2vec">
|
|
106
104
|
<img src="https://static.pepy.tech/badge/model2vec" alt="Downloads">
|
|
107
105
|
</a>
|
|
@@ -114,6 +112,9 @@ Dynamic: license-file
|
|
|
114
112
|
<a href="https://github.com/MinishLab/model2vec/blob/main/LICENSE">
|
|
115
113
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
116
114
|
</a>
|
|
115
|
+
<a href="https://github.com/MinishLab/model2vec/stargazers">
|
|
116
|
+
<img src="https://img.shields.io/github/stars/minishlab/model2vec.svg" alt=Stars">
|
|
117
|
+
</a>
|
|
117
118
|
</h2>
|
|
118
119
|
</div>
|
|
119
120
|
|
|
@@ -121,7 +122,7 @@ Dynamic: license-file
|
|
|
121
122
|
|
|
122
123
|
|
|
123
124
|
|
|
124
|
-
Model2Vec is a technique to turn any sentence transformer into a
|
|
125
|
+
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](https://huggingface.co/minishlab/potion-base-8M) is the most performant static embedding model in the world. See our [results](results/README.md), read our [docs](https://minish.ai/packages/model2vec/introduction), or dive in to see how it works.
|
|
125
126
|
|
|
126
127
|
<div align="center">
|
|
127
128
|
<h3>
|
|
@@ -151,30 +152,29 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
151
152
|
# Make sequences of token embeddings
|
|
152
153
|
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
153
154
|
```
|
|
154
|
-
|
|
155
|
-
Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `distillation` extras with:
|
|
155
|
+
For advanced usage, see our [inference docs](https://minish.ai/packages/model2vec/inference). Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `distillation` extras with:
|
|
156
156
|
|
|
157
157
|
```bash
|
|
158
158
|
pip install model2vec[distill]
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
Then, you can distill a model in ~30 seconds on a CPU with the following code snippet:
|
|
163
163
|
|
|
164
164
|
```python
|
|
165
165
|
from model2vec.distill import distill
|
|
166
166
|
|
|
167
167
|
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
|
|
168
|
-
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5"
|
|
168
|
+
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
|
|
169
169
|
|
|
170
170
|
# Save the model
|
|
171
171
|
m2v_model.save_pretrained("m2v_model")
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
After distillation, you can also fine-tune your own classification models on top of the distilled model, or on a pre-trained model. First, make sure you install the `training` extras with:
|
|
174
|
+
For advanced usage, see our [distillation docs](https://minish.ai/packages/model2vec/distillation), which includes some [distillation best practices](https://minish.ai/packages/model2vec/distillation#distillation-best-practices). After distillation, you can also fine-tune your own classification models on top of the distilled model, or on a pre-trained model. First, make sure you install the `training` extras with:
|
|
175
175
|
|
|
176
176
|
```bash
|
|
177
|
-
pip install model2vec[
|
|
177
|
+
pip install model2vec[train]
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
Then, you can fine-tune a model as follows:
|
|
@@ -197,15 +197,17 @@ classifier.fit(ds["train"]["text"], ds["train"]["label"])
|
|
|
197
197
|
classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["label"])
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
For advanced usage,
|
|
200
|
+
For advanced usage, see our [training docs](https://minish.ai/packages/model2vec/training).
|
|
201
201
|
|
|
202
202
|
## Updates & Announcements
|
|
203
203
|
|
|
204
|
-
- **
|
|
204
|
+
- **23/05/2025**: We released [potion-multilingual-128M](https://huggingface.co/minishlab/potion-multilingual-128M), a multilingual model trained on 101 languages. It is the best performing static embedding model for multilingual tasks, and is capable of generating embeddings for any text in any language. The results can be found in our [results](results/README.md#mmteb-results-multilingual) section.
|
|
205
205
|
|
|
206
|
-
- **
|
|
206
|
+
- **01/05/2025**: We released backend support for `BPE` and `Unigram` tokenizers, along with quantization and dimensionality reduction. New Model2Vec models are now 50% of the original models size, and can be quantized to int8 to be 25% of the size, without loss of performance.
|
|
207
207
|
|
|
208
|
-
- **
|
|
208
|
+
- **12/02/2025**: We released **Model2Vec training**, allowing you to fine-tune your own classification models on top of Model2Vec models. Find out more in our [training documentation](https://github.com/MinishLab/model2vec/blob/main/model2vec/train/README.md) and [results](results/README.md#training-results).
|
|
209
|
+
|
|
210
|
+
- **30/01/2025**: We released two new models: [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) and [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M). [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) is our most performant model to date, using a larger vocabulary and higher dimensions. [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M) is a finetune of [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) that is optimized for retrieval tasks, and is the best performing static retrieval model currently available.
|
|
209
211
|
|
|
210
212
|
- **30/10/2024**: We released three new models: [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M), [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M), and [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M). These models are trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). Find out more in our [blog post](https://minishlab.github.io/tokenlearn_blogpost/). NOTE: for users of any of our old English M2V models, we recommend switching to these new models as they [perform better on all tasks](https://github.com/MinishLab/model2vec/tree/main/results).
|
|
211
213
|
|
|
@@ -217,24 +219,18 @@ For advanced usage, please refer to our [usage documentation](https://github.com
|
|
|
217
219
|
- **Lightning-fast Inference**: up to 500 times faster on CPU than the original model.
|
|
218
220
|
- **Fast, Dataset-free Distillation**: distill your own model in 30 seconds on a CPU, without a dataset.
|
|
219
221
|
- **Fine-tuning**: fine-tune your own classification models on top of Model2Vec models.
|
|
220
|
-
- **Integrated in many popular libraries**: Model2Vec is integrated direclty into popular libraries such as [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [LangChain](https://github.com/langchain-ai/langchain). For more information, see our [integrations documentation](https://
|
|
222
|
+
- **Integrated in many popular libraries**: Model2Vec is integrated direclty into popular libraries such as [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [LangChain](https://github.com/langchain-ai/langchain). For more information, see our [integrations documentation](https://minish.ai/packages/model2vec/integrations).
|
|
221
223
|
- **Tightly integrated with HuggingFace hub**: easily share and load models from the HuggingFace hub, using the familiar `from_pretrained` and `push_to_hub`. Our own models can be found [here](https://huggingface.co/minishlab).
|
|
222
224
|
|
|
223
225
|
## What is Model2Vec?
|
|
224
226
|
|
|
225
227
|
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.
|
|
226
228
|
|
|
227
|
-
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. For a more extensive deepdive, please refer to
|
|
228
|
-
- Our initial [Model2Vec blog post](https://huggingface.co/blog/Pringled/model2vec). Note that, while this post gives a good overview of the core idea, we've made a number of substantial improvements since then.
|
|
229
|
-
- Our [Tokenlearn blog post](https://minishlab.github.io/tokenlearn_blogpost/). This post describes the Tokenlearn method we used to train our [potion models](https://huggingface.co/collections/minishlab/potion-6721e0abd4ea41881417f062).
|
|
230
|
-
- Our official [documentation](https://github.com/MinishLab/model2vec/blob/main/docs/what_is_model2vec.md). This document provides a high-level overview of how Model2Vec works.
|
|
229
|
+
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](https://minish.ai/packages/model2vec/introduction#how-mode2vec-works).
|
|
231
230
|
|
|
232
231
|
## Documentation
|
|
233
232
|
|
|
234
|
-
Our official documentation can be found [here](https://
|
|
235
|
-
- [Usage documentation](https://github.com/MinishLab/model2vec/blob/main/docs/usage.md): provides a technical overview of how to use Model2Vec.
|
|
236
|
-
- [Integrations documentation](https://github.com/MinishLab/model2vec/blob/main/docs/integrations.md): provides examples of how to use Model2Vec in various downstream libraries.
|
|
237
|
-
- [Model2Vec technical documentation](https://github.com/MinishLab/model2vec/blob/main/docs/what_is_model2vec.md): provides a high-level overview of how Model2Vec works.
|
|
233
|
+
Our official documentation can be found [here](https://minish.ai/packages/model2vec/introduction). This includes in-depth documentation on [inference](https://minish.ai/packages/model2vec/inference), [distillation](https://minish.ai/packages/model2vec/distillation), [training](https://minish.ai/packages/model2vec/training), and [integrations](https://minish.ai/packages/model2vec/integrations).
|
|
238
234
|
|
|
239
235
|
|
|
240
236
|
## Model List
|
|
@@ -246,11 +242,13 @@ We provide a number of models that can be used out of the box. These models are
|
|
|
246
242
|
| Model | Language | Sentence Transformer | Params | Task |
|
|
247
243
|
|-----------------------------------------------------------------------|------------|-----------------------------------------------------------------|---------|-----------|
|
|
248
244
|
| [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 32.3M | General |
|
|
245
|
+
| [potion-multilingual-128M](https://huggingface.co/minishlab/potion-multilingual-128M) | Multilingual | [bge-m3](https://huggingface.co/BAAI/bge-m3) | 128M | General |
|
|
246
|
+
| [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 32.3M | Retrieval |
|
|
249
247
|
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 7.5M | General |
|
|
250
248
|
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 3.7M | General |
|
|
251
249
|
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 1.8M | General |
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
|
|
251
|
+
|
|
254
252
|
|
|
255
253
|
|
|
256
254
|
## Results
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
</div>
|
|
2
|
+
<h2 align="center">
|
|
3
|
+
<img width="35%" alt="Model2Vec logo" src="assets/images/model2vec_logo.png"><br/>
|
|
4
|
+
Fast State-of-the-Art Static Embeddings
|
|
5
|
+
</h2>
|
|
6
|
+
|
|
8
7
|
|
|
9
|
-
<div align="center">
|
|
10
|
-
<h2>Fast State-of-the-Art Static Embeddings</h2>
|
|
11
|
-
</div>
|
|
12
8
|
|
|
13
9
|
<div align="center">
|
|
14
10
|
<h2>
|
|
15
11
|
<a href="https://huggingface.co/minishlab"><strong>🤗 Models</strong></a> |
|
|
16
|
-
<a href="https://
|
|
17
|
-
<a href="https://minishlab.github.io/"><strong>🌐 Blog</strong></a> |
|
|
12
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><strong>📖 Docs</strong></a> |
|
|
18
13
|
<a href="https://github.com/MinishLab/model2vec/blob/main/results/README.md"><strong>🏆 Results</strong></a> |
|
|
19
|
-
<a href="https://github.com/MinishLab/model2vec/
|
|
20
|
-
|
|
14
|
+
<a href="https://github.com/MinishLab/model2vec/tree/main/tutorials"><strong>📚 Tutorials</strong></a> |
|
|
15
|
+
<a href="https://minish.ai/blog"><strong>🌐 Blog</strong></a>
|
|
21
16
|
</div>
|
|
22
17
|
|
|
23
18
|
<div align="center">
|
|
24
19
|
<h2>
|
|
25
20
|
<a href="https://pypi.org/project/model2vec/"><img src="https://img.shields.io/pypi/v/model2vec?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
|
|
26
|
-
<a href="https://
|
|
21
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><img src="https://img.shields.io/badge/docs-minish.ai-blue.svg" alt="Docs"></a>
|
|
27
22
|
<a href="https://pepy.tech/project/model2vec">
|
|
28
23
|
<img src="https://static.pepy.tech/badge/model2vec" alt="Downloads">
|
|
29
24
|
</a>
|
|
@@ -36,6 +31,9 @@
|
|
|
36
31
|
<a href="https://github.com/MinishLab/model2vec/blob/main/LICENSE">
|
|
37
32
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
38
33
|
</a>
|
|
34
|
+
<a href="https://github.com/MinishLab/model2vec/stargazers">
|
|
35
|
+
<img src="https://img.shields.io/github/stars/minishlab/model2vec.svg" alt=Stars">
|
|
36
|
+
</a>
|
|
39
37
|
</h2>
|
|
40
38
|
</div>
|
|
41
39
|
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
|
|
44
42
|
|
|
45
43
|
|
|
46
|
-
Model2Vec is a technique to turn any sentence transformer into a
|
|
44
|
+
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](https://huggingface.co/minishlab/potion-base-8M) is the most performant static embedding model in the world. See our [results](results/README.md), read our [docs](https://minish.ai/packages/model2vec/introduction), or dive in to see how it works.
|
|
47
45
|
|
|
48
46
|
<div align="center">
|
|
49
47
|
<h3>
|
|
@@ -73,30 +71,29 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
73
71
|
# Make sequences of token embeddings
|
|
74
72
|
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
75
73
|
```
|
|
76
|
-
|
|
77
|
-
Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `distillation` extras with:
|
|
74
|
+
For advanced usage, see our [inference docs](https://minish.ai/packages/model2vec/inference). Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `distillation` extras with:
|
|
78
75
|
|
|
79
76
|
```bash
|
|
80
77
|
pip install model2vec[distill]
|
|
81
78
|
```
|
|
82
79
|
|
|
83
80
|
|
|
84
|
-
|
|
81
|
+
Then, you can distill a model in ~30 seconds on a CPU with the following code snippet:
|
|
85
82
|
|
|
86
83
|
```python
|
|
87
84
|
from model2vec.distill import distill
|
|
88
85
|
|
|
89
86
|
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
|
|
90
|
-
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5"
|
|
87
|
+
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
|
|
91
88
|
|
|
92
89
|
# Save the model
|
|
93
90
|
m2v_model.save_pretrained("m2v_model")
|
|
94
91
|
```
|
|
95
92
|
|
|
96
|
-
After distillation, you can also fine-tune your own classification models on top of the distilled model, or on a pre-trained model. First, make sure you install the `training` extras with:
|
|
93
|
+
For advanced usage, see our [distillation docs](https://minish.ai/packages/model2vec/distillation), which includes some [distillation best practices](https://minish.ai/packages/model2vec/distillation#distillation-best-practices). After distillation, you can also fine-tune your own classification models on top of the distilled model, or on a pre-trained model. First, make sure you install the `training` extras with:
|
|
97
94
|
|
|
98
95
|
```bash
|
|
99
|
-
pip install model2vec[
|
|
96
|
+
pip install model2vec[train]
|
|
100
97
|
```
|
|
101
98
|
|
|
102
99
|
Then, you can fine-tune a model as follows:
|
|
@@ -119,15 +116,17 @@ classifier.fit(ds["train"]["text"], ds["train"]["label"])
|
|
|
119
116
|
classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["label"])
|
|
120
117
|
```
|
|
121
118
|
|
|
122
|
-
For advanced usage,
|
|
119
|
+
For advanced usage, see our [training docs](https://minish.ai/packages/model2vec/training).
|
|
123
120
|
|
|
124
121
|
## Updates & Announcements
|
|
125
122
|
|
|
126
|
-
- **
|
|
123
|
+
- **23/05/2025**: We released [potion-multilingual-128M](https://huggingface.co/minishlab/potion-multilingual-128M), a multilingual model trained on 101 languages. It is the best performing static embedding model for multilingual tasks, and is capable of generating embeddings for any text in any language. The results can be found in our [results](results/README.md#mmteb-results-multilingual) section.
|
|
127
124
|
|
|
128
|
-
- **
|
|
125
|
+
- **01/05/2025**: We released backend support for `BPE` and `Unigram` tokenizers, along with quantization and dimensionality reduction. New Model2Vec models are now 50% of the original models size, and can be quantized to int8 to be 25% of the size, without loss of performance.
|
|
129
126
|
|
|
130
|
-
- **
|
|
127
|
+
- **12/02/2025**: We released **Model2Vec training**, allowing you to fine-tune your own classification models on top of Model2Vec models. Find out more in our [training documentation](https://github.com/MinishLab/model2vec/blob/main/model2vec/train/README.md) and [results](results/README.md#training-results).
|
|
128
|
+
|
|
129
|
+
- **30/01/2025**: We released two new models: [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) and [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M). [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) is our most performant model to date, using a larger vocabulary and higher dimensions. [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M) is a finetune of [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) that is optimized for retrieval tasks, and is the best performing static retrieval model currently available.
|
|
131
130
|
|
|
132
131
|
- **30/10/2024**: We released three new models: [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M), [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M), and [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M). These models are trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). Find out more in our [blog post](https://minishlab.github.io/tokenlearn_blogpost/). NOTE: for users of any of our old English M2V models, we recommend switching to these new models as they [perform better on all tasks](https://github.com/MinishLab/model2vec/tree/main/results).
|
|
133
132
|
|
|
@@ -139,24 +138,18 @@ For advanced usage, please refer to our [usage documentation](https://github.com
|
|
|
139
138
|
- **Lightning-fast Inference**: up to 500 times faster on CPU than the original model.
|
|
140
139
|
- **Fast, Dataset-free Distillation**: distill your own model in 30 seconds on a CPU, without a dataset.
|
|
141
140
|
- **Fine-tuning**: fine-tune your own classification models on top of Model2Vec models.
|
|
142
|
-
- **Integrated in many popular libraries**: Model2Vec is integrated direclty into popular libraries such as [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [LangChain](https://github.com/langchain-ai/langchain). For more information, see our [integrations documentation](https://
|
|
141
|
+
- **Integrated in many popular libraries**: Model2Vec is integrated direclty into popular libraries such as [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [LangChain](https://github.com/langchain-ai/langchain). For more information, see our [integrations documentation](https://minish.ai/packages/model2vec/integrations).
|
|
143
142
|
- **Tightly integrated with HuggingFace hub**: easily share and load models from the HuggingFace hub, using the familiar `from_pretrained` and `push_to_hub`. Our own models can be found [here](https://huggingface.co/minishlab).
|
|
144
143
|
|
|
145
144
|
## What is Model2Vec?
|
|
146
145
|
|
|
147
146
|
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.
|
|
148
147
|
|
|
149
|
-
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. For a more extensive deepdive, please refer to
|
|
150
|
-
- Our initial [Model2Vec blog post](https://huggingface.co/blog/Pringled/model2vec). Note that, while this post gives a good overview of the core idea, we've made a number of substantial improvements since then.
|
|
151
|
-
- Our [Tokenlearn blog post](https://minishlab.github.io/tokenlearn_blogpost/). This post describes the Tokenlearn method we used to train our [potion models](https://huggingface.co/collections/minishlab/potion-6721e0abd4ea41881417f062).
|
|
152
|
-
- Our official [documentation](https://github.com/MinishLab/model2vec/blob/main/docs/what_is_model2vec.md). This document provides a high-level overview of how Model2Vec works.
|
|
148
|
+
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](https://minish.ai/packages/model2vec/introduction#how-mode2vec-works).
|
|
153
149
|
|
|
154
150
|
## Documentation
|
|
155
151
|
|
|
156
|
-
Our official documentation can be found [here](https://
|
|
157
|
-
- [Usage documentation](https://github.com/MinishLab/model2vec/blob/main/docs/usage.md): provides a technical overview of how to use Model2Vec.
|
|
158
|
-
- [Integrations documentation](https://github.com/MinishLab/model2vec/blob/main/docs/integrations.md): provides examples of how to use Model2Vec in various downstream libraries.
|
|
159
|
-
- [Model2Vec technical documentation](https://github.com/MinishLab/model2vec/blob/main/docs/what_is_model2vec.md): provides a high-level overview of how Model2Vec works.
|
|
152
|
+
Our official documentation can be found [here](https://minish.ai/packages/model2vec/introduction). This includes in-depth documentation on [inference](https://minish.ai/packages/model2vec/inference), [distillation](https://minish.ai/packages/model2vec/distillation), [training](https://minish.ai/packages/model2vec/training), and [integrations](https://minish.ai/packages/model2vec/integrations).
|
|
160
153
|
|
|
161
154
|
|
|
162
155
|
## Model List
|
|
@@ -168,11 +161,13 @@ We provide a number of models that can be used out of the box. These models are
|
|
|
168
161
|
| Model | Language | Sentence Transformer | Params | Task |
|
|
169
162
|
|-----------------------------------------------------------------------|------------|-----------------------------------------------------------------|---------|-----------|
|
|
170
163
|
| [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 32.3M | General |
|
|
164
|
+
| [potion-multilingual-128M](https://huggingface.co/minishlab/potion-multilingual-128M) | Multilingual | [bge-m3](https://huggingface.co/BAAI/bge-m3) | 128M | General |
|
|
165
|
+
| [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 32.3M | Retrieval |
|
|
171
166
|
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 7.5M | General |
|
|
172
167
|
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 3.7M | General |
|
|
173
168
|
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 1.8M | General |
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
|
|
170
|
+
|
|
176
171
|
|
|
177
172
|
|
|
178
173
|
## Results
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Documentation
|
|
2
|
+
|
|
3
|
+
Model2Vec's extensive documentation can be found on [our documentation website](https://minish.ai/packages/model2vec/introduction). This includes in-depth documentation on:
|
|
4
|
+
- [Inference](https://minish.ai/packages/model2vec/inference)
|
|
5
|
+
- [Distillation](https://minish.ai/packages/model2vec/distillation)
|
|
6
|
+
- [Training](https://minish.ai/packages/model2vec/training)
|
|
7
|
+
- [Integrations](https://minish.ai/packages/model2vec/integrations)
|
|
8
|
+
- [How Model2Vec works](https://minish.ai/packages/model2vec/introduction#how-mode2vec-works)
|