CoolFace
Modelpublic

vishaalsai29/qwen2.5-7b-json-extraction-sft

sourceHugging Faceapache-2.0updated 7mo agoView on Hugging Face
0likes13downloads
Model Card

Qwen2.5-7B JSON Extraction (QLoRA Fine-tuned)

A QLoRA fine-tuned version of Qwen2.5-7B-Instruct for structured JSON extraction from unstructured text.

Results

MetricBase ModelAfter SFT
JSON Validity Rate100%100%
Exact Match Accuracy39%100%
Field Coverage Rate80.2%100%

What It Does

Extracts clean, schema-compliant JSON from messy natural language text.

Example:

Input:
"Please add Alice Johnson to the mailing list.
City: Austin, Age: 32, Email: alice@example.com."

Output:
{"name": "Alice Johnson", "age": 32,
 "email": "alice@example.com", "city": "Austin"}

Supports 4 schema types: person contacts, product listings, event details, and invoice data.

Training Details

  • —Base model: Qwen/Qwen2.5-7B-Instruct
  • —Method: QLoRA (4-bit NF4 quantization + LoRA adapters)
  • —LoRA rank: 16, alpha: 32
  • —Training examples: 1,687
  • —Epochs: 3
  • —Hardware: NVIDIA A40 48GB
  • —Framework: HuggingFace TRL SFTTrainer

Usage

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

base = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-7B-Instruct",
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
model = PeftModel.from_pretrained(
    base,
    "vishaalsai29/qwen2.5-7b-json-extraction-sft"
)
tokenizer = AutoTokenizer.from_pretrained(
    "vishaalsai29/qwen2.5-7b-json-extraction-sft"
)

SYSTEM = """You are a precise JSON extraction assistant.
Given unstructured text, extract the requested fields and
return ONLY valid JSON. No explanation, no markdown."""

messages = [
    {"role": "system", "content": SYSTEM},
    {"role": "user", "content": "Extract name, age, email, city.\n\nText: Alice Johnson is 32, based in Austin. Email: alice@example.com"}
]

text = tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    out = model.generate(**inputs, max_new_tokens=128, temperature=0.1, do_sample=True)

print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
# {"name": "Alice Johnson", "age": 32, "email": "alice@example.com", "city": "Austin"}

GitHub

Full training code, notebooks, and documentation: github.com/vishaalsai/lora-dpo