rooa commited on
Commit
d3cb58e
1 Parent(s): d687509
Files changed (2) hide show
  1. README.md +104 -0
  2. pytorch_model.bin +3 -0
README.md CHANGED
@@ -1,3 +1,107 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+
5
+ # CodeGen2 (CodeGen2-1B)
6
+
7
+ ## Model description
8
+
9
+ [CodeGen2](https://github.com/salesforce/CodeGen2) is a family of autoregressive language models for **program synthesis**, introduced in the paper:
10
+
11
+ [CodeGen2: Lessons for Training LLMs on Programming and Natural Languages]() by Erik Nijkamp\*, Hiroaki Hayashi\*, Caiming Xiong, Silvio Savarese, Yingbo Zhou.
12
+
13
+ Unlike the original CodeGen model family (i.e., CodeGen1), CodeGen2 is capable of infilling, and supports more programming languages.
14
+
15
+ Four model sizes are released: `1B`, `3.7B`, `7B`, `16B`.
16
+
17
+ ## How to use
18
+
19
+ This model can be easily loaded using the `AutoModelForCausalLM` functionality.
20
+
21
+ ### Causal sampling
22
+
23
+ For regular causal sampling, simply generate completions given the context:
24
+ ```python
25
+ from transformers import AutoTokenizer, AutoModelForCausalLM
26
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-1B")
27
+ model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-1B", trust_remote_code=True, revision="main")
28
+
29
+ text = "def hello_world():"
30
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
31
+ generated_ids = model.generate(input_ids, max_length=128)
32
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
33
+ ```
34
+
35
+ ### Infill sampling
36
+
37
+ For **infill** sampling, we introduce three new special token types:
38
+
39
+ * `<mask_N>`: N-th span to be masked. In practice, use `<mask_1>` to where you want to sample infill.
40
+ * `<sep>`: Seperator token between the suffix and the infilled sample. See below.
41
+ * `<eom>`: "End-Of-Mask" token that model will output at the end of infilling. You may use this token to truncate the output.
42
+
43
+ For example, if we want to generate infill for the following cursor position of a function:
44
+ ```python
45
+ def hello_world():
46
+ |
47
+ return name
48
+ ```
49
+ we construct an input to the model by
50
+
51
+ 1. Inserting `<mask_1>` token in place of cursor position
52
+ 2. Append `<sep>` token to indicate the boundary
53
+ 3. Insert another `<mask_1>` to indicate which mask we want to infill.
54
+
55
+ The final snippet looks as follows:
56
+
57
+ ```python
58
+ from transformers import AutoTokenizer, AutoModelForCausalLM
59
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-1B")
60
+ model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-1B")
61
+
62
+
63
+ def format(prefix, suffix):
64
+ return prefix + "<mask_1>" + suffix + "<|endoftext|>" + "<sep>" + "<mask_1>"
65
+
66
+
67
+ prefix = "def hello_world():\n "
68
+ suffix = " return name"
69
+ text = format(prefix, suffix)
70
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
71
+ generated_ids = model.generate(input_ids, max_length=128)
72
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=False)[len(text):])
73
+ ```
74
+
75
+ You might want to truncate the model output with `<eom>`.
76
+
77
+ ## Training data
78
+
79
+ This checkpoint is trained on the stricter permissive subset of [the deduplicated version of the Stack dataset (v1.1)](). Supported languages (and frameworks) are as follows:
80
+ `c`, `c++`, `c-sharp`, `dart`, `go`, `java`, `javascript`, `kotlin`, `lua`, `php`, `python`, `ruby`, `rust`, `scala`, `shell`, `sql`, `swift`, `typescript`, `vue`.
81
+
82
+ ## Training procedure
83
+
84
+ CodeGen2 was trained using cross-entropy loss to maximize the likelihood of sequential inputs.
85
+ The input sequences are formatted in two ways: (1) causal language modeling and (2) file-level span corruption.
86
+ Please refer to the paper for more details.
87
+
88
+ ## Evaluation results
89
+
90
+ We evaluate our models on HumanEval and HumanEval-Infill. Please refer to the [paper]() for more details.
91
+
92
+ ## Intended use and limitations
93
+
94
+ As an autoregressive language model, CodeGen2 is capable of extracting features from given natural language and programming language texts, and calculating the likelihood of them.
95
+ However, the model is intended for and best at **program synthesis**, that is, generating executable code given English prompts, where the prompts should be in the form of a comment string. The model can complete partially-generated code as well.
96
+
97
+
98
+ ## BibTeX entry and citation info
99
+
100
+ ```bibtex
101
+ @article{Nijkamp2023codegen2,
102
+ title={CodeGen2: Lessons for Training LLMs on Programming and Natural Languages},
103
+ author={Nijkamp, Erik and Hayashi, Hiroaki and Xiong, Caiming and Savarese, Silvio and Zhou, Yingbo},
104
+ journal={arXiv preprint},
105
+ year={2022}
106
+ }
107
+ ```
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49e82b23a40d46cce476867101dd557f6468c40da617f37b77f20f4e82e75da5
3
+ size 4128380705