Schakel Intent Router

A LoRA adapter fine-tuned on google/gemma-4-E2B-it for Spanish-language intent classification.

Classifies user input into one of three intents and responds with strict JSON:

{"intent": "DOMOTICA"}

Intents

Intent Description
DOMOTICA Home automation commands (lights, temperature, appliances)
MUSICA Music playback requests
GENERAL Everything else (time, jokes, general questions)

Usage

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

model_id = "google/gemma-4-E2B-it"
adapter_path = "RagnarokReinier/schakel-gemma-router"

tokenizer = AutoTokenizer.from_pretrained(adapter_path)
base_model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base_model, adapter_path)
model.eval()

messages = [
    {"role": "system", "content": "Clasifica la intención del usuario. Responde solo JSON válido con una clave intent y un valor entre DOMOTICA, MUSICA o GENERAL."},
    {"role": "user", "content": "enciende la luz del salón"},
]

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

with torch.no_grad():
    output_ids = model.generate(**inputs, max_new_tokens=64, do_sample=False)

new_tokens = output_ids[0, inputs["input_ids"].shape[1]:]
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
# {"intent":"DOMOTICA"}

Training Details

  • Base model: google/gemma-4-E2B-it
  • Method: LoRA (rank 16, alpha 32) via SFTTrainer
  • Precision: bf16
  • Target modules: language model attention + MLP projections (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj)
  • Dataset: 240 train / 60 validation examples (Spanish voice assistant text)
  • Epochs: 3
  • Learning rate: 2e-4
  • Max sequence length: 256
  • Batch size: 4 (gradient accumulation: 4)

Results

Metric Value
Train loss 4.07
Eval loss 0.48
Token accuracy ~90%
Training time ~3.5 min (Apple Silicon, MPS)

Framework versions

  • PEFT 0.18.1
  • TRL 1.1.0
  • Transformers 5.5.4
  • PyTorch 2.11.0
Downloads last month
1
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for RagnarokReinier/schakel-gemma-router

Adapter
(80)
this model