Edit model card

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

  1. 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"
  1. 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
)
  1. 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>
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference API
Unable to determine this modelโ€™s pipeline type. Check the docs .

Model tree for limecoding/gemma2-2b-it-finetuned-patent-lora

Finetuned
(84)
this model