Pringled commited on
Commit
7873955
·
verified ·
1 Parent(s): 0a07cdd

Card: feature-extraction and sentence-similarity tags, as the other blink models

Browse files
Files changed (1) hide show
  1. README.md +204 -202
README.md CHANGED
@@ -1,202 +1,204 @@
1
- ---
2
- language:
3
- - code
4
- license: mit
5
- library_name: model2vec
6
- tags:
7
- - model2vec
8
- - embeddings
9
- - code
10
- - retrieval
11
- - static-embeddings
12
- - sentence-transformers
13
- datasets:
14
- - minishlab/cornstack-queries-docs
15
- - minishlab/tokenlearn-cornstack-docs-coderankembed-v2
16
- - minishlab/tokenlearn-cornstack-queries-coderankembed-v2
17
- - minishlab/coir-train-hard-negatives
18
- - minishlab/cornstack-hard-negatives
19
- - nomic-ai/cornstack-python-v1
20
- - nomic-ai/cornstack-java-v1
21
- - nomic-ai/cornstack-javascript-v1
22
- - nomic-ai/cornstack-go-v1
23
- - nomic-ai/cornstack-php-v1
24
- - nomic-ai/cornstack-ruby-v1
25
- ---
26
-
27
- <div align="center">
28
- <img src="figures/sparkle_2_blink.svg" alt="blink logo" width="325">
29
- </div>
30
-
31
- blink-code-16M is a fast static embedding model for code retrieval by [Minish](https://minish.ai): a single 62,500 × 256 token embedding table (16.0M parameters, 64MB in float32) with mean pooling. It supersedes [`potion-code-16M-v2`](https://huggingface.co/minishlab/potion-code-16M-v2): it's the same size and better on every benchmark we measured, improving CoIR from 40.67 to 46.82.
32
- Static models are models without any active parameters; all model parameters are just embedding parameters. Because of this, they are many orders of magnitude faster than transformers. Although this comes at a cost, this cost is much lower than you would expect.
33
-
34
- ## Usage
35
-
36
- With [model2vec](https://github.com/MinishLab/model2vec):
37
-
38
- ```python
39
- from model2vec import StaticModel
40
-
41
- model = StaticModel.from_pretrained("minishlab/blink-code-16M")
42
- embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
43
- ```
44
-
45
- With [model2vec-rs](https://github.com/MinishLab/model2vec-rs)
46
-
47
- ```rust
48
- use anyhow::Result;
49
- use model2vec_rs::model::StaticModel;
50
-
51
- fn main() -> Result<()> {
52
- let model = StaticModel::from_pretrained(
53
- "minishlab/blink-code-16M",
54
- )?;
55
-
56
- let sentences = vec![
57
- "read a json file".to_string(),
58
- "fn read_json(path: &str) -> Value".to_string(),
59
- ];
60
-
61
- let embeddings = model.encode(&sentences);
62
- println!("Generated {} embeddings.", embeddings.len());
63
-
64
- Ok(())
65
- }
66
- ```
67
-
68
- With [Sentence Transformers](https://www.sbert.net):
69
-
70
- ```python
71
- from sentence_transformers import SentenceTransformer
72
-
73
- model = SentenceTransformer("minishlab/blink-code-16M")
74
- embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
75
- ```
76
-
77
- ## Results
78
-
79
- ![CoIR mean against RTEB(Code) mean for blink-code-16M, BM25 and the potion-code models](figures/coir_vs_rteb.png)
80
-
81
- All scores are nDCG@10 from mteb 2.27.1.
82
-
83
- ### CoIR
84
-
85
- [CoIR](https://github.com/CoIR-team/coir) is the standard code retrieval benchmark: 10 tasks covering text-to-code, code-to-code, code-to-text and code Q&A.
86
-
87
- | Model | Mean | Apps | CodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
88
- |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
89
- | **blink-code-16M** | **46.82** | **6.08** | **53.59** | 51.72 | 65.87 | 51.42 | **57.31** | **38.34** | 24.34 | 64.03 | **55.45** |
90
- | BM25 | 42.31 | 4.76 | 40.86 | **59.19** | **68.15** | **53.97** | 47.78 | 34.42 | 18.75 | **70.26** | 24.94 |
91
- | potion-code-16M-v2 | 40.67 | 5.05 | 46.34 | 46.50 | 54.40 | 43.70 | 48.55 | 33.48 | **24.39** | 60.13 | 44.12 |
92
- | potion-code-16M | 38.78 | 4.11 | 43.10 | 45.09 | 52.24 | 43.09 | 45.40 | 32.81 | 22.19 | 58.10 | 41.66 |
93
-
94
- The potion-code models ship with a 512-token cap in their tokenizer, which mteb applies: potion-code-16M-v2's card reports 39.08 with it, against 40.67 here without it.
95
-
96
- #### Summary
97
-
98
- - **Mean:** blink-code-16M scores 46.82, 6.15 points above potion-code-16M-v2 and 4.51 above BM25.
99
- - **By task:** it's best on 5 of 10 tasks. BM25 is best on CodeFeedbackMT, CodeFeedbackST, CodeSearchNetCC and StackOverflow, and potion-code-16M-v2 on CosQA (24.39 against 24.34).
100
-
101
- ### RTEB(Code)
102
-
103
- [RTEB(Code)](https://huggingface.co/blog/rteb) is the code part of the Retrieval Embedding Benchmark. None of it is in our training data.
104
-
105
- - **DS1000**: data science tasks to their solution (pandas, numpy, matplotlib, scikit-learn, scipy).
106
- - **HumanEval** and **MBPP**: a programming problem to its Python solution.
107
- - **WikiSQL**: a question about a table to its SQL query.
108
- - **FreshStack**: programming tasks to their solution in Python, JavaScript or Go.
109
- - **SWE-bench**: a GitHub issue to the source files that need changing to resolve it (SWE-bench Verified).
110
-
111
- We use the public English tasks. Apps is left out (it is in CoIR above) and Code1 is one of RTEB's private sets.
112
-
113
- | Model | Mean | DS1000 | HumanEval | MBPP | WikiSQL | FreshStack | SWE-bench |
114
- |---|---:|---:|---:|---:|---:|---:|---:|
115
- | **blink-code-16M** | **34.67** | 29.17 | **64.84** | **56.75** | 30.94 | 22.92 | 3.39 |
116
- | BM25 | 29.90 | **41.45** | 38.47 | 11.64 | **52.16** | **27.89** | **7.76** |
117
- | potion-code-16M-v2 | 29.21 | 20.83 | 55.31 | 51.53 | 22.96 | 21.14 | 3.50 |
118
- | potion-code-16M | 27.34 | 20.14 | 49.95 | 47.03 | 22.54 | 21.55 | 2.83 |
119
-
120
- #### Summary
121
-
122
- - **Mean:** blink-code-16M scores 34.67, against 29.90 for BM25 and 29.21 for potion-code-16M-v2.
123
- - **By task:** it's far ahead on HumanEval and MBPP, where a short description has to find code it shares few words with (MBPP: 56.75 against 11.64 for BM25). BM25 is best on DS1000, WikiSQL, FreshStack and SWE-bench.
124
- - **Against potion-code-16M-v2:** better on 5 of 6 tasks; SWE-bench is below 4 for both.
125
-
126
- ### CodeEditSearch
127
-
128
- [CodeEditSearch](https://huggingface.co/datasets/cassanof/CodeEditSearch) retrieves a code change (a diff) from its commit message, 1,000 commits per language from CommitPackFT. Seven of the 13 languages (TypeScript, C, C++, Rust, Swift, Scala, Shell) are not in our training data.
129
-
130
- | Model | Mean | Python | JS | TS | Go | Ruby | Java | PHP | C | C++ | Rust | Swift | Scala | Shell |
131
- |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
132
- | **blink-code-16M** | **49.58** | **53.1** | **54.5** | **54.7** | **52.6** | **54.0** | **51.7** | **50.7** | **41.4** | **41.8** | **44.2** | **49.6** | **47.5** | 48.8 |
133
- | potion-code-16M-v2 | 46.50 | 51.6 | 51.2 | 50.5 | 49.3 | 50.6 | 49.5 | 47.2 | 37.4 | 36.4 | 43.7 | 47.8 | 44.2 | 45.0 |
134
- | potion-code-16M | 45.06 | 49.7 | 50.1 | 49.6 | 47.2 | 49.3 | 48.3 | 46.1 | 36.5 | 34.3 | 43.8 | 47.1 | 40.6 | 43.4 |
135
- | BM25 | 44.39 | 48.7 | 47.8 | 47.9 | 48.2 | 48.9 | 41.3 | 41.3 | 35.0 | 37.9 | 44.0 | 39.3 | 44.6 | **52.0** |
136
-
137
- #### Summary
138
-
139
- - **Mean:** blink-code-16M scores 49.58, against 46.50 for potion-code-16M-v2 and 44.39 for BM25.
140
- - **Languages we didn't train on:** it beats potion-code-16M-v2 on all 13 languages, including the seven unseen ones; the largest gains are on C++ (+5.4), TypeScript (+4.2) and C (+4.0). BM25 is best on Shell.
141
-
142
- ## Training
143
-
144
- We followed a four-step procedure, starting from [potion-code-16M-v2's recipe](https://huggingface.co/minishlab/potion-code-16M-v2).
145
-
146
- ### 1. Tokenizer and distillation
147
-
148
- We train a 62,500-token uncased WordPiece tokenizer on 1.2M queries and documents from [CornStack](https://huggingface.co/datasets/minishlab/cornstack-queries-docs) (Go, Java, JavaScript, PHP, Python and Ruby) plus the 4.1M texts of the [CoIR train splits](https://huggingface.co/datasets/minishlab/coir-train-hard-negatives). We then distill [CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) into it with Model2Vec, reducing the dimensions to 256 with PCA and applying SIF weighting.
149
-
150
- ### 2. Tokenlearn
151
-
152
- We then distill CodeRankEmbed into the model with Tokenlearn, on 1.2M CornStack [documents](https://huggingface.co/datasets/minishlab/tokenlearn-cornstack-docs-coderankembed-v2) and [queries](https://huggingface.co/datasets/minishlab/tokenlearn-cornstack-queries-coderankembed-v2) embedded by CodeRankEmbed.
153
-
154
- ### 3. Contrastive training
155
-
156
- We train with a contrastive loss (in-batch negatives plus one hard negative per pair) for 3 epochs, with batch size 4096, learning rate 0.05 and a cosine schedule, on 4.5M triplets from two datasets we built for this model:
157
-
158
- - [**coir-train-hard-negatives**](https://huggingface.co/datasets/minishlab/coir-train-hard-negatives) (2.09M): query and document pairs from the train splits of the CoIR tasks, with hard negatives mined in two rounds. We first mine them with CodeRankEmbed and train on them with this recipe. We then mine them again with the model this produces and train once more: a static model's negatives are closer to what is actually hard for a static model than those of a transformer (see the ablation below).
159
- - [**cornstack-hard-negatives**](https://huggingface.co/datasets/minishlab/cornstack-hard-negatives) (2.4M, 400k per language): triplets from [CornStack](https://huggingface.co/datasets/nomic-ai/cornstack-python-v1), using the highest-scoring of CornStack's own mined negatives that still scores below the document.
160
-
161
- **Decontamination.** CoIR's train and test splits share queries and documents, so we remove every triplet whose query is a CoIR test query, or whose document or negative is a relevant CoIR test document (matched after whitespace normalization). This removes 19,073 CoIR train pairs (0.9%) and 6 CornStack triplets. See the dataset cards for details.
162
-
163
- ### 4. Weight averaging
164
-
165
- The final model is 20% of the Tokenlearn model from step 2 and 80% of the contrastive model from step 3.
166
-
167
- ### Ablation
168
-
169
- To show the effect of each step of our training process, this table shows how much each one adds on our benchmarks (in brackets: the change from the row above). Each row adds one thing to the row above it.
170
-
171
- | Step | CoIR | RTEB(Code) | CodeEditSearch | semble |
172
- |---|---:|---:|---:|---:|
173
- | 1. Distill CodeRankEmbed | 32.61 | 25.09 | 35.72 | 0.559 |
174
- | 2. + Our code tokenizer with an expanded vocabulary | 34.50 (+1.89) | 23.82 (-1.27) | 39.82 (+4.10) | 0.609 (+0.050) |
175
- | 3. + Tokenlearn | 40.03 (+5.53) | 26.75 (+2.93) | 44.23 (+4.41) | 0.638 (+0.029) |
176
- | 4. + Contrastive training on CornStack | 42.60 (+2.57) | 33.41 (+6.66) | 49.81 (+5.58) | 0.653 (+0.015) |
177
- | 5. + CoIR train pairs | 45.92 (+3.32) | 34.60 (+1.19) | 49.58 (-0.23) | 0.642 (-0.011) |
178
- | 6. + Hard negatives from CodeRankEmbed | 46.19 (+0.27) | 34.42 (-0.18) | 49.20 (-0.38) | 0.644 (+0.002) |
179
- | 7. + Hard negatives re-mined with the step-6 model | 46.74 (+0.55) | 34.88 (+0.46) | 49.20 (0.00) | 0.643 (-0.001) |
180
- | 8. + Weight averaging | **46.82** (+0.08) | **34.67** (-0.21) | **49.58** (+0.38) | **0.652** (+0.009) |
181
-
182
- [semble](https://github.com/MinishLab/semble) is our code search library; we run only its semantic benchmark, to show the isolated effect of the model. We don't include semble results for the other models because trained models all saturate around 0.65, but we include it here as a control task for the effect of each step.
183
-
184
- ## Library Authors
185
-
186
- Model2Vec was developed by the [Minish](https://minish.ai) team consisting of [Stephan Tulkens](https://github.com/stephantul) and [Thomas van Dongen](https://github.com/Pringled).
187
-
188
- ## Citation
189
-
190
- Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
191
-
192
- ```bibtex
193
- @software{minishlab2024model2vec,
194
- author = {Stephan Tulkens and {van Dongen}, Thomas},
195
- title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
196
- year = {2024},
197
- publisher = {Zenodo},
198
- doi = {10.5281/zenodo.17270888},
199
- url = {https://github.com/MinishLab/model2vec},
200
- license = {MIT}
201
- }
202
- ```
 
 
 
1
+ ---
2
+ language:
3
+ - code
4
+ license: mit
5
+ library_name: model2vec
6
+ tags:
7
+ - model2vec
8
+ - embeddings
9
+ - code
10
+ - retrieval
11
+ - static-embeddings
12
+ - sentence-transformers
13
+ - sentence-similarity
14
+ - feature-extraction
15
+ datasets:
16
+ - minishlab/cornstack-queries-docs
17
+ - minishlab/tokenlearn-cornstack-docs-coderankembed-v2
18
+ - minishlab/tokenlearn-cornstack-queries-coderankembed-v2
19
+ - minishlab/coir-train-hard-negatives
20
+ - minishlab/cornstack-hard-negatives
21
+ - nomic-ai/cornstack-python-v1
22
+ - nomic-ai/cornstack-java-v1
23
+ - nomic-ai/cornstack-javascript-v1
24
+ - nomic-ai/cornstack-go-v1
25
+ - nomic-ai/cornstack-php-v1
26
+ - nomic-ai/cornstack-ruby-v1
27
+ ---
28
+
29
+ <div align="center">
30
+ <img src="figures/sparkle_2_blink.svg" alt="blink logo" width="325">
31
+ </div>
32
+
33
+ blink-code-16M is a fast static embedding model for code retrieval by [Minish](https://minish.ai): a single 62,500 × 256 token embedding table (16.0M parameters, 64MB in float32) with mean pooling. It supersedes [`potion-code-16M-v2`](https://huggingface.co/minishlab/potion-code-16M-v2): it's the same size and better on every benchmark we measured, improving CoIR from 40.67 to 46.82.
34
+ Static models are models without any active parameters; all model parameters are just embedding parameters. Because of this, they are many orders of magnitude faster than transformers. Although this comes at a cost, this cost is much lower than you would expect.
35
+
36
+ ## Usage
37
+
38
+ With [model2vec](https://github.com/MinishLab/model2vec):
39
+
40
+ ```python
41
+ from model2vec import StaticModel
42
+
43
+ model = StaticModel.from_pretrained("minishlab/blink-code-16M")
44
+ embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
45
+ ```
46
+
47
+ With [model2vec-rs](https://github.com/MinishLab/model2vec-rs)
48
+
49
+ ```rust
50
+ use anyhow::Result;
51
+ use model2vec_rs::model::StaticModel;
52
+
53
+ fn main() -> Result<()> {
54
+ let model = StaticModel::from_pretrained(
55
+ "minishlab/blink-code-16M",
56
+ )?;
57
+
58
+ let sentences = vec![
59
+ "read a json file".to_string(),
60
+ "fn read_json(path: &str) -> Value".to_string(),
61
+ ];
62
+
63
+ let embeddings = model.encode(&sentences);
64
+ println!("Generated {} embeddings.", embeddings.len());
65
+
66
+ Ok(())
67
+ }
68
+ ```
69
+
70
+ With [Sentence Transformers](https://www.sbert.net):
71
+
72
+ ```python
73
+ from sentence_transformers import SentenceTransformer
74
+
75
+ model = SentenceTransformer("minishlab/blink-code-16M")
76
+ embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
77
+ ```
78
+
79
+ ## Results
80
+
81
+ ![CoIR mean against RTEB(Code) mean for blink-code-16M, BM25 and the potion-code models](figures/coir_vs_rteb.png)
82
+
83
+ All scores are nDCG@10 from mteb 2.27.1.
84
+
85
+ ### CoIR
86
+
87
+ [CoIR](https://github.com/CoIR-team/coir) is the standard code retrieval benchmark: 10 tasks covering text-to-code, code-to-code, code-to-text and code Q&A.
88
+
89
+ | Model | Mean | Apps | CodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
90
+ |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
91
+ | **blink-code-16M** | **46.82** | **6.08** | **53.59** | 51.72 | 65.87 | 51.42 | **57.31** | **38.34** | 24.34 | 64.03 | **55.45** |
92
+ | BM25 | 42.31 | 4.76 | 40.86 | **59.19** | **68.15** | **53.97** | 47.78 | 34.42 | 18.75 | **70.26** | 24.94 |
93
+ | potion-code-16M-v2 | 40.67 | 5.05 | 46.34 | 46.50 | 54.40 | 43.70 | 48.55 | 33.48 | **24.39** | 60.13 | 44.12 |
94
+ | potion-code-16M | 38.78 | 4.11 | 43.10 | 45.09 | 52.24 | 43.09 | 45.40 | 32.81 | 22.19 | 58.10 | 41.66 |
95
+
96
+ The potion-code models ship with a 512-token cap in their tokenizer, which mteb applies: potion-code-16M-v2's card reports 39.08 with it, against 40.67 here without it.
97
+
98
+ #### Summary
99
+
100
+ - **Mean:** blink-code-16M scores 46.82, 6.15 points above potion-code-16M-v2 and 4.51 above BM25.
101
+ - **By task:** it's best on 5 of 10 tasks. BM25 is best on CodeFeedbackMT, CodeFeedbackST, CodeSearchNetCC and StackOverflow, and potion-code-16M-v2 on CosQA (24.39 against 24.34).
102
+
103
+ ### RTEB(Code)
104
+
105
+ [RTEB(Code)](https://huggingface.co/blog/rteb) is the code part of the Retrieval Embedding Benchmark. None of it is in our training data.
106
+
107
+ - **DS1000**: data science tasks to their solution (pandas, numpy, matplotlib, scikit-learn, scipy).
108
+ - **HumanEval** and **MBPP**: a programming problem to its Python solution.
109
+ - **WikiSQL**: a question about a table to its SQL query.
110
+ - **FreshStack**: programming tasks to their solution in Python, JavaScript or Go.
111
+ - **SWE-bench**: a GitHub issue to the source files that need changing to resolve it (SWE-bench Verified).
112
+
113
+ We use the public English tasks. Apps is left out (it is in CoIR above) and Code1 is one of RTEB's private sets.
114
+
115
+ | Model | Mean | DS1000 | HumanEval | MBPP | WikiSQL | FreshStack | SWE-bench |
116
+ |---|---:|---:|---:|---:|---:|---:|---:|
117
+ | **blink-code-16M** | **34.67** | 29.17 | **64.84** | **56.75** | 30.94 | 22.92 | 3.39 |
118
+ | BM25 | 29.90 | **41.45** | 38.47 | 11.64 | **52.16** | **27.89** | **7.76** |
119
+ | potion-code-16M-v2 | 29.21 | 20.83 | 55.31 | 51.53 | 22.96 | 21.14 | 3.50 |
120
+ | potion-code-16M | 27.34 | 20.14 | 49.95 | 47.03 | 22.54 | 21.55 | 2.83 |
121
+
122
+ #### Summary
123
+
124
+ - **Mean:** blink-code-16M scores 34.67, against 29.90 for BM25 and 29.21 for potion-code-16M-v2.
125
+ - **By task:** it's far ahead on HumanEval and MBPP, where a short description has to find code it shares few words with (MBPP: 56.75 against 11.64 for BM25). BM25 is best on DS1000, WikiSQL, FreshStack and SWE-bench.
126
+ - **Against potion-code-16M-v2:** better on 5 of 6 tasks; SWE-bench is below 4 for both.
127
+
128
+ ### CodeEditSearch
129
+
130
+ [CodeEditSearch](https://huggingface.co/datasets/cassanof/CodeEditSearch) retrieves a code change (a diff) from its commit message, 1,000 commits per language from CommitPackFT. Seven of the 13 languages (TypeScript, C, C++, Rust, Swift, Scala, Shell) are not in our training data.
131
+
132
+ | Model | Mean | Python | JS | TS | Go | Ruby | Java | PHP | C | C++ | Rust | Swift | Scala | Shell |
133
+ |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
134
+ | **blink-code-16M** | **49.58** | **53.1** | **54.5** | **54.7** | **52.6** | **54.0** | **51.7** | **50.7** | **41.4** | **41.8** | **44.2** | **49.6** | **47.5** | 48.8 |
135
+ | potion-code-16M-v2 | 46.50 | 51.6 | 51.2 | 50.5 | 49.3 | 50.6 | 49.5 | 47.2 | 37.4 | 36.4 | 43.7 | 47.8 | 44.2 | 45.0 |
136
+ | potion-code-16M | 45.06 | 49.7 | 50.1 | 49.6 | 47.2 | 49.3 | 48.3 | 46.1 | 36.5 | 34.3 | 43.8 | 47.1 | 40.6 | 43.4 |
137
+ | BM25 | 44.39 | 48.7 | 47.8 | 47.9 | 48.2 | 48.9 | 41.3 | 41.3 | 35.0 | 37.9 | 44.0 | 39.3 | 44.6 | **52.0** |
138
+
139
+ #### Summary
140
+
141
+ - **Mean:** blink-code-16M scores 49.58, against 46.50 for potion-code-16M-v2 and 44.39 for BM25.
142
+ - **Languages we didn't train on:** it beats potion-code-16M-v2 on all 13 languages, including the seven unseen ones; the largest gains are on C++ (+5.4), TypeScript (+4.2) and C (+4.0). BM25 is best on Shell.
143
+
144
+ ## Training
145
+
146
+ We followed a four-step procedure, starting from [potion-code-16M-v2's recipe](https://huggingface.co/minishlab/potion-code-16M-v2).
147
+
148
+ ### 1. Tokenizer and distillation
149
+
150
+ We train a 62,500-token uncased WordPiece tokenizer on 1.2M queries and documents from [CornStack](https://huggingface.co/datasets/minishlab/cornstack-queries-docs) (Go, Java, JavaScript, PHP, Python and Ruby) plus the 4.1M texts of the [CoIR train splits](https://huggingface.co/datasets/minishlab/coir-train-hard-negatives). We then distill [CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) into it with Model2Vec, reducing the dimensions to 256 with PCA and applying SIF weighting.
151
+
152
+ ### 2. Tokenlearn
153
+
154
+ We then distill CodeRankEmbed into the model with Tokenlearn, on 1.2M CornStack [documents](https://huggingface.co/datasets/minishlab/tokenlearn-cornstack-docs-coderankembed-v2) and [queries](https://huggingface.co/datasets/minishlab/tokenlearn-cornstack-queries-coderankembed-v2) embedded by CodeRankEmbed.
155
+
156
+ ### 3. Contrastive training
157
+
158
+ We train with a contrastive loss (in-batch negatives plus one hard negative per pair) for 3 epochs, with batch size 4096, learning rate 0.05 and a cosine schedule, on 4.5M triplets from two datasets we built for this model:
159
+
160
+ - [**coir-train-hard-negatives**](https://huggingface.co/datasets/minishlab/coir-train-hard-negatives) (2.09M): query and document pairs from the train splits of the CoIR tasks, with hard negatives mined in two rounds. We first mine them with CodeRankEmbed and train on them with this recipe. We then mine them again with the model this produces and train once more: a static model's negatives are closer to what is actually hard for a static model than those of a transformer (see the ablation below).
161
+ - [**cornstack-hard-negatives**](https://huggingface.co/datasets/minishlab/cornstack-hard-negatives) (2.4M, 400k per language): triplets from [CornStack](https://huggingface.co/datasets/nomic-ai/cornstack-python-v1), using the highest-scoring of CornStack's own mined negatives that still scores below the document.
162
+
163
+ **Decontamination.** CoIR's train and test splits share queries and documents, so we remove every triplet whose query is a CoIR test query, or whose document or negative is a relevant CoIR test document (matched after whitespace normalization). This removes 19,073 CoIR train pairs (0.9%) and 6 CornStack triplets. See the dataset cards for details.
164
+
165
+ ### 4. Weight averaging
166
+
167
+ The final model is 20% of the Tokenlearn model from step 2 and 80% of the contrastive model from step 3.
168
+
169
+ ### Ablation
170
+
171
+ To show the effect of each step of our training process, this table shows how much each one adds on our benchmarks (in brackets: the change from the row above). Each row adds one thing to the row above it.
172
+
173
+ | Step | CoIR | RTEB(Code) | CodeEditSearch | semble |
174
+ |---|---:|---:|---:|---:|
175
+ | 1. Distill CodeRankEmbed | 32.61 | 25.09 | 35.72 | 0.559 |
176
+ | 2. + Our code tokenizer with an expanded vocabulary | 34.50 (+1.89) | 23.82 (-1.27) | 39.82 (+4.10) | 0.609 (+0.050) |
177
+ | 3. + Tokenlearn | 40.03 (+5.53) | 26.75 (+2.93) | 44.23 (+4.41) | 0.638 (+0.029) |
178
+ | 4. + Contrastive training on CornStack | 42.60 (+2.57) | 33.41 (+6.66) | 49.81 (+5.58) | 0.653 (+0.015) |
179
+ | 5. + CoIR train pairs | 45.92 (+3.32) | 34.60 (+1.19) | 49.58 (-0.23) | 0.642 (-0.011) |
180
+ | 6. + Hard negatives from CodeRankEmbed | 46.19 (+0.27) | 34.42 (-0.18) | 49.20 (-0.38) | 0.644 (+0.002) |
181
+ | 7. + Hard negatives re-mined with the step-6 model | 46.74 (+0.55) | 34.88 (+0.46) | 49.20 (0.00) | 0.643 (-0.001) |
182
+ | 8. + Weight averaging | **46.82** (+0.08) | **34.67** (-0.21) | **49.58** (+0.38) | **0.652** (+0.009) |
183
+
184
+ [semble](https://github.com/MinishLab/semble) is our code search library; we run only its semantic benchmark, to show the isolated effect of the model. We don't include semble results for the other models because trained models all saturate around 0.65, but we include it here as a control task for the effect of each step.
185
+
186
+ ## Library Authors
187
+
188
+ Model2Vec was developed by the [Minish](https://minish.ai) team consisting of [Stephan Tulkens](https://github.com/stephantul) and [Thomas van Dongen](https://github.com/Pringled).
189
+
190
+ ## Citation
191
+
192
+ Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
193
+
194
+ ```bibtex
195
+ @software{minishlab2024model2vec,
196
+ author = {Stephan Tulkens and {van Dongen}, Thomas},
197
+ title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
198
+ year = {2024},
199
+ publisher = {Zenodo},
200
+ doi = {10.5281/zenodo.17270888},
201
+ url = {https://github.com/MinishLab/model2vec},
202
+ license = {MIT}
203
+ }
204
+ ```