model2vec 0.3.0__tar.gz → 0.3.2__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.3.0 → model2vec-0.3.2}/PKG-INFO +27 -18
- {model2vec-0.3.0 → model2vec-0.3.2}/README.md +25 -17
- model2vec-0.3.2/assets/images/speed_vs_accuracy_v4.png +0 -0
- model2vec-0.3.2/assets/images/speed_vs_mteb_score.png +0 -0
- model2vec-0.3.2/assets/images/speed_vs_mteb_score_v2.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/distill/inference.py +9 -1
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/distill/tokenizer.py +7 -6
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/model.py +11 -2
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/utils.py +10 -8
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/version.py +1 -1
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec.egg-info/PKG-INFO +27 -18
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec.egg-info/SOURCES.txt +3 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec.egg-info/requires.txt +1 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/pyproject.toml +1 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/results/README.md +14 -36
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/conftest.py +1 -1
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/test_model.py +32 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/uv.lock +3 -1
- {model2vec-0.3.0 → model2vec-0.3.2}/.github/workflows/ci.yaml +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/.gitignore +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/.pre-commit-config.yaml +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/LICENSE +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/Makefile +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/logo.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/logo_v2.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/model2vec_model_diagram.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/model2vec_model_diagram_transparant_dark.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/model2vec_model_diagram_transparant_light.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/sentences_per_second_vs_average_score.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/speed_vs_accuracy.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/speed_vs_accuracy_v2.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/speed_vs_accuracy_v3.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/assets/images/tutorial_ezlo.png +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/__init__.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/distill/__init__.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/distill/distillation.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/distill/utils.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/hf_utils.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec/model_card_template.md +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec.egg-info/dependency_links.txt +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/model2vec.egg-info/top_level.txt +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/setup.cfg +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/__init__.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/data/test_tokenizer/special_tokens_map.json +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/data/test_tokenizer/tokenizer.json +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/data/test_tokenizer/tokenizer_config.json +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/test_distillation.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tests/test_utils.py +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tutorials/README.md +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tutorials/recipe_search.ipynb +0 -0
- {model2vec-0.3.0 → model2vec-0.3.2}/tutorials/semantic_deduplication.ipynb +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: model2vec
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Distill a Small Static Model from any Sentence Transformer
|
|
5
5
|
Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
|
|
6
6
|
License: MIT License
|
|
@@ -47,6 +47,7 @@ Requires-Dist: numpy
|
|
|
47
47
|
Requires-Dist: rich
|
|
48
48
|
Requires-Dist: tqdm
|
|
49
49
|
Requires-Dist: tokenizers>=0.20
|
|
50
|
+
Requires-Dist: safetensors
|
|
50
51
|
Requires-Dist: setuptools
|
|
51
52
|
Provides-Extra: dev
|
|
52
53
|
Requires-Dist: black; extra == "dev"
|
|
@@ -104,14 +105,19 @@ Requires-Dist: scikit-learn; extra == "distill"
|
|
|
104
105
|
|
|
105
106
|
Model2Vec is a technique to turn any sentence transformer into a really small static model, reducing model size by 15x and making the models up to 500x faster, with a small drop in performance. See our results [here](results/README.md), or dive in to see how it works.
|
|
106
107
|
|
|
108
|
+
|
|
109
|
+
## Updates & Announcements
|
|
110
|
+
|
|
111
|
+
- **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).
|
|
112
|
+
|
|
107
113
|
## Table of Contents
|
|
108
114
|
- [Quickstart](#quickstart)
|
|
109
115
|
- [Main Features](#main-features)
|
|
110
116
|
- [What is Model2Vec?](#what-is-model2vec)
|
|
111
117
|
- [Usage](#usage)
|
|
112
|
-
- [
|
|
113
|
-
- [
|
|
114
|
-
- [
|
|
118
|
+
- [Distillation](#distillation)
|
|
119
|
+
- [Inference](#inference)
|
|
120
|
+
- [Evaluation](#evaluation)
|
|
115
121
|
- [Model List](#model-list)
|
|
116
122
|
- [Results](#results)
|
|
117
123
|
- [Related Work](#related-work)
|
|
@@ -134,8 +140,8 @@ The easiest way to get started with Model2Vec is to download one of our [flagshi
|
|
|
134
140
|
```python
|
|
135
141
|
from model2vec import StaticModel
|
|
136
142
|
|
|
137
|
-
# Load a model from the HuggingFace hub (in this case the
|
|
138
|
-
model_name = "minishlab/
|
|
143
|
+
# Load a model from the HuggingFace hub (in this case the potion-base-8M model)
|
|
144
|
+
model_name = "minishlab/potion-base-8M"
|
|
139
145
|
model = StaticModel.from_pretrained(model_name)
|
|
140
146
|
|
|
141
147
|
# Make embeddings
|
|
@@ -169,7 +175,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
169
175
|
from sentence_transformers.models import StaticEmbedding
|
|
170
176
|
|
|
171
177
|
# Initialize a StaticEmbedding module
|
|
172
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
178
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
173
179
|
model = SentenceTransformer(modules=[static_embedding])
|
|
174
180
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
175
181
|
```
|
|
@@ -215,6 +221,9 @@ Model2vec has 3 modes:
|
|
|
215
221
|
|
|
216
222
|
For a technical deepdive into Model2Vec, please refer to our [blog post](https://huggingface.co/blog/Pringled/model2vec).
|
|
217
223
|
|
|
224
|
+
### Tokenlearn
|
|
225
|
+
|
|
226
|
+
Our flagship POTION models are pre-trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). This method is described in our [Tokenlearn blogpost](https://minishlab.github.io/tokenlearn_blogpost/).
|
|
218
227
|
|
|
219
228
|
|
|
220
229
|
## Usage
|
|
@@ -328,7 +337,7 @@ Inference works as follows. The example shows one of our own models, but you can
|
|
|
328
337
|
from model2vec import StaticModel
|
|
329
338
|
|
|
330
339
|
# Load a model from the HuggingFace hub, or a local one.
|
|
331
|
-
model_name = "minishlab/
|
|
340
|
+
model_name = "minishlab/potion-base-8M"
|
|
332
341
|
# You can optionally pass a token if you're loading a private model
|
|
333
342
|
model = StaticModel.from_pretrained(model_name, token=None)
|
|
334
343
|
|
|
@@ -352,7 +361,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
352
361
|
from sentence_transformers.models import StaticEmbedding
|
|
353
362
|
|
|
354
363
|
# Initialize a StaticEmbedding module
|
|
355
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
364
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
356
365
|
model = SentenceTransformer(modules=[static_embedding])
|
|
357
366
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
358
367
|
```
|
|
@@ -370,7 +379,7 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
370
379
|
Our models can be evaluated using our [evaluation package](https://github.com/MinishLab/evaluation). Install the evaluation package with:
|
|
371
380
|
|
|
372
381
|
```bash
|
|
373
|
-
pip install
|
|
382
|
+
pip install git+https://github.com/MinishLab/evaluation.git@main
|
|
374
383
|
```
|
|
375
384
|
</details>
|
|
376
385
|
|
|
@@ -415,19 +424,19 @@ print(make_leaderboard(task_scores))
|
|
|
415
424
|
|
|
416
425
|
We provide a number of models that can be used out of the box. These models are available on the [HuggingFace hub](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e) and can be loaded using the `from_pretrained` method. The models are listed below.
|
|
417
426
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
| [
|
|
422
|
-
| [
|
|
423
|
-
| [
|
|
427
|
+
|
|
428
|
+
| Model | Language | Vocab | Sentence Transformer | Tokenizer Type | Params | Tokenlearn |
|
|
429
|
+
|-----------------------------------------------------------------------|-------------|------------------|-----------------------------------------------------------------|----------------|---------|------------|
|
|
430
|
+
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 7.5M | True |
|
|
431
|
+
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 3.7M | True |
|
|
432
|
+
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 1.8M | True |
|
|
433
|
+
| [M2V_multilingual_output](https://huggingface.co/minishlab/M2V_multilingual_output) | Multilingual | Output | [LaBSE](https://huggingface.co/sentence-transformers/LaBSE) | Subword | 471M | False |
|
|
424
434
|
|
|
425
435
|
|
|
426
436
|
## Results
|
|
427
437
|
|
|
428
438
|
We have performed extensive experiments to evaluate the performance of Model2Vec models. The results are documented in the [results](results/README.md) folder. The results are presented in the following sections:
|
|
429
439
|
- [MTEB Results](results/README.md#mteb-results)
|
|
430
|
-
- [Classification and Speed Benchmarks](results/README.md#classification-and-speed-benchmarks)
|
|
431
440
|
- [Ablations](results/README.md#ablations)
|
|
432
441
|
|
|
433
442
|
## Related work
|
|
@@ -435,7 +444,7 @@ We have performed extensive experiments to evaluate the performance of Model2Vec
|
|
|
435
444
|
If you are interested in fast small models, also consider looking at these techniques:
|
|
436
445
|
* [BPEmb](https://bpemb.h-its.org/): GLoVE embeddings trained on BPE-encoded Wikipedias. Huge inspiration to this project, multilingual, very fast. If you don't find a sentence transformer in the language you need, check this out.
|
|
437
446
|
* [fast-sentence-transformers](https://github.com/davidberenstein1957/fast-sentence-transformers): distillation using Model2Vec comes at a cost. If that cost is too steep for you, and you have access to a GPU, this package is for you. It automates the quantization and optimization of sentence transformers without loss of performance.
|
|
438
|
-
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings.
|
|
447
|
+
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings. We think this is a bit overfit on MTEB, as the model is trained on MTEB datasets, and only evaluated on MTEB. Fun fact: this was invented at the same time as Model2Vec.
|
|
439
448
|
|
|
440
449
|
If you find other related work, please let us know.
|
|
441
450
|
|
|
@@ -41,14 +41,19 @@
|
|
|
41
41
|
|
|
42
42
|
Model2Vec is a technique to turn any sentence transformer into a really small static model, reducing model size by 15x and making the models up to 500x faster, with a small drop in performance. See our results [here](results/README.md), or dive in to see how it works.
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
## Updates & Announcements
|
|
46
|
+
|
|
47
|
+
- **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).
|
|
48
|
+
|
|
44
49
|
## Table of Contents
|
|
45
50
|
- [Quickstart](#quickstart)
|
|
46
51
|
- [Main Features](#main-features)
|
|
47
52
|
- [What is Model2Vec?](#what-is-model2vec)
|
|
48
53
|
- [Usage](#usage)
|
|
49
|
-
- [
|
|
50
|
-
- [
|
|
51
|
-
- [
|
|
54
|
+
- [Distillation](#distillation)
|
|
55
|
+
- [Inference](#inference)
|
|
56
|
+
- [Evaluation](#evaluation)
|
|
52
57
|
- [Model List](#model-list)
|
|
53
58
|
- [Results](#results)
|
|
54
59
|
- [Related Work](#related-work)
|
|
@@ -71,8 +76,8 @@ The easiest way to get started with Model2Vec is to download one of our [flagshi
|
|
|
71
76
|
```python
|
|
72
77
|
from model2vec import StaticModel
|
|
73
78
|
|
|
74
|
-
# Load a model from the HuggingFace hub (in this case the
|
|
75
|
-
model_name = "minishlab/
|
|
79
|
+
# Load a model from the HuggingFace hub (in this case the potion-base-8M model)
|
|
80
|
+
model_name = "minishlab/potion-base-8M"
|
|
76
81
|
model = StaticModel.from_pretrained(model_name)
|
|
77
82
|
|
|
78
83
|
# Make embeddings
|
|
@@ -106,7 +111,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
106
111
|
from sentence_transformers.models import StaticEmbedding
|
|
107
112
|
|
|
108
113
|
# Initialize a StaticEmbedding module
|
|
109
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
114
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
110
115
|
model = SentenceTransformer(modules=[static_embedding])
|
|
111
116
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
112
117
|
```
|
|
@@ -152,6 +157,9 @@ Model2vec has 3 modes:
|
|
|
152
157
|
|
|
153
158
|
For a technical deepdive into Model2Vec, please refer to our [blog post](https://huggingface.co/blog/Pringled/model2vec).
|
|
154
159
|
|
|
160
|
+
### Tokenlearn
|
|
161
|
+
|
|
162
|
+
Our flagship POTION models are pre-trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). This method is described in our [Tokenlearn blogpost](https://minishlab.github.io/tokenlearn_blogpost/).
|
|
155
163
|
|
|
156
164
|
|
|
157
165
|
## Usage
|
|
@@ -265,7 +273,7 @@ Inference works as follows. The example shows one of our own models, but you can
|
|
|
265
273
|
from model2vec import StaticModel
|
|
266
274
|
|
|
267
275
|
# Load a model from the HuggingFace hub, or a local one.
|
|
268
|
-
model_name = "minishlab/
|
|
276
|
+
model_name = "minishlab/potion-base-8M"
|
|
269
277
|
# You can optionally pass a token if you're loading a private model
|
|
270
278
|
model = StaticModel.from_pretrained(model_name, token=None)
|
|
271
279
|
|
|
@@ -289,7 +297,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
289
297
|
from sentence_transformers.models import StaticEmbedding
|
|
290
298
|
|
|
291
299
|
# Initialize a StaticEmbedding module
|
|
292
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
300
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
293
301
|
model = SentenceTransformer(modules=[static_embedding])
|
|
294
302
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
295
303
|
```
|
|
@@ -307,7 +315,7 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
307
315
|
Our models can be evaluated using our [evaluation package](https://github.com/MinishLab/evaluation). Install the evaluation package with:
|
|
308
316
|
|
|
309
317
|
```bash
|
|
310
|
-
pip install
|
|
318
|
+
pip install git+https://github.com/MinishLab/evaluation.git@main
|
|
311
319
|
```
|
|
312
320
|
</details>
|
|
313
321
|
|
|
@@ -352,19 +360,19 @@ print(make_leaderboard(task_scores))
|
|
|
352
360
|
|
|
353
361
|
We provide a number of models that can be used out of the box. These models are available on the [HuggingFace hub](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e) and can be loaded using the `from_pretrained` method. The models are listed below.
|
|
354
362
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
| [
|
|
359
|
-
| [
|
|
360
|
-
| [
|
|
363
|
+
|
|
364
|
+
| Model | Language | Vocab | Sentence Transformer | Tokenizer Type | Params | Tokenlearn |
|
|
365
|
+
|-----------------------------------------------------------------------|-------------|------------------|-----------------------------------------------------------------|----------------|---------|------------|
|
|
366
|
+
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 7.5M | True |
|
|
367
|
+
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 3.7M | True |
|
|
368
|
+
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 1.8M | True |
|
|
369
|
+
| [M2V_multilingual_output](https://huggingface.co/minishlab/M2V_multilingual_output) | Multilingual | Output | [LaBSE](https://huggingface.co/sentence-transformers/LaBSE) | Subword | 471M | False |
|
|
361
370
|
|
|
362
371
|
|
|
363
372
|
## Results
|
|
364
373
|
|
|
365
374
|
We have performed extensive experiments to evaluate the performance of Model2Vec models. The results are documented in the [results](results/README.md) folder. The results are presented in the following sections:
|
|
366
375
|
- [MTEB Results](results/README.md#mteb-results)
|
|
367
|
-
- [Classification and Speed Benchmarks](results/README.md#classification-and-speed-benchmarks)
|
|
368
376
|
- [Ablations](results/README.md#ablations)
|
|
369
377
|
|
|
370
378
|
## Related work
|
|
@@ -372,7 +380,7 @@ We have performed extensive experiments to evaluate the performance of Model2Vec
|
|
|
372
380
|
If you are interested in fast small models, also consider looking at these techniques:
|
|
373
381
|
* [BPEmb](https://bpemb.h-its.org/): GLoVE embeddings trained on BPE-encoded Wikipedias. Huge inspiration to this project, multilingual, very fast. If you don't find a sentence transformer in the language you need, check this out.
|
|
374
382
|
* [fast-sentence-transformers](https://github.com/davidberenstein1957/fast-sentence-transformers): distillation using Model2Vec comes at a cost. If that cost is too steep for you, and you have access to a GPU, this package is for you. It automates the quantization and optimization of sentence transformers without loss of performance.
|
|
375
|
-
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings.
|
|
383
|
+
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings. We think this is a bit overfit on MTEB, as the model is trained on MTEB datasets, and only evaluated on MTEB. Fun fact: this was invented at the same time as Model2Vec.
|
|
376
384
|
|
|
377
385
|
If you find other related work, please let us know.
|
|
378
386
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -115,7 +115,15 @@ def create_output_embeddings_from_model_name(
|
|
|
115
115
|
:return: The tokens and output embeddings.
|
|
116
116
|
"""
|
|
117
117
|
model = model.to(device)
|
|
118
|
-
|
|
118
|
+
|
|
119
|
+
# Quick check to see if the tokenizer is consistent.
|
|
120
|
+
vocab_length = len(tokenizer.get_vocab())
|
|
121
|
+
if vocab_length != tokenizer.vocab_size:
|
|
122
|
+
logger.warning(
|
|
123
|
+
f"Reported vocab size {tokenizer.vocab_size} is inconsistent with the vocab size {vocab_length}."
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
ids = torch.arange(vocab_length)
|
|
119
127
|
|
|
120
128
|
# Work-around to get the eos and bos token ids without having to go into tokenizer internals.
|
|
121
129
|
dummy_encoding = tokenizer.encode("A")
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import logging
|
|
5
|
+
from typing import Any
|
|
5
6
|
|
|
6
7
|
from tokenizers import Tokenizer
|
|
7
8
|
|
|
@@ -36,11 +37,11 @@ def remove_tokens(tokenizer: Tokenizer, tokens_to_remove: list[str]) -> Tokenize
|
|
|
36
37
|
logger.info("No tokens to remove.")
|
|
37
38
|
return Tokenizer.from_str(tokenizer.to_str())
|
|
38
39
|
|
|
39
|
-
tokenizer_data = json.loads(tokenizer.to_str())
|
|
40
|
+
tokenizer_data: dict[str, Any] = json.loads(tokenizer.to_str())
|
|
40
41
|
|
|
41
42
|
# Find all added tokens
|
|
42
|
-
added_tokens = tokenizer_data
|
|
43
|
-
added_tokens_str = {token["content"] for token in added_tokens}
|
|
43
|
+
added_tokens: list[dict[str, Any]] = tokenizer_data.get("added_tokens", [])
|
|
44
|
+
added_tokens_str: set[str] = {token["content"] for token in added_tokens}
|
|
44
45
|
|
|
45
46
|
# Remove all added tokens from the list of tokens to remove.
|
|
46
47
|
# Things will go bad if we keep them.
|
|
@@ -76,9 +77,9 @@ def remove_tokens(tokenizer: Tokenizer, tokens_to_remove: list[str]) -> Tokenize
|
|
|
76
77
|
raise ValueError(f"Unknown model type {model_type}")
|
|
77
78
|
|
|
78
79
|
# Reindex the special tokens (i.e., CLS and SEP for BertTokenizers.)
|
|
79
|
-
|
|
80
|
-
for
|
|
81
|
-
token_data["
|
|
80
|
+
added_tokens = tokenizer_data.get("added_tokens", [])
|
|
81
|
+
for token_data in added_tokens:
|
|
82
|
+
token_data["id"] = reindexed[token_data["content"]]
|
|
82
83
|
|
|
83
84
|
# Reinitialize the tokenizer from the json.
|
|
84
85
|
tokenizer = Tokenizer.from_str(json.dumps(tokenizer_data))
|
|
@@ -59,6 +59,10 @@ class StaticModel:
|
|
|
59
59
|
self.config = config or {}
|
|
60
60
|
self.base_model_name = base_model_name
|
|
61
61
|
self.language = language
|
|
62
|
+
if hasattr(self.tokenizer, "encode_batch_fast"):
|
|
63
|
+
self._can_encode_fast = True
|
|
64
|
+
else:
|
|
65
|
+
self._can_encode_fast = False
|
|
62
66
|
|
|
63
67
|
if normalize is not None:
|
|
64
68
|
self.normalize = normalize
|
|
@@ -121,7 +125,11 @@ class StaticModel:
|
|
|
121
125
|
m = max_length * self.median_token_length
|
|
122
126
|
sentences = [sentence[:m] for sentence in sentences]
|
|
123
127
|
|
|
124
|
-
|
|
128
|
+
if self._can_encode_fast:
|
|
129
|
+
encodings: list[Encoding] = self.tokenizer.encode_batch_fast(sentences, add_special_tokens=False)
|
|
130
|
+
else:
|
|
131
|
+
encodings = self.tokenizer.encode_batch(sentences, add_special_tokens=False)
|
|
132
|
+
|
|
125
133
|
encodings_ids = [encoding.ids for encoding in encodings]
|
|
126
134
|
|
|
127
135
|
if self.unk_token_id is not None:
|
|
@@ -264,7 +272,8 @@ class StaticModel:
|
|
|
264
272
|
|
|
265
273
|
out_array = np.stack(out)
|
|
266
274
|
if self.normalize:
|
|
267
|
-
|
|
275
|
+
norm = np.linalg.norm(out_array, axis=1, keepdims=True) + 1e-32
|
|
276
|
+
out_array = out_array / norm
|
|
268
277
|
|
|
269
278
|
return out_array
|
|
270
279
|
|
|
@@ -26,17 +26,19 @@ _MODULE_MAP = (("scikit-learn", "sklearn"),)
|
|
|
26
26
|
|
|
27
27
|
def get_package_extras(package: str, extra: str) -> Iterator[str]:
|
|
28
28
|
"""Get the extras of the package."""
|
|
29
|
-
|
|
29
|
+
try:
|
|
30
|
+
message = metadata(package)
|
|
31
|
+
except Exception as e:
|
|
32
|
+
raise ImportError(f"Could not retrieve metadata for package '{package}': {e}")
|
|
33
|
+
|
|
30
34
|
all_packages = message.get_all("Requires-Dist") or []
|
|
31
35
|
for package in all_packages:
|
|
32
36
|
name, *rest = package.split(";", maxsplit=1)
|
|
33
|
-
if
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if found_extra == extra:
|
|
39
|
-
yield name
|
|
37
|
+
if rest:
|
|
38
|
+
# Extract and clean the extra requirement
|
|
39
|
+
found_extra = rest[0].split("==")[-1].strip(" \"'")
|
|
40
|
+
if found_extra == extra:
|
|
41
|
+
yield name.strip()
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
def importable(module: str, extra: str) -> None:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_triple__ = (0, 3,
|
|
1
|
+
__version_triple__ = (0, 3, 2)
|
|
2
2
|
__version__ = ".".join(map(str, __version_triple__))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: model2vec
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Distill a Small Static Model from any Sentence Transformer
|
|
5
5
|
Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
|
|
6
6
|
License: MIT License
|
|
@@ -47,6 +47,7 @@ Requires-Dist: numpy
|
|
|
47
47
|
Requires-Dist: rich
|
|
48
48
|
Requires-Dist: tqdm
|
|
49
49
|
Requires-Dist: tokenizers>=0.20
|
|
50
|
+
Requires-Dist: safetensors
|
|
50
51
|
Requires-Dist: setuptools
|
|
51
52
|
Provides-Extra: dev
|
|
52
53
|
Requires-Dist: black; extra == "dev"
|
|
@@ -104,14 +105,19 @@ Requires-Dist: scikit-learn; extra == "distill"
|
|
|
104
105
|
|
|
105
106
|
Model2Vec is a technique to turn any sentence transformer into a really small static model, reducing model size by 15x and making the models up to 500x faster, with a small drop in performance. See our results [here](results/README.md), or dive in to see how it works.
|
|
106
107
|
|
|
108
|
+
|
|
109
|
+
## Updates & Announcements
|
|
110
|
+
|
|
111
|
+
- **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).
|
|
112
|
+
|
|
107
113
|
## Table of Contents
|
|
108
114
|
- [Quickstart](#quickstart)
|
|
109
115
|
- [Main Features](#main-features)
|
|
110
116
|
- [What is Model2Vec?](#what-is-model2vec)
|
|
111
117
|
- [Usage](#usage)
|
|
112
|
-
- [
|
|
113
|
-
- [
|
|
114
|
-
- [
|
|
118
|
+
- [Distillation](#distillation)
|
|
119
|
+
- [Inference](#inference)
|
|
120
|
+
- [Evaluation](#evaluation)
|
|
115
121
|
- [Model List](#model-list)
|
|
116
122
|
- [Results](#results)
|
|
117
123
|
- [Related Work](#related-work)
|
|
@@ -134,8 +140,8 @@ The easiest way to get started with Model2Vec is to download one of our [flagshi
|
|
|
134
140
|
```python
|
|
135
141
|
from model2vec import StaticModel
|
|
136
142
|
|
|
137
|
-
# Load a model from the HuggingFace hub (in this case the
|
|
138
|
-
model_name = "minishlab/
|
|
143
|
+
# Load a model from the HuggingFace hub (in this case the potion-base-8M model)
|
|
144
|
+
model_name = "minishlab/potion-base-8M"
|
|
139
145
|
model = StaticModel.from_pretrained(model_name)
|
|
140
146
|
|
|
141
147
|
# Make embeddings
|
|
@@ -169,7 +175,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
169
175
|
from sentence_transformers.models import StaticEmbedding
|
|
170
176
|
|
|
171
177
|
# Initialize a StaticEmbedding module
|
|
172
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
178
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
173
179
|
model = SentenceTransformer(modules=[static_embedding])
|
|
174
180
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
175
181
|
```
|
|
@@ -215,6 +221,9 @@ Model2vec has 3 modes:
|
|
|
215
221
|
|
|
216
222
|
For a technical deepdive into Model2Vec, please refer to our [blog post](https://huggingface.co/blog/Pringled/model2vec).
|
|
217
223
|
|
|
224
|
+
### Tokenlearn
|
|
225
|
+
|
|
226
|
+
Our flagship POTION models are pre-trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). This method is described in our [Tokenlearn blogpost](https://minishlab.github.io/tokenlearn_blogpost/).
|
|
218
227
|
|
|
219
228
|
|
|
220
229
|
## Usage
|
|
@@ -328,7 +337,7 @@ Inference works as follows. The example shows one of our own models, but you can
|
|
|
328
337
|
from model2vec import StaticModel
|
|
329
338
|
|
|
330
339
|
# Load a model from the HuggingFace hub, or a local one.
|
|
331
|
-
model_name = "minishlab/
|
|
340
|
+
model_name = "minishlab/potion-base-8M"
|
|
332
341
|
# You can optionally pass a token if you're loading a private model
|
|
333
342
|
model = StaticModel.from_pretrained(model_name, token=None)
|
|
334
343
|
|
|
@@ -352,7 +361,7 @@ from sentence_transformers import SentenceTransformer
|
|
|
352
361
|
from sentence_transformers.models import StaticEmbedding
|
|
353
362
|
|
|
354
363
|
# Initialize a StaticEmbedding module
|
|
355
|
-
static_embedding = StaticEmbedding.from_model2vec("minishlab/
|
|
364
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
356
365
|
model = SentenceTransformer(modules=[static_embedding])
|
|
357
366
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
358
367
|
```
|
|
@@ -370,7 +379,7 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
370
379
|
Our models can be evaluated using our [evaluation package](https://github.com/MinishLab/evaluation). Install the evaluation package with:
|
|
371
380
|
|
|
372
381
|
```bash
|
|
373
|
-
pip install
|
|
382
|
+
pip install git+https://github.com/MinishLab/evaluation.git@main
|
|
374
383
|
```
|
|
375
384
|
</details>
|
|
376
385
|
|
|
@@ -415,19 +424,19 @@ print(make_leaderboard(task_scores))
|
|
|
415
424
|
|
|
416
425
|
We provide a number of models that can be used out of the box. These models are available on the [HuggingFace hub](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e) and can be loaded using the `from_pretrained` method. The models are listed below.
|
|
417
426
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
| [
|
|
422
|
-
| [
|
|
423
|
-
| [
|
|
427
|
+
|
|
428
|
+
| Model | Language | Vocab | Sentence Transformer | Tokenizer Type | Params | Tokenlearn |
|
|
429
|
+
|-----------------------------------------------------------------------|-------------|------------------|-----------------------------------------------------------------|----------------|---------|------------|
|
|
430
|
+
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 7.5M | True |
|
|
431
|
+
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 3.7M | True |
|
|
432
|
+
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | Output | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | Subword | 1.8M | True |
|
|
433
|
+
| [M2V_multilingual_output](https://huggingface.co/minishlab/M2V_multilingual_output) | Multilingual | Output | [LaBSE](https://huggingface.co/sentence-transformers/LaBSE) | Subword | 471M | False |
|
|
424
434
|
|
|
425
435
|
|
|
426
436
|
## Results
|
|
427
437
|
|
|
428
438
|
We have performed extensive experiments to evaluate the performance of Model2Vec models. The results are documented in the [results](results/README.md) folder. The results are presented in the following sections:
|
|
429
439
|
- [MTEB Results](results/README.md#mteb-results)
|
|
430
|
-
- [Classification and Speed Benchmarks](results/README.md#classification-and-speed-benchmarks)
|
|
431
440
|
- [Ablations](results/README.md#ablations)
|
|
432
441
|
|
|
433
442
|
## Related work
|
|
@@ -435,7 +444,7 @@ We have performed extensive experiments to evaluate the performance of Model2Vec
|
|
|
435
444
|
If you are interested in fast small models, also consider looking at these techniques:
|
|
436
445
|
* [BPEmb](https://bpemb.h-its.org/): GLoVE embeddings trained on BPE-encoded Wikipedias. Huge inspiration to this project, multilingual, very fast. If you don't find a sentence transformer in the language you need, check this out.
|
|
437
446
|
* [fast-sentence-transformers](https://github.com/davidberenstein1957/fast-sentence-transformers): distillation using Model2Vec comes at a cost. If that cost is too steep for you, and you have access to a GPU, this package is for you. It automates the quantization and optimization of sentence transformers without loss of performance.
|
|
438
|
-
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings.
|
|
447
|
+
* [wordllama](https://github.com/dleemiller/WordLlama): Uses the _input_ embeddings of a LLama2 model and then performs contrastive learning on these embeddings. We think this is a bit overfit on MTEB, as the model is trained on MTEB datasets, and only evaluated on MTEB. Fun fact: this was invented at the same time as Model2Vec.
|
|
439
448
|
|
|
440
449
|
If you find other related work, please let us know.
|
|
441
450
|
|
|
@@ -15,6 +15,9 @@ assets/images/sentences_per_second_vs_average_score.png
|
|
|
15
15
|
assets/images/speed_vs_accuracy.png
|
|
16
16
|
assets/images/speed_vs_accuracy_v2.png
|
|
17
17
|
assets/images/speed_vs_accuracy_v3.png
|
|
18
|
+
assets/images/speed_vs_accuracy_v4.png
|
|
19
|
+
assets/images/speed_vs_mteb_score.png
|
|
20
|
+
assets/images/speed_vs_mteb_score_v2.png
|
|
18
21
|
assets/images/tutorial_ezlo.png
|
|
19
22
|
model2vec/__init__.py
|
|
20
23
|
model2vec/hf_utils.py
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
This page contains the experiments results of the Model2Vec project. The results are presented in the following sections:
|
|
4
4
|
- [MTEB Results](#mteb-results)
|
|
5
|
-
- [Classification and Speed Benchmarks](#classification-and-speed-benchmarks)
|
|
6
5
|
- [Ablations](#ablations)
|
|
7
6
|
|
|
8
7
|
## MTEB Results
|
|
@@ -10,16 +9,17 @@ This page contains the experiments results of the Model2Vec project. The results
|
|
|
10
9
|
Model2Vec is evaluated on MTEB, as well as two additional tasks: [PEARL](https://github.com/tigerchen52/PEARL) (a phrase representation task) and WordSim (a collection of _word_ similarity tasks). The results are shown in the table below.
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|:-----------------------|:---------:|:----------:|:------:|:------:|:---------:|:------:|:------:|:------:|:------:|:------:|:-------:|
|
|
12
|
+
| Model | Avg (All) | Avg (MTEB) | Class | Clust | PairClass | Rank | Ret | STS | Sum | Pearl | WordSim |
|
|
13
|
+
|:-----------------------|------------:|-------------:|--------:|--------:|------------:|-------:|-------:|-------:|-------:|--------:|----------:|
|
|
16
14
|
| all-MiniLM-L6-v2 | 56.08 | 56.09 | 62.62 | 41.94 | 82.37 | 58.04 | 41.95 | 78.90 | 30.81 | 60.83 | 49.91 |
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
15
|
+
| potion-base-8M | 50.54 | 50.03 | 64.44 | 32.93 | 76.62 | 49.73 | 31.71 | 73.24 | 29.28 | 53.54 | 50.75 |
|
|
16
|
+
| M2V_base_glove_subword | 49.06 | 46.69 | 61.27 | 30.03 | 74.71 | 49.15 | 27.16 | 69.09 | 30.08 | 56.82 | 57.99 |
|
|
17
|
+
| potion-base-4M | 48.87 | 48.23 | 62.19 | 31.47 | 75.37 | 48.75 | 29.11 | 72.19 | 28.89 | 52.55 | 49.21 |
|
|
18
|
+
| M2V_base_glove | 48.58 | 47.6 | 61.35 | 30.52 | 75.34 | 48.5 | 29.26 | 70.31 | 31.5 | 50.28 | 54.29 |
|
|
19
|
+
| M2V_base_output | 46.79 | 45.34 | 61.25 | 25.58 | 74.9 | 47.63 | 26.14 | 68.58 | 29.2 | 54.02 | 49.18 |
|
|
20
|
+
| potion-base-2M | 45.52 | 44.77 | 58.45 | 27.5 | 73.72 | 46.82 | 24.13 | 70.14 | 31.51 | 50.82 | 44.72 |
|
|
21
|
+
| GloVe_300d | 42.84 | 42.36 | 57.31 | 27.66 | 72.48 | 43.3 | 22.78 | 61.9 | 28.81 | 45.65 | 43.05 |
|
|
22
|
+
| BPEmb_50k_300d | 39.34 | 37.78 | 55.76 | 23.35 | 57.86 | 43.21 | 17.5 | 55.1 | 29.74 | 47.56 | 41.28 |
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
<details>
|
|
@@ -35,34 +35,12 @@ For readability, the MTEB task names are abbreviated as follows:
|
|
|
35
35
|
- Sum: Summarization
|
|
36
36
|
</details>
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## Classification and Speed Benchmarks
|
|
42
|
-
|
|
43
|
-
In addition to the MTEB evaluation, we evaluate Model2Vec on a number of classification datasets. These are used as additional evidence to avoid overfitting to the MTEB dataset and to benchmark the speed of the model. The results are shown in the table below.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
| Model | Average | SST2 | IMDB | TREC | AG News |
|
|
47
|
-
|:-----------------------|:-------:|:------:|:-----:|:------:|:-------:|
|
|
48
|
-
| bge-base-en-v1.5 | 90.00 | 91.54 | 91.88 | 85.16 | 91.45 |
|
|
49
|
-
| all-MiniLM-L6-v2 | 84.10 | 83.95 | 81.36 | 81.31 | 89.77 |
|
|
50
|
-
| M2V_base_output | 82.23 | 80.92 | 84.56 | 75.27 | 88.17 |
|
|
51
|
-
| M2V_base_glove_subword | 81.95 | 82.84 | 85.96 | 70.51 | 88.49 |
|
|
52
|
-
| BPEmb_50k_300d | 81.15 | 80.42 | 84.04 | 71.25 | 88.92 |
|
|
53
|
-
| M2V_base_glove | 80.76 | 83.07 | 85.24 | 66.12 | 88.61 |
|
|
54
|
-
| WL256 | 78.48 | 76.88 | 80.12 | 69.23 | 87.68 |
|
|
55
|
-
| GloVe_300d | 77.77 | 81.68 | 84.00 | 55.67 | 89.71 |
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
As can be seen, Model2Vec models outperform the GloVe, BPEmb, and WL256 models on all classification tasks, and are competitive with the all-MiniLM-L6-v2 model, while being much faster.
|
|
59
|
-
|
|
60
|
-
The figure below shows the relationship between the number of sentences per second and the average classification score. The circle sizes correspond to the number of parameters in the models (larger = more parameters).
|
|
61
|
-
This plot shows that the Model2Vec models are much faster than the other models, while still being competitive in terms of classification performance with the [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) model.
|
|
38
|
+
The figure below shows the relationship between the number of sentences per second and the average MTEB score. The circle sizes correspond to the number of parameters in the models (larger = more parameters).
|
|
39
|
+
This plot shows that the Model2Vec models are much faster than the other models, while still being competitive in terms of performance with the [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) model.
|
|
62
40
|
|
|
63
|
-
|  |
|
|
64
42
|
|:--:|
|
|
65
|
-
|*Figure: The average
|
|
43
|
+
|*Figure: The average MTEB score plotted against sentences per second. The circle size indicates model size.*|
|
|
66
44
|
|
|
67
45
|
|
|
68
46
|
## Ablations
|
|
@@ -24,7 +24,7 @@ def mock_tokenizer() -> Tokenizer:
|
|
|
24
24
|
return tokenizer
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
@pytest.fixture
|
|
27
|
+
@pytest.fixture(scope="function")
|
|
28
28
|
def mock_berttokenizer() -> AutoTokenizer:
|
|
29
29
|
"""Load the real BertTokenizerFast from the provided tokenizer.json file."""
|
|
30
30
|
return AutoTokenizer.from_pretrained("tests/data/test_tokenizer")
|
|
@@ -25,6 +25,27 @@ def test_initialization_token_vector_mismatch(mock_tokenizer: Tokenizer, mock_co
|
|
|
25
25
|
StaticModel(vectors=mock_vectors, tokenizer=mock_tokenizer, config=mock_config)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
def test_tokenize(mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, mock_config: dict[str, str]) -> None:
|
|
29
|
+
"""Test tokenization of a sentence."""
|
|
30
|
+
model = StaticModel(vectors=mock_vectors, tokenizer=mock_tokenizer, config=mock_config)
|
|
31
|
+
model._can_encode_fast = True
|
|
32
|
+
tokens_fast = model.tokenize(["word1 word2"])
|
|
33
|
+
model._can_encode_fast = False
|
|
34
|
+
tokens_slow = model.tokenize(["word1 word2"])
|
|
35
|
+
|
|
36
|
+
assert tokens_fast == tokens_slow
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_encode_batch_fast(
|
|
40
|
+
mock_vectors: np.ndarray, mock_berttokenizer: Tokenizer, mock_config: dict[str, str]
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Test tokenization of a sentence."""
|
|
43
|
+
if hasattr(mock_berttokenizer, "encode_batch_fast"):
|
|
44
|
+
del mock_berttokenizer.encode_batch_fast
|
|
45
|
+
model = StaticModel(vectors=mock_vectors, tokenizer=mock_berttokenizer, config=mock_config)
|
|
46
|
+
assert not model._can_encode_fast
|
|
47
|
+
|
|
48
|
+
|
|
28
49
|
def test_encode_single_sentence(
|
|
29
50
|
mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, mock_config: dict[str, str]
|
|
30
51
|
) -> None:
|
|
@@ -34,6 +55,17 @@ def test_encode_single_sentence(
|
|
|
34
55
|
assert encoded.shape == (2,)
|
|
35
56
|
|
|
36
57
|
|
|
58
|
+
def test_encode_single_sentence_empty(
|
|
59
|
+
mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, mock_config: dict[str, str]
|
|
60
|
+
) -> None:
|
|
61
|
+
"""Test encoding of a single empty sentence."""
|
|
62
|
+
model = StaticModel(vectors=mock_vectors, tokenizer=mock_tokenizer, config=mock_config)
|
|
63
|
+
model.normalize = True
|
|
64
|
+
encoded = model.encode("")
|
|
65
|
+
assert not np.isnan(encoded).any()
|
|
66
|
+
assert np.all(encoded == 0)
|
|
67
|
+
|
|
68
|
+
|
|
37
69
|
def test_encode_multiple_sentences(
|
|
38
70
|
mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, mock_config: dict[str, str]
|
|
39
71
|
) -> None:
|
|
@@ -505,11 +505,12 @@ wheels = [
|
|
|
505
505
|
|
|
506
506
|
[[package]]
|
|
507
507
|
name = "model2vec"
|
|
508
|
-
version = "0.
|
|
508
|
+
version = "0.3.1"
|
|
509
509
|
source = { editable = "." }
|
|
510
510
|
dependencies = [
|
|
511
511
|
{ name = "numpy" },
|
|
512
512
|
{ name = "rich" },
|
|
513
|
+
{ name = "safetensors" },
|
|
513
514
|
{ name = "setuptools" },
|
|
514
515
|
{ name = "tokenizers" },
|
|
515
516
|
{ name = "tqdm" },
|
|
@@ -542,6 +543,7 @@ requires-dist = [
|
|
|
542
543
|
{ name = "pytest-coverage", marker = "extra == 'dev'" },
|
|
543
544
|
{ name = "rich" },
|
|
544
545
|
{ name = "ruff", marker = "extra == 'dev'" },
|
|
546
|
+
{ name = "safetensors" },
|
|
545
547
|
{ name = "scikit-learn", marker = "extra == 'distill'" },
|
|
546
548
|
{ name = "setuptools" },
|
|
547
549
|
{ name = "tokenizers", specifier = ">=0.20" },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{model2vec-0.3.0 → model2vec-0.3.2}/assets/images/model2vec_model_diagram_transparant_dark.png
RENAMED
|
File without changes
|
{model2vec-0.3.0 → model2vec-0.3.2}/assets/images/model2vec_model_diagram_transparant_light.png
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|