dkmodel2vec Model Card
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:
from model2vec import StaticModel
# Load a pretrained Model2Vec model
model = StaticModel.from_pretrained("andersborges/model2vecdk")
# Compute text embeddings
embeddings = model.encode(["Jeg elsker kage"])
Using Sentence Transformers
You can also use the Sentence Transformers library to load and use the model:
from sentence_transformers import SentenceTransformer
# Load a pretrained Sentence Transformer model
model = SentenceTransformer("andersborges/model2vecdk")
# Compute text embeddings
embeddings = 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:
# distill model
python scripts/hyperparams.py --output-dim 256 --sif-coefficient 0.0001 --strip-upper-case --strip-exotic --focus-pca --normalize-embeddings --vocab-size 150000
# dump features
python scripts/featurize.py --max-means 100000 --max-length 800
#fine tune
python scripts/finetune.py --model2vec-model-name scripts/models/dk-llm2vec-model2vec-dim256_sif0.0001_strip_upper_case_strip_exotic_focus_pca_stem_normalize_embeddings-features_100000_max_length_800 --data-path features/features_100000_max_length_800
Evaluation
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:
| Model | Recall@30 |
|---|---|
| model2vecdk-stem | 0.379 |
| BM25 (model2vecdk-stem tokenizer) | 0.342 |
| multilingual-e5-large-instruct | 0.51 |
| hybrid model2vecdk-stem + BM25 + RRF | 0.403 |
The model was also evaluated using the Scandinavian Embedding Benchmark and achieved the following performance:
| Rank | Model | Average Score | Average Rank | Angry Tweets | Bornholm Parallel | DKHate | Da Political Comments | DanFEVER | LCC | Language Identification | Massive Intent | Massive Scenario | ScaLA | TV2Nord Retrieval | Twitterhjerne |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | TTC-L2V-supervised-2 | 0.68 | 4.75 | 67.09 | 54.59 | 69.00 | 45.84 | 38.31 | 73.67 | 88.61 | 74.80 | 78.35 | 53.04 | 92.79 | 85.02 |
| 2 | multilingual-e5-large-instruct | 0.66 | 7.67 | 64.57 | 55.02 | 67.14 | 45.33 | 39.52 | 70.60 | 82.48 | 71.89 | 77.51 | 50.18 | 93.69 | 77.23 |
| 3 | text-embedding-3-large | 0.64 | 8.92 | 57.80 | 43.34 | 70.21 | 43.41 | 39.61 | 58.07 | 79.74 | 69.27 | 75.92 | 50.69 | 95.20 | 81.08 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 42 | dfm-encoder-small-v1 (SimCSE) | 0.42 | 33.62 | 51.92 | 40.82 | 60.00 | 35.25 | 16.99 | 58.53 | 50.50 | 47.92 | 52.95 | 51.36 | 22.28 | 20.02 |
| 43 | NEW: model2vecdk-stem | 0.42 | 37.67 | 46.18 | 9.17 | 60.76 | 29.86 | 27.69 | 43.93 | 61.55 | 48.78 | 55.90 | 50.12 | 57.34 | 25.56 |
| 44 | xlm-roberta-large | 0.40 | 36.00 | 51.74 | 4.34 | 60.21 | 31.85 | 10.62 | 48.73 | 81.29 | 47.26 | 49.55 | 60.29 | 6.11 | 20.39 |
Additional Resources
- Repo used to finetune
- Model2Vec Repo
- Model2Vec Base Models
- Model2Vec Results
- Model2Vec Tutorials
- Website
Library Authors
Model2Vec was developed by the Minish Lab team consisting of Stephan Tulkens and Thomas van Dongen.
Citation
Please cite the Model2Vec repository if you use this model in your work.
@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}
}
- Downloads last month
- 52
Model tree for andersborges/model2vecdk-stem
Base model
meta-llama/Meta-Llama-3-8B