model2vec 0.6.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.6.0 → model2vec-0.7.0}/.github/workflows/ci.yaml +3 -22
- {model2vec-0.6.0 → model2vec-0.7.0}/.pre-commit-config.yaml +1 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/Makefile +0 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/PKG-INFO +23 -27
- {model2vec-0.6.0 → model2vec-0.7.0}/README.md +18 -23
- model2vec-0.7.0/docs/README.md +8 -0
- model2vec-0.7.0/model2vec/__init__.py +4 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/distill/distillation.py +44 -42
- model2vec-0.7.0/model2vec/distill/inference.py +254 -0
- model2vec-0.7.0/model2vec/distill/utils.py +49 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/hf_utils.py +83 -31
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/inference/model.py +15 -9
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/model.py +178 -64
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/quantization.py +29 -7
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/normalizer.py +1 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/tokenizer.py +5 -2
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/train/README.md +1 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/train/base.py +43 -11
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/train/classifier.py +37 -7
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/utils.py +1 -29
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/version.py +1 -1
- model2vec-0.7.0/model2vec/vocabulary_quantization.py +45 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec.egg-info/PKG-INFO +23 -27
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec.egg-info/SOURCES.txt +1 -15
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec.egg-info/requires.txt +4 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/pyproject.toml +7 -2
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/conftest.py +22 -19
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/test_distillation.py +87 -80
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/test_model.py +47 -25
- model2vec-0.7.0/tests/test_quantization.py +76 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/test_tokenizer.py +1 -1
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/test_trainable.py +20 -2
- model2vec-0.7.0/tests/test_utils.py +84 -0
- model2vec-0.7.0/uv.lock +2931 -0
- model2vec-0.6.0/assets/images/logo.png +0 -0
- model2vec-0.6.0/assets/images/logo_v2.png +0 -0
- model2vec-0.6.0/assets/images/model2vec_model_diagram.png +0 -0
- model2vec-0.6.0/assets/images/model2vec_model_diagram_transparant_dark.png +0 -0
- model2vec-0.6.0/assets/images/model2vec_model_diagram_transparant_light.png +0 -0
- model2vec-0.6.0/assets/images/sentences_per_second_vs_average_score.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_accuracy.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_accuracy_v2.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_accuracy_v3.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_accuracy_v4.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_mteb_score.png +0 -0
- model2vec-0.6.0/assets/images/speed_vs_mteb_score_v2.png +0 -0
- model2vec-0.6.0/docs/README.md +0 -6
- model2vec-0.6.0/docs/integrations.md +0 -155
- model2vec-0.6.0/docs/usage.md +0 -250
- model2vec-0.6.0/docs/what_is_model2vec.md +0 -11
- model2vec-0.6.0/model2vec/__init__.py +0 -4
- model2vec-0.6.0/model2vec/distill/inference.py +0 -158
- model2vec-0.6.0/model2vec/distill/utils.py +0 -28
- model2vec-0.6.0/tests/test_quantization.py +0 -30
- model2vec-0.6.0/tests/test_utils.py +0 -121
- model2vec-0.6.0/uv.lock +0 -2553
- {model2vec-0.6.0 → model2vec-0.7.0}/.gitignore +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/LICENSE +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/assets/images/model2vec_logo.png +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/assets/images/speed_vs_mteb_score_v3.png +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/assets/images/training_speed_vs_score.png +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/assets/images/tutorial_ezlo.png +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/distill/__init__.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/inference/README.md +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/inference/__init__.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/modelcards/classifier_template.md +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/modelcards/model_card_template.md +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/py.typed +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/__init__.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/datamodels.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/model.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/tokenizer/pretokenizer.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec/train/__init__.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec.egg-info/dependency_links.txt +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/model2vec.egg-info/top_level.txt +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/results/README.md +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/results/make_speed_vs_mteb_plot.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/scripts/export_to_onnx.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/setup.cfg +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/__init__.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/data/test_tokenizer/special_tokens_map.json +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/data/test_tokenizer/tokenizer.json +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/data/test_tokenizer/tokenizer_config.json +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tests/test_inference.py +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tutorials/README.md +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tutorials/recipe_search.ipynb +0 -0
- {model2vec-0.6.0 → model2vec-0.7.0}/tutorials/semantic_chunking.ipynb +0 -0
- {model2vec-0.6.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
|
|
@@ -61,7 +61,7 @@ Requires-Dist: pytest-cov; extra == "dev"
|
|
|
61
61
|
Requires-Dist: ruff; extra == "dev"
|
|
62
62
|
Provides-Extra: distill
|
|
63
63
|
Requires-Dist: torch; extra == "distill"
|
|
64
|
-
Requires-Dist: transformers
|
|
64
|
+
Requires-Dist: transformers; extra == "distill"
|
|
65
65
|
Requires-Dist: scikit-learn; extra == "distill"
|
|
66
66
|
Provides-Extra: onnx
|
|
67
67
|
Requires-Dist: onnx; extra == "onnx"
|
|
@@ -76,7 +76,8 @@ Requires-Dist: scikit-learn; extra == "inference"
|
|
|
76
76
|
Requires-Dist: skops; extra == "inference"
|
|
77
77
|
Provides-Extra: tokenizer
|
|
78
78
|
Requires-Dist: transformers; extra == "tokenizer"
|
|
79
|
-
|
|
79
|
+
Provides-Extra: quantization
|
|
80
|
+
Requires-Dist: scikit-learn; extra == "quantization"
|
|
80
81
|
|
|
81
82
|
|
|
82
83
|
<h2 align="center">
|
|
@@ -89,17 +90,16 @@ Dynamic: license-file
|
|
|
89
90
|
<div align="center">
|
|
90
91
|
<h2>
|
|
91
92
|
<a href="https://huggingface.co/minishlab"><strong>🤗 Models</strong></a> |
|
|
92
|
-
<a href="https://
|
|
93
|
-
<a href="https://minishlab.github.io/"><strong>🌐 Blog</strong></a> |
|
|
93
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><strong>📖 Docs</strong></a> |
|
|
94
94
|
<a href="https://github.com/MinishLab/model2vec/blob/main/results/README.md"><strong>🏆 Results</strong></a> |
|
|
95
|
-
<a href="https://github.com/MinishLab/model2vec/
|
|
96
|
-
|
|
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>
|
|
97
97
|
</div>
|
|
98
98
|
|
|
99
99
|
<div align="center">
|
|
100
100
|
<h2>
|
|
101
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>
|
|
102
|
-
<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>
|
|
103
103
|
<a href="https://pepy.tech/project/model2vec">
|
|
104
104
|
<img src="https://static.pepy.tech/badge/model2vec" alt="Downloads">
|
|
105
105
|
</a>
|
|
@@ -112,6 +112,9 @@ Dynamic: license-file
|
|
|
112
112
|
<a href="https://github.com/MinishLab/model2vec/blob/main/LICENSE">
|
|
113
113
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
114
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>
|
|
115
118
|
</h2>
|
|
116
119
|
</div>
|
|
117
120
|
|
|
@@ -119,7 +122,7 @@ Dynamic: license-file
|
|
|
119
122
|
|
|
120
123
|
|
|
121
124
|
|
|
122
|
-
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.
|
|
123
126
|
|
|
124
127
|
<div align="center">
|
|
125
128
|
<h3>
|
|
@@ -149,30 +152,29 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
149
152
|
# Make sequences of token embeddings
|
|
150
153
|
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
151
154
|
```
|
|
152
|
-
|
|
153
|
-
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:
|
|
154
156
|
|
|
155
157
|
```bash
|
|
156
158
|
pip install model2vec[distill]
|
|
157
159
|
```
|
|
158
160
|
|
|
159
161
|
|
|
160
|
-
|
|
162
|
+
Then, you can distill a model in ~30 seconds on a CPU with the following code snippet:
|
|
161
163
|
|
|
162
164
|
```python
|
|
163
165
|
from model2vec.distill import distill
|
|
164
166
|
|
|
165
167
|
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
|
|
166
|
-
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5"
|
|
168
|
+
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
|
|
167
169
|
|
|
168
170
|
# Save the model
|
|
169
171
|
m2v_model.save_pretrained("m2v_model")
|
|
170
172
|
```
|
|
171
173
|
|
|
172
|
-
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:
|
|
173
175
|
|
|
174
176
|
```bash
|
|
175
|
-
pip install model2vec[
|
|
177
|
+
pip install model2vec[train]
|
|
176
178
|
```
|
|
177
179
|
|
|
178
180
|
Then, you can fine-tune a model as follows:
|
|
@@ -195,13 +197,13 @@ classifier.fit(ds["train"]["text"], ds["train"]["label"])
|
|
|
195
197
|
classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["label"])
|
|
196
198
|
```
|
|
197
199
|
|
|
198
|
-
For advanced usage,
|
|
200
|
+
For advanced usage, see our [training docs](https://minish.ai/packages/model2vec/training).
|
|
199
201
|
|
|
200
202
|
## Updates & Announcements
|
|
201
203
|
|
|
202
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.
|
|
203
205
|
|
|
204
|
-
- **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, and can be quantized to int8 to be 25% of the size, without loss of performance.
|
|
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.
|
|
205
207
|
|
|
206
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).
|
|
207
209
|
|
|
@@ -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
|
|
@@ -9,17 +9,16 @@
|
|
|
9
9
|
<div align="center">
|
|
10
10
|
<h2>
|
|
11
11
|
<a href="https://huggingface.co/minishlab"><strong>🤗 Models</strong></a> |
|
|
12
|
-
<a href="https://
|
|
13
|
-
<a href="https://minishlab.github.io/"><strong>🌐 Blog</strong></a> |
|
|
12
|
+
<a href="https://minish.ai/packages/model2vec/introduction"><strong>📖 Docs</strong></a> |
|
|
14
13
|
<a href="https://github.com/MinishLab/model2vec/blob/main/results/README.md"><strong>🏆 Results</strong></a> |
|
|
15
|
-
<a href="https://github.com/MinishLab/model2vec/
|
|
16
|
-
|
|
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>
|
|
17
16
|
</div>
|
|
18
17
|
|
|
19
18
|
<div align="center">
|
|
20
19
|
<h2>
|
|
21
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>
|
|
22
|
-
<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>
|
|
23
22
|
<a href="https://pepy.tech/project/model2vec">
|
|
24
23
|
<img src="https://static.pepy.tech/badge/model2vec" alt="Downloads">
|
|
25
24
|
</a>
|
|
@@ -32,6 +31,9 @@
|
|
|
32
31
|
<a href="https://github.com/MinishLab/model2vec/blob/main/LICENSE">
|
|
33
32
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
34
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>
|
|
35
37
|
</h2>
|
|
36
38
|
</div>
|
|
37
39
|
|
|
@@ -39,7 +41,7 @@
|
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
|
|
42
|
-
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.
|
|
43
45
|
|
|
44
46
|
<div align="center">
|
|
45
47
|
<h3>
|
|
@@ -69,30 +71,29 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
69
71
|
# Make sequences of token embeddings
|
|
70
72
|
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
71
73
|
```
|
|
72
|
-
|
|
73
|
-
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:
|
|
74
75
|
|
|
75
76
|
```bash
|
|
76
77
|
pip install model2vec[distill]
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
Then, you can distill a model in ~30 seconds on a CPU with the following code snippet:
|
|
81
82
|
|
|
82
83
|
```python
|
|
83
84
|
from model2vec.distill import distill
|
|
84
85
|
|
|
85
86
|
# Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
|
|
86
|
-
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5"
|
|
87
|
+
m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
|
|
87
88
|
|
|
88
89
|
# Save the model
|
|
89
90
|
m2v_model.save_pretrained("m2v_model")
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
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:
|
|
93
94
|
|
|
94
95
|
```bash
|
|
95
|
-
pip install model2vec[
|
|
96
|
+
pip install model2vec[train]
|
|
96
97
|
```
|
|
97
98
|
|
|
98
99
|
Then, you can fine-tune a model as follows:
|
|
@@ -115,13 +116,13 @@ classifier.fit(ds["train"]["text"], ds["train"]["label"])
|
|
|
115
116
|
classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["label"])
|
|
116
117
|
```
|
|
117
118
|
|
|
118
|
-
For advanced usage,
|
|
119
|
+
For advanced usage, see our [training docs](https://minish.ai/packages/model2vec/training).
|
|
119
120
|
|
|
120
121
|
## Updates & Announcements
|
|
121
122
|
|
|
122
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.
|
|
123
124
|
|
|
124
|
-
- **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, and can be quantized to int8 to be 25% of the size, without loss of performance.
|
|
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.
|
|
125
126
|
|
|
126
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).
|
|
127
128
|
|
|
@@ -137,24 +138,18 @@ For advanced usage, please refer to our [usage documentation](https://github.com
|
|
|
137
138
|
- **Lightning-fast Inference**: up to 500 times faster on CPU than the original model.
|
|
138
139
|
- **Fast, Dataset-free Distillation**: distill your own model in 30 seconds on a CPU, without a dataset.
|
|
139
140
|
- **Fine-tuning**: fine-tune your own classification models on top of Model2Vec models.
|
|
140
|
-
- **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).
|
|
141
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).
|
|
142
143
|
|
|
143
144
|
## What is Model2Vec?
|
|
144
145
|
|
|
145
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.
|
|
146
147
|
|
|
147
|
-
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
|
|
148
|
-
- 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.
|
|
149
|
-
- 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).
|
|
150
|
-
- 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).
|
|
151
149
|
|
|
152
150
|
## Documentation
|
|
153
151
|
|
|
154
|
-
Our official documentation can be found [here](https://
|
|
155
|
-
- [Usage documentation](https://github.com/MinishLab/model2vec/blob/main/docs/usage.md): provides a technical overview of how to use Model2Vec.
|
|
156
|
-
- [Integrations documentation](https://github.com/MinishLab/model2vec/blob/main/docs/integrations.md): provides examples of how to use Model2Vec in various downstream libraries.
|
|
157
|
-
- [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).
|
|
158
153
|
|
|
159
154
|
|
|
160
155
|
## Model List
|
|
@@ -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)
|
|
@@ -6,14 +6,17 @@ import re
|
|
|
6
6
|
from typing import Optional, cast
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
9
|
-
from huggingface_hub import model_info
|
|
10
|
-
from transformers import AutoModel, AutoTokenizer
|
|
9
|
+
from huggingface_hub.hf_api import model_info
|
|
10
|
+
from transformers import AutoModel, AutoTokenizer
|
|
11
|
+
from transformers.modeling_utils import PreTrainedModel
|
|
12
|
+
from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
|
|
11
13
|
|
|
12
|
-
from model2vec.distill.inference import PCADimType, create_embeddings, post_process_embeddings
|
|
14
|
+
from model2vec.distill.inference import PCADimType, PoolingMode, create_embeddings, post_process_embeddings
|
|
13
15
|
from model2vec.distill.utils import select_optimal_device
|
|
14
16
|
from model2vec.model import StaticModel
|
|
15
17
|
from model2vec.quantization import DType, quantize_embeddings
|
|
16
18
|
from model2vec.tokenizer import clean_and_create_vocabulary, replace_vocabulary, turn_tokens_into_ids
|
|
19
|
+
from model2vec.vocabulary_quantization import quantize_vocabulary
|
|
17
20
|
|
|
18
21
|
logger = logging.getLogger(__name__)
|
|
19
22
|
|
|
@@ -24,11 +27,11 @@ def distill_from_model(
|
|
|
24
27
|
vocabulary: list[str] | None = None,
|
|
25
28
|
device: str | None = None,
|
|
26
29
|
pca_dims: PCADimType = 256,
|
|
27
|
-
apply_zipf: bool | None = None,
|
|
28
30
|
sif_coefficient: float | None = 1e-4,
|
|
29
31
|
token_remove_pattern: str | None = r"\[unused\d+\]",
|
|
30
32
|
quantize_to: DType | str = DType.Float16,
|
|
31
|
-
|
|
33
|
+
vocabulary_quantization: int | None = None,
|
|
34
|
+
pooling: PoolingMode | str = PoolingMode.MEAN,
|
|
32
35
|
) -> StaticModel:
|
|
33
36
|
"""
|
|
34
37
|
Distill a staticmodel from a sentence transformer.
|
|
@@ -46,25 +49,24 @@ def distill_from_model(
|
|
|
46
49
|
:param pca_dims: The number of components to use for PCA.
|
|
47
50
|
If this is None, we don't apply PCA.
|
|
48
51
|
If this is 'auto', we don't reduce dimensionality, but still apply PCA.
|
|
49
|
-
:param apply_zipf: DEPRECATED: This parameter used to control whether Zipf is applied.
|
|
50
|
-
Zipf weighting is now controlled by the sif_coefficient parameter. If this is set to None, no weighting is applied.
|
|
51
52
|
:param sif_coefficient: The SIF coefficient to use. If this is None, no weighting is applied.
|
|
52
53
|
Should be a value > 0 and < 1.0. A value of 1e-4 is a good default.
|
|
53
54
|
:param token_remove_pattern: If this is set to a string, we compile this into a regex. Any tokens that conform to this regex pattern will be removed from the vocabulary.
|
|
54
55
|
If the pattern is so general that it removes all tokens, we throw an error. If the pattern can't be compiled into a valid regex, we also throw an error.
|
|
55
56
|
:param quantize_to: The data type to quantize to. Can be any of the DType enum members or their string equivalents.
|
|
56
|
-
:param
|
|
57
|
-
:
|
|
57
|
+
:param vocabulary_quantization: The number of clusters to use for vocabulary quantization. If this is None, no quantization is performed.
|
|
58
|
+
:param pooling: The pooling mode to use for creating embeddings. Can be one of:
|
|
59
|
+
'mean' (default): mean over all tokens. Robust and works well in most cases.
|
|
60
|
+
'last': use the last token's hidden state (often the [EOS] token). Common for decoder-style models.
|
|
61
|
+
'first': use the first token's hidden state ([CLS] token in BERT-style models).
|
|
62
|
+
'pooler': use the pooler output (if available). This is often a non-linear projection of the [CLS] token.
|
|
63
|
+
:return: A StaticModel.
|
|
58
64
|
:raises: ValueError if the vocabulary is empty after preprocessing.
|
|
59
65
|
|
|
60
66
|
"""
|
|
61
|
-
if use_subword is not None:
|
|
62
|
-
logger.warning(
|
|
63
|
-
"The `use_subword` parameter is deprecated and will be removed in the next release. It doesn't do anything."
|
|
64
|
-
)
|
|
65
67
|
quantize_to = DType(quantize_to)
|
|
66
68
|
backend_tokenizer = tokenizer.backend_tokenizer
|
|
67
|
-
sif_coefficient, token_remove_regex = _validate_parameters(
|
|
69
|
+
sif_coefficient, token_remove_regex = _validate_parameters(sif_coefficient, token_remove_pattern)
|
|
68
70
|
|
|
69
71
|
if vocabulary is None:
|
|
70
72
|
vocabulary = []
|
|
@@ -103,18 +105,29 @@ def distill_from_model(
|
|
|
103
105
|
|
|
104
106
|
# Replace the vocabulary in the tokenizer with the new vocabulary.
|
|
105
107
|
backend_tokenizer = replace_vocabulary(backend_tokenizer, all_tokens, unk_token=unk_token, pad_token=pad_token)
|
|
106
|
-
|
|
107
108
|
logger.info(f"Creating embeddings for {len(all_tokens)} tokens")
|
|
108
109
|
# Convert tokens to IDs
|
|
109
110
|
token_ids = turn_tokens_into_ids(all_tokens, tokenizer, unk_token)
|
|
110
111
|
|
|
111
112
|
# Create the embeddings
|
|
112
113
|
embeddings = create_embeddings(
|
|
113
|
-
tokenized=token_ids,
|
|
114
|
+
tokenized=token_ids,
|
|
115
|
+
model=model,
|
|
116
|
+
device=device,
|
|
117
|
+
pad_token_id=tokenizer.get_vocab()[pad_token],
|
|
118
|
+
pooling=pooling,
|
|
114
119
|
)
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
if vocabulary_quantization is not None:
|
|
122
|
+
_, weights = post_process_embeddings(np.asarray(embeddings), None, sif_coefficient=sif_coefficient)
|
|
123
|
+
embeddings, token_mapping, weights = quantize_vocabulary(
|
|
124
|
+
n_clusters=vocabulary_quantization, weights=weights, embeddings=np.asarray(embeddings)
|
|
125
|
+
)
|
|
126
|
+
embeddings, _ = post_process_embeddings(embeddings, pca_dims, sif_coefficient=sif_coefficient)
|
|
127
|
+
else:
|
|
128
|
+
# Post-process the embeddings.
|
|
129
|
+
embeddings, weights = post_process_embeddings(np.asarray(embeddings), pca_dims, sif_coefficient=sif_coefficient)
|
|
130
|
+
token_mapping = None
|
|
118
131
|
# Quantize the embeddings.
|
|
119
132
|
embeddings = quantize_embeddings(embeddings, quantize_to)
|
|
120
133
|
|
|
@@ -125,11 +138,11 @@ def distill_from_model(
|
|
|
125
138
|
"architectures": ["StaticModel"],
|
|
126
139
|
"tokenizer_name": model_name,
|
|
127
140
|
"apply_pca": pca_dims,
|
|
128
|
-
"apply_zipf": apply_zipf,
|
|
129
141
|
"sif_coefficient": sif_coefficient,
|
|
130
142
|
"hidden_dim": embeddings.shape[1],
|
|
131
143
|
"seq_length": 1000000, # Set this to a high value since we don't have a sequence length limit.
|
|
132
144
|
"normalize": True,
|
|
145
|
+
"pooling": pooling,
|
|
133
146
|
}
|
|
134
147
|
|
|
135
148
|
if os.path.exists(model_name):
|
|
@@ -148,6 +161,8 @@ def distill_from_model(
|
|
|
148
161
|
|
|
149
162
|
return StaticModel(
|
|
150
163
|
vectors=embeddings,
|
|
164
|
+
weights=weights,
|
|
165
|
+
token_mapping=token_mapping,
|
|
151
166
|
tokenizer=backend_tokenizer,
|
|
152
167
|
config=config,
|
|
153
168
|
base_model_name=model_name,
|
|
@@ -157,15 +172,12 @@ def distill_from_model(
|
|
|
157
172
|
|
|
158
173
|
|
|
159
174
|
def _validate_parameters(
|
|
160
|
-
apply_zipf: bool | None,
|
|
161
175
|
sif_coefficient: float | None,
|
|
162
176
|
token_remove_pattern: str | None,
|
|
163
177
|
) -> tuple[float | None, re.Pattern | None]:
|
|
164
178
|
"""
|
|
165
179
|
Validate the parameters passed to the distillation function.
|
|
166
180
|
|
|
167
|
-
:param apply_zipf: DEPRECATED: This parameter used to control whether Zipf is applied.
|
|
168
|
-
Zipf weighting is now controlled by the sif_coefficient parameter. If this is set to None, no weighting is applied.
|
|
169
181
|
:param sif_coefficient: The SIF coefficient to use. If this is None, no weighting is applied.
|
|
170
182
|
Should be a value >= 0 and < 1.0. A value of 1e-4 is a good default.
|
|
171
183
|
:param token_remove_pattern: If this is set to a string, we compile this into a regex. Any tokens that conform to this regex pattern will be removed from the vocabulary.
|
|
@@ -173,19 +185,6 @@ def _validate_parameters(
|
|
|
173
185
|
:raises: ValueError if the regex can't be compiled.
|
|
174
186
|
|
|
175
187
|
"""
|
|
176
|
-
if apply_zipf is not None:
|
|
177
|
-
logger.warning(
|
|
178
|
-
"The `apply_zipf` parameter is deprecated and will be removed in the next release. "
|
|
179
|
-
"Zipf weighting is applied based on the sif_coefficient parameter. If this is set to None, "
|
|
180
|
-
"no weighting is applied."
|
|
181
|
-
)
|
|
182
|
-
if apply_zipf and sif_coefficient is None:
|
|
183
|
-
logger.warning("You set apply_zipf to True, but sif_coefficient is None. Setting sif_coefficient to 1e-4.")
|
|
184
|
-
sif_coefficient = 1e-4
|
|
185
|
-
elif not apply_zipf:
|
|
186
|
-
logger.warning("Because you set apply_zipf to False, we ignore the sif_coefficient parameter.")
|
|
187
|
-
sif_coefficient = None
|
|
188
|
-
|
|
189
188
|
if sif_coefficient is not None:
|
|
190
189
|
if not 0 < sif_coefficient < 1.0:
|
|
191
190
|
raise ValueError("SIF coefficient must be a value > 0 and < 1.0.")
|
|
@@ -205,12 +204,12 @@ def distill(
|
|
|
205
204
|
vocabulary: list[str] | None = None,
|
|
206
205
|
device: str | None = None,
|
|
207
206
|
pca_dims: PCADimType = 256,
|
|
208
|
-
apply_zipf: bool | None = None,
|
|
209
207
|
sif_coefficient: float | None = 1e-4,
|
|
210
208
|
token_remove_pattern: str | None = r"\[unused\d+\]",
|
|
211
209
|
trust_remote_code: bool = False,
|
|
212
210
|
quantize_to: DType | str = DType.Float16,
|
|
213
|
-
|
|
211
|
+
vocabulary_quantization: int | None = None,
|
|
212
|
+
pooling: PoolingMode | str = PoolingMode.MEAN,
|
|
214
213
|
) -> StaticModel:
|
|
215
214
|
"""
|
|
216
215
|
Distill a staticmodel from a sentence transformer.
|
|
@@ -227,14 +226,17 @@ def distill(
|
|
|
227
226
|
:param pca_dims: The number of components to use for PCA.
|
|
228
227
|
If this is None, we don't apply PCA.
|
|
229
228
|
If this is 'auto', we don't reduce dimenionality, but still apply PCA.
|
|
230
|
-
:param apply_zipf: DEPRECATED: This parameter used to control whether Zipf is applied.
|
|
231
|
-
Zipf weighting is now controlled by the sif_coefficient parameter. If this is set to None, no weighting is applied.
|
|
232
229
|
:param sif_coefficient: The SIF coefficient to use. If this is None, no weighting is applied.
|
|
233
230
|
Should be a value >= 0 and < 1.0. A value of 1e-4 is a good default.
|
|
234
231
|
:param token_remove_pattern: If this is set to a string, we compile this into a regex. Any tokens that conform to this regex pattern will be removed from the vocabulary.
|
|
235
232
|
:param trust_remote_code: Whether to trust the remote code. If this is False, we will only load components coming from `transformers`. If this is True, we will load all components.
|
|
236
233
|
:param quantize_to: The data type to quantize to. Can be any of the DType enum members or their string equivalents.
|
|
237
|
-
:param
|
|
234
|
+
:param vocabulary_quantization: The number of clusters to use for vocabulary quantization. If this is None, no quantization is performed.
|
|
235
|
+
:param pooling: The pooling mode to use for creating embeddings. Can be one of:
|
|
236
|
+
'mean' (default): mean over all tokens. Robust and works well in most cases.
|
|
237
|
+
'last': use the last token's hidden state (often the [EOS] token). Common for decoder-style models.
|
|
238
|
+
'first': use the first token's hidden state ([CLS] token in BERT-style models).
|
|
239
|
+
'pooler': use the pooler output (if available). This is often a non-linear projection of the [CLS] token.
|
|
238
240
|
:return: A StaticModel
|
|
239
241
|
|
|
240
242
|
"""
|
|
@@ -250,9 +252,9 @@ def distill(
|
|
|
250
252
|
vocabulary=vocabulary,
|
|
251
253
|
device=device,
|
|
252
254
|
pca_dims=pca_dims,
|
|
253
|
-
apply_zipf=apply_zipf,
|
|
254
255
|
token_remove_pattern=token_remove_pattern,
|
|
255
256
|
sif_coefficient=sif_coefficient,
|
|
256
257
|
quantize_to=quantize_to,
|
|
257
|
-
|
|
258
|
+
vocabulary_quantization=vocabulary_quantization,
|
|
259
|
+
pooling=pooling,
|
|
258
260
|
)
|