Update README.md
Browse files
README.md
CHANGED
@@ -9,6 +9,11 @@ language:
|
|
9 |
|
10 |
## CodeSage-Base
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
### Model description
|
13 |
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:
|
14 |
|
@@ -21,25 +26,31 @@ This checkpoint is trained on the Stack data (https://huggingface.co/datasets/bi
|
|
21 |
### Training procedure
|
22 |
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.
|
23 |
|
24 |
-
### How to
|
25 |
-
This checkpoint consists of an encoder (356M model), which can be used to extract code embeddings of 1024 dimension.
|
26 |
|
|
|
|
|
27 |
```
|
28 |
from transformers import AutoModel, AutoTokenizer
|
29 |
|
30 |
checkpoint = "codesage/codesage-base"
|
31 |
-
device = "cuda" #
|
|
|
|
|
32 |
|
33 |
-
# Note: CodeSage requires adding eos token at the end of
|
34 |
-
# each tokenized sequence to ensure good performance
|
35 |
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True, add_eos_token=True)
|
36 |
|
37 |
model = AutoModel.from_pretrained(checkpoint, trust_remote_code=True).to(device)
|
38 |
|
39 |
inputs = tokenizer.encode("def print_hello_world():\tprint('Hello World!')", return_tensors="pt").to(device)
|
40 |
embedding = model(inputs)[0]
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
```
|
44 |
|
45 |
### BibTeX entry and citation info
|
|
|
9 |
|
10 |
## CodeSage-Base
|
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 |
+
|
17 |
### Model description
|
18 |
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:
|
19 |
|
|
|
26 |
### Training procedure
|
27 |
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.
|
28 |
|
29 |
+
### How to Use
|
30 |
+
This checkpoint consists of an encoder (356M model), which can be used to extract code embeddings of 1024 dimension.
|
31 |
|
32 |
+
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).
|
33 |
+
|
34 |
```
|
35 |
from transformers import AutoModel, AutoTokenizer
|
36 |
|
37 |
checkpoint = "codesage/codesage-base"
|
38 |
+
device = "cuda" # "cpu" for CPU usage
|
39 |
+
|
40 |
+
# Note: CodeSage requires adding eos token at the end of each tokenized sequence
|
41 |
|
|
|
|
|
42 |
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True, add_eos_token=True)
|
43 |
|
44 |
model = AutoModel.from_pretrained(checkpoint, trust_remote_code=True).to(device)
|
45 |
|
46 |
inputs = tokenizer.encode("def print_hello_world():\tprint('Hello World!')", return_tensors="pt").to(device)
|
47 |
embedding = model(inputs)[0]
|
48 |
+
```
|
49 |
+
|
50 |
+
2. Accessing CodeSage via SentenceTransformer
|
51 |
+
```
|
52 |
+
from sentence_transformers import SentenceTransformer
|
53 |
+
model = SentenceTransformer("codesage/codesage-base", trust_remote_code=True)
|
54 |
```
|
55 |
|
56 |
### BibTeX entry and citation info
|