This Model2Vec model is a distilled version of a LLM2Vec model. 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.
Installation
Install model2vec using pip:
pip install model2vec
Usage
Using Model2Vec
The Model2Vec library is the fastest and most lightweight way to run Model2Vec models.
Load this model using the from_pretrained method:
python
1from model2vec import StaticModel
23# Load a pretrained Model2Vec model4model = StaticModel.from_pretrained("andersborges/model2vecdk")56# Compute text embeddings7embeddings = model.encode(["Jeg elsker kage"])
1from sentence_transformers import SentenceTransformer
23# Load a pretrained Sentence Transformer model4model = SentenceTransformer("andersborges/model2vecdk")56# Compute text embeddings7embeddings = model.encode(["Jeg elsker kage"])
How it works
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.
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. During inference, we simply take the mean of all token embeddings occurring in a sentence.
Training
See repo. The model was trained with the following commands:
The model was evaluated on the 10% of unseen data from the DDSC/nordic-embedding-training-data which contains examples of triplets containing a query, a positive (relevant) document and a negative (not relevant) document. The model achieved the following performance:
Model
Accuracy
model2vecdk-stem
0.861
BM25
0.882
multilingual-e5-large-instruct
0.963
The model can be used as a retriever and it achieved the following performance on on the same 48351 triplets of data:
@article{minishlab2024model2vec,
author = {Tulkens, Stephan and {van Dongen}, Thomas},
title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
year = {2024},
url = {https://github.com/MinishLab/model2vec}
}