Update README.md
Browse files
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 |
-
|
28 |
-
|
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
|
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 |
+
```
|