barha/granite-text-to-json-350m-lora
Granite 4.0 350M — Text-to-JSON LoRA
A LoRA adapter for `ibm-granite/granite-4.0-350m` that turns a natural-language request plus a target JSON Schema into a single schema-conforming JSON object.
This is one of three adapters built to share a single Granite Switch checkpoint (alongside CTI technique-mapping and GenAI attack-vector classification), so its LoRA shape is identical across all three: rank 16, alpha 32, on the fused q/k/v/o attention projections and the input_linear / output_linear MLP projections.
Evaluation
Held-out eval (n = 2000), greedy decoding:
Key-F1 is the headline metric; schema conformance is reported as a diagnostic only (some synthesized gold objects do not validate against their own schema, so it reads low relative to the true generation quality).
Intended use
Constrained JSON generation where the caller supplies the schema in-context. Not a general chat model — use the base Granite model for open-ended conversation.
Quick start
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = "ibm-granite/granite-4.0-350m"
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, device_map="cuda")
model = PeftModel.from_pretrained(model, "barha/granite-text-to-json-350m-lora")
messages = [{"role": "user", "content": "<your request + JSON schema here>"}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
out = model.generate(inputs, max_new_tokens=1024)
print(tok.decode(out[0, inputs.shape[1]:], skip_special_tokens=True))Training
- Base:
ibm-granite/granite-4.0-350m - Method: supervised fine-tuning (TRL), LoRA r=16 / α=32, dropout 0.05
- Target modules:
q_proj,k_proj,v_proj,o_proj,input_linear,output_linear - Data: `ChristianAzinn/json-training`
License: Apache-2.0
