Feature Extraction
Model2Vec
Safetensors
sentence-transformers
code
embeddings
retrieval
static-embeddings
sentence-similarity
Instructions to use minishlab/blink-code-16M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Model2Vec
How to use minishlab/blink-code-16M with Model2Vec:
from model2vec import StaticModel model = StaticModel.from_pretrained("minishlab/blink-code-16M") embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."]) print(embeddings.shape) - sentence-transformers
How to use minishlab/blink-code-16M with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("minishlab/blink-code-16M") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Model card and logo
Browse files- README.md +181 -0
- figures/sparkle_2_blink.svg +15 -0
README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: model2vec
|
| 3 |
+
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- embeddings
|
| 6 |
+
- static-embeddings
|
| 7 |
+
- sentence-transformers
|
| 8 |
+
- sentence-similarity
|
| 9 |
+
- feature-extraction
|
| 10 |
+
- code
|
| 11 |
+
language: en
|
| 12 |
+
base_model: nomic-ai/CodeRankEmbed
|
| 13 |
+
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
|
| 20 |
+
- nomic-ai/cornstack-go-v1
|
| 21 |
+
- nomic-ai/cornstack-php-v1
|
| 22 |
+
- nomic-ai/cornstack-ruby-v1
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
<div align="center">
|
| 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
|
| 33 |
+
|
| 34 |
+
With [model2vec](https://github.com/MinishLab/model2vec):
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from model2vec import StaticModel
|
| 38 |
+
|
| 39 |
+
model = StaticModel.from_pretrained("minishlab/blink-code-16M")
|
| 40 |
+
embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
With [model2vec-rs](https://github.com/MinishLab/model2vec-rs)
|
| 44 |
+
|
| 45 |
+
```rust
|
| 46 |
+
use anyhow::Result;
|
| 47 |
+
use model2vec_rs::model::StaticModel;
|
| 48 |
+
|
| 49 |
+
fn main() -> Result<()> {
|
| 50 |
+
let model = StaticModel::from_pretrained(
|
| 51 |
+
"minishlab/blink-code-16M",
|
| 52 |
+
)?;
|
| 53 |
+
|
| 54 |
+
let sentences = vec![
|
| 55 |
+
"read a json file".to_string(),
|
| 56 |
+
"fn read_json(path: &str) -> Value".to_string(),
|
| 57 |
+
];
|
| 58 |
+
|
| 59 |
+
let embeddings = model.encode(&sentences);
|
| 60 |
+
println!("Generated {} embeddings.", embeddings.len());
|
| 61 |
+
|
| 62 |
+
Ok(())
|
| 63 |
+
}
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
With [Sentence Transformers](https://www.sbert.net):
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from sentence_transformers import SentenceTransformer
|
| 70 |
+
|
| 71 |
+
model = SentenceTransformer("minishlab/blink-code-16M")
|
| 72 |
+
embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Results
|
| 76 |
+
|
| 77 |
+
All scores are nDCG@10 from mteb 2.27.1 with the Sentence Transformers loader, without a length cap. BM25 is `mteb/baseline-bm25s`.
|
| 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 |
+
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
| 85 |
+
| **blink-code-16M** | **46.90** | **6.23** | **53.64** | 51.67 | 65.85 | 51.40 | **57.20** | **39.19** | **24.78** | 63.79 | **55.23** |
|
| 86 |
+
| BM25 | 42.31 | 4.76 | 40.86 | **59.19** | **68.15** | **53.97** | 47.78 | 34.42 | 18.75 | **70.26** | 24.94 |
|
| 87 |
+
| 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 |
|
| 88 |
+
| 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 |
|
| 89 |
+
|
| 90 |
+
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.
|
| 91 |
+
|
| 92 |
+
#### Summary
|
| 93 |
+
|
| 94 |
+
- **Mean:** blink-code-16M scores 46.90, 6.23 points above potion-code-16M-v2 and 4.59 above BM25.
|
| 95 |
+
- **By task:** it's best on 6 of 10 tasks. BM25 is best on the other four: CodeFeedbackMT, CodeFeedbackST, CodeSearchNetCC and StackOverflow.
|
| 96 |
+
|
| 97 |
+
### RTEB(Code)
|
| 98 |
+
|
| 99 |
+
[RTEB(Code)](https://huggingface.co/blog/rteb) is the code part of the Retrieval Embedding Benchmark. None of it is in our training data.
|
| 100 |
+
|
| 101 |
+
- **DS1000**: data science tasks to their solution (pandas, numpy, matplotlib, scikit-learn, scipy).
|
| 102 |
+
- **HumanEval** and **MBPP**: a programming problem to its Python solution.
|
| 103 |
+
- **WikiSQL**: a question about a table to its SQL query.
|
| 104 |
+
- **FreshStack**: programming tasks to their solution in Python, JavaScript or Go.
|
| 105 |
+
- **SWE-bench**: a GitHub issue to the source files that need changing to resolve it (SWE-bench Verified).
|
| 106 |
+
|
| 107 |
+
We use the public English tasks. Apps is left out (it is in CoIR above) and Code1 is one of RTEB's private sets.
|
| 108 |
+
|
| 109 |
+
| Model | Mean | DS1000 | HumanEval | MBPP | WikiSQL | FreshStack | SWE-bench |
|
| 110 |
+
|---|---:|---:|---:|---:|---:|---:|---:|
|
| 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 |
+
|
| 117 |
+
- **Mean:** blink-code-16M scores 34.48, against 29.90 for BM25 and 29.21 for potion-code-16M-v2.
|
| 118 |
+
- **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.91 against 11.64 for BM25). BM25 is best on DS1000, WikiSQL, FreshStack and SWE-bench.
|
| 119 |
+
- **Against potion-code-16M-v2:** better on 5 of 6 tasks; SWE-bench is below 4 for both.
|
| 120 |
+
|
| 121 |
+
### CodeEditSearch
|
| 122 |
+
|
| 123 |
+
[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.
|
| 124 |
+
|
| 125 |
+
| Model | Mean | Python | JS | TS | Go | Ruby | Java | PHP | C | C++ | Rust | Swift | Scala | Shell |
|
| 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
|
| 132 |
+
|
| 133 |
+
- **Mean:** blink-code-16M scores 49.50, against 46.50 for potion-code-16M-v2 and 44.39 for BM25.
|
| 134 |
+
- **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 (+4.2) and C++ (+5.3). BM25 is best on Rust and Shell.
|
| 135 |
+
|
| 136 |
+
## Training
|
| 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 |
+
|
| 146 |
+
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.
|
| 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).
|
| 166 |
+
|
| 167 |
+
## Citation
|
| 168 |
+
|
| 169 |
+
Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
|
| 170 |
+
|
| 171 |
+
```bibtex
|
| 172 |
+
@software{minishlab2024model2vec,
|
| 173 |
+
author = {Stephan Tulkens and {van Dongen}, Thomas},
|
| 174 |
+
title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
|
| 175 |
+
year = {2024},
|
| 176 |
+
publisher = {Zenodo},
|
| 177 |
+
doi = {10.5281/zenodo.17270888},
|
| 178 |
+
url = {https://github.com/MinishLab/model2vec},
|
| 179 |
+
license = {MIT}
|
| 180 |
+
}
|
| 181 |
+
```
|
figures/sparkle_2_blink.svg
ADDED
|
|