model2vec 0.3.2__py3-none-any.whl → 0.3.3__py3-none-any.whl
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/version.py +1 -1
- {model2vec-0.3.2.dist-info → model2vec-0.3.3.dist-info}/METADATA +94 -6
- {model2vec-0.3.2.dist-info → model2vec-0.3.3.dist-info}/RECORD +6 -6
- {model2vec-0.3.2.dist-info → model2vec-0.3.3.dist-info}/WHEEL +1 -1
- {model2vec-0.3.2.dist-info → model2vec-0.3.3.dist-info}/LICENSE +0 -0
- {model2vec-0.3.2.dist-info → model2vec-0.3.3.dist-info}/top_level.txt +0 -0
model2vec/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_triple__ = (0, 3,
|
|
1
|
+
__version_triple__ = (0, 3, 3)
|
|
2
2
|
__version__ = ".".join(map(str, __version_triple__))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: model2vec
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: The Fastest State-of-the-Art Static Embeddings in the World
|
|
5
5
|
Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomas123@live.nl>
|
|
6
6
|
License: MIT License
|
|
7
7
|
|
|
@@ -43,12 +43,13 @@ Classifier: Natural Language :: English
|
|
|
43
43
|
Requires-Python: >=3.9
|
|
44
44
|
Description-Content-Type: text/markdown
|
|
45
45
|
License-File: LICENSE
|
|
46
|
+
Requires-Dist: jinja2
|
|
46
47
|
Requires-Dist: numpy
|
|
47
48
|
Requires-Dist: rich
|
|
48
|
-
Requires-Dist: tqdm
|
|
49
|
-
Requires-Dist: tokenizers >=0.20
|
|
50
49
|
Requires-Dist: safetensors
|
|
51
50
|
Requires-Dist: setuptools
|
|
51
|
+
Requires-Dist: tokenizers >=0.20
|
|
52
|
+
Requires-Dist: tqdm
|
|
52
53
|
Provides-Extra: dev
|
|
53
54
|
Requires-Dist: black ; extra == 'dev'
|
|
54
55
|
Requires-Dist: ipython ; extra == 'dev'
|
|
@@ -61,6 +62,9 @@ Provides-Extra: distill
|
|
|
61
62
|
Requires-Dist: torch ; extra == 'distill'
|
|
62
63
|
Requires-Dist: transformers ; extra == 'distill'
|
|
63
64
|
Requires-Dist: scikit-learn ; extra == 'distill'
|
|
65
|
+
Provides-Extra: onnx
|
|
66
|
+
Requires-Dist: onnx ; extra == 'onnx'
|
|
67
|
+
Requires-Dist: torch ; extra == 'onnx'
|
|
64
68
|
|
|
65
69
|
|
|
66
70
|
<div align="center">
|
|
@@ -71,7 +75,7 @@ Requires-Dist: scikit-learn ; extra == 'distill'
|
|
|
71
75
|
</div>
|
|
72
76
|
|
|
73
77
|
<div align="center">
|
|
74
|
-
<h2>
|
|
78
|
+
<h2>The Fastest State-of-the-Art Static Embeddings in the World</h2>
|
|
75
79
|
</div>
|
|
76
80
|
|
|
77
81
|
<div align="center">
|
|
@@ -103,7 +107,7 @@ Requires-Dist: scikit-learn ; extra == 'distill'
|
|
|
103
107
|
<img src="assets/images/model2vec_model_diagram_transparant_light.png#gh-light-mode-only" width="90%">
|
|
104
108
|
</div>
|
|
105
109
|
|
|
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.
|
|
110
|
+
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. Our [best model](https://huggingface.co/minishlab/potion-base-8M) is the most performant static embedding model in the world. See our results [here](results/README.md), or dive in to see how it works.
|
|
107
111
|
|
|
108
112
|
|
|
109
113
|
## Updates & Announcements
|
|
@@ -118,6 +122,7 @@ Model2Vec is a technique to turn any sentence transformer into a really small st
|
|
|
118
122
|
- [Distillation](#distillation)
|
|
119
123
|
- [Inference](#inference)
|
|
120
124
|
- [Evaluation](#evaluation)
|
|
125
|
+
- [Integrations](#integrations)
|
|
121
126
|
- [Model List](#model-list)
|
|
122
127
|
- [Results](#results)
|
|
123
128
|
- [Related Work](#related-work)
|
|
@@ -420,6 +425,89 @@ print(make_leaderboard(task_scores))
|
|
|
420
425
|
```
|
|
421
426
|
</details>
|
|
422
427
|
|
|
428
|
+
### Integrations
|
|
429
|
+
<details>
|
|
430
|
+
<summary> Sentence Transformers </summary>
|
|
431
|
+
<br>
|
|
432
|
+
|
|
433
|
+
Model2Vec can be used directly in [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) using the `StaticEmbedding` module.
|
|
434
|
+
|
|
435
|
+
The following code snippet shows how to load a Model2Vec model into a Sentence Transformer model:
|
|
436
|
+
```python
|
|
437
|
+
from sentence_transformers import SentenceTransformer
|
|
438
|
+
from sentence_transformers.models import StaticEmbedding
|
|
439
|
+
|
|
440
|
+
# Initialize a StaticEmbedding module
|
|
441
|
+
static_embedding = StaticEmbedding.from_model2vec("minishlab/potion-base-8M")
|
|
442
|
+
model = SentenceTransformer(modules=[static_embedding])
|
|
443
|
+
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
The following code snippet shows how to distill a model directly into a Sentence Transformer model:
|
|
447
|
+
|
|
448
|
+
```python
|
|
449
|
+
from sentence_transformers import SentenceTransformer
|
|
450
|
+
from sentence_transformers.models import StaticEmbedding
|
|
451
|
+
|
|
452
|
+
static_embedding = StaticEmbedding.from_distillation("BAAI/bge-base-en-v1.5", device="cpu", pca_dims=256)
|
|
453
|
+
model = SentenceTransformer(modules=[static_embedding])
|
|
454
|
+
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
</details>
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
<details>
|
|
461
|
+
<summary> Transformers.js </summary>
|
|
462
|
+
|
|
463
|
+
<br>
|
|
464
|
+
|
|
465
|
+
To use a Model2Vec model in [transformers.js](https://github.com/huggingface/transformers.js), the following code snippet can be used as a starting point:
|
|
466
|
+
|
|
467
|
+
```javascript
|
|
468
|
+
import { AutoModel, AutoTokenizer, Tensor } from '@huggingface/transformers';
|
|
469
|
+
|
|
470
|
+
const modelName = 'minishlab/potion-base-8M';
|
|
471
|
+
|
|
472
|
+
const modelConfig = {
|
|
473
|
+
config: { model_type: 'model2vec' },
|
|
474
|
+
dtype: 'fp32',
|
|
475
|
+
revision: 'refs/pr/1'
|
|
476
|
+
};
|
|
477
|
+
const tokenizerConfig = {
|
|
478
|
+
revision: 'refs/pr/2'
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
const model = await AutoModel.from_pretrained(modelName, modelConfig);
|
|
482
|
+
const tokenizer = await AutoTokenizer.from_pretrained(modelName, tokenizerConfig);
|
|
483
|
+
|
|
484
|
+
const texts = ['hello', 'hello world'];
|
|
485
|
+
const { input_ids } = await tokenizer(texts, { add_special_tokens: false, return_tensor: false });
|
|
486
|
+
|
|
487
|
+
const cumsum = arr => arr.reduce((acc, num, i) => [...acc, num + (acc[i - 1] || 0)], []);
|
|
488
|
+
const offsets = [0, ...cumsum(input_ids.slice(0, -1).map(x => x.length))];
|
|
489
|
+
|
|
490
|
+
const flattened_input_ids = input_ids.flat();
|
|
491
|
+
const modelInputs = {
|
|
492
|
+
input_ids: new Tensor('int64', flattened_input_ids, [flattened_input_ids.length]),
|
|
493
|
+
offsets: new Tensor('int64', offsets, [offsets.length])
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const { embeddings } = await model(modelInputs);
|
|
497
|
+
console.log(embeddings.tolist()); // output matches python version
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Note that this requires that the Model2Vec has a `model.onnx` file and several required tokenizers file. To generate these for a model that does not have them yet, the following code snippet can be used:
|
|
501
|
+
|
|
502
|
+
```bash
|
|
503
|
+
python scripts/export_to_onnx.py --model_path <path-to-a-model2vec-model> --save_path "<path-to-save-the-onnx-model>"
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
<br>
|
|
508
|
+
</details>
|
|
509
|
+
|
|
510
|
+
|
|
423
511
|
## Model List
|
|
424
512
|
|
|
425
513
|
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.
|
|
@@ -3,14 +3,14 @@ model2vec/hf_utils.py,sha256=Z-_V2kYagBX7m9_--e2ZAGP4irfRpqIlBQgGwYswpoU,7772
|
|
|
3
3
|
model2vec/model.py,sha256=DuzsHaTBf0fTsp0ovVPzFs3EzDqGnFd5bGC94vumYuU,12031
|
|
4
4
|
model2vec/model_card_template.md,sha256=rQo4bE3VPXH3XB9OUCe7FCenhBc4wv6L1sNURVT4Sro,2747
|
|
5
5
|
model2vec/utils.py,sha256=AyKPu7w7XO2DhJEBN8NrO53vZj5rZpbwWJNxjagCKIk,2684
|
|
6
|
-
model2vec/version.py,sha256=
|
|
6
|
+
model2vec/version.py,sha256=azyH_mT8eRQuggt3kh7T7FSoYvfnwcLHjURqaYWVK0Q,84
|
|
7
7
|
model2vec/distill/__init__.py,sha256=KpFRhafXVceM1xhorJhXbd8OnX8dwOGcWMbXglZxd4U,330
|
|
8
8
|
model2vec/distill/distillation.py,sha256=yDdIW4nqR5Vw4cUYL4p7hrJnIzZWO9fV9LiqZHe_z8s,11504
|
|
9
9
|
model2vec/distill/inference.py,sha256=QgHAEkLoeq-jPyKnFTB6p6Ry-ZGZqonkZaEg2S7VTOY,6123
|
|
10
10
|
model2vec/distill/tokenizer.py,sha256=xtVsMTxquqTufoP9z39C4Itg2LLcGViqeguz-M7y-u8,4293
|
|
11
11
|
model2vec/distill/utils.py,sha256=lzGyvFUO8mUcz63wnTRimGhQCsXzqnQfG5vRRKDGxic,721
|
|
12
|
-
model2vec-0.3.
|
|
13
|
-
model2vec-0.3.
|
|
14
|
-
model2vec-0.3.
|
|
15
|
-
model2vec-0.3.
|
|
16
|
-
model2vec-0.3.
|
|
12
|
+
model2vec-0.3.3.dist-info/LICENSE,sha256=sCFPFI7OrnOfkWIJ54z-FXEsS4EMi8nUS2wtHRYWqrY,1074
|
|
13
|
+
model2vec-0.3.3.dist-info/METADATA,sha256=1kDQ4KrbGMom8ZKMx3b0DJ4XpUcJtkQsAmdEfZWPd0o,25800
|
|
14
|
+
model2vec-0.3.3.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
15
|
+
model2vec-0.3.3.dist-info/top_level.txt,sha256=cprhxJcbtkFiydp0BGvdCVNupTWg07-3p93jFStc78g,10
|
|
16
|
+
model2vec-0.3.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|