stephantulkens commited on
Commit
ca3f09d
·
verified ·
1 Parent(s): 133fa7b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -52
README.md CHANGED
@@ -1,92 +1,101 @@
1
  ---
2
- library_name: model2vec
 
3
  license: mit
4
- model_name: minishlab/potion-code-16M-v2
5
  tags:
 
6
  - embeddings
 
 
7
  - static-embeddings
8
- - sentence-transformers
 
 
 
 
 
 
 
 
9
  ---
10
 
11
- # minishlab/potion-code-16M-v2 Model Card
12
 
13
- This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of a Sentence Transformer. 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.
14
 
 
 
 
15
 
16
  ## Installation
17
 
18
- Install model2vec using pip:
19
- ```
20
  pip install model2vec
21
  ```
22
 
23
  ## Usage
24
 
25
- ### Using Model2Vec
26
-
27
- The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
28
-
29
- Load this model using the `from_pretrained` method:
30
  ```python
31
  from model2vec import StaticModel
32
 
33
- # Load a pretrained Model2Vec model
34
  model = StaticModel.from_pretrained("minishlab/potion-code-16M-v2")
35
 
36
- # Compute text embeddings
37
- embeddings = model.encode(["Example sentence"])
38
- ```
39
-
40
- ### Using Sentence Transformers
41
-
42
- You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:
43
-
44
- ```python
45
- from sentence_transformers import SentenceTransformer
46
-
47
- # Load a pretrained Sentence Transformer model
48
- model = SentenceTransformer("minishlab/potion-code-16M-v2")
49
 
50
- # Compute text embeddings
51
- embeddings = model.encode(["Example sentence"])
52
  ```
53
 
54
- ### Distilling a Model2Vec model
55
-
56
- You can distill a Model2Vec model from a Sentence Transformer model using the `distill` method. First, install the `distill` extra with `pip install model2vec[distill]`. Then, run the following code:
57
-
58
- ```python
59
- from model2vec.distill import distill
60
 
61
- # Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
62
- m2v_model = distill(model_name="BAAI/bge-base-en-v1.5", pca_dims=256)
63
 
64
- # Save the model
65
- m2v_model.save_pretrained("m2v_model")
66
- ```
 
67
 
68
- ## How it works
69
 
70
- 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.
71
 
72
- 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.
 
 
 
 
 
 
 
73
 
74
- ## Additional Resources
75
 
76
- - [Model2Vec Repo](https://github.com/MinishLab/model2vec)
77
- - [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)
78
- - [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)
79
- - [Model2Vec Docs](https://minish.ai/packages/model2vec/introduction)
80
 
 
 
 
 
 
 
 
 
81
 
82
- ## Library Authors
83
 
84
- 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).
 
 
 
 
 
 
85
 
86
  ## Citation
87
 
88
- Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
89
- ```
90
  @software{minishlab2024model2vec,
91
  author = {Stephan Tulkens and {van Dongen}, Thomas},
92
  title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
@@ -96,4 +105,4 @@ Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) i
96
  url = {https://github.com/MinishLab/model2vec},
97
  license = {MIT}
98
  }
99
- ```
 
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
+ datasets:
13
+ - minishlab/tokenlearn-cornstack-queries-coderankembed
14
+ - minishlab/tokenlearn-cornstack-docs-coderankembed
15
+ - nomic-ai/cornstack-python-v1
16
+ - nomic-ai/cornstack-java-v1
17
+ - nomic-ai/cornstack-php-v1
18
+ - nomic-ai/cornstack-go-v1
19
+ - nomic-ai/cornstack-javascript-v1
20
+ - nomic-ai/cornstack-ruby-v1
21
  ---
22
 
23
+ # potion-code-16M-v2 Model Card
24
 
25
+ ## Overview
26
 
27
+ **potion-code-16M-v2** is a fast static code embedding model optimized for code retrieval tasks. It powers [Semble](https://github.com/MinishLab/semble), a code search library for agents. It is distilled from [nomic-ai/CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) and trained on the [CornStack](https://huggingface.co/datasets/nomic-ai/cornstack-python-v1) code corpus using [Tokenlearn](https://github.com/MinishLab/tokenlearn) and contrastive fine-tuning.
28
+ It is the successor to [potion-code-16M](https://huggingface.co/minishlab/potion-code-16M).
29
+ It uses static embeddings, allowing text and code embeddings to be computed orders of magnitude faster than transformer-based models on both GPU and CPU.
30
 
31
  ## Installation
32
 
33
+ ```bash
 
34
  pip install model2vec
35
  ```
36
 
37
  ## Usage
38
 
 
 
 
 
 
39
  ```python
40
  from model2vec import StaticModel
41
 
 
42
  model = StaticModel.from_pretrained("minishlab/potion-code-16M-v2")
43
 
44
+ # Embed natural language queries
45
+ query_embeddings = model.encode(["How to read a file in Python?"])
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ # Embed code documents
48
+ code_embeddings = model.encode(["def read_file(path):\n with open(path) as f:\n return f.read()"])
49
  ```
50
 
51
+ ## How it works
 
 
 
 
 
52
 
53
+ potion-code-16M-v2 is created using the following pipeline:
 
54
 
55
+ 1. **Vocabulary mining**: code-specific tokens are mined from CornStack and added to the base CodeRankEmbed tokenizer (43k extra tokens → ~63.5k total)
56
+ 2. **Distillation**: the extended vocabulary is distilled from CodeRankEmbed using Model2Vec (256-dimensional embeddings, PCA)
57
+ 3. **Tokenlearn**: the distilled model is fine-tuned on 1.2 million (query, document) pairs from CornStack using cosine similarity loss
58
+ 4. **Contrastive fine-tuning**: the model is further fine-tuned using MultipleNegativesRankingLoss on 1.2 million CornStack query-document pairs
59
 
60
+ ## Results
61
 
62
+ Results on the [CoIR benchmark](https://github.com/CoIR-team/coir) on [MTEB](https://github.com/embeddings-benchmark/mteb) (NDCG@10, `mteb>=2.10`):
63
 
64
+ | Model | Params | AVG | AppsRetrieval | COIRCodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
65
+ |---|---|---|---|---|---|---|---|---|---|---|---|---|
66
+ | CodeRankEmbed | 137M | 59.14 | 23.46 | 94.70 | 42.61 | 78.11 | 76.39 | 66.43 | 34.84 | 35.92 | 80.53 | 58.37 |
67
+ | **potion-code-16M + Hybrid** | **16M** | **40.41** | **5.23** | **34.03** | **51.23** | **64.26** | **33.22** | **52.67** | **31.14** | **21.63** | **69.65** | **41.03** |
68
+ | BM25 | — | 39.11 | 4.76 | 32.45 | 59.69 | 67.85 | 33.00 | 47.29 | 32.97 | 15.53 | 69.54 | 28.07 |
69
+ | **potion-code-16M** | **16M** | **37.05** | **3.97** | **42.99** | **36.26** | **50.27** | **43.40** | **39.76** | **31.72** | **21.37** | **57.47** | **43.34** |
70
+ | potion-retrieval-32M | 32M | 32.10 | 4.22 | 31.80 | 36.71 | 45.11 | 38.64 | 29.97 | 32.62 | 8.70 | 56.26 | 36.93 |
71
+ | potion-base-32M | 32M | 31.42 | 3.37 | 29.58 | 34.77 | 42.69 | 37.88 | 28.51 | 30.55 | 14.61 | 53.36 | 38.88 |
72
 
73
+ CoIR covers a broad range of code retrieval scenarios. For the use case of finding code given a natural language query, **CosQA** and **CodeFeedback (ST/MT)** are the most relevant tasks. Others are less so: **COIRCodeSearchNetRetrieval** retrieves text given a code query (the reverse direction), and the **CodeTransOcean** tasks target cross-language code translation. The hybrid row combines dense retrieval with BM25 using min-max score normalization and equal weighting (alpha=0.5).
74
 
75
+ ## Model Details
 
 
 
76
 
77
+ | Property | Value |
78
+ |---|---|
79
+ | Parameters | ~16M |
80
+ | Embedding dimensions | 256 |
81
+ | Vocabulary size | ~63,500 |
82
+ | Teacher model | nomic-ai/CodeRankEmbed |
83
+ | Training corpus | CornStack (6 languages: Python, Java, JavaScript, Go, PHP, Ruby) |
84
+ | Max sequence length | 1,000,000 tokens (static, no limit in practice) |
85
 
86
+ ## Additional Resources
87
 
88
+ - [Semble repository](https://github.com/MinishLab/semble)
89
+ - [Model2Vec repository](https://github.com/MinishLab/model2vec)
90
+ - [Tokenlearn repository](https://github.com/MinishLab/tokenlearn)
91
+ - [Tokenlearn document dataset](https://huggingface.co/minishlab/tokenlearn-cornstack-docs-coderankembed-v2)
92
+ - [Tokenlearn query dataset](https://huggingface.co/minishlab/tokenlearn-cornstack-queries-coderankembed-v2)
93
+ - [CornStack dataset](https://huggingface.co/datasets/nomic-ai/cornstack-python-v1)
94
+ - [CoIR benchmark](https://github.com/CoIR-team/coir)
95
 
96
  ## Citation
97
 
98
+ ```bibtex
 
99
  @software{minishlab2024model2vec,
100
  author = {Stephan Tulkens and {van Dongen}, Thomas},
101
  title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
 
105
  url = {https://github.com/MinishLab/model2vec},
106
  license = {MIT}
107
  }
108
+ ```