Pringled commited on
Commit
217a670
·
verified ·
1 Parent(s): 05e2004

Card: potion-code-16M rows, datasets and decontamination

Browse files
Files changed (1) hide show
  1. README.md +12 -10
README.md CHANGED
@@ -14,6 +14,8 @@ datasets:
14
  - minishlab/cornstack-queries-docs
15
  - minishlab/tokenlearn-cornstack-docs-coderankembed-v2
16
  - minishlab/tokenlearn-cornstack-queries-coderankembed-v2
 
 
17
  - nomic-ai/cornstack-python-v1
18
  - nomic-ai/cornstack-java-v1
19
  - nomic-ai/cornstack-javascript-v1
@@ -26,7 +28,7 @@ datasets:
26
  <img src="figures/sparkle_2_blink.svg" alt="blink logo" width="325">
27
  </div>
28
 
29
- 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 CoIR (46.90 against 40.67), RTEB(Code) (34.48 against 29.21) and CodeEditSearch (49.50 against 46.50).
30
  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.
31
 
32
  ## Usage
@@ -78,7 +80,7 @@ All scores are nDCG@10 from mteb 2.27.1 with the Sentence Transformers loader, w
78
 
79
  ### CoIR
80
 
81
- [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. blink-code-16M is trained on the CoIR train splits (see [Training](#training)); the potion-code models are not.
82
 
83
  | Model | Mean | Apps | CodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
84
  |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
@@ -111,6 +113,7 @@ We use the public English tasks. Apps is left out (it is in CoIR above) and Code
111
  | **blink-code-16M** | **34.48** | 29.23 | **64.66** | **56.91** | 30.00 | 22.96 | 3.15 |
112
  | BM25 | 29.90 | **41.45** | 38.47 | 11.64 | **52.16** | **27.89** | **7.76** |
113
  | potion-code-16M-v2 | 29.21 | 20.83 | 55.31 | 51.53 | 22.96 | 21.14 | 3.50 |
 
114
 
115
  #### Summary
116
 
@@ -126,6 +129,7 @@ We use the public English tasks. Apps is left out (it is in CoIR above) and Code
126
  |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
127
  | **blink-code-16M** | **49.50** | **53.1** | **54.0** | **54.5** | **52.4** | **53.5** | **51.8** | **50.2** | **41.6** | **41.7** | 43.9 | **49.7** | **48.3** | 48.9 |
128
  | 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 |
 
129
  | 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** |
130
 
131
  #### Summary
@@ -137,9 +141,9 @@ We use the public English tasks. Apps is left out (it is in CoIR above) and Code
137
 
138
  We followed a four-step procedure, starting from [potion-code-16M-v2's recipe](https://huggingface.co/minishlab/potion-code-16M-v2).
139
 
140
- ### 1. Tokenizer and initialization
141
 
142
- 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. The CoIR texts bring in vocabulary that CornStack lacks, such as C++, SQL and machine learning terms. Each token is embedded with [CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed), reduced to 256 dimensions with PCA, and weighted by token frequency (SIF).
143
 
144
  ### 2. Tokenlearn
145
 
@@ -147,19 +151,17 @@ We then distill CodeRankEmbed into the model with Tokenlearn, on 1.2M CornStack
147
 
148
  ### 3. Contrastive training
149
 
150
- 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:
151
 
152
- - **CoIR train pairs** (2.09M): the train splits of the CoIR tasks. Hard negatives were mined with an earlier version of this model.
153
- - **CornStack hard negatives** (2.4M, 400k per language): (query, document, negative) triplets from [CornStack](https://huggingface.co/datasets/nomic-ai/cornstack-python-v1), using the highest-scoring negative that still scores below the document.
154
 
155
- All training data is cleaned against the CoIR test sets: we drop every pair whose query is a test query, or whose document or negative is a relevant test document (after whitespace normalization).
156
 
157
  ### 4. Weight averaging
158
 
159
  The final model is 20% of the Tokenlearn model from step 2 and 80% of the contrastive model from step 3.
160
 
161
- Things we tried that didn't help enough to keep: all 6M CornStack pairs instead of hard-negative triplets, averaging two contrastive runs (within 0.1 of one run), splitting identifiers (`camelCase` to `camel case`), and a 32M version with twice the vocabulary (+0.15 on CoIR over a 16M model with CornStack-only vocabulary, which the CoIR texts in step 1 matched).
162
-
163
  ## Library Authors
164
 
165
  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).
 
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
 
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.90.
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
 
80
 
81
  ### CoIR
82
 
83
+ [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.
84
 
85
  | Model | Mean | Apps | CodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
86
  |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
 
113
  | **blink-code-16M** | **34.48** | 29.23 | **64.66** | **56.91** | 30.00 | 22.96 | 3.15 |
114
  | BM25 | 29.90 | **41.45** | 38.47 | 11.64 | **52.16** | **27.89** | **7.76** |
115
  | potion-code-16M-v2 | 29.21 | 20.83 | 55.31 | 51.53 | 22.96 | 21.14 | 3.50 |
116
+ | potion-code-16M | 27.34 | 20.14 | 49.95 | 47.03 | 22.54 | 21.55 | 2.83 |
117
 
118
  #### Summary
119
 
 
129
  |---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
130
  | **blink-code-16M** | **49.50** | **53.1** | **54.0** | **54.5** | **52.4** | **53.5** | **51.8** | **50.2** | **41.6** | **41.7** | 43.9 | **49.7** | **48.3** | 48.9 |
131
  | 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 |
132
+ | 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 |
133
  | 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** |
134
 
135
  #### Summary
 
141
 
142
  We followed a four-step procedure, starting from [potion-code-16M-v2's recipe](https://huggingface.co/minishlab/potion-code-16M-v2).
143
 
144
+ ### 1. Tokenizer and distillation
145
 
146
+ 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.
147
 
148
  ### 2. Tokenlearn
149
 
 
151
 
152
  ### 3. Contrastive training
153
 
154
+ 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:
155
 
156
+ - [**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. The hard negatives are mined with a first version of blink-code, trained without them.
157
+ - [**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.
158
 
159
+ **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,069 CoIR train pairs (0.9%) and 6 CornStack triplets. See the dataset cards for details.
160
 
161
  ### 4. Weight averaging
162
 
163
  The final model is 20% of the Tokenlearn model from step 2 and 80% of the contrastive model from step 3.
164
 
 
 
165
  ## Library Authors
166
 
167
  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).