CoolFace
Modelpublic

alinashrestha/qlora-mistral-y02-v2

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes11downloads
Model Card

qloramistraly02_V2 — Y02 Green Patent Classifier

This is a QLoRA fine-tuned adapter for mistralai/Mistral-7B-Instruct-v0.2, trained to classify patent claims as GREEN (Y02) or NOT GREEN.

It was developed as the Judge agent's brain in a 3-agent MAS pipeline for Y02 green patent classification (M4 Final Assignment — AAU).


Model Details

PropertyValue
Base modelmistralai/Mistral-7B-Instruct-v0.2
Adapter typeQLoRA (4-bit NF4)
LoRA rankr=16, alpha=32
Target modulesq, k, v, o, gate, up, down projections
Max sequence length512 tokens
Training epochs1 (full)
Effective batch size32 (batch=8, grad_accum=4)
Learning rate2e-4 with cosine scheduler
Warmup ratio0.05
Precisionbfloat16
HardwareNVIDIA L4 GPU
TrainerSFTTrainer (trl 0.29.0)

Training Data

  • —Source: patents_50k_green.parquet — 50,000 patent claims with Y02 silver labels derived from CPC codes
  • —Train split: 28,500 rows (train_silver, 95%)
  • —Eval split: 1,500 rows (5% held-out, stratified)
  • —Label balance: 50% GREEN / 50% NOT GREEN
  • —Prompt format: Mistral [INST]...[/INST] chat template
  • —Target output: Strict JSON — {"is_green": 0/1, "rationale": "one sentence"}

Training History

VersionEpochsTrainerResult
V2 (this model)1.0 (full)SFTTrainerStable — loss 0.87→0.83

V2 used Mistral [INST] template and trained to completion, resuming from checkpoint-800 after an SSH disconnection at step 725/891.


Usage

python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel

BASE_MODEL  = "mistralai/Mistral-7B-Instruct-v0.2"
ADAPTER_DIR = "qlora_mistral_y02_V2"

bnb = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype=torch.bfloat16,
)

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
base      = AutoModelForCausalLM.from_pretrained(
    BASE_MODEL, quantization_config=bnb, device_map="auto"
)
model = PeftModel.from_pretrained(base, ADAPTER_DIR)
model.eval()

claim = "A photovoltaic solar panel system for residential energy generation."

prompt = (
    "You are an expert patent examiner for Y02 green technology. "
    "Classify the following patent claim as GREEN (1) or NOT GREEN (0).\n\n"
    'Return STRICT JSON only: {"is_green": 0 or 1, "rationale": "one sentence"}\n\n'
    f"Patent claim:\n{claim}"
)

messages  = [{"role": "user", "content": prompt}]
formatted = tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(formatted, return_tensors="pt").to(model.device)

with torch.no_grad():
    out = model.generate(
        **inputs,
        max_new_tokens=150,
        do_sample=False,
        pad_token_id=tokenizer.eos_token_id,
    )

response = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], 
                             skip_special_tokens=True)
print(response)
# {"is_green": 1, "rationale": "Photovoltaic system directly generates 
#  renewable electricity, qualifying under Y02E 10/50."}

Role in MAS Pipeline

This adapter was used as the Judge agent in a 3-agent pipeline:

Advocate (this model) → argues FOR green classification
Skeptic  (this model) → argues AGAINST green classification  
Judge    (this model) → weighs both sides → final JSON verdict

All 3 agents share this same model — differentiated only by role-specific prompts. HITL was triggered when confidence < 0.65 or deadlock=True.


Framework Versions

LibraryVersion
PEFT0.18.1
TRL0.29.0
Transformers4.57.6
PyTorch2.9.1
Datasets4.6.1
Tokenizers0.22.2