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: model2vec/modelcards/model_card_template.md
+34-13Lines changed: 34 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
# {{ model_name }} Model Card
6
6
7
-
This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of {% if base_model %}the {{ base_model }}(https://huggingface.co/{{ base_model }}){% else %}a{% endif %} Sentence Transformer. It uses static embeddings, allowing text embeddings to be computed orders of magnitude faster on both GPU and CPU. It is designed for applications where computational resources are limited or where real-time performance is critical.
7
+
This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of {% if base_model %}the {{ base_model }}(https://huggingface.co/{{ base_model }}){% else %}a{% endif %} Sentence Transformer. It uses static embeddings, allowing text embeddings to be computed orders of magnitude faster on both GPU and CPU. It is designed for applications where computational resources are limited or where real-time performance is critical. Model2Vec models are the smallest, fastest, and most performant static embedders available. The distilled models are up to 50 times smaller and 500 times faster than traditional Sentence Transformers.
8
8
9
9
10
10
## Installation
@@ -15,6 +15,11 @@ pip install model2vec
15
15
```
16
16
17
17
## Usage
18
+
19
+
### Using Model2Vec
20
+
21
+
The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
22
+
18
23
Load this model using the `from_pretrained` method:
19
24
```python
20
25
from model2vec import StaticModel
@@ -26,15 +31,29 @@ model = StaticModel.from_pretrained("{{ model_name }}")
26
31
embeddings = model.encode(["Example sentence"])
27
32
```
28
33
29
-
Alternatively, you can distill your own model using the `distill` method:
34
+
### Using Sentence Transformers
35
+
36
+
You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:
37
+
30
38
```python
31
-
from model2vec.distill import distill
39
+
from sentence_transformers import SentenceTransformer
40
+
41
+
# Load a pretrained Sentence Transformer model
42
+
model = SentenceTransformer("{{ model_name }}")
43
+
44
+
# Compute text embeddings
45
+
embeddings = model.encode(["Example sentence"])
46
+
```
47
+
48
+
### Distilling a Model2Vec model
32
49
33
-
# Choose a Sentence Transformer model
34
-
model_name ="BAAI/bge-base-en-v1.5"
50
+
You can distill a Model2Vec model from a Sentence Transformer model using the `distill` method. First, install the `distill` extra with `pip install model2vec[distill]`. Then, run the following code:
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. Best of all, you don't need any data to distill a model using Model2Vec.
46
65
47
-
It works by passing a vocabulary through a sentence transformer model, then reducing the dimensionality of the resulting embeddings using PCA, and finally weighting the embeddings using zipf weighting. During inference, we simply take the mean of all token embeddings occurring in a sentence.
66
+
It works by passing a vocabulary through a sentence transformer model, then reducing the dimensionality of the resulting embeddings using PCA, and finally weighting the embeddings using [SIF weighting](https://openreview.net/pdf?id=SyK00v5xx). During inference, we simply take the mean of all token embeddings occurring in a sentence.
48
67
49
68
## Additional Resources
50
69
51
-
-[All Model2Vec models on the hub](https://huggingface.co/models?library=model2vec)
0 commit comments