Add new SentenceTransformer model
Browse files- 1_Pooling/config.json +10 -0
- README.md +65 -0
- added_tokens.json +4 -0
- config.json +32 -0
- config_sentence_transformers.json +10 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- modules.json +20 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +58 -0
- tokenizer_config.json +213 -0
- vocab.json +0 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
7 |
+
"pooling_mode_weightedmean_tokens": false,
|
8 |
+
"pooling_mode_lasttoken": false,
|
9 |
+
"include_prompt": true
|
10 |
+
}
|
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- bigcode/the-stack-dedup
|
5 |
+
library_name: transformers
|
6 |
+
language:
|
7 |
+
- code
|
8 |
+
---
|
9 |
+
|
10 |
+
## CodeSage-Small
|
11 |
+
|
12 |
+
### Updates
|
13 |
+
* [12/2024] <span style="color:blue">We are excited to announce the release of the CodeSage V2 model family with largely improved performance and flexible embedding dimensions!</span> Please check out our [models](https://huggingface.co/codesage) and [blogpost](https://code-representation-learning.github.io/codesage-v2.html) for more details.
|
14 |
+
* [11/2024] You can now access CodeSage models through SentenceTransformer.
|
15 |
+
|
16 |
+
### Model description
|
17 |
+
CodeSage is a new family of open code embedding models with an encoder architecture that support a wide range of source code understanding tasks. It is introduced in the paper:
|
18 |
+
|
19 |
+
[Code Representation Learning At Scale by
|
20 |
+
Dejiao Zhang*, Wasi Uddin Ahmad*, Ming Tan, Hantian Ding, Ramesh Nallapati, Dan Roth, Xiaofei Ma, Bing Xiang](https://arxiv.org/abs/2402.01935) (* indicates equal contribution).
|
21 |
+
|
22 |
+
### Pretraining data
|
23 |
+
This checkpoint is trained on the Stack data (https://huggingface.co/datasets/bigcode/the-stack-dedup). Supported languages (9 in total) are as follows: c, c-sharp, go, java, javascript, typescript, php, python, ruby.
|
24 |
+
|
25 |
+
### Training procedure
|
26 |
+
This checkpoint is first trained on code data via masked language modeling (MLM) and then on bimodal text-code pair data. Please refer to the paper for more details.
|
27 |
+
|
28 |
+
### How to Use
|
29 |
+
This checkpoint consists of an encoder (130M model), which can be used to extract code embeddings of 1024 dimension.
|
30 |
+
|
31 |
+
1. Accessing CodeSage via HuggingFace: it can be easily loaded using the AutoModel functionality and employs the [Starcoder Tokenizer](https://arxiv.org/pdf/2305.06161.pdf).
|
32 |
+
|
33 |
+
```
|
34 |
+
from transformers import AutoModel, AutoTokenizer
|
35 |
+
|
36 |
+
checkpoint = "codesage/codesage-small"
|
37 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
38 |
+
|
39 |
+
# Note: CodeSage requires adding eos token at the end of each tokenized sequence
|
40 |
+
|
41 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True, add_eos_token=True)
|
42 |
+
|
43 |
+
model = AutoModel.from_pretrained(checkpoint, trust_remote_code=True).to(device)
|
44 |
+
|
45 |
+
inputs = tokenizer.encode("def print_hello_world():\tprint('Hello World!')", return_tensors="pt").to(device)
|
46 |
+
embedding = model(inputs)[0]
|
47 |
+
```
|
48 |
+
|
49 |
+
2. Accessing CodeSage via SentenceTransformer
|
50 |
+
```
|
51 |
+
from sentence_transformers import SentenceTransformer
|
52 |
+
model = SentenceTransformer("codesage/codesage-small", trust_remote_code=True)
|
53 |
+
```
|
54 |
+
|
55 |
+
### BibTeX entry and citation info
|
56 |
+
```
|
57 |
+
@inproceedings{
|
58 |
+
zhang2024code,
|
59 |
+
title={{CODE} {REPRESENTATION} {LEARNING} {AT} {SCALE}},
|
60 |
+
author={Dejiao Zhang and Wasi Uddin Ahmad and Ming Tan and Hantian Ding and Ramesh Nallapati and Dan Roth and Xiaofei Ma and Bing Xiang},
|
61 |
+
booktitle={The Twelfth International Conference on Learning Representations},
|
62 |
+
year={2024},
|
63 |
+
url={https://openreview.net/forum?id=vfzRRjumpX}
|
64 |
+
}
|
65 |
+
```
|
added_tokens.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<mask>": 49152,
|
3 |
+
"<pad>": 49153
|
4 |
+
}
|
config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "codesage/codesage-small",
|
3 |
+
"activation_function": "gelu_new",
|
4 |
+
"architectures": [
|
5 |
+
"CodeSageModel"
|
6 |
+
],
|
7 |
+
"attention_dropout_prob": 0.1,
|
8 |
+
"auto_map": {
|
9 |
+
"AutoConfig": "codesage/codesage-small--config_codesage.CodeSageConfig",
|
10 |
+
"AutoModel": "codesage/codesage-small--modeling_codesage.CodeSageModel",
|
11 |
+
"AutoModelForMaskedLM": "codesage/codesage-small--modeling_codesage.CodeSageForMaskedLM",
|
12 |
+
"AutoModelForSequenceClassification": "codesage/codesage-small--modeling_codesage.CodeSageForSequenceClassification",
|
13 |
+
"AutoTokenizer": "codesage/codesage-small--tokenization_codesage.CodeSageTokenizer"
|
14 |
+
},
|
15 |
+
"bos_token_id": 0,
|
16 |
+
"embedding_dropout_prob": 0.1,
|
17 |
+
"eos_token_id": 0,
|
18 |
+
"hidden_size": 1024,
|
19 |
+
"initializer_range": 0.02,
|
20 |
+
"intermediate_size": 4096,
|
21 |
+
"layer_norm_epsilon": 1e-05,
|
22 |
+
"max_position_embeddings": 2048,
|
23 |
+
"model_type": "codesage",
|
24 |
+
"num_attention_heads": 8,
|
25 |
+
"num_hidden_layers": 6,
|
26 |
+
"pad_token_id": 49153,
|
27 |
+
"position_embedding_type": "absolute",
|
28 |
+
"residual_dropout_prob": 0.1,
|
29 |
+
"torch_dtype": "float32",
|
30 |
+
"transformers_version": "4.48.0.dev0",
|
31 |
+
"vocab_size": 49154
|
32 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "3.3.0",
|
4 |
+
"transformers": "4.48.0.dev0",
|
5 |
+
"pytorch": "2.4.0"
|
6 |
+
},
|
7 |
+
"prompts": {},
|
8 |
+
"default_prompt_name": null,
|
9 |
+
"similarity_fn_name": "cosine"
|
10 |
+
}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:08c4572853e48b68d738b0fd1e9a60e3884b649fe91a505a9f6a4b0c5efac053
|
3 |
+
size 512047808
|
modules.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"idx": 2,
|
16 |
+
"name": "2",
|
17 |
+
"path": "2_Normalize",
|
18 |
+
"type": "sentence_transformers.models.Normalize"
|
19 |
+
}
|
20 |
+
]
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 1024,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<|endoftext|>",
|
4 |
+
"<fim_prefix>",
|
5 |
+
"<fim_middle>",
|
6 |
+
"<fim_suffix>",
|
7 |
+
"<fim_pad>",
|
8 |
+
"<filename>",
|
9 |
+
"<gh_stars>",
|
10 |
+
"<issue_start>",
|
11 |
+
"<issue_comment>",
|
12 |
+
"<issue_closed>",
|
13 |
+
"<jupyter_start>",
|
14 |
+
"<jupyter_text>",
|
15 |
+
"<jupyter_code>",
|
16 |
+
"<jupyter_output>",
|
17 |
+
"<empty_output>",
|
18 |
+
"<commit_before>",
|
19 |
+
"<commit_msg>",
|
20 |
+
"<commit_after>",
|
21 |
+
"<reponame>"
|
22 |
+
],
|
23 |
+
"bos_token": {
|
24 |
+
"content": "<|endoftext|>",
|
25 |
+
"lstrip": false,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"eos_token": {
|
31 |
+
"content": "<|endoftext|>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"mask_token": {
|
38 |
+
"content": "<mask>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"pad_token": {
|
45 |
+
"content": "<pad>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
},
|
51 |
+
"unk_token": {
|
52 |
+
"content": "<|endoftext|>",
|
53 |
+
"lstrip": false,
|
54 |
+
"normalized": false,
|
55 |
+
"rstrip": false,
|
56 |
+
"single_word": false
|
57 |
+
}
|
58 |
+
}
|
tokenizer_config.json
ADDED
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_eos_token": true,
|
4 |
+
"add_prefix_space": false,
|
5 |
+
"added_tokens_decoder": {
|
6 |
+
"0": {
|
7 |
+
"content": "<|endoftext|>",
|
8 |
+
"lstrip": false,
|
9 |
+
"normalized": false,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false,
|
12 |
+
"special": true
|
13 |
+
},
|
14 |
+
"1": {
|
15 |
+
"content": "<fim_prefix>",
|
16 |
+
"lstrip": false,
|
17 |
+
"normalized": false,
|
18 |
+
"rstrip": false,
|
19 |
+
"single_word": false,
|
20 |
+
"special": true
|
21 |
+
},
|
22 |
+
"2": {
|
23 |
+
"content": "<fim_middle>",
|
24 |
+
"lstrip": false,
|
25 |
+
"normalized": false,
|
26 |
+
"rstrip": false,
|
27 |
+
"single_word": false,
|
28 |
+
"special": true
|
29 |
+
},
|
30 |
+
"3": {
|
31 |
+
"content": "<fim_suffix>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false,
|
36 |
+
"special": true
|
37 |
+
},
|
38 |
+
"4": {
|
39 |
+
"content": "<fim_pad>",
|
40 |
+
"lstrip": false,
|
41 |
+
"normalized": false,
|
42 |
+
"rstrip": false,
|
43 |
+
"single_word": false,
|
44 |
+
"special": true
|
45 |
+
},
|
46 |
+
"5": {
|
47 |
+
"content": "<filename>",
|
48 |
+
"lstrip": false,
|
49 |
+
"normalized": false,
|
50 |
+
"rstrip": false,
|
51 |
+
"single_word": false,
|
52 |
+
"special": true
|
53 |
+
},
|
54 |
+
"6": {
|
55 |
+
"content": "<gh_stars>",
|
56 |
+
"lstrip": false,
|
57 |
+
"normalized": false,
|
58 |
+
"rstrip": false,
|
59 |
+
"single_word": false,
|
60 |
+
"special": true
|
61 |
+
},
|
62 |
+
"7": {
|
63 |
+
"content": "<issue_start>",
|
64 |
+
"lstrip": false,
|
65 |
+
"normalized": false,
|
66 |
+
"rstrip": false,
|
67 |
+
"single_word": false,
|
68 |
+
"special": true
|
69 |
+
},
|
70 |
+
"8": {
|
71 |
+
"content": "<issue_comment>",
|
72 |
+
"lstrip": false,
|
73 |
+
"normalized": false,
|
74 |
+
"rstrip": false,
|
75 |
+
"single_word": false,
|
76 |
+
"special": true
|
77 |
+
},
|
78 |
+
"9": {
|
79 |
+
"content": "<issue_closed>",
|
80 |
+
"lstrip": false,
|
81 |
+
"normalized": false,
|
82 |
+
"rstrip": false,
|
83 |
+
"single_word": false,
|
84 |
+
"special": true
|
85 |
+
},
|
86 |
+
"10": {
|
87 |
+
"content": "<jupyter_start>",
|
88 |
+
"lstrip": false,
|
89 |
+
"normalized": false,
|
90 |
+
"rstrip": false,
|
91 |
+
"single_word": false,
|
92 |
+
"special": true
|
93 |
+
},
|
94 |
+
"11": {
|
95 |
+
"content": "<jupyter_text>",
|
96 |
+
"lstrip": false,
|
97 |
+
"normalized": false,
|
98 |
+
"rstrip": false,
|
99 |
+
"single_word": false,
|
100 |
+
"special": true
|
101 |
+
},
|
102 |
+
"12": {
|
103 |
+
"content": "<jupyter_code>",
|
104 |
+
"lstrip": false,
|
105 |
+
"normalized": false,
|
106 |
+
"rstrip": false,
|
107 |
+
"single_word": false,
|
108 |
+
"special": true
|
109 |
+
},
|
110 |
+
"13": {
|
111 |
+
"content": "<jupyter_output>",
|
112 |
+
"lstrip": false,
|
113 |
+
"normalized": false,
|
114 |
+
"rstrip": false,
|
115 |
+
"single_word": false,
|
116 |
+
"special": true
|
117 |
+
},
|
118 |
+
"14": {
|
119 |
+
"content": "<empty_output>",
|
120 |
+
"lstrip": false,
|
121 |
+
"normalized": false,
|
122 |
+
"rstrip": false,
|
123 |
+
"single_word": false,
|
124 |
+
"special": true
|
125 |
+
},
|
126 |
+
"15": {
|
127 |
+
"content": "<commit_before>",
|
128 |
+
"lstrip": false,
|
129 |
+
"normalized": false,
|
130 |
+
"rstrip": false,
|
131 |
+
"single_word": false,
|
132 |
+
"special": true
|
133 |
+
},
|
134 |
+
"16": {
|
135 |
+
"content": "<commit_msg>",
|
136 |
+
"lstrip": false,
|
137 |
+
"normalized": false,
|
138 |
+
"rstrip": false,
|
139 |
+
"single_word": false,
|
140 |
+
"special": true
|
141 |
+
},
|
142 |
+
"17": {
|
143 |
+
"content": "<commit_after>",
|
144 |
+
"lstrip": false,
|
145 |
+
"normalized": false,
|
146 |
+
"rstrip": false,
|
147 |
+
"single_word": false,
|
148 |
+
"special": true
|
149 |
+
},
|
150 |
+
"18": {
|
151 |
+
"content": "<reponame>",
|
152 |
+
"lstrip": false,
|
153 |
+
"normalized": false,
|
154 |
+
"rstrip": false,
|
155 |
+
"single_word": false,
|
156 |
+
"special": true
|
157 |
+
},
|
158 |
+
"49152": {
|
159 |
+
"content": "<mask>",
|
160 |
+
"lstrip": false,
|
161 |
+
"normalized": false,
|
162 |
+
"rstrip": false,
|
163 |
+
"single_word": false,
|
164 |
+
"special": true
|
165 |
+
},
|
166 |
+
"49153": {
|
167 |
+
"content": "<pad>",
|
168 |
+
"lstrip": false,
|
169 |
+
"normalized": false,
|
170 |
+
"rstrip": false,
|
171 |
+
"single_word": false,
|
172 |
+
"special": true
|
173 |
+
}
|
174 |
+
},
|
175 |
+
"additional_special_tokens": [
|
176 |
+
"<|endoftext|>",
|
177 |
+
"<fim_prefix>",
|
178 |
+
"<fim_middle>",
|
179 |
+
"<fim_suffix>",
|
180 |
+
"<fim_pad>",
|
181 |
+
"<filename>",
|
182 |
+
"<gh_stars>",
|
183 |
+
"<issue_start>",
|
184 |
+
"<issue_comment>",
|
185 |
+
"<issue_closed>",
|
186 |
+
"<jupyter_start>",
|
187 |
+
"<jupyter_text>",
|
188 |
+
"<jupyter_code>",
|
189 |
+
"<jupyter_output>",
|
190 |
+
"<empty_output>",
|
191 |
+
"<commit_before>",
|
192 |
+
"<commit_msg>",
|
193 |
+
"<commit_after>",
|
194 |
+
"<reponame>"
|
195 |
+
],
|
196 |
+
"auto_map": {
|
197 |
+
"AutoTokenizer": [
|
198 |
+
"codesage/codesage-small--tokenization_codesage.CodeSageTokenizer",
|
199 |
+
null
|
200 |
+
]
|
201 |
+
},
|
202 |
+
"bos_token": "<|endoftext|>",
|
203 |
+
"clean_up_tokenization_spaces": true,
|
204 |
+
"eos_token": "<|endoftext|>",
|
205 |
+
"errors": "replace",
|
206 |
+
"extra_special_tokens": {},
|
207 |
+
"mask_token": "<mask>",
|
208 |
+
"model_max_length": 1024,
|
209 |
+
"pad_token": "<pad>",
|
210 |
+
"tokenizer_class": "CodeSageTokenizer",
|
211 |
+
"unk_token": "<|endoftext|>",
|
212 |
+
"vocab_size": 49152
|
213 |
+
}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|