File size: 15,799 Bytes
2dd6909 |
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
---
datasets:
- nlpai-lab/kullm-v2
language:
- ko
- en
---
<br/>
# ๐ฐ๐ท๐ฆ KoLlama2-7b ์ ์ฅ์์
๋๋ค ๐ฆ๐ฐ๐ท
โ
KoLlama2 ์ฒซ๋ฒ์ ์ ๊ณ ๋ ค๋ํ๊ต NLP & AI ์ฐ๊ตฌ์ค๊ณผ HIAI ์ฐ๊ตฌ์๊ฐ ๊ณต๊ฐํ ํ๊ตญ์ด instruction dataset kullm-v2๋ฅผ ์ฌ์ฉํ LoRA ํ์ธํ๋์
๋๋ค.
<br/>
[Read English](#kollama2--open-source-language-model-based-on-llama2-optimized-for-korean)
# KoLlama2 : ํ๊ตญ์ด์ ์ต์ ํ๋ Llama2 ๊ธฐ๋ฐ ์คํ์์ค ์ธ์ด๋ชจ๋ธ
KoLlama2(Korean Large Language Model Meta AI 2)๋ ์์ด ๊ธฐ๋ฐ LLM์ธ Llama2์ ํ๊ตญ์ด ์ฑ๋ฅ์ ํฅ์ํ๊ธฐ ์ํ ์คํ์์ค ํ๋ก์ ํธ์
๋๋ค.
<br/>
## ํ์์ฑ
GPT3๋ถํฐ Bert, Llama2์ ์ด๋ฅด๊ธฐ๊น์ง ๋๊ท๋ชจ ์ธ์ด๋ชจ๋ธ์ ๋๋ผ์ด ๋ฐ์ ์ ๋ชจ๋ ์ด์ ์ด๋ชฉ์ ๋๊ณ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋๊ท๋ชจ ๋ง๋ญ์น๋ฅผ ์ฌ์ ํ์ตํ๋ LLM์ ํน์ฑ์ ํ์ต ๋ฐ์ดํฐ ์ค ๋๋ค์๋ ์์ด๋ก ๊ตฌ์ ๋๋ฉฐ, ํ๊ตญ์ด๋ ๋งค์ฐ ์ ์ ๋น์จ์ ์ฐจ์งํฉ๋๋ค.
- GPT3์ ์ฌ์ ํ์ต ๋ฐ์ดํฐ ์ค ํ๊ตญ์ด ๋น์จ: 0.01697%
<p align="center" style="color:gray">
<img style="margin:20px 0 10px 0" src="https://github.com/psymon-dev/KoLlama2/assets/91517542/b50b9283-fb54-46b6-bc84-00bd363601c8" alt="image" width=482 />
<br/>์ถ์ฒ: https://github.com/openai/gpt-3/blob/master/dataset_statistics/languages_by_word_count.csv
</p>
- Llama2 ๋ชจ๋ธ์ ์ฌ์ ํ์ต ๋ฐ์ดํฐ ์ค ํ๊ตญ์ด ๋น์จ: 0.06%
<p align="center" style="color:gray">
<img style="margin:20px 0 10px 0" src="https://github.com/psymon-dev/KoLlama2/assets/91517542/79b72fee-3517-4a7e-a0a5-fda4c8f2a7ca" alt="image" width=482 />
<br/>์ถ์ฒ: 22p Table 10, Llama 2: Open Foundation and Fine-Tuned Chat Models, Hugo Touvron et al, July 18-2023.
</p>
์ด ๋น์จ์ ์ ์ธ๊ณ ์ธ๊ตฌ(7.888 billion) ์ค ํ๊ตญ์ด ํ์(81.7M) ๋น์จ(1.035%)๊ณผ ๋น๊ตํด๋ ํฌ๊ฒ ๋ฎ์ ์์น์
๋๋ค. ์ด๋ ๊ณ ๋ฆฝ์ด๋ผ๋ ํ๊ตญ์ด ํน์ฑ, ์ค๋น๋์ง ์์ ํ๊ตญ์ด ๋ง๋ญ์น ๋ฑ ์ฌ๋ฌ ์์ธ์ ๊ธฐ๋ฐํ ๊ฒ์ด์ง๋ง ๊ฒฐ๊ณผ์ ์ผ๋ก ํ๊ตญ์ด ์ฌ์ฉ์๊ฐ LLM์ ํ๋ถํ ๋ฅ๋ ฅ์ ๊ฒฝํํ๋ ๊ฒ์ ๋งค์ฐ ์ ํํ๊ณ ์์ต๋๋ค.
<br/>
## ๊ธฐ์กด ์๋๋ค
### ํ๊ตญ์ด๊ธฐ๋ฐ LLM ์ฌ์ ํ์ต
๊ฐ์ฅ ์ข์ ํด๊ฒฐ์ฑ
์ค ํ๋๋ ํ๊ตญ์ด ๋ฐ์ดํฐ๋ก ์ฌ์ ํ์ตํ ์์ฒด ์ธ์ด๋ชจ๋ธ์ ๋ง๋๋ ๊ฒ์
๋๋ค. ์ด๋ฌํ ์๋๋ ์๋ณธ๋ ฅ์ ๊ฐ์ถ ๋๊ธฐ์
์ ์ฃผ๋๋ก ์งํ๋๊ณ ์์ต๋๋ค.
* Naver์ HyperCLOVA X : https://clova.ai/hyperclova
* Kakao์ KoGPT : https://github.com/kakaobrain/kogpt
* EleutherAI์ polyglot-ko : https://github.com/EleutherAI/polyglot
์ด๋ฌํ ์ ๊ทผ๋ฒ์ LLM์ ํ๊ตญ์ด ๋ฅ๋ ฅ ๋ถ์กฑ์ ๊ฐ์ฅ ํ์คํ๊ฒ ํด๊ฒฐํ ์ ์์ต๋๋ค. ๋ค๋ง ๋ฌธ์ ๋ LLM์ ๋ณํ์๋๊ฐ ๋๋ฌด ๋น ๋ฅด๋ค๋ ๋ฐ ์์ต๋๋ค. LLaMA ๋ชจ๋ธ์ด ๊ณต๊ฐ๋ ํ Llama2 ๋ชจ๋ธ์ด ๊ณต๊ฐ๋๊ธฐ๊น์ง ๊ณ ์ 5๊ฐ์ ๋ฐ์ ๊ฑธ๋ฆฌ์ง ์์์ต๋๋ค. ๋งค์ฃผ ์๋ก์ด ๊ธฐ์ ์ด ๋ฐํ๋๋ ํ ์ํฉ์์ ๋ฏธ๋ ๋ฐ์ ๋ฐฉํฅ์ ์ ํํ ์์ธกํ๊ฑฐ๋, ๋งค๋ฒ ์๋ก์ด ๋ณํ์ ๋ง์ถฐ ๋๊ท๋ชจ ์ธ์ด๋ชจ๋ธ์ ํ์ตํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค.
๋ฐ๋ผ์ ์ฐ๋ฆฌ๋ ์์ฒด ์ธ์ด๋ชจ๋ธ์ ํ์ตํ๋ ๊ฒ๊ณผ ๋ณํํ ์ ์๋ ๋ ๊ฐ๋ณ๊ณ ๋น ๋ฅธ ๋ฐฉ๋ฒ์ด ํ์ํฉ๋๋ค.
### ์ธ๊ตญ์ด๊ธฐ๋ฐ LLM ๋ฏธ์ธ์กฐ์
์ธ๊ตญ์ด๊ธฐ๋ฐ LLM์ ํ๊ตญ์ด๋ก ๋ฏธ์ธ์กฐ์ ํ๋ ๊ฒ์ ์ด ๋ฌธ์ ์ ๋ํ ์ข์ ํด๊ฒฐ ์ฑ
์
๋๋ค. LLaMa ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก ์๋์ ๊ฐ์ ์๋๋ค์ด ์์์ต๋๋ค.
* KoAlpaca : https://github.com/Beomi/KoAlpaca
* KULLM : https://github.com/nlpai-lab/KULLM
* KoVicuna : https://github.com/melodysdreamj/KoVicuna
* KORani : https://github.com/krafton-ai/KORani
์ด๋ฌํ ์๋๋ค์ ์คํ์์ค LLM์ ๋ํ ๊ด์ฌ์ ๋๋ฆฌ๊ณ ๋ค์ํ ๋ฏธ์ธ์กฐ์ ๋ฐฉ๋ฒ์ ์ดํดํ๋ ๋ฐ ๋์์ ์ฃผ์์ง๋ง ํ๊ณ์ ๋ ๋ช
ํํ์ต๋๋ค.
1. LLaMA ๋ชจ๋ธ์ ๊ฒฝ์ฐ ์ฌ์ ํ์ต ๋ฐ์ดํฐ์ ํ๊ตญ์ด๊ฐ ์ ์ธ๋์ด Full-Finetuning, LoRA, QLoRA ๋ฑ ์ด๋ค ๋ฐฉ๋ฒ์ผ๋ก๋ ๋ง์กฑ์ค๋ฌ์ด ํ๊ตญ์ด ์ฑ๋ฅ์ ๋ด์ง ๋ชปํ์ต๋๋ค.
2. ํต์ผ๋ ํ๊ตญ์ด ํ์ต ํ๊ฐ ๋ฐฉ๋ฒ์ด ์์ด ์ด๋ค ํ์ต ๋ฐฉ๋ฒ์ด ๊ฐ์ฅ ํจ๊ณผ์ ์ธ์ง ํ๋จํ๊ธฐ ์ด๋ ค์ ์ต๋๋ค.
3. ๊ฐ ํ๋ก์ ํธ๊ฐ ๊ฐ๋ณ ์ฃผ์ฒด์ ์ํด ์ฐ๋ฐ๋ก ์ ๊ฐ๋์ด ์ค๋ณต๋ ์๋๊ฐ ๋ฐ๋ณต๋์์ต๋๋ค.
## KoLlama2 ํ๋ก์ ํธ ์ ์
KoLlama2๋ LLaMA ๋ชจ๋ธ์์ ์ป์ ๊ฒฝํ์ ๋ฐํ์ผ๋ก ์ธ๊ตญ์ด ๊ธฐ๋ฐ LLM์ ํ๊ตญ์ด๋ก ๋ฏธ์ธ์กฐ์ ํ๋ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ ์ฐพ๋ ํ๋ก์ ํธ์
๋๋ค. ์ด๋ฅผ ์ํด ์๋์ ๊ฐ์ ์๋๋ค์ด ํ์ํฉ๋๋ค.
1. QLoRA, LoRA, Full-Finetuning ๋ฑ ๋ค์ํ ๋ฐฉ๋ฒ๋ก ์ ์๋ํ์ฌ Llama2์ ํฌํจ๋ 0.01697% ํ๊ตญ์ด ๋ฅ๋ ฅ์ด ์ผ๋ง๋ ํฅ์๋๋์ง ํ์ธ.
2. Alpaca, Vicuna ๋ฑ ๋ค์ํ ๋ฐ์ดํฐ์ธํธ๋ฅผ ์ ์ฉํ์ฌ ์ด๋ค ํํ ํ
์ดํฐ์ธํธ๊ฐ ํ๊ตญ์ด ๋ฅ๋ ฅํฅ์์ ๊ฐ์ฅ ํจ๊ณผ์ ์ธ์ง ํ์ธ.
3. ๊ฐ๋จํ ํ์ ๋ฒ์ญ๋ถํฐ ์ ์ฐจ ๋์ด๋๋ฅผ ์ฌ๋ฆฌ๋ Curriculum Learning, ๋๊ท๋ชจ ํ๊ตญ์ด ๋ง๋ญ์น๋ก ์ฌ์ ํ์ต Step์ ์ถ๊ฐ ํ์ต, Chinese-LLaMA์์ ์ฌ์ฉํ ์ดํํ์ฅ ๋ฑ ์๋ก์ด ๊ธฐ๋ฒ๋ค ์๋.
4. ๊ฐ ๋ฐฉ๋ฒ๋ก ์ ํ๊ฐํ ํฉ๋ฆฌ์ ํ๊ฐ๋ฒ ๊ณ ์.
## Benchmarks
## ์ฐธ๊ณ ์๋ฃ
<br/>
---
# KoLlama2 : Open source language model based on Llama2 optimized for Korean
KoLlama2 (Korean Large Language Model Meta AI 2) is an open-source project to improve the Korean performance of Llama2, an English-based LLM.
## Problem
From GPT3 to Bert to Llama2, the amazing advances in large-scale language models have captured everyone's attention. However, due to the nature of LLMs pre-training on large corpora, the vast majority of training data is spoken in English, with Korean representing a very small percentage.
- Percentage of Korean in GPT3's pretraining data: 0.01697
<p align="center" style="color:gray">
<img style="margin:20px 0 10px 0" src="https://github.com/psymon-dev/KoLlama2/assets/91517542/b50b9283-fb54-46b6-bc84-00bd363601c8" alt="image" width=482 />
<br/>https://github.com/openai/gpt-3/blob/master/dataset_statistics/languages_by_word_count.csv
</p>
- Percentage of Korean in the Llama2 model's pre-training data: 0.06%.
<p align="center" style="color:gray">
<img style="margin:20px 0 10px 0" src="https://github.com/psymon-dev/KoLlama2/assets/91517542/79b72fee-3517-4a7e-a0a5-fda4c8f2a7ca" alt="image" width=482 />
<br/>22p Table 10, Llama 2: Open Foundation and Fine-Tuned Chat Models, Hugo Touvron et al, July 18-2023.
</p>
This percentage is significantly lower than the percentage of Korean speakers (81.7M) in the world's population (7.888 billion) (1.035%). This is based on a number of factors, including the isolated nature of Korean, an unprepared Korean corpus, and more, but the end result is that Korean speakers are severely limited in experiencing the richness of LLM.
## Problem Statement
### Korean-based LLM Pretrain
One of the best solutions is to create your own language model, pre-trained with Korean data. This is being done by large, well-funded companies.
* Naver HyperCLOVA X : https://clova.ai/hyperclova
* Kakao KoGPT : https://github.com/kakaobrain/kogpt
* EleutherAI polyglot-ko : https://github.com/EleutherAI/polyglot
This approach would most certainly address the LLM's lack of Korean language skills. The problem is that the LLM is changing so fast. It took only five months between the release of the LLaMA model and the release of the Llama2 model. With new technologies being released every week, it's impossible to accurately predict future developments, or to train a large language model to adapt to each new change.
Therefore, we need a lighter and faster method that can be used in parallel with learning our own language models.
### Fine-tuning a English-based LLM
Fine-tuning a foreign language-based LLM into Korean is a good solution to this problem. The following attempts have been made based on the LLaMa model.
* KoAlpaca : https://github.com/Beomi/KoAlpaca
* KULLM : https://github.com/nlpai-lab/KULLM
* KoVicuna : https://github.com/melodysdreamj/KoVicuna
* KORani : https://github.com/krafton-ai/KORani
While these attempts have increased interest in open source LLMs and helped me understand the various ways to fine-tune them, the limitations are clear.
1. For the LLaMA model, Korean was excluded from the pre-training data, so no method, including Full-Finetuning, LoRA, and QLoRA, could produce satisfactory Korean performance.
2. There was no unified method for evaluating Korean language learning, making it difficult to determine which learning method was most effective.
3. Each project was developed sporadically by individual entities, resulting in redundant attempts.
## KoLlama2 Project Suggested
KoLlama2 is a project to find the best way to fine-tune a English-based LLM into Korean based on the experience gained from the LLaMA model. To achieve this, the following attempts are required.
1. try different methodologies such as QLoRA, LoRA, and Full-Finetuning to see how much the 0.01697% Korean proficiency included in Llama2 improves.
2. Apply various datasets such as Alpaca and Vicuna to see which type of dataset is most effective for improving Korean proficiency.
3. try new techniques such as curriculum learning that gradually increases the difficulty from simple English to Korean translation, additional pre-learning steps with a large Korean corpus, and vocabulary expansion used in Chinese-LLaMA.
4. devising a reasonable evaluation method to assess each methodology.
## Benchmarks
## References
# Llama 2
We are unlocking the power of large language models. Our latest version of Llama is now accessible to individuals, creators, researchers and businesses of all sizes so that they can experiment, innovate and scale their ideas responsibly.
This release includes model weights and starting code for pretrained and fine-tuned Llama language models โ ranging from 7B to 70B parameters.
This repository is intended as a minimal example to load [Llama 2](https://ai.meta.com/research/publications/llama-2-open-foundation-and-fine-tuned-chat-models/) models and run inference. For more detailed examples leveraging HuggingFace, see [llama-recipes](https://github.com/facebookresearch/llama-recipes/).
## Download
โ ๏ธ **7/18: We're aware of people encountering a number of download issues today. Anyone still encountering issues should remove all local files, re-clone the repository, and [request a new download link](https://ai.meta.com/resources/models-and-libraries/llama-downloads/). It's critical to do all of these in case you have local corrupt files. When you receive the email, copy *only* the link text - it should begin with https://download.llamameta.net and not with https://l.facebook.com, which will give errors.**
In order to download the model weights and tokenizer, please visit the [Meta AI website](https://ai.meta.com/resources/models-and-libraries/llama-downloads/) and accept our License.
Once your request is approved, you will receive a signed URL over email. Then run the download.sh script, passing the URL provided when prompted to start the download. Make sure that you copy the URL text itself, **do not use the 'Copy link address' option** when you right click the URL. If the copied URL text starts with: https://download.llamameta.net, you copied it correctly. If the copied URL text starts with: https://l.facebook.com, you copied it the wrong way.
Pre-requisites: make sure you have `wget` and `md5sum` installed. Then to run the script: `./download.sh`.
Keep in mind that the links expire after 24 hours and a certain amount of downloads. If you start seeing errors such as `403: Forbidden`, you can always re-request a link.
### Access on Hugging Face
We are also providing downloads on [Hugging Face](https://huggingface.co/meta-llama). You must first request a download from the Meta AI website using the same email address as your Hugging Face account. After doing so, you can request access to any of the models on Hugging Face and within 1-2 days your account will be granted access to all versions.
## Setup
In a conda env with PyTorch / CUDA available, clone the repo and run in the top-level directory:
```
pip install -e .
```
## Inference
Different models require different model-parallel (MP) values:
| Model | MP |
|--------|----|
| 7B | 1 |
| 13B | 2 |
| 70B | 8 |
All models support sequence length up to 4096 tokens, but we pre-allocate the cache according to `max_seq_len` and `max_batch_size` values. So set those according to your hardware.
### Pretrained Models
These models are not finetuned for chat or Q&A. They should be prompted so that the expected answer is the natural continuation of the prompt.
See `example_text_completion.py` for some examples. To illustrate, see command below to run it with the llama-2-7b model (`nproc_per_node` needs to be set to the `MP` value):
```
torchrun --nproc_per_node 1 example_text_completion.py \
--ckpt_dir llama-2-7b/ \
--tokenizer_path tokenizer.model \
--max_seq_len 128 --max_batch_size 4
```
### Fine-tuned Chat Models
The fine-tuned models were trained for dialogue applications. To get the expected features and performance for them, a specific formatting defined in [`chat_completion`](https://github.com/facebookresearch/llama/blob/main/llama/generation.py#L212)
needs to be followed, including the `INST` and `<<SYS>>` tags, `BOS` and `EOS` tokens, and the whitespaces and breaklines in between (we recommend calling `strip()` on inputs to avoid double-spaces).
You can also deploy additional classifiers for filtering out inputs and outputs that are deemed unsafe. See the llama-recipes repo for [an example](https://github.com/facebookresearch/llama-recipes/blob/main/inference/inference.py) of how to add a safety checker to the inputs and outputs of your inference code.
Examples using llama-2-7b-chat:
```
torchrun --nproc_per_node 1 example_chat_completion.py \
--ckpt_dir llama-2-7b-chat/ \
--tokenizer_path tokenizer.model \
--max_seq_len 512 --max_batch_size 4
```
Llama 2 is a new technology that carries potential risks with use. Testing conducted to date has not โ and could not โ cover all scenarios.
In order to help developers address these risks, we have created the [Responsible Use Guide](Responsible-Use-Guide.pdf). More details can be found in our research paper as well.
## Issues
Please report any software โbug,โ or other problems with the models through one of the following means:
- Reporting issues with the model: [github.com/facebookresearch/llama](http://github.com/facebookresearch/llama)
- Reporting risky content generated by the model: [developers.facebook.com/llama_output_feedback](http://developers.facebook.com/llama_output_feedback)
- Reporting bugs and security concerns: [facebook.com/whitehat/info](http://facebook.com/whitehat/info)
## Model Card
See [MODEL_CARD.md](MODEL_CARD.md).
## License
Our model and weights are licensed for both researchers and commercial entities, upholding the principles of openness. Our mission is to empower individuals, and industry through this opportunity, while fostering an environment of discovery and ethical AI advancements.
See the [LICENSE](LICENSE) file, as well as our accompanying [Acceptable Use Policy](USE_POLICY.md)
## References
1. [Research Paper](https://ai.meta.com/research/publications/llama-2-open-foundation-and-fine-tuned-chat-models/)
2. [Llama 2 technical overview](https://ai.meta.com/resources/models-and-libraries/llama)
3. [Open Innovation AI Research Community](https://ai.meta.com/llama/open-innovation-ai-research-community/)
## Original LLaMA
The repo for the original llama release is in the [`llama_v1`](https://github.com/facebookresearch/llama/tree/llama_v1) branch.
|