Instructions to use limecoding/gemma2-2b-it-finetuned-patent 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 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="limecoding/gemma2-2b-it-finetuned-patent") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("limecoding/gemma2-2b-it-finetuned-patent") model = AutoModelForCausalLM.from_pretrained("limecoding/gemma2-2b-it-finetuned-patent", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use limecoding/gemma2-2b-it-finetuned-patent with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M # Run inference directly in the terminal: llama cli -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M # Run inference directly in the terminal: llama cli -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
Use Docker
docker model run hf.co/limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use limecoding/gemma2-2b-it-finetuned-patent with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "limecoding/gemma2-2b-it-finetuned-patent" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "limecoding/gemma2-2b-it-finetuned-patent", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
- SGLang
How to use limecoding/gemma2-2b-it-finetuned-patent with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "limecoding/gemma2-2b-it-finetuned-patent" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "limecoding/gemma2-2b-it-finetuned-patent", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "limecoding/gemma2-2b-it-finetuned-patent" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "limecoding/gemma2-2b-it-finetuned-patent", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use limecoding/gemma2-2b-it-finetuned-patent with Ollama:
ollama run hf.co/limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
- Unsloth Studio
How to use limecoding/gemma2-2b-it-finetuned-patent 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 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 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 to start chatting
- Atomic Chat new
- Docker Model Runner
How to use limecoding/gemma2-2b-it-finetuned-patent with Docker Model Runner:
docker model run hf.co/limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
- Lemonade
How to use limecoding/gemma2-2b-it-finetuned-patent with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull limecoding/gemma2-2b-it-finetuned-patent:Q4_K_M
Run and chat with the model
lemonade run user.gemma2-2b-it-finetuned-patent-Q4_K_M
List all available models
lemonade list
Uploaded model
- Developed by: limecoding
- License: apache-2.0
- Finetuned from model : fine-tuned-model
This gemma2 model was trained 2x faster with Unsloth and Huggingface's TRL library.
Model Overview
This model is fine-tuned to assist with drafting patent specifications based on a general description of an invention. The base model is unsloth/gemma-2-2b-it, and I used unsloth to merge the fine-tuned adapter.
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>
- Downloads last month
- 49

docker model run hf.co/limecoding/gemma2-2b-it-finetuned-patent: