File size: 4,242 Bytes
b8e37e3
 
 
 
 
 
 
 
 
 
 
 
 
9ac3c9f
b8e37e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ac3c9f
b8e37e3
9ac3c9f
b8e37e3
9ac3c9f
 
 
 
 
b8e37e3
9ac3c9f
b8e37e3
9ac3c9f
 
 
 
 
 
 
b8e37e3
9ac3c9f
b8e37e3
 
 
9ac3c9f
b8e37e3
9ac3c9f
 
b8e37e3
 
 
 
 
9ac3c9f
 
 
 
 
 
 
 
 
b8e37e3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
library_name: model2vec
license: mit
model_name: potion-256d-compact-v3
tags:
- embeddings
- static-embeddings
- sentence-transformers
- model2vec
---

# potion-256d-compact-v3 Model Card

This [Model2Vec](https://github.com/MinishLab/model2vec) model is an improved v3 compact static embedding model, pre-trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn) with contrastive learning and born-again self-distillation. It is distilled from [mixedbread-ai/mxbai-embed-large-v1](https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1). 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. This compact variant uses a curated 29.5K vocabulary for roughly half the size of the full [potion-256d-v3](https://huggingface.co/blobbybob/potion-256d-v3) model, improving on [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) by +2.16 CatAVG.

## Installation

Install model2vec using pip:
```
pip install model2vec
```

## Usage

Load this model using the `from_pretrained` method:
```python
from model2vec import StaticModel

# Load a pretrained Model2Vec model
model = StaticModel.from_pretrained("blobbybob/potion-256d-compact-v3")

# Compute text embeddings
embeddings = model.encode(["Example sentence"])
```

## How it works

Model2vec creates a small, static model that outperforms other static embedding models by a large margin on all tasks on [MTEB](https://huggingface.co/spaces/mteb/leaderboard). This model is pre-trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). It's created using the following steps:

- **Distillation:** a model is distilled from [mxbai-embed-large-v1](https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1) at 256 dimensions using Model2Vec with a curated 29.5K token vocabulary.
- **Training data creation:** the teacher model is used to create training data by encoding 500K sentences from C4.
- **Contrastive training:** the distilled model is trained on the training data using Tokenlearn with contrastive loss.
- **Born-again self-distillation:** the trained model is further improved by distilling from itself (alpha=1.0), gaining +0.5 CatAVG.
- **Power normalization:** embeddings are transformed with sign(E) * |E|^0.7 for improved isotropy.

## Results

| Model | STS | Classification | PairClassification | CatAVG |
|:------|----:|---------------:|-------------------:|-------:|
| **[potion-256d-compact-v3](https://huggingface.co/blobbybob/potion-256d-compact-v3)** | **79.75** | **62.74** | **73.57** | **72.02** |
| [potion-256d-v3](https://huggingface.co/blobbybob/potion-256d-v3) | 79.32 | 63.23 | 73.97 | 72.17 |
| [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) | 78.97 | 61.42 | 69.18 | 69.86 |
| [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) | 78.95 | 69.25 | 82.37 | 74.65 |
| [GloVe 300d](https://huggingface.co/sentence-transformers/average_word_embeddings_glove.6B.300d) | 61.52 | 62.73 | 72.48 | 61.45 |

The results show that **potion-256d-compact-v3** outperforms potion-base-32M by +2.16 CatAVG at a comparable model size, with only -0.15 CatAVG tradeoff compared to the full potion-256d-v3 model.

## Additional Resources

- [All Model2Vec models on the hub](https://huggingface.co/models?library=model2vec)
- [Model2Vec Repo](https://github.com/MinishLab/model2vec)
- [Tokenlearn repo](https://github.com/MinishLab/tokenlearn)
- [Model2Vec Results](https://github.com/MinishLab/model2vec/blob/main/results/README.md)
- [Model2Vec Tutorials](https://github.com/MinishLab/model2vec/tree/main/tutorials)

## Citation

Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
```bibtex
@software{minishlab2024model2vec,
  author       = {Stephan Tulkens and {van Dongen}, Thomas},
  title        = {Model2Vec: Fast State-of-the-Art Static Embeddings},
  year         = {2024},
  publisher    = {Zenodo},
  doi          = {10.5281/zenodo.17270888},
  url          = {https://github.com/MinishLab/model2vec},
  license      = {MIT}
}
```