CoolFace
Modelpublic

blue-machines/Gemma3-270M-sentence-intent-v1

sourceHugging Faceupdated 20d agoView on Hugging Face
0likes20downloads
Model Card

Gemma 3 270M Sentence Intent v1

blue-machines/Gemma3-270M-sentence-intent-v1 is a sentence-level intent classifier.

  • —Base model: google/gemma-3-270m (~269M)
  • —Task: 7-class utterance intent
  • —Runtime: ONNX Runtime (model.onnx INT8 deploy + model_fp32.onnx)
  • —Input format: a single bare sentence / utterance (no dialogue tags like [assistant] / [user])
  • —Output: intent class label + confidence (softmax max probability)

Intent labels

idlabel
0provide_info
1affirm
2deny
3correction
4question
5clarify_request
6unclear

Files

FileRole
model.onnxDeploy — dynamic INT8 encoder; GeGLU head kept FP32
model_fp32.onnxFull FP32 ONNX reference
model.safetensorsOriginal PyTorch weights
label_map.jsonLabel id ↔ name map
tokenizer.jsonGemma tokenizer
config.jsonTransformer config

Recommended confidence threshold

Optimal threshold (selected for performance + coverage): `0.55`

Serving rule:

text
probs = softmax(intent_logits)
pred  = argmax(probs)
conf  = max(probs)
if conf < 0.55:
    pred = unclear   # safe abstain

Selection rule: among thresholds with coverage ≥ 0.97, maximize selective accuracy (tie-break: lower false-intent rate). This keeps most examples committed while cutting false specific intents.

Test-set metrics (sentence-direct test)

VariantAccuracyMacro-F1False-intentCoverageSelective acc
FP32 raw (no gate)0.94520.94440.04481.00000.9452
Deploy raw (no gate)0.94510.94450.04561.00000.9451
Deploy @ thr=0.550.93920.94030.03620.97550.9572

Input / output contract

Input: pass one individual sentence (or a batch of independent sentences). Do not wrap with dialogue markers.

Valid examples:

  • —Haan, ye sahi hai. Proceed karo.
  • —What is the minimum balance required?
  • —Nahi, maine ye payment nahi kiya.
  • —Sorry I meant March not April.

Tensors

NameTypeShapeNotes
input_idsint64[batch, seq]pad/truncate to 64
attention_maskint64[batch, seq]1 = real, 0 = pad
logits / intent_logitsfloat[batch, 7]apply softmax for confidence

Inference snippet

python
import json
from pathlib import Path

import numpy as np
from transformers import AutoTokenizer, CanineTokenizer

MODEL_DIR = Path(".")  # or huggingface_hub.snapshot_download(...)
MAX_LEN = 64
CONF_THRESHOLD = 0.55  # optimal gate (coverage>=0.97, max selective acc)
UNCLEAR_ID = 6

# tokenizer — Gemma tokenizer (max length 64).
tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token

with open(MODEL_DIR / "label_map.json", encoding="utf-8") as f:
    maps = json.load(f)
id2intent = {int(k): v for k, v in maps["head4_intent"]["id2label"].items()}

import onnxruntime as ort

session = ort.InferenceSession(
    str(MODEL_DIR / "model.onnx"),  # or model_fp32.onnx
    providers=["CPUExecutionProvider"],
)

def predict_intent(sentence: str) -> dict:
    """Pass a single bare sentence; returns label + confidence."""
    enc = tokenizer(
        sentence,
        return_tensors="np",
        truncation=True,
        max_length=MAX_LEN,
        padding="max_length",
    )
    feed = {
        "input_ids": enc["input_ids"].astype(np.int64),
        "attention_mask": enc["attention_mask"].astype(np.int64),
    }
    logits = session.run(None, feed)[0][0]

    x = logits.astype(np.float64)
    x = x - x.max()
    probs = np.exp(x)
    probs = probs / probs.sum()
    pred_id = int(probs.argmax())
    conf = float(probs.max())
    abstained = conf < CONF_THRESHOLD
    if abstained:
        pred_id = UNCLEAR_ID
    return {
        "text": sentence,
        "intent": id2intent[pred_id],
        "confidence": conf,
        "abstained": abstained,
        "threshold": CONF_THRESHOLD,
        "probs": {id2intent[i]: float(probs[i]) for i in range(7)},
    }

for s in [
    "Haan, ye sahi hai. Proceed karo.",
    "What is the minimum balance required?",
    "Nahi, maine ye payment nahi kiya.",
]:
    print(predict_intent(s))

Notes

  • —Intent-only model (no LID / LSD heads).
  • —Trained on sentence-direct data (Gemini synth + Muthoot user turns + noisy unclear), without [assistant]/[user] packing.