Views
No views yet
| Property | Value |
|---|---|
| Base model | mistralai/Mistral-7B-Instruct-v0.2 |
| Adapter type | QLoRA (4-bit NF4) |
| LoRA rank | r=16, alpha=32 |
| Target modules | q, k, v, o, gate, up, down projections |
| Max sequence length | 512 tokens |
| Training epochs | 1 (full) |
| Effective batch size | 32 (batch=8, grad_accum=4) |
| Learning rate | 2e-4 with cosine scheduler |
| Warmup ratio | 0.05 |
| Precision | bfloat16 |
| Hardware | NVIDIA L4 GPU |
| Trainer | SFTTrainer (trl 0.29.0) |
patents_50k_green.parquet — 50,000 patent claims with
Y02 silver labels derived from CPC codestrain_silver, 95%)[INST]...[/INST] chat template{"is_green": 0/1, "rationale": "one sentence"}[INST] template and trained to completion, resuming from
checkpoint-800 after an SSH disconnection at step 725/891.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3from peft import PeftModel
4
5BASE_MODEL = "mistralai/Mistral-7B-Instruct-v0.2"
6ADAPTER_DIR = "qlora_mistral_y02_V2"
7
8bnb = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_use_double_quant=True,
12 bnb_4bit_compute_dtype=torch.bfloat16,
13)
14
15tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
16base = AutoModelForCausalLM.from_pretrained(
17 BASE_MODEL, quantization_config=bnb, device_map="auto"
18)
19model = PeftModel.from_pretrained(base, ADAPTER_DIR)
20model.eval()
21
22claim = "A photovoltaic solar panel system for residential energy generation."
23
24prompt = (
25 "You are an expert patent examiner for Y02 green technology. "
26 "Classify the following patent claim as GREEN (1) or NOT GREEN (0).\n\n"
27 'Return STRICT JSON only: {"is_green": 0 or 1, "rationale": "one sentence"}\n\n'
28 f"Patent claim:\n{claim}"
29)
30
31messages = [{"role": "user", "content": prompt}]
32formatted = tokenizer.apply_chat_template(
33 messages, tokenize=False, add_generation_prompt=True
34)
35inputs = tokenizer(formatted, return_tensors="pt").to(model.device)
36
37with torch.no_grad():
38 out = model.generate(
39 **inputs,
40 max_new_tokens=150,
41 do_sample=False,
42 pad_token_id=tokenizer.eos_token_id,
43 )
44
45response = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:],
46 skip_special_tokens=True)
47print(response)
48# {"is_green": 1, "rationale": "Photovoltaic system directly generates
49# renewable electricity, qualifying under Y02E 10/50."}Advocate (this model) → argues FOR green classification
Skeptic (this model) → argues AGAINST green classification
Judge (this model) → weighs both sides → final JSON verdict| Library | Version |
|---|---|
| PEFT | 0.18.1 |
| TRL | 0.29.0 |
| Transformers | 4.57.6 |
| PyTorch | 2.9.1 |
| Datasets | 4.6.1 |
| Tokenizers | 0.22.2 |