andersborges commited on
Commit
cba10f9
·
verified ·
1 Parent(s): c53d96f

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. README.md +141 -3
  2. config.json +3 -0
  3. model.safetensors +3 -0
  4. modules.json +14 -0
  5. tokenizer.json +0 -0
README.md CHANGED
@@ -1,3 +1,141 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: model2vec
3
+ license: mit
4
+ model_name: model2vecdk-stem
5
+ tags:
6
+ - embeddings
7
+ - static-embeddings
8
+ - sentence-transformers
9
+ base_model:
10
+ - jealk/TTC-L2V-supervised-2
11
+ language:
12
+ - da
13
+ datasets:
14
+ - DDSC/nordic-embedding-training-data
15
+ repo_url: https://github.com/andersborges/dkmodel2vec
16
+ ---
17
+
18
+ # dkmodel2vec Model Card
19
+
20
+ This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of a [LLM2Vec](https://github.com/McGill-NLP/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.
21
+
22
+
23
+ ## Installation
24
+
25
+ Install model2vec using pip:
26
+ ```
27
+ pip install model2vec
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Using Model2Vec
33
+
34
+ The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
35
+
36
+ Load this model using the `from_pretrained` method:
37
+ ```python
38
+ from model2vec import StaticModel
39
+
40
+ # Load a pretrained Model2Vec model
41
+ model = StaticModel.from_pretrained("andersborges/model2vecdk")
42
+
43
+ # Compute text embeddings
44
+ embeddings = model.encode(["Jeg elsker kage"])
45
+ ```
46
+
47
+ ### Using Sentence Transformers
48
+
49
+ You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:
50
+
51
+ ```python
52
+ from sentence_transformers import SentenceTransformer
53
+
54
+ # Load a pretrained Sentence Transformer model
55
+ model = SentenceTransformer("andersborges/model2vecdk")
56
+
57
+ # Compute text embeddings
58
+ embeddings = model.encode(["Jeg elsker kage"])
59
+ ```
60
+
61
+ ## How it works
62
+
63
+ 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.
64
+
65
+ 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.
66
+
67
+ ## Training
68
+
69
+ See [repo](https://github.com/andersborges/dkmodel2vec). The model was trained with the following commands:
70
+
71
+ ```bash
72
+ # distill model
73
+ python scripts/hyperparams.py --output-dim 256 --sif-coefficient 0.0001 --strip-upper-case --strip-exotic --focus-pca --normalize-embeddings --vocab-size 150000
74
+
75
+ # dump features
76
+ python scripts/featurize.py --max-means 100000 --max-length 800
77
+
78
+ #fine tune
79
+ 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
80
+ ```
81
+
82
+ ## Evaluation
83
+ 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:
84
+
85
+ | Model | Accuracy |
86
+ | ------------------------------ | --------- |
87
+ | **model2vecdk-stem** | 0.861 |
88
+ | BM25 | 0.882 |
89
+ | multilingual-e5-large-instruct | 0.963 |
90
+
91
+ The model can be used as a retriever and it achieved the following performance on on the same 48351 triplets of data:
92
+
93
+
94
+ | Model | Recall@30 |
95
+ | ------------------------------ | --------- |
96
+ | **model2vecdk-stem** | 0.379 |
97
+ | BM25 (model2vecdk-stem tokenizer) | 0.342 |
98
+ | multilingual-e5-large-instruct | 0.51 |
99
+ | hybrid **model2vecdk-stem** + BM25 + RRF | 0.403 |
100
+
101
+
102
+ The model was also evaluated using the [Scandinavian Embedding Benchmark](https://kennethenevoldsen.github.io/scandinavian-embedding-benchmark/) and achieved the following performance:
103
+
104
+ | 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 |
105
+ |------|--------------------------------|----------------|--------------|--------------|--------------------|--------|------------------------|----------|-------|---------------------------|----------------|------------------|--------|---------------------|----------------|
106
+ | 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 |
107
+ | 2 | multilingual-e5-large-instruct | 0.66 | 7.75 | 64.57 | 55.02 | 67.14 | 45.33 | 39.52 | 70.60 | 82.48 | 71.89 | 77.51 | 50.18 | 93.69 | 77.23 |
108
+ | 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 |
109
+ | 42 | dfm-encoder-small-v1 (SimCSE) | 0.42 | 33.54 | 51.92 | 40.82 | 60.00 | 35.25 | 16.99 | 58.53 | 50.50 | 47.92 | 52.95 | 51.36 | 22.28 | 20.02 |
110
+ | 43 | **model2vecdk-stem** | 0.42 | 36.62 | 48.19 | 7.83 | 59.73 | 32.40 | 26.04 | 47.67 | 63.97 | 51.23 | 60.87 | 50.18 | 55.47 | 20.19 |
111
+ | 44 | xlm-roberta-large | 0.40 | 35.92 | 51.74 | 4.34 | 60.21 | 31.85 | 10.62 | 48.73 | 81.29 | 47.26 | 49.55 | 60.29 | 6.11 | 20.39 |
112
+
113
+
114
+
115
+
116
+
117
+ ## Additional Resources
118
+
119
+ - [Repo used to finetune](https://github.com/andersborges/dkmodel2vec)
120
+ - [Model2Vec Repo](https://github.com/MinishLab/model2vec)
121
+ - [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)
122
+ - [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)
123
+ - [Model2Vec Tutorials](https://github.com/MinishLab/model2vec/tree/main/tutorials)
124
+ - [Website](https://minishlab.github.io/)
125
+
126
+
127
+ ## Library Authors
128
+
129
+ Model2Vec was developed by the [Minish Lab](https://github.com/MinishLab) team consisting of [Stephan Tulkens](https://github.com/stephantul) and [Thomas van Dongen](https://github.com/Pringled).
130
+
131
+ ## Citation
132
+
133
+ Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
134
+ ```
135
+ @article{minishlab2024model2vec,
136
+ author = {Tulkens, Stephan and {van Dongen}, Thomas},
137
+ title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
138
+ year = {2024},
139
+ url = {https://github.com/MinishLab/model2vec}
140
+ }
141
+ ```
config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "normalize": true
3
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e994bef428c2e9e2ce0d46bcd964536636bea9848654297e361d149e28a0067a
3
+ size 194314328
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": ".",
6
+ "type": "sentence_transformers.models.StaticEmbedding"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Normalize",
12
+ "type": "sentence_transformers.models.Normalize"
13
+ }
14
+ ]
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff