File size: 5,571 Bytes
8b821fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
<!--Copyright 2022 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# CodeGen[[Codegen]]
<div class="flex flex-wrap space-x-1">
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white">
</div>
## ๊ฐ์[[Overview]]
CodeGen ๋ชจ๋ธ์ Erik Nijkamp, Bo Pang, Hiroaki Hayashi, Lifu Tu, Huan Wang, Yingbo Zhou, Silvio Savarese, Caiming Xiong์ด ์์ฑํ ๋
ผ๋ฌธ [A Conversational Paradigm for Program Synthesis](https://arxiv.org/abs/2203.13474)์์ ์ ์๋์์ต๋๋ค.
CodeGen ๋ชจ๋ธ์ ํ๋ก๊ทธ๋จ ํฉ์ฑ(program synthesis)์ ์ํ ์๊ธฐํ๊ท(autoregressive) ์ธ์ด ๋ชจ๋ธ๋ก, [The Pile](https://pile.eleuther.ai/), BigQuery, BigPython ๋ฐ์ดํฐ๋ก ์์ฐจ์ ์ผ๋ก ํ์ต๋์์ต๋๋ค.
๋
ผ๋ฌธ์ ์ด๋ก์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:
*ํ๋ก๊ทธ๋จ ํฉ์ฑ(program synthesis)์ ์ฃผ์ด์ง ๋ฌธ์ ๋ช
์ธ์ ๋ํ ํด๋ต์ผ๋ก ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ ๊ฒ์ ๋ชฉํ๋ก ํฉ๋๋ค. ์ด ๋
ผ๋ฌธ์์๋ ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ(LLM)์ ํ์ฉํ ๋ํํ ํ๋ก๊ทธ๋จ ํฉ์ฑ(conversational program synthesis) ์ ๊ทผ๋ฒ์ ์ ์ํ์ฌ, ๊ธฐ์กด ์ ๊ทผ๋ฒ์์์ ๋ฐฉ๋ํ ํ๋ก๊ทธ๋จ ํ์ ๊ณต๊ฐ๊ณผ ์ฌ์ฉ์์ ์๋๋ฅผ ๋ช
์ธํํ๋ ๊ณผ์ ์์์ ์ด๋ ค์์ ํด๊ฒฐํฉ๋๋ค. ์ ์๋ ๋ฐฉ์์์๋ ํ๋ก๊ทธ๋จ ๋ช
์ธ ์์ฑ๊ณผ ์ค์ ํ๋ก๊ทธ๋จ ์์ฑ์ ์ฌ์ฉ์์ ์์คํ
๊ฐ ๋คํ ๋ํ(multi-turn conversation)๋ก ๋ฐ๋ผ๋ด
๋๋ค. ์ฆ, ํ๋ก๊ทธ๋จ ํฉ์ฑ ๊ณผ์ ๋ช
์ธ๋ฅผ ์์ฐ์ด๋ก ํํํ๊ณ , ๊ธฐ๋ํ๋ ํ๋ก๊ทธ๋จ ํฉ์ฑ์ ์กฐ๊ฑด๋ถ๋ก ์์ธกํ์ฌ ์์ฑํ๋ ์ผ์ข
์ ์์ฐจ์ ์์ธก ๋ฌธ์ (sequence prediction problem)๋ก ์ ๊ทผํ์ต๋๋ค. ์ด๋ฅผ ์ํด ์์ฐ์ด์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก CodeGen์ด๋ผ๋ ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ ๊ทธ๋ฃน์ ํ์ต์์ผฐ์ผ๋ฉฐ, ๋ฐ์ดํฐ๋ก๋ถํฐ ์ฝํ ์ง๋(weak supervision)์ ๋ฐ์ดํฐ ๋ฐ ๋ชจ๋ธ ๊ท๋ชจ์ ํ์ฅ๋ง์ผ๋ก๋ ๋ชจ๋ธ์ด ์์ฐ์ค๋ฝ๊ฒ ๋ํ ๋ฅ๋ ฅ์ ๊ฐ์ถ๊ฒ ๋๋ค๋ ์ ์ ํ์ธํ์์ต๋๋ค. ๋ํด์ ๋ชจ๋ธ์ ๋ํํ ํ๋ก๊ทธ๋จ ํฉ์ฑ ๋ฅ๋ ฅ์ ํ๊ฐํ๊ธฐ ์ํด ๋คํ ๋ํ ๊ธฐ๋ฐ ํ๋ก๊ทธ๋๋ฐ ๋ฒค์น๋งํฌ(MTPB)๋ฅผ ๊ฐ๋ฐํ์ต๋๋ค. ์ด ๋ฒค์น๋งํฌ๋ ๊ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์ฌ์ฉ์์ ๋ชจ๋ธ ๊ฐ ์ฌ๋ฌ ๋จ๊ณ์ ๋ํ๋ฅผ ๊ฑฐ์ณ ํ๋ก๊ทธ๋จ์ด ์ ์ง์ ์ผ๋ก ํฉ์ฑ๋๋ ๊ณผ์ ์ ์๊ตฌํฉ๋๋ค. ์ฐ๊ตฌ ๊ฒฐ๊ณผ, CodeGen ๋ชจ๋ธ์ ๋ํํ ๋ฅ๋ ฅ์ ์ฑ๊ณต์ ์ผ๋ก ๋ฐํํ์ผ๋ฉฐ ๋ณธ ๋
ผ๋ฌธ์์ ์ ์ํ ๋ํํ ํฉ์ฑ ํจ๋ฌ๋ค์์ ์ฐ์์ฑ๊ณผ ํจ์จ์ฑ์ ์
์ฆํ์ต๋๋ค. ํนํ 16B ํ๋ผ๋ฏธํฐ ๊ท๋ชจ๋ก TPU-v4์์ ํ์ต๋ CodeGen ๋ชจ๋ธ์ HumanEval ๋ฒค์น๋งํฌ์์ OpenAI์ Codex๋ฅผ ๋ฐ์ด๋๋ ์ฑ๋ฅ์ ๊ธฐ๋กํ์ต๋๋ค. ํ์ต๋ ์ฌ์ฉ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ JaxFormer์ ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ ์คํ์์ค๋ก ๊ณต๊ฐ๋์์ต๋๋ค: [์ด https URL์์ ํ์ธํ์ธ์](https://github.com/salesforce/codegen).*
์ด ๋ชจ๋ธ์[Hiroaki Hayashi](https://huggingface.co/rooa)๊ฐ ๊ธฐ์ฌํ์ต๋๋ค.
๋ชจ๋ธ์ ์๋ณธ ์ฝ๋๋ [์ฌ๊ธฐ](https://github.com/salesforce/codegen)์ ์์ต๋๋ค.
## ์ฒดํฌํฌ์ธํธ ๋ช
๋ช
๊ท์น[[Checkpoint Naming]]
* CodeGen ๋ชจ๋ธ์ [์ฒดํฌํฌ์ธํธ](https://huggingface.co/models?other=codegen)๋ ์๋ก ๋ค๋ฅธ ์ฌ์ ํ์ต ๋ฐ์ดํฐ์ ๋ค์ํ ํฌ๊ธฐ๋ก ์ ๊ณต๋ฉ๋๋ค.
* ์ฒดํฌํฌ์ธํธ์ ํ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: `Salesforce/codegen-{size}-{data}`
* `size`: `350M`, `2B`, `6B`, `16B`
* `data`:
* `nl`: The Pile ๋ฐ์ดํฐ๋ก ์ฌ์ ํ์ต๋ ๋ชจ๋ธ
* `multi`: `nl` ๋ชจ๋ธ์์ ์์ํ์ฌ ๋ค์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ฅผ ์ถ๊ฐ์ ์ผ๋ก ํ์ตํ ๋ชจ๋ธ
* `mono`: `multi` ๋ชจ๋ธ์์ ์์ํ์ฌ ์ถ๊ฐ๋ก Python ๋ฐ์ดํฐ์ ๋ํด ํ์ต๋ ๋ชจ๋ธ
* ์๋ฅผ ๋ค์ด, `Salesforce/codegen-350M-mono`๋ 3์ต 5์ฒ๋ง(350M) ๊ฐ์ ํ๋ผ๋ฏธํฐ๋ฅผ ๋ชจ๋ธ๋ก, The Pile, ๋ค์ํ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด, Python ๋ฐ์ดํฐ์ ์์๋ก ๋จ๊ณ์ ์ผ๋ก ํ์ตํ ์ฒดํฌํฌ์ธํธ๋ฅผ ์๋ฏธํฉ๋๋ค.
## ์ฌ์ฉ ์์[[Usage example]]
```python
>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> checkpoint = "Salesforce/codegen-350M-mono"
>>> model = AutoModelForCausalLM.from_pretrained(checkpoint)
>>> tokenizer = AutoTokenizer.from_pretrained(checkpoint)
>>> text = "def hello_world():"
>>> completion = model.generate(**tokenizer(text, return_tensors="pt"))
>>> print(tokenizer.decode(completion[0]))
def hello_world():
print("Hello World")
hello_world()
```
## ์๋ฃ[[Resources]]
- [Causal language modeling task guide](../tasks/language_modeling)
## CodeGenConfig
[[autodoc]] CodeGenConfig
- all
## CodeGenTokenizer
[[autodoc]] CodeGenTokenizer
- create_token_type_ids_from_sequences
- save_vocabulary
## CodeGenTokenizerFast
[[autodoc]] CodeGenTokenizerFast
## CodeGenModel
[[autodoc]] CodeGenModel
- forward
## CodeGenForCausalLM
[[autodoc]] CodeGenForCausalLM
- forward
|