Instructions to use limecoding/gemma2-2b-it-finetuned-patent-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use limecoding/gemma2-2b-it-finetuned-patent-lora with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("limecoding/gemma2-2b-it-finetuned-patent-lora", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use limecoding/gemma2-2b-it-finetuned-patent-lora with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for limecoding/gemma2-2b-it-finetuned-patent-lora to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for limecoding/gemma2-2b-it-finetuned-patent-lora to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for limecoding/gemma2-2b-it-finetuned-patent-lora to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="limecoding/gemma2-2b-it-finetuned-patent-lora", max_seq_length=2048, )
Uploaded model
- Developed by: limecoding
- License: apache-2.0
- Finetuned from model : unsloth/gemma-2-2b-it-bnb-4bit
This gemma2 model was trained 2x faster with Unsloth and Huggingface's TRL library.
Model Overview
This fine-tuned LoRA model assists with drafting patent specifications based on a general description of an invention. The base model is unsloth/gemma-2-2b-it-bnb-4bit, and the fine-tuning was carried out using unsloth.
Dataset
The dataset used for fine-tuning includes a combination of research paper summary datasets from AI-Hub and patent claims data directly retrieved from KIPRIS (Korea Intellectual Property Rights Information Service).
Model Training The model was trained using LoRA (Low-Rank Adaptation). The following code was used for training:
model = FastLanguageModel.get_peft_model(
model,
r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj",],
lora_alpha = 16,
lora_dropout = 0, # Supports any, but = 0 is optimized
bias = "none", # Supports any, but = "none" is optimized
# [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
random_state = 3407,
use_rslora = False, # We support rank stabilized LoRA
loftq_config = None, # And LoftQ
)
from trl import SFTTrainer
from transformers import TrainingArguments
from unsloth import is_bfloat16_supported
trainer = SFTTrainer(
model = model,
tokenizer = tokenizer,
train_dataset = train_data,
max_seq_length = max_seq_length,
formatting_func = generate_prompt,
dataset_num_proc = 2,
packing = False, # Can make training 5x faster for short sequences.
args = TrainingArguments(
per_device_train_batch_size = 2,
gradient_accumulation_steps = 4,
warmup_steps = 5,
num_train_epochs = 1, # Set this for 1 full training run.
# max_steps = 100,
learning_rate = 2e-4,
fp16 = not is_bfloat16_supported(),
bf16 = is_bfloat16_supported(),
logging_steps = 10,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "linear",
seed = 3407,
output_dir = "outputs",
),
)
How to Use the Model
- Install unsloth:
%%capture
!pip install unsloth
# Also get the latest nightly Unsloth!
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
# Install Flash Attention 2 for softcapping support
import torch
if torch.cuda.get_device_capability()[0] >= 8:
!pip install --no-deps packaging ninja einops "flash-attn>=2.6.3"
- Load the fine-tuned model and use it for inference:
from unsloth import FastLanguageModel
import torch
max_seq_length = 4096
dtype = None
load_in_4bit = True
token = "your-huggingface-token"
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "limecoding/gemma2-2b-it-finetuned-patent",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
token = token
)
- Write a prompt and generate text:
input = """
์์ ํ ๊ณผ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ์ฌ, ๋ณธ ๊ณ ์์ ๋ด๋ถ์ ๋ณด๊ดํ ๋ฌผ๊ฑด์ ๋ฃ์ ์ ์๋ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ๊ณผ ์ด๋ฅผ ๋๋ฌ์ผ
์ธํผ๋ฅผ ํฌํจํ๋ ๊ฐ๋ฐฉ์ ์์ด์, ์๊ธฐ ์ธํผ์๋ ์ด๋ฆฌ๊ณ ๋ซํ๋ ํ์ฅ ์ธํผ ์งํผ๊ฐ ํ์ฑ๋์ด ์๊ณ , ์๊ธฐ ํ์ฅ ์ธ
ํผ ์งํผ์ ๋ด์ธก์๋ ์๊ธฐ ํ์ฅ ์ธํผ ์งํผ๊ฐ ์ด๋ฆฌ๋ ๊ฒฝ์ฐ ํผ์ณ์ง๋ ํ์ฅ ๋ดํผ๋ฅผ ๋ ํฌํจํ๋, ์๊ธฐ ํ์ฅ ๋ดํผ์
๋ด์ธก์ผ๋ก ์ถ๊ฐ ๊ณต๊ฐ์ด ํ์ฑ๋์ด ์ถ๊ฐ ์๋ฉ๊ณต๊ฐ์ ๊ตฌ๋นํ ๋ก ํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ๋ ์ถ๊ฐ ์๋ฉ๊ณต๊ฐ์ด ๊ตฌ๋น๋ ๊ฐ
๋ฐฉ์ ์ ๊ณตํ๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ํ์ฅ ์ธํผ ์งํผ๋ ์๊ธฐ ๊ฐ๋ฐฉ์ ์ธ์ฃผ ์ ์ฒด๋ฅผ ๊ฐ์ธ๋ฉด์, ์๊ธฐ ํ์ฅ ๋ดํผ๋ก ์ฐ์ฅ๋์ด, ์๊ธฐ ํ์ฅ
์ธํผ ์งํผ๋ฅผ ์ ๋ถ ์ฌ๋ ๊ฒฝ์ฐ ์๊ธฐ ์ธํผ๊ฐ ์๊ธฐ ํ์ฅ ๋ดํผ๋ก ์ฐ๊ฒฐ๋๋ฉด์ ๋ถ๋ฆฌ๋์ด ๊ทธ ๋ด๋ถ์ ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ์
ํ์ฑํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ์ ์๊ธฐ ๊ฐ๋ฐฉ์ ์์ธก์ ๊ตฌ๋น๋๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
์๊ธฐ ๊ฐ๋ฐฉ์ ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ์ด ํ์ฅ๋ ์ ์๋ ์๋จ์ ๋ ํฌํจํ๋, ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ์ด ํ์ฅ๋ ์ ์
๋ ์๋จ์ ์๊ธฐ ํ์ฅ ์ธํผ ์งํผ์ ๋ด์ธก์ ํ์ฑ๋ ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ์ด ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ๊ณผ ํตํ์ฌ ์๊ธฐ ๊ธฐ๋ณธ ๋ด
์ฅ ๊ณต๊ฐ์ด ํ์ฅ๋๋๋ก ํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ๊ณผ ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ ์ฌ์ด์๋ ๊ฒฉ๋ฒฝ์ด ํ์ฑ๋์ด ๋ณ๋์ ์ถ๊ฐ ์๋ฉ๊ณต๊ฐ์ด ํ์ฑ๋๋
๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๊ฒฉ๋ฒฝ์ ์๊ธฐ ๊ฐ๋ฐฉ์ ๋ด์ธก์์ ํ์ฐฉ๋๋ ๊ฒ์ผ๋ก์, ํ์์ ๋ฐ๋ผ ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ๊ณผ ์๊ธฐ ์ถ
๊ฐ ๊ณต๊ฐ์ ๋ถ๋ฆฌ์ํค๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ์ ๋ด์ธก์๋ ๋ถ๋ฆฌํ ์นธ๋ง์ด๊ฐ ํ์ฐฉ ๊ฐ๋ฅํ๊ฒ ๋ถ์ค๋์ด ์๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์
์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ์ธํผ์ ์ธ์ธก์ผ๋ก ๋ณด์กฐํฌ์ผ์ด ํ์ฑ๋์ด ๋ณ๋์ ์๋ฉ๊ณต๊ฐ์ด ํ์ฑ๋๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๋ณด์กฐํฌ์ผ์ ๋ด๋ถ์๋ ํ๋ ฅ๋ฐด๋๊ฐ ๋ถ์ฐฉ๋๋ ๊ฐ๊ฒฉ์ ๋๊ณ ๊ทธ ์ผ๋ถ๊ฐ ๋ถ์ฐฉ๋จ์ผ๋ก์จ ๋ถ์ฐฉ๋์ง ์๋
๊ณต๊ฐ์ผ๋ก ๋ณด๊ดํ๋ ๋ฌผ๊ฑด์ ๋ผ์๋ ์ ์๋๋ก ํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ํ์ฅ ๋ดํผ์ ์๋ถ์๋ ๋ดํผ ๊ฐํ ์งํผ๊ฐ ํ์ฑ๋์ด, ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ์ ๋ด๋ถ๋ฅผ ์ด๊ณ ๋ซ์ ์ ์๋
๋ก ํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ์ถ๊ฐ ๊ณต๊ฐ์ ํ์ฑ๋ ์๊ธฐ ๋ดํผ ๊ฐํ ์งํผ์ ์์ชฝ๋ถ๋ ๋ด๋ถ๊ฐ ๋ณด์ด๋ ๋ง์ฌํ ์ง๋ฌผ๋ถ๋ก ํ์ฑํ์ฌ
๋ด์ฅ๋ ๋ฌผํ์ ๋ฐ๋ก ํ์ธํ ์ ์๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๊ฐ๋ฐฉ์ ๊ฐ๋ฐฉ ํด๋์๊ฐ ์ด๊นจ์ ๋ฉ ์ ์๋๋ก ์ด๊นจ์ฉ ๋ ์ฐ๊ฒฐ๋ถ๊ฐ ํ์ฑ๋์ด ์๋ ๊ฒ์ ํน์ง์ผ๋ก
ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ์ด๊นจ์ฉ ๋ ์ฐ๊ฒฐ๋ถ์ ์์ธก ๋๋จ์ด ๊ณ ์ ๋๋ ์ด๊นจ์ฉ ๋์ ๋ ํฌํจํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ ์ ์๋ค.
๋ณธ ๊ณ ์์ ์๊ธฐ ๊ฐ๋ฐฉ์ ์ธํผ์ ๋ถ์ฐฉ๋์ด ์๊ธฐ ๊ฐ๋ฐฉ์ ๋ค ์ ์๋๋ก ํ์ฑ๋๋ ์์ก์ด๋ฅผ ๋ ํฌํจํ๋ ๊ฒ์ ํน์ง์ผ
๋ก ํ ์ ์๋ค
"""
FastLanguageModel.for_inference(model)
inputs = tokenizer(
[
r"""<bos><start_of_turn>user
๋ค์ ๊ณผ์ ํด๊ฒฐ์๋จ์ ๋ณด๊ณ ๋ฐ๋ช
์ ๋ช
์นญ, ๊ธฐ์ ๋ถ์ผ, ์ฒญ๊ตฌํญ์ ๋ฝ์์ฃผ์ธ์.: {}<end_of_turn>
<start_of_turn>model""".format(input)
], return_tensors = "pt").to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 1000)
Model Results
The model was tested using the "Means to Solve the Problem" section from actual patent specifications. When compared with real patent documents, the model generated content that was relatively similar in structure and meaning.
[๋ฐ๋ช
์ ๋ช
์นญ]
๊ฐ๋ฐฉ
[๊ธฐ์ ๋ถ์ผ]
๋ณธ ๋ฐ๋ช
์ ๊ฐ๋ฐฉ์ ๊ดํ ๊ฒ์ผ๋ก, ๋ณด๋ค ์์ธํ๊ฒ๋ ํ์ฅ ๊ฐ๋ฅํ ๊ฐ๋ฐฉ์ ๊ดํ ๊ฒ์ด๋ค.
[์ฒญ๊ตฌํญ]
๋ด๋ถ์ ๋ณด๊ดํ ๋ฌผ๊ฑด์ ๋ฃ์ ์ ์๋ ๊ธฐ๋ณธ ๋ด์ฅ ๊ณต๊ฐ๊ณผ ์ด๋ฅผ ๋๋ฌ์ผ ์ธํผ๋ฅผ ํฌํจํ๋ ๊ฐ๋ฐฉ์ ์์ด์,
์๊ธฐ ์ธํผ์๋ ์ด๋ฆฌ๊ณ ๋ซํ๋ ํ์ฅ ์ธํผ ์งํผ๊ฐ ํ์ฑ๋์ด ์๊ณ ,
์๊ธฐ ํ์ฅ ์ธํผ ์งํผ์ ๋ด์ธก์๋ ์๊ธฐ ํ์ฅ ์ธํผ ์งํผ๊ฐ ์ด๋ฆฌ๋ ๊ฒฝ์ฐ ํผ์ณ์ง๋ ํ์ฅ ๋ดํผ๋ฅผ ๋ ํฌํจํ๋,
์๊ธฐ ํ์ฅ ๋ดํผ์ ๋ด์ธก์ผ๋ก ์ถ๊ฐ ๊ณต๊ฐ์ด ํ์ฑ๋์ด ์ถ๊ฐ ์๋ฉ๊ณต๊ฐ์ ๊ตฌ๋นํ ๋ก ํ๋ ๊ฒ์ ํน์ง์ผ๋ก ํ๋ ์ถ๊ฐ ์๋ฉ๊ณต๊ฐ์ด ๊ตฌ๋น๋ ๊ฐ๋ฐฉ.<end_of_turn>
Model tree for limecoding/gemma2-2b-it-finetuned-patent-lora
Base model
unsloth/gemma-2-2b-it-bnb-4bit