CoolFace
Modelpublic

tmiyamoto/qwen3-4b-20260205_1331-exp02-basic

sourceHugging Faceapache-2.0updated 8mo agoView on Hugging Face
0likes14downloads
Model Card

<【松尾研課題】qwen3-4b-structured-output-lora−EX03>

This repository provides a LoRA adapter fine-tuned from Qwen/Qwen3-4B-Instruct-2507 using QLoRA (4-bit, Unsloth) for structured data output tasks.

This repository contains LoRA adapter weights only. The base model must be loaded separately.

Training Objective

This adapter is trained to improve structured output accuracy for multiple formats:

  • JSON, YAML, XML, TOML, CSV
  • Text-to-structured conversion
  • Format-to-format conversion (e.g., CSV to JSON, JSON to YAML)

Key training features:

  • Loss is applied only to the final assistant output
  • Intermediate reasoning (Chain-of-Thought) is masked during training
  • Task distribution optimized for evaluation benchmark
  • texttotoml: 2.5x
  • csvtojson: 1.5x
  • jsontoyaml: 1.5x
  • tomltojson: 1.3x
  • xmltojson: 1.3x

Training Configuration

Model & Method

  • Base model: Qwen/Qwen3-4B-Instruct-2507
  • Method: QLoRA (4-bit quantization)
  • Max sequence length: 512 tokens
  • LoRA configuration: r=64, alpha=128, dropout=0

Training Hyperparameters

  • Epochs: 1
  • Learning rate: 2e-06
  • Batch size: 2 per device × 8 gradient accumulation = 16 effective batch size
  • Warmup ratio: 10%
  • Weight decay: 0.05

Training Data

  • Total datasets: 5 datasets
  • Approximate training samples: ~22,000 rows
  • Upsampling: Enabled
  • texttotoml: 2.5x
  • csvtojson: 1.5x
  • jsontoyaml: 1.5x
  • tomltojson: 1.3x
  • xmltojson: 1.3x

Datasets Used

  • u-10bei/structureddatawithcotdataset512v2
  • u-10bei/structureddatawithcotdataset512v4
  • u-10bei/structureddatawithcotdataset512v5
  • daichira/structured-5k-mix-sft
  • daichira/structured-hard-sft-4k

Usage

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

base = "Qwen/Qwen3-4B-Instruct-2507"
adapter = "your_id/your-repo"

tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    base,
    torch_dtype=torch.float16,
    device_map="auto",
    trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter)

# Example: Generate structured output
messages = [{"role": "user", "content": "Convert this CSV to JSON: name,age\nAlice,30"}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.0)
print(tokenizer.decode(outputs[0]))

Performance

This adapter is optimized for the StructEvalT benchmark, focusing on:

  • High accuracy for Text-to-TOML tasks (17% of evaluation)
  • Strong performance on JSON/YAML output tasks (56% of evaluation)
  • Robust format conversion capabilities

Sources & Terms (IMPORTANT)

Training data: u-10bei/structureddatawithcotdataset512v2, u-10bei/structureddatawithcotdataset512v4, u-10bei/structureddatawithcotdataset512v5, daichira/structured-5k-mix-sft, daichira/structured-hard-sft-4k

Dataset Licenses:

  • MIT License (u-10bei datasets)
  • CC-BY-4.0 (daichira datasets)

Compliance: Users must comply with the respective dataset licenses (MIT and CC-BY-4.0) and the base model's original terms of use.