Downloads · 30 days
6
11% of all-time downloads
tree193nn/patent-qa-llama3-qlora
patent-qa-llama3-qlora is a text generation model from tree193nn. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as llama3.
Downloads · 30 days
6
11% of all-time downloads
All-time downloads
57
Public
Repo size
185 MB
Likes
0
Public
Click a slice to open those files.
.safetensors168 MB · 91%
From the Hugging Face model README
This is a QLoRA adapter for LLaMA-3-Korean-Bllossom-8B, fine-tuned on 8,502 Korean patent and trademark decision documents from the Korean Intellectual Property Tribunal. The model specializes in answering questions about Korean patent law, trademark law, and design rights with high accuracy and confidence.
| Metric | Value | Description |
|---|---|---|
| Token Accuracy | 81.0% | Percentage of correctly predicted tokens |
| Validation Loss | 0.651 | Cross-entropy loss on validation set |
| Entropy | 0.665 | Low entropy indicates confident predictions |
| Training Loss | 0.494 | Final training loss (epoch 3) |
The model showed consistent improvement across 3 epochs:
pip install torch transformers peft bitsandbytes accelerate
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
# Configuration for 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
# Load base model
base_model_name = "MLP-KTLim/llama-3-Korean-Bllossom-8B"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name,
quantization_config=bnb_config,
device_map="auto",
torch_dtype=torch.bfloat16,
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "tree193nn/patent-qa-llama3-qlora")
model.eval()
# Inference
question = "상표권의 보호기간은 얼마나 되나요?"
prompt = f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
당신은 지식재산권법 전문가입니다. 특허 및 상표 관련 법률 질문에 대해 정확하고 상세한 답변을 제공해주세요.<|eot_id|><|start_header_id|>user<|end_header_id|>
{question}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.7,
top_p=0.9,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(answer)
questions = [
"상표권의 보호기간은 얼마나 되나요?", # How long is trademark protection?
"특허 출원 시 필요한 서류는 무엇인가요?", # What documents are needed for patent filing?
"디자인권과 저작권의 차이는 무엇인가요?", # What's the difference between design rights and copyright?
]
✅ Question Answering about Korean intellectual property law ✅ Legal Research assistance for patent and trademark matters ✅ Educational Tool for learning Korean IP law ✅ Information Retrieval from patent decision documents
❌ Legal Advice: This model should NOT be used as a substitute for professional legal counsel ❌ Official Decisions: Outputs are not legally binding ❌ Non-Korean Languages: Optimized for Korean only ❌ General Purpose QA: Specializes in IP law, may not perform well on general topics
⚠️ Important Notice: This model is intended for research and educational purposes only. Users should:
Minimum:
Recommended:
# QLoRA Configuration
lora_r: 16
lora_alpha: 32
lora_dropout: 0.05
quantization: 4-bit (NF4)
# Training Configuration
epochs: 3
batch_size: 2 (per device)
gradient_accumulation_steps: 8
effective_batch_size: 16
learning_rate: 2e-4
lr_scheduler: cosine
warmup_ratio: 0.03
weight_decay: 0.01
optimizer: paged_adamw_32bit
max_seq_length: 2048
The fine-tuned adapter shows significant improvements in the legal domain:
If you use this model in your research, please cite:
@misc{patent-qa-llama3-qlora,
author = {tree193nn},
title = {Korean Patent QA with LLaMA-3 QLoRA},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/tree193nn/patent-qa-llama3-qlora}},
note = {QLoRA adapter for Korean patent and trademark law question answering}
}