limecoding commited on
Commit
093c349
โ€ข
1 Parent(s): 9227dde

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -14
README.md CHANGED
@@ -21,20 +21,69 @@ This gemma2 model was trained 2x faster with [Unsloth](https://github.com/unslot
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
23
 
 
 
 
24
 
25
- ## ๋ชจ๋ธ ์†Œ๊ฐœ
 
 
 
26
 
27
- ํ•ด๋‹น ๋ชจ๋ธ์€ ๋Œ€๋žต์ ์ธ ๋ฐœ๋ช…ํ’ˆ์˜ ์„ค๋ช…์„ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ํŠนํ—ˆ ๋ช…์„ธ์„œ ์ž‘์„ฑ์„ ๋„์™€์ฃผ๋Š” ํŒŒ์ธํŠœ๋‹๋œ roLA ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
28
- ๋ฒ ์ด์Šค ๋ชจ๋ธ์€ unsloth/gemma-2-2b-it-bnb-4bit์ด๋ฉฐ, unsloth๋ฅผ ์ด์šฉํ•ด ํŒŒ์ธํŠœ๋‹์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.
29
-
30
-
31
- ## ๋ฐ์ดํ„ฐ์…‹
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- ๋ฐ์ดํ„ฐ์…‹์€ AI-Hub์— ์žˆ๋Š” ๋…ผ๋ฌธ์ž๋ฃŒ ์š”์•ฝ ๋ฐ์ดํ„ฐ ์…‹๊ณผ ํ‚คํ”„๋ฆฌ์Šค์—์„œ ์ง์ ‘ ์ฒญ๊ตฌํ•ญ์„ ๊ฐ€์ ธ์™€ ์กฐํ•ฉํ•œ ๋ฐ์ดํ„ฐ์…‹์„ ์ด์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
34
 
35
- ## ๋ชจ๋ธ ์‚ฌ์šฉ๋ฒ•
36
 
37
- 1. unsloth๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค
38
  ```
39
  %%capture
40
  !pip install unsloth
@@ -47,7 +96,7 @@ if torch.cuda.get_device_capability()[0] >= 8:
47
  !pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
48
  ```
49
 
50
- 2. ๋ชจ๋ธ์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
51
  ```
52
  from unsloth import FastLanguageModel
53
  import torch
@@ -57,14 +106,14 @@ load_in_4bit = True
57
  token = "your-huggingface-token"
58
 
59
  model, tokenizer = FastLanguageModel.from_pretrained(
60
- model_name = "limecoding/gemma2-2b-it-finetuned-patent-lora",
61
  max_seq_length = max_seq_length,
62
  dtype = dtype,
63
  load_in_4bit = load_in_4bit,
64
  token = token
65
  )
66
  ```
67
- 3. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ํ…์ŠคํŠธ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
68
  ```
69
  input = """
70
  ์ƒ์ˆ ํ•œ ๊ณผ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•˜์—ฌ, ๋ณธ ๊ณ ์•ˆ์€ ๋‚ด๋ถ€์— ๋ณด๊ด€ํ•  ๋ฌผ๊ฑด์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ณธ ๋‚ด์žฅ ๊ณต๊ฐ„๊ณผ ์ด๋ฅผ ๋‘˜๋Ÿฌ์‹ผ
@@ -105,10 +154,33 @@ inputs = tokenizer(
105
  r"""<bos><start_of_turn>user
106
  ๋‹ค์Œ ๊ณผ์ œํ•ด๊ฒฐ์ˆ˜๋‹จ์„ ๋ณด๊ณ  ๋ฐœ๋ช…์˜ ๋ช…์นญ, ๊ธฐ์ˆ ๋ถ„์•ผ, ์ฒญ๊ตฌํ•ญ์„ ๋ฝ‘์•„์ฃผ์„ธ์š”.: {}<end_of_turn>
107
  <start_of_turn>model""".format(input)
108
- # train_data[0]["๊ณผ์ œ์˜ ํ•ด๊ฒฐ ์ˆ˜๋‹จ"]
109
  ], return_tensors = "pt").to("cuda")
110
 
111
  from transformers import TextStreamer
112
  text_streamer = TextStreamer(tokenizer)
113
  _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 1000)
114
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
23
 
24
+ ## Model Overview
25
+ This fine-tuned LoRA model assists with drafting patent specifications based on a general description of an invention.
26
+ The base model is unsloth/gemma-2-2b-it-bnb-4bit, and the fine-tuning was carried out using unsloth.
27
 
28
+ ## Dataset
29
+ The dataset used for fine-tuning includes a combination of research paper
30
+ summary datasets from AI-Hub and patent claims data directly retrieved from KIPRIS
31
+ (Korea Intellectual Property Rights Information Service).
32
 
33
+ Model Training
34
+ The model was trained using LoRA (Low-Rank Adaptation). The following code was used for training:
35
+ ```
36
+ model = FastLanguageModel.get_peft_model(
37
+ model,
38
+ r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
39
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
40
+ "gate_proj", "up_proj", "down_proj",],
41
+ lora_alpha = 16,
42
+ lora_dropout = 0, # Supports any, but = 0 is optimized
43
+ bias = "none", # Supports any, but = "none" is optimized
44
+ # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
45
+ use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
46
+ random_state = 3407,
47
+ use_rslora = False, # We support rank stabilized LoRA
48
+ loftq_config = None, # And LoftQ
49
+ )
50
+ ```
51
+ ```
52
+ from trl import SFTTrainer
53
+ from transformers import TrainingArguments
54
+ from unsloth import is_bfloat16_supported
55
+
56
+ trainer = SFTTrainer(
57
+ model = model,
58
+ tokenizer = tokenizer,
59
+ train_dataset = train_data,
60
+ max_seq_length = max_seq_length,
61
+ formatting_func = generate_prompt,
62
+ dataset_num_proc = 2,
63
+ packing = False, # Can make training 5x faster for short sequences.
64
+ args = TrainingArguments(
65
+ per_device_train_batch_size = 2,
66
+ gradient_accumulation_steps = 4,
67
+ warmup_steps = 5,
68
+ num_train_epochs = 1, # Set this for 1 full training run.
69
+ # max_steps = 100,
70
+ learning_rate = 2e-4,
71
+ fp16 = not is_bfloat16_supported(),
72
+ bf16 = is_bfloat16_supported(),
73
+ logging_steps = 10,
74
+ optim = "adamw_8bit",
75
+ weight_decay = 0.01,
76
+ lr_scheduler_type = "linear",
77
+ seed = 3407,
78
+ output_dir = "outputs",
79
+ ),
80
+ )
81
+ ```
82
 
 
83
 
84
+ ## How to Use the Model
85
 
86
+ 1. Install unsloth:
87
  ```
88
  %%capture
89
  !pip install unsloth
 
96
  !pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
97
  ```
98
 
99
+ 2. Load the fine-tuned model and use it for inference:
100
  ```
101
  from unsloth import FastLanguageModel
102
  import torch
 
106
  token = "your-huggingface-token"
107
 
108
  model, tokenizer = FastLanguageModel.from_pretrained(
109
+ model_name = "limecoding/gemma2-2b-it-finetuned-patent",
110
  max_seq_length = max_seq_length,
111
  dtype = dtype,
112
  load_in_4bit = load_in_4bit,
113
  token = token
114
  )
115
  ```
116
+ 3. Write a prompt and generate text:
117
  ```
118
  input = """
119
  ์ƒ์ˆ ํ•œ ๊ณผ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•˜์—ฌ, ๋ณธ ๊ณ ์•ˆ์€ ๋‚ด๋ถ€์— ๋ณด๊ด€ํ•  ๋ฌผ๊ฑด์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ณธ ๋‚ด์žฅ ๊ณต๊ฐ„๊ณผ ์ด๋ฅผ ๋‘˜๋Ÿฌ์‹ผ
 
154
  r"""<bos><start_of_turn>user
155
  ๋‹ค์Œ ๊ณผ์ œํ•ด๊ฒฐ์ˆ˜๋‹จ์„ ๋ณด๊ณ  ๋ฐœ๋ช…์˜ ๋ช…์นญ, ๊ธฐ์ˆ ๋ถ„์•ผ, ์ฒญ๊ตฌํ•ญ์„ ๋ฝ‘์•„์ฃผ์„ธ์š”.: {}<end_of_turn>
156
  <start_of_turn>model""".format(input)
 
157
  ], return_tensors = "pt").to("cuda")
158
 
159
  from transformers import TextStreamer
160
  text_streamer = TextStreamer(tokenizer)
161
  _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 1000)
162
+ ```
163
+
164
+
165
+ ## Model Results
166
+ The model was tested using the "Means to Solve the Problem" section from actual patent specifications.
167
+ When compared with real patent documents, the model generated content that was relatively similar in
168
+ structure and meaning.
169
+ ```
170
+ [๋ฐœ๋ช…์˜ ๋ช…์นญ]
171
+ ๊ฐ€๋ฐฉ
172
+
173
+
174
+ [๊ธฐ์ˆ ๋ถ„์•ผ]
175
+ ๋ณธ ๋ฐœ๋ช…์€ ๊ฐ€๋ฐฉ์— ๊ด€ํ•œ ๊ฒƒ์œผ๋กœ, ๋ณด๋‹ค ์ƒ์„ธํ•˜๊ฒŒ๋Š” ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ๊ฐ€๋ฐฉ์— ๊ด€ํ•œ ๊ฒƒ์ด๋‹ค.
176
+
177
+
178
+ [์ฒญ๊ตฌํ•ญ]
179
+ ๋‚ด๋ถ€์— ๋ณด๊ด€ํ•  ๋ฌผ๊ฑด์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ณธ ๋‚ด์žฅ ๊ณต๊ฐ„๊ณผ ์ด๋ฅผ ๋‘˜๋Ÿฌ์‹ผ ์™ธํ”ผ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ€๋ฐฉ์— ๏ฟฝ๏ฟฝ๏ฟฝ์–ด์„œ,
180
+
181
+ ์ƒ๊ธฐ ์™ธํ”ผ์—๋Š” ์—ด๋ฆฌ๊ณ  ๋‹ซํžˆ๋Š” ํ™•์žฅ ์™ธํ”ผ ์ง€ํผ๊ฐ€ ํ˜•์„ฑ๋˜์–ด ์žˆ๊ณ ,
182
+
183
+ ์ƒ๊ธฐ ํ™•์žฅ ์™ธํ”ผ ์ง€ํผ์˜ ๋‚ด์ธก์—๋Š” ์ƒ๊ธฐ ํ™•์žฅ ์™ธํ”ผ ์ง€ํผ๊ฐ€ ์—ด๋ฆฌ๋Š” ๊ฒฝ์šฐ ํŽผ์ณ์ง€๋Š” ํ™•์žฅ ๋‚ดํ”ผ๋ฅผ ๋” ํฌํ•จํ•˜๋˜,
184
+
185
+ ์ƒ๊ธฐ ํ™•์žฅ ๋‚ดํ”ผ์˜ ๋‚ด์ธก์œผ๋กœ ์ถ”๊ฐ€ ๊ณต๊ฐ„์ด ํ˜•์„ฑ๋˜์–ด ์ถ”๊ฐ€ ์ˆ˜๋‚ฉ๊ณต๊ฐ„์„ ๊ตฌ๋น„ํ† ๋ก ํ•˜๋Š” ๊ฒƒ์„ ํŠน์ง•์œผ๋กœ ํ•˜๋Š” ์ถ”๊ฐ€ ์ˆ˜๋‚ฉ๊ณต๊ฐ„์ด ๊ตฌ๋น„๋œ ๊ฐ€๋ฐฉ.<end_of_turn>
186
+ ```