Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,143 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
library_name: peft
|
4 |
---
|
5 |
+
|
6 |
+
# Food Order Understanding in Korean
|
7 |
+
|
8 |
+
This is a LoRA adapter as a result of fine-tuning the pre-trained model 'meta-llama/Llama-2-13b-chat-hf'. It is designed with the expectation of understanding Korean food ordering sentences, and analyzing food menus, option names, and quantities.
|
9 |
+
|
10 |
+
## Usage
|
11 |
+
|
12 |
+
Here is an example of loading the model.
|
13 |
+
Note the pretrained model is `meta-llama/Llama-2-13b-chat-hf`.
|
14 |
+
|
15 |
+
```python
|
16 |
+
peft_model_id = "jangmin/qlora-llama2-13b-chat-hf-food-order-understanding-30K"
|
17 |
+
|
18 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
19 |
+
|
20 |
+
bnb_config = BitsAndBytesConfig(
|
21 |
+
load_in_4bit=True,
|
22 |
+
bnb_4bit_use_double_quant=True,
|
23 |
+
bnb_4bit_quant_type="nf4",
|
24 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
25 |
+
)
|
26 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, quantization_config=bnb_config, cache_dir=cache_dir, device_map={"":0})
|
27 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path, cache_dir=cache_dir)
|
29 |
+
|
30 |
+
model.eval()
|
31 |
+
```
|
32 |
+
|
33 |
+
Inferece can be done as follows.
|
34 |
+
```python
|
35 |
+
instruction_prompt_template = """
|
36 |
+
๋ค์์ ๋งค์ฅ์์ ๊ณ ๊ฐ์ด ์์์ ์ฃผ๋ฌธํ๋ ์ฃผ๋ฌธ ๋ฌธ์ฅ์ด๋ค. ์ด๋ฅผ ๋ถ์ํ์ฌ ์์๋ช
, ์ต์
, ์๋์ ์ถ์ถํ์ฌ ๊ณ ๊ฐ์ ์๋๋ฅผ ์ดํดํ๊ณ ์ ํ๋ค.
|
37 |
+
๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํด์ฃผ๊ธฐ ๋ฐ๋๋ค.
|
38 |
+
|
39 |
+
### ์ฃผ๋ฌธ ๋ฌธ์ฅ: {0} ### ๋ถ์ ๊ฒฐ๊ณผ:
|
40 |
+
"""
|
41 |
+
def gen(x):
|
42 |
+
q = instruction_prompt_template.format(x)
|
43 |
+
gened = model.generate(
|
44 |
+
**tokenizer(
|
45 |
+
q,
|
46 |
+
return_tensors='pt',
|
47 |
+
return_token_type_ids=False
|
48 |
+
).to('cuda'),
|
49 |
+
max_new_tokens=256,
|
50 |
+
early_stopping=True,
|
51 |
+
do_sample=True,
|
52 |
+
eos_token_id=tokenizer.eos_token_id
|
53 |
+
)
|
54 |
+
decoded_results = tokenizer.batch_decode(gened, skip_special_tokens=True)
|
55 |
+
return decoded_results[0]
|
56 |
+
```
|
57 |
+
|
58 |
+
A generated sample is as follows.
|
59 |
+
```python
|
60 |
+
print(gen("์์ด์ค์๋ฉ๋ฆฌ์นด๋
ธ ํจ์ฌ์ด์ฆ ํ์ ํ๊ณ ์. ๋ธ๊ธฐ์ค๋ฌด๋ ํ์ ์ฃผ์ธ์. ๋, ์ฝ๋๋ธ๋ฃจ๋ผ๋ผ ํ๋์."))
|
61 |
+
```
|
62 |
+
```
|
63 |
+
๋ค์์ ๋งค์ฅ์์ ๊ณ ๊ฐ์ด ์์์ ์ฃผ๋ฌธํ๋ ์ฃผ๋ฌธ ๋ฌธ์ฅ์ด๋ค. ์ด๋ฅผ ๋ถ์ํ์ฌ ์์๋ช
, ์ต์
๋ช
, ์๋์ ์ถ์ถํ์ฌ ๊ณ ๊ฐ์ ์๋๋ฅผ ์ดํดํ๊ณ ์ ํ๋ค.
|
64 |
+
๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํด์ฃผ๊ธฐ ๋ฐ๋๋ค.
|
65 |
+
|
66 |
+
### ๋ช
๋ น: ์์ด์ค์๋ฉ๋ฆฌ์นด๋
ธ ํจ์ฌ์ด์ฆ ํ์ ํ๊ณ ์. ๋ธ๊ธฐ์ค๋ฌด๋ ํ์ ์ฃผ์ธ์. ๋, ์ฝ๋๋ธ๋ฃจ๋ผ๋ผ ํ๋์. ### ์๋ต:
|
67 |
+
- ๋ถ์ ๊ฒฐ๊ณผ 0: ์์๋ช
:์์ด์ค์๋ฉ๋ฆฌ์นด๋
ธ, ์ต์
:ํจ์ฌ์ด์ฆ, ์๋:ํ์
|
68 |
+
- ๋ถ์ ๊ฒฐ๊ณผ 1: ์์๋ช
:๋ธ๊ธฐ์ค๋ฌด๋, ์๋:ํ์
|
69 |
+
- ๋ถ์ ๊ฒฐ๊ณผ 2: ์์๋ช
:์ฝ๋๋ธ๋ฃจ๋ผ๋ผ, ์๋:ํ๋
|
70 |
+
``````
|
71 |
+
|
72 |
+
## Training
|
73 |
+
|
74 |
+
Fine-tuning was performed using https://github.com/artidoro/qlora.
|
75 |
+
Here is my training script.
|
76 |
+
```bash
|
77 |
+
python qlora.py \
|
78 |
+
--cache_dir /Jupyter/huggingface/.cache \
|
79 |
+
--model_name_or_path meta-llama/Llama-2-13b-chat-hf \
|
80 |
+
--use_auth \
|
81 |
+
--output_dir ../output/llama2-gpt4-30k-food-order-understanding-13b \
|
82 |
+
--logging_steps 10 \
|
83 |
+
--save_strategy steps \
|
84 |
+
--data_seed 42 \
|
85 |
+
--save_steps 500 \
|
86 |
+
--save_total_limit 40 \
|
87 |
+
--evaluation_strategy steps \
|
88 |
+
--eval_dataset_size 1024 \
|
89 |
+
--max_eval_samples 1000 \
|
90 |
+
--per_device_eval_batch_size 12 \
|
91 |
+
--max_new_tokens 32 \
|
92 |
+
--dataloader_num_workers 1 \
|
93 |
+
--group_by_length \
|
94 |
+
--logging_strategy steps \
|
95 |
+
--remove_unused_columns False \
|
96 |
+
--do_train \
|
97 |
+
--do_eval \
|
98 |
+
--lora_r 64 \
|
99 |
+
--lora_alpha 16 \
|
100 |
+
--lora_modules all \
|
101 |
+
--double_quant \
|
102 |
+
--quant_type nf4 \
|
103 |
+
--bf16 \
|
104 |
+
--bits 4 \
|
105 |
+
--warmup_ratio 0.03 \
|
106 |
+
--lr_scheduler_type constant \
|
107 |
+
--gradient_checkpointing \
|
108 |
+
--dataset /Jupyter/dev_src/ASR-for-noisy-edge-devices/data/food-order-understanding-gpt4-30k.json \
|
109 |
+
--target_max_len 512 \
|
110 |
+
--per_device_train_batch_size 12 \
|
111 |
+
--gradient_accumulation_steps 1 \
|
112 |
+
--max_steps 5000 \
|
113 |
+
--eval_steps 500 \
|
114 |
+
--learning_rate 0.0002 \
|
115 |
+
--adam_beta2 0.999 \
|
116 |
+
--max_grad_norm 0.3 \
|
117 |
+
--lora_dropout 0.1 \
|
118 |
+
--weight_decay 0.0 \
|
119 |
+
--seed 0 \
|
120 |
+
--report_to tensorboard
|
121 |
+
```
|
122 |
+
|
123 |
+
## Dataset
|
124 |
+
|
125 |
+
The dataset was constructed using GPT-API with `gpt-4`. A prompt template is desginged to generate examples of sentence pairs of a food order and its understanding. Total 30k examples were generated.
|
126 |
+
Note that it cost about $400 to generate 30K examples through 3,000 API calls.
|
127 |
+
|
128 |
+
Some generated examples are as follows:
|
129 |
+
|
130 |
+
```json
|
131 |
+
{
|
132 |
+
'input': '๋ค์์ ๋งค์ฅ์์ ๊ณ ๊ฐ์ด ์์์ ์ฃผ๋ฌธํ๋ ์ฃผ๋ฌธ ๋ฌธ์ฅ์ด๋ค. ์ด๋ฅผ ๋ถ์ํ์ฌ ์์๋ช
, ์ต์
๋ช
, ์๋์ ์ถ์ถํ์ฌ ๊ณ ๊ฐ์ ์๋๋ฅผ ์ดํดํ๊ณ ์ ํ๋ค.\n๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํด์ฃผ๊ธฐ ๋ฐ๋๋ค.\n\n### ๋ช
๋ น: ์ ์ก๋ณถ์ ํ๊ทธ๋ฆํ๊ณ ์, ๋น๋น๋ฐฅ ํ๊ทธ๋ฆ ์ถ๊ฐํด์ฃผ์ธ์. ### ์๋ต:\n',
|
133 |
+
'output': '- ๋ถ์ ๊ฒฐ๊ณผ 0: ์์๋ช
:์ ์ก๋ณถ์,์๋:ํ๊ทธ๋ฆ\n- ๋ถ์ ๊ฒฐ๊ณผ 1: ์์๋ช
:๋น๋น๋ฐฅ,์๋:ํ๊ทธ๋ฆ'
|
134 |
+
},
|
135 |
+
{
|
136 |
+
'input': '๋ค์์ ๋งค์ฅ์์ ๊ณ ๊ฐ์ด ์์์ ์ฃผ๋ฌธํ๋ ์ฃผ๋ฌธ ๋ฌธ์ฅ์ด๋ค. ์ด๋ฅผ ๋ถ์ํ์ฌ ์์๋ช
, ์ต์
๋ช
, ์๋์ ์ถ์ถํ์ฌ ๊ณ ๊ฐ์ ์๋๋ฅผ ์ดํดํ๊ณ ์ ํ๋ค.\n๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํด์ฃผ๊ธฐ ๋ฐ๋๋ค.\n\n### ๋ช
๋ น: ์ฌ์ฒํ์์ก ๊ณฑ๋ฐฐ๊ธฐ ์ฃผ๋ฌธํ๊ณ ์, ์ค์ํฌ๋ฆผ์นํจ๋ ํ๋ ์ถ๊ฐํด์ฃผ์ธ์. ### ์๋ต:\n',
|
137 |
+
'output': '- ๋ถ์ ๊ฒฐ๊ณผ 0: ์์๋ช
:์ฌ์ฒํ์์ก,์ต์
:๊ณฑ๋ฐฐ๊ธฐ\n- ๋ถ์ ๊ฒฐ๊ณผ 1: ์์๋ช
:์ค์ํฌ๋ฆผ์นํจ,์๋:ํ๋'
|
138 |
+
}
|
139 |
+
```
|
140 |
+
|
141 |
+
## Note
|
142 |
+
|
143 |
+
I have another fine-tuned Language Model, 'jangmin/qlora-polyglot-ko-12.8b-food-order-understanding-32K', which is based on 'EleutherAI/polyglot-ko-12.8b'. The dataset was generated using 'gpt-3.5-turbo-16k'. I believe that the quality of a dataset generated by 'GPT-4' would be superior to that generated by 'GPT-3.5'.
|