You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-67Lines changed: 83 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,35 +51,35 @@ Model2Vec is a technique to turn any sentence transformer into a really small st
51
51
-[Main Features](#main-features)
52
52
-[What is Model2Vec?](#what-is-model2vec)
53
53
-[Usage](#usage)
54
-
-[Distillation](#distillation)
55
54
-[Inference](#inference)
55
+
-[Distillation](#distillation)
56
56
-[Evaluation](#evaluation)
57
-
-[Integrations](#integrations)
57
+
-[Integrations](#integrations)
58
58
-[Model List](#model-list)
59
59
-[Results](#results)
60
60
-[Related Work](#related-work)
61
61
-[Citing](#citing)
62
62
63
63
## Quickstart
64
64
65
-
Install the package and all required extras with:
65
+
Install the package with:
66
+
66
67
```bash
67
-
pip install model2vec[distill]
68
+
pip install model2vec
68
69
```
69
70
70
-
If you want a light-weight version of the package which only requires `numpy`, omit the `distill` extra. This means you can't distill your own models, but you can use pre-trained models. This is useful for inference pipelines.
71
+
This will install the base inference package, which only depends on `numpy` and a few other minor dependencies. If you want to distill your own models, you can install the distillation extras with:
71
72
72
73
```bash
73
-
pip install model2vec
74
+
pip install model2vec[distill]
74
75
```
75
76
76
-
The easiest way to get started with Model2Vec is to download one of our [flagship models from the HuggingFace hub](https://huggingface.co/minishlab). These models are pre-trained and ready to use. The following code snippet shows how to load a model and make embeddings:
77
+
The easiest way to get started with Model2Vec is to load one of our [flagship models from the HuggingFace hub](https://huggingface.co/minishlab). These models are pre-trained and ready to use. The following code snippet shows how to load a model and make embeddings:
77
78
```python
78
79
from model2vec import StaticModel
79
80
80
81
# Load a model from the HuggingFace hub (in this case the potion-base-8M model)
81
-
model_name ="minishlab/potion-base-8M"
82
-
model = StaticModel.from_pretrained(model_name)
82
+
model = StaticModel.from_pretrained("minishlab/potion-base-8M")
83
83
84
84
# Make embeddings
85
85
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
@@ -94,11 +94,8 @@ Instead of using one of our models, you can distill your own Model2Vec model fro
@@ -134,11 +131,12 @@ Model2Vec has the following features:
134
131
135
132
-**Small**: reduces the size of a Sentence Transformer model by a factor of 15, from 120M params, down to 7.5M (30 MB on disk, making it the smallest model on [MTEB](https://huggingface.co/spaces/mteb/leaderboard)!).
136
133
-**Static, but better**: smaller than GLoVe and BPEmb, but [much more performant](results/README.md), even with the same vocabulary.
134
+
-**Lightweight inference**: the base package's only major dependency is `numpy`.
137
135
-**Fast distillation**: make your own model in 30 seconds.
138
136
-**Fast inference**: up to 500 times faster on CPU than the original model. Go green or go home.
139
137
-**No data needed**: Distillation happens directly on the token level, so no dataset is needed.
140
138
-**Simple to use**: An easy to use interface for distilling and inferencing.
141
-
-**Integrated into Sentence Transformers**: Model2Vec can be used directly in [Sentence Transformers](https://github.com/UKPLab/sentence-transformers).
139
+
-**Integrated into Sentence Transformers and txtai**: Model2Vec can be used directly in [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [txtai](https://github.com/neuml/txtai).
142
140
-**Bring your own model**: Can be applied to any Sentence Transformer model.
143
141
-**Bring your own vocabulary**: Can be applied to any vocabulary, allowing you to use your own domain-specific vocabulary. Need biomedical? Just get a medical dictionary, a biomedical model, and inference it.
144
142
-**Multi-lingual**: Use any language. Need a French model? [Pick one](https://huggingface.co/models?library=sentence-transformers&language=fr&sort=trending). Need multilingual? [Here you go](https://huggingface.co/sentence-transformers/LaBSE).
@@ -166,6 +164,46 @@ Our flagship POTION models are pre-trained using [Tokenlearn](https://github.com
166
164
## Usage
167
165
168
166
167
+
### Inference
168
+
169
+
<details>
170
+
<summary> Inference using pretrained model </summary>
171
+
<br>
172
+
173
+
Inference works as follows. The example shows one of our own models, but you can also just load a local one, or another one from the hub.
174
+
```python
175
+
from model2vec import StaticModel
176
+
177
+
# Load a model from the Hub. You can optionally pass a token when loading a private model
178
+
model = StaticModel.from_pretrained(model_name="minishlab/potion-base-8M", token=None)
179
+
180
+
# Make embeddings
181
+
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
182
+
183
+
# Make sequences of token embeddings
184
+
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
185
+
```
186
+
</details>
187
+
188
+
189
+
<details>
190
+
<summary> Inference using the Sentence Transformers library </summary>
191
+
<br>
192
+
193
+
The following code snippet shows how to use a Model2Vec model in the [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) library. This is useful if you want to use the model in a Sentence Transformers pipeline.
194
+
195
+
```python
196
+
from sentence_transformers import SentenceTransformer
197
+
from sentence_transformers.models import StaticEmbedding
<summary> Inference using pretrained model </summary>
270
-
<br>
271
-
272
-
Inference works as follows. The example shows one of our own models, but you can also just load a local one, or another one from the hub.
273
-
```python
274
-
from model2vec import StaticModel
275
-
276
-
# Load a model from the HuggingFace hub, or a local one.
277
-
model_name ="minishlab/potion-base-8M"
278
-
# You can optionally pass a token if you're loading a private model
279
-
model = StaticModel.from_pretrained(model_name, token=None)
280
-
281
-
# Make embeddings
282
-
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
283
-
284
-
# Make sequences of token embeddings
285
-
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
286
-
```
287
-
</details>
288
-
289
-
290
-
<details>
291
-
<summary> Inference using the Sentence Transformers library </summary>
292
-
<br>
293
-
294
-
The following code snippet shows how to use a Model2Vec model in the [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) library. This is useful if you want to use the model in a Sentence Transformers pipeline.
295
-
296
-
```python
297
-
from sentence_transformers import SentenceTransformer
298
-
from sentence_transformers.models import StaticEmbedding
@@ -389,6 +380,31 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
389
380
</details>
390
381
391
382
383
+
<details>
384
+
<summary> Txtai </summary>
385
+
<br>
386
+
387
+
Model2Vec can be used in [txtai](https://github.com/neuml/txtai) for text embeddings, nearest-neighbors search, and any of the other functionalities that txtai offers. The following code snippet shows how to use Model2Vec in txtai:
0 commit comments