werty1248 commited on
Commit
b2a5828
โ€ข
1 Parent(s): 0d55da6

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +186 -0
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - werty1248/Korean-1930-Novel-Scene-Summarize
5
+ language:
6
+ - ko
7
+ pipeline_tag: text-generation
8
+ ---
9
+
10
+ ## Model Card
11
+
12
+ - ์š”์•ฝ ์‹œ๋‚˜๋ฆฌ์˜ค ๊ธฐ๋ฐ˜ ์†Œ์„ค ์ƒ์„ฑ ๋ชจ๋ธ
13
+ - [werty1248/Korean-1930-Novel-Scene-Summarize](https://huggingface.co/datasets/werty1248/Korean-1930-Novel-Scene-Summarize) ์ž‘์—…์˜ ํšจ๊ณผ ํ™•์ธ์šฉ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
14
+
15
+ ## Training Details
16
+
17
+ ### Dataset
18
+
19
+ - [werty1248/Korean-1930-Novel-Scene-Summarize](https://huggingface.co/datasets/werty1248/Korean-1930-Novel-Scene-Summarize)
20
+ - ์ €์ž‘๊ถŒ์ด ๋งŒ๋ฃŒ๋œ 20์„ธ๊ธฐ ์ดˆ ํ•œ๊ตญ ๊ทผ๋Œ€๋ฌธํ•™ 97ํŽธ
21
+
22
+ ### Preprocessing
23
+
24
+ - system prompt์™€ ํ•จ๊ป˜ ์†Œ์„ค์˜ ์ฒซ ๋ฌธ๋‹จ์„ ์ œ๊ณต
25
+ - ์ดํ›„ user๊ฐ€ ์‹œ๋‚˜๋ฆฌ์˜ค(50%) ๋˜๋Š” ์ด๋ฒคํŠธ(50%)๋ฅผ ์ œ๊ณตํ•˜๋ฉด assistant๊ฐ€ ๋‹ต๋ณ€์„ ์ƒ์„ฑ
26
+ - 3-shot multi-turn ๋ฐ์ดํ„ฐ ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ•™์Šต
27
+
28
+ - ํ”„๋กฌํ”„ํŠธ ์˜ˆ์‹œ๋Š” ์•„๋ž˜์— ์žˆ์Šต๋‹ˆ๋‹ค.
29
+
30
+ - Axolotl(full config๋Š” ์•„๋ž˜์— ์žˆ์Šต๋‹ˆ๋‹ค)
31
+ - LoRA: (rank=32, alpha=128)
32
+ - NefTune_alpha: 5
33
+ - total_batch_size: 8
34
+ - num_epoch: 3
35
+
36
+ - 1xA100์—์„œ ์•ฝ 8์‹œ๊ฐ„ ํ•™์Šต
37
+
38
+ ## Template & How to use
39
+
40
+ - ์œ ์ € instruction์„ ๋ฌด์‹œํ•˜๋Š” ๊ฒฝํ–ฅ ์žˆ์Œ
41
+ - ํ•œ์ž/์˜์–ด ๋‹จ์–ด๊ฐ€ ์„ž์ด๋Š” ํ˜„์ƒ ์™„ํ™”๋จ
42
+ - ํ•œ๊ตญ์–ด ๋Šฅ๋ ฅ์ด ๋” ๋–จ์–ด์ง„ ๊ฒƒ ๊ฐ™์Œ
43
+
44
+ ### Input(๋ˆˆ๋ฌผ์„ ๋งˆ์‹œ๋Š” ์ƒˆ ๋„์ž…๋ถ€)
45
+
46
+ ```
47
+ import torch
48
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
49
+
50
+ tokenizer = AutoTokenizer.from_pretrained("werty1248/Qwen2-7B-Korean-1930-Novel-sft")
51
+ model = AutoModelForCausalLM.from_pretrained("werty1248/Qwen2-7B-Korean-1930-Novel-sft", torch_dtype=torch.bfloat16).to('cuda')
52
+
53
+ system_prompt = """๋‹น์‹ ์€ ์†Œ์„ค ์ž‘์„ฑ ์–ด์‹œ์Šคํ„ดํŠธ์ž…๋‹ˆ๋‹ค. ๋‹น์‹ ์˜ ์ž„๋ฌด๋Š” ์œ ์ €์˜ ๊ฐ€์ด๋“œ์— ๋”ฐ๋ผ 1900~1940๋…„๋Œ€ ๊ทผ๋Œ€ ํ•œ๊ตญ ์†Œ์„ค์„ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
54
+ - ์ฃผ์–ด์ง„ ์‹œ๋‚˜๋ฆฌ์˜ค ์š”์•ฝ์„ ํ™•์ธํ•˜๊ณ , ์ด์ „ ๋Œ€ํ™”๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ”Œ๋กฏ์„ ๊ตฌ์„ฑํ•˜์‹ญ์‹œ์˜ค.
55
+ - ํ’๋ถ€ํ•œ ํ•œ๊ตญ์–ด ํ‘œํ˜„ ๋ฐ ๋Œ€ํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฐฝ์˜์ ์œผ๋กœ ์งง์€ ์”ฌ์„ ์™„์„ฑํ•˜์„ธ์š”.
56
+ - ์”ฌ์˜ ๋Œ€์‚ฌ์— ๊ทผ๋Œ€ ํ•œ๊ตญ ํŠน์œ ์˜ ํ‘œํ˜„, ์–ดํœ˜, ์‚ฌํˆฌ๋ฆฌ, ์กด๋Œ“๋ง๊ณผ ๋ฐ˜๋ง์„ ๋ฐ˜์˜ํ•˜์‹ญ์‹œ์˜ค.
57
+ - ์”ฌ์˜ ์ฃผ์š” ์‚ฌ๊ฑด์— ๊ทผ๋Œ€ ํ•œ๊ตญ์˜ ์—ญ์‚ฌ์ , ๊ธฐ์ˆ ์  ํŠน์„ฑ์„ ๋ฐ˜์˜ํ•˜์‹ญ์‹œ์˜ค.
58
+ - ์”ฌ์€ 5~10๋ฌธ์žฅ์œผ๋กœ ๊ตฌ์„ฑํ•˜์„ธ์š”.
59
+ """
60
+
61
+ first_message = """### ์ฒซ ๋ฌธ๋‹จ
62
+ ํ•˜๋Š˜์„ ๋ถˆ์‚ฌ๋ฅด๋˜ ์šฉ์˜ ๋…ธ์—ฌ์›€๋„ ์žŠํ˜€์ง€๊ณ 
63
+ ์™•์ž๋“ค์˜ ์„๋น„๋„ ์‚ฌํ†  ์†์— ๋ฌปํ˜€๋ฒ„๋ฆฐ
64
+ ๊ทธ๋ฆฌ๊ณ  ๊ทธ๋Ÿฐ ๊ฒƒ๋“ค์— ๋ˆ„๊ตฌ๋„ ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š๋Š”
65
+ ์ƒ์กด์ด ์ฒœ๋ฐ•ํ•œ ๋†๋‹ด์ด ๋œ ์‹œ๋Œ€์—
66
+
67
+ ํ•œ ๋‚จ์ž๊ฐ€ ์‚ฌ๋ง‰์„ ๊ฑท๊ณ  ์žˆ์—ˆ๋‹ค.
68
+ """
69
+
70
+ scenario = """### ๋“ฑ์žฅ์ธ๋ฌผ
71
+ ์—ฌ๊ด€ ์ฃผ์ธ, ์ผ€์ด๊ฑด ๋“œ๋ผ์นด
72
+
73
+ ### ์‹œ๋‚˜๋ฆฌ์˜ค
74
+ ์—ฌ๊ด€ ์ฃผ์ธ์ด ๋ฌธ๋“ ์ฐฝ๋ฐ–์„ ๋ฐ”๋ผ๋ณธ๋‹ค. ์—ฌ๊ด€ ์ฃผ๋ณ€์€ ์˜จํ†ต ์‚ฌ๋ง‰์ด๋‹ค. ์ง€ํ‰์„  ์ € ๋ฉ€๋ฆฌ์„œ ํ•œ ์‚ฌ๋‚ด๊ฐ€ ํผ์ง€๋ง‰ํ•œ ์ž๋ฃจ๋ฅผ ์งˆ์งˆ ๋Œ๋ฉด์„œ ์—ฌ๊ด€ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฑธ์–ด์˜จ๋‹ค.
75
+ """
76
+ messages = [{'role':'system', 'content':system_prompt + first_message},
77
+ {'role':'user', 'content':scenario},]
78
+
79
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=512)
80
+
81
+ prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
82
+ outputs = pipe(
83
+ prompt,
84
+ do_sample=True,
85
+ temperature=0.8,
86
+ top_k=50,
87
+ top_p=0.95,
88
+ add_special_tokens=True
89
+ )
90
+ print(outputs[0]["generated_text"][len(prompt):])
91
+ ```
92
+
93
+ ### Result
94
+ ```
95
+ ํ•˜๋Š˜์€ ๊นจ๋—ํ•˜์˜€๋‹ค. ๋ฐ”๋žŒ๋„ ์˜์ด์ง€ ์•Š์•˜๋‹ค. ๋ฐ”์œ„ ์œ„์— ๊ตด๋Ÿฌ์ ธ ์žˆ๋Š” ํฌ์˜น์ด ํ•œ ๋ฉ๋งŒํ•˜๊ณ  ํ‘ธ๋ฅธ ํ–‡๋น› ์•„๋ž˜ ์ž˜ ๋ณด์˜€๋‹ค.
96
+
97
+ ๊ฑฐ๊ธฐ๋Š” ๋งˆ์นจ ํ•œ ์ฑ„์˜ ์—ฌ๊ด€์ด ์ง€์ฒด๋กœ ๊ฝ‚ํ˜€ ์žˆ์—ˆ๋‹ค. ์ขŒ์šฐ ๋ฉ€๋ฆฌ ๋ฐ”์œ„๊ฐ€ ์„ฐ์„ ๋ฟ์ด๋‹ค. ๋‚˜๋ฌด๋„ ์ˆ˜๋ชฉ๋„ ์—†๋Š” ์˜จ ์ฒœ์ง€๊ฐ€ ํ›คํžˆ ์—ฌ๊ด€ ์˜†์„ ์—์›Œ์‹ธ๊ณ  ์žˆ๋Š” ๊ฒƒ์ด๋‹ค. ์–ผ๋ฅธ ๋ณด๋ฉด ํ•œ ์กฐ๊ฐ ์„์ถ• ์† ๊ฐ™๊ธฐ๋„ ํ•˜์ง€๋งŒ ๊ฑด์ถ•์ด๋ผ๋Š๋‹ˆ ๋ณด๋‹ค๋Š” ๋„ํšŒ์— ๋•…์„ ๋‚ด์–ด๋†“๊ณ  ๋‹จ์ˆœํ•œ ๊ฐ„ํŒ ํ•˜๋‚˜๋ฅผ ๊ฑธ์–ด์„œ ๊ทธ๋Œ€๋กœ ๋ฒŒ์ดํ•˜๋Š” โ€˜์—ฌ๊ด€โ€™์ด๋‹ค. ๋ช‡๋ช‡ ์ข์€ ๊ธธ๋งŒ ๋“ค์–ด์™”๋‹ค๊ฐ€ ์‚ฌ๋ผ์กŒ์„ ๋ฟ ํ•œ ๊ธธ๋„ ์•ˆ ๋šซ๋ ค์ง„ ๊ทธ ์ž๋ฆฌ์— ๊ทธ๋Œ€๋กœ ์ง€ํƒฑ๋˜์–ด ์žˆ๋Š” ์—ฌ๊ด€์ด๋‹ค. ๊ธธ์— ๋‚˜ํƒ€๋‚˜๋Š” ์‚ฌ๋žŒ์€ ์—†๋‹ค. ์ขŒ์šฐ๋กœ ๋ฐ”์œ„๋ฅผ ๋ผ๊ณ  ๋Š˜ ๋น„์–ด ์žˆ๋Š” ์‚ฐ ์ค‘์—์„œ ๊ฐ„๊ฐ„์ด ๊ณ ๊ธฐ ๊ตฝ๋Š” ๋‹ฅ์ด์™€ ์‚ฏ๋ฐ”๊ตฌ๋‹ˆ๋ฉฐ ๊ณ ๊นƒ๊ฐ€๋งˆ๋ฅผ ๊ฑธ๊ณ  ํ–‰์ธ๋งŒ ๋ช‡ ๋งˆ๋ฆฌ์”ฉ ์ง€๋‚˜๊ฐ€๊ณ  ํ›คํ•˜๊ฒŒ ์„ ๋ฐ”๋‹ฅ์— ํ–‡๋น›๋งŒ ๋น„์น˜๊ณ  ํ•˜๋Š” ์“ธ์“ธํ•œ ์—ฌ๊ด€์ด๋‹ค. ๊ทธ๊ฒƒ์ด ๋ฃธ_service๋ผ๋Š” ์„ธ๊ณ„์™€๋„ ๋‹ฌ๋ฆฌ ์ฃผ์ธ๋„ ์—†๊ณ  ์‚ฌ์žฅ๋„ ์—†๊ณ  ์†๋„ ์—†๊ณ  ํ•œ ๊ฐ„ํŒ๋งŒ ๊ฑธ๊ณ  ์ฒœ๋‹น์ฒ˜๋Ÿผ ์™ธ๋กญ๊ฒŒ ์ง€ํ‚ค๊ณ  ์žˆ๋Š” ๋ชจ์–‘์ด๋‹ค.
98
+
99
+ ๊ทธ๋Ÿฐ ์—ฌ๊ด€์—์„œ ์ด์œฝ๊ณ  ์†์ด ํ•œ ์‚ฌ๋žŒ ๋‚˜ํƒ€๋‚ฌ๋‹ค. ์ฐฝ๋ฌธ์ด ์—ด๋ ธ๋‹ค. ๋ฐ–์„ ๋‚ด๋‹ค๋ณด๋Š” ํ•œ ์ ์˜ ๊ฒ€์€ ๊ทธ๋ฆผ์ž๊ฐ€ ์ฐฝ ์•ž์—์„œ ๋๋๋‚ด ์˜ค๋ฏ€๋Ÿฌ์ง„๋‹ค. ๊ทธ๋Ÿฌ๋”๋‹ˆ ๋‹ค์‹œ ํ•œ์ฐธ ํ›„์— ๊ทธ ๊ฒ€์€ ๊ทธ๋ฆผ์ž๋Š” ์›ƒ๋ชฉ์œผ๋กœ ์ฐจ์ฐจ ๋‚˜์™€ ๊ฐ€์ง€๊ณ ๋Š” ๊ทธ๋Œ€๋กœ ์‚ฌ๋ผ์ง€๋Š” ๊ฒƒ์ด๋‹ค.
100
+
101
+ ๊ทธ๋กœ๋ถ€ํ„ฐ ์—ฌ๊ด€์€ ์ƒˆ๋กœ์šด ์ผ์„ ๋‹นํ•˜์˜€๋‹ค. ๋ฐ”์‹œ๋ฆฌ์˜ค ์ž๋ฃจ๋ฅผ ๋“ค๊ณ  ํ•œ ์‚ฌ๋‚˜์ด๊ฐ€ ๊ฑธ์–ด ๋“ค์–ด์˜ค์ง€ ์•Š์•˜๋Š”๊ฐ€. ์–ผ๊ตด์€ ๋จผ๋น›์œผ๋กœ ๋˜‘๋˜‘ํžˆ ๋ชป ๋ณด์ด๋‚˜ ๋ฒŒ์จ ์‚ฌ๋ฉด ์‚ฌ์˜ค ๊ฐ„๋ฐ–์— ์•ˆ ๋˜๋Š” ๊ณณ์— ํผ์ง๏ฟฝ๏ฟฝ ์ž๋ฃจ๋ฅผ
102
+ ```
103
+
104
+ ### Result of Original model(Qwen/Qwen2-7b-instruct)
105
+
106
+ ```
107
+ "๊ทธ๊ฒŒ ๋ˆ„๊ตฌ๋ƒ? ์™œ ์ด๋ ‡๊ฒŒ ๋จผ ๊ณณ์—์„œ ์ด๊ณณ์œผ๋กœ ์™€?" ์—ฌ๊ด€ ์ฃผ์ธ์ด ๋ฌผ์–ด๋ณด๋ฉฐ ์ฐฝ๋ฌธ์„ ๋ฒŒ๋ฆฌ๊ณ  ๋งํ–ˆ๋‹ค. ๊ทธ๋…€์˜ ๋ชฉ์†Œ๋ฆฌ๋Š” ์‚ฌ๋ง‰์˜ ๊ฑด์กฐํ•จ๊ณผ ํ•จ๊ป˜ ๊ฑฐ์นœ ๋ฐ”๋žŒ์— ๊ฐ€๋ผ์•‰์•˜๋‹ค.
108
+
109
+ ์ผ€์ด๊ฑด ๋“œ๋ผ์นด๋ผ๋Š” ์‚ฌ๋‚ด๋Š” ์ž์‹ ์˜ ์ž๋ฃจ๋ฅผ ๋” ์งˆ์งˆ ๋Œ๋ฉฐ ์—ฌ๊ด€ ์ชฝ์œผ๋กœ ๋‹ค๊ฐ€๊ฐ”๋‹ค. ๊ทธ์˜ ๋ˆˆ์—๋Š” ํฌ๋ฏธํ•˜๊ฒŒ ๋ณด์ด๋Š” ๋จผ์ง€์™€ ๋จผ์ง€๊ฐ€ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ํ–‡๋น›์ด ๋น›๋‚˜๋Š” ๋“ฏํ–ˆ๋‹ค. ๊ทธ์˜ ์–ผ๊ตด์—๋Š” ๋•€๋ฐฉ์šธ์ด ๊ตด๋Ÿฌ ๋‚ด๋ ค๊ฐ€๋ฉฐ, ๊ทธ์˜ ์ž…์€ ๋งํ•  ์ค€๋น„๋ฅผ ํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.
110
+
111
+ "์—ฌ๊ด€ ์ฃผ์ธ๋‹˜, ์ €๋ฅผ ๋ฐ›์•„์ฃผ์‹ค ์ˆ˜ ์žˆ์„๊นŒ์š”? ์ œ๊ฐ€ ์ด๊ณณ์—์„œ ์ž ์‹œ ์‰ฌ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค." ๊ทธ์˜ ๋ชฉ์†Œ๋ฆฌ๋Š” ์‚ฌ๋ง‰์˜ ๋ฌด๋””ํ•œ ์กฐ์šฉํ•จ์„ ๊นจ์šฐ๋ฉฐ ์ „ํ•ด์กŒ๋‹ค.
112
+
113
+ ์—ฌ๊ด€ ์ฃผ์ธ์€ ๊ทธ์˜ ์ฒด์œก๋ณต๊ณผ ๋•€ๆฑƒๆฑƒํ•œ ๋ชจ์Šต์„ ๋ณด๋ฉฐ, ์ด ์‚ฌ๋‚ด์˜ ์ƒํ™ฉ์— ๋Œ€ํ•ด ๊ฑฑ์ •์Šค๋Ÿฌ์› ๋‹ค. "๊ทธ๋ž˜, ๋„ค๊ฐ€ ํ•„์š”ํ•˜๋‹ค๊ณ  ๋Š๊ผˆ๋‹ค๋ฉด, ์—ฌ๊ธฐ์„œ ์‰ฌ์–ด๋ผ. ํ•˜์ง€๋งŒ ์™œ ์ด๋Ÿฐ ๊ณณ๊นŒ์ง€ ์™”๋Š”์ง€ ์„ค๋ช…ํ•ด ์ค˜์•ผ ํ•  ๊ฒƒ ๊ฐ™์•„." ๊ทธ๋…€์˜ ๋งํˆฌ๋Š” ์นœ๊ทผํ•˜๋ฉด์„œ๋„ ๋ถ„๋ช…ํ•œ ์ง€์‹œ์˜€๋‹ค.
114
+ ```
115
+
116
+ ## Others
117
+
118
+ ### Axolotl config
119
+
120
+ ```
121
+ base_model: Qwen/Qwen2-7B-Instruct
122
+ trust_remote_code: true
123
+
124
+ load_in_8bit: false
125
+ load_in_4bit: false
126
+ strict: false
127
+
128
+ datasets:
129
+ - path: train_data.jsonl
130
+ type: sharegpt
131
+ dataset_prepared_path:
132
+ val_set_size: 0.05
133
+ output_dir: ./outputs/out
134
+
135
+ sequence_len: 4096
136
+ sample_packing: true
137
+ eval_sample_packing: true
138
+ pad_to_sequence_len: true
139
+
140
+ adapter: lora
141
+ lora_model_dir:
142
+ lora_r: 32
143
+ lora_alpha: 128
144
+ lora_dropout: 0.05
145
+ lora_target_linear: true
146
+ lora_fan_in_fan_out:
147
+
148
+ wandb_project:
149
+ wandb_entity:
150
+ wandb_watch:
151
+ wandb_name:
152
+ wandb_log_model:
153
+
154
+ neftune_noise_alpha: 5
155
+ gradient_accumulation_steps: 4
156
+ micro_batch_size: 2
157
+ num_epochs: 3
158
+ optimizer: adamw_torch
159
+ lr_scheduler: cosine
160
+ learning_rate: 0.0002
161
+
162
+ train_on_inputs: false
163
+ group_by_length: false
164
+ bf16: auto
165
+ fp16:
166
+ tf32: false
167
+
168
+ gradient_checkpointing: true
169
+ gradient_checkpointing_kwargs:
170
+ use_reentrant: false
171
+ early_stopping_patience:
172
+ resume_from_checkpoint:
173
+ local_rank:
174
+ logging_steps: 1
175
+ xformers_attention:
176
+ flash_attention: true
177
+
178
+ warmup_steps: 10
179
+ evals_per_epoch: 4
180
+ saves_per_epoch: 1
181
+ debug:
182
+ deepspeed:
183
+ weight_decay: 0.0
184
+ fsdp:
185
+ special_tokens:
186
+ ```