Flow with LSD v1
blue-machines/Flow-with-LSD-v1 is a Gemma 3 270M two-head ONNX model (intent removed):
- LID โ sentence language (10 Indian languages)
- LSD โ language switch detection (10 languages +
no_switch)
Derived from blue-machines/Floe-with-intent-classifer-v1 by stripping the intent head
from the deploy ONNX graph. Encoder + LID remain INT8; LSD head stays FP32.
Quantization
| Part | Precision |
|---|---|
| Gemma encoder | INT8 |
| LID head | INT8 |
| LSD head | FP32 |
Deploy size: ~258 MB (model.onnx).
Gate metrics (from parent Floe checkpoint)
| Task | Metric | Value |
|---|---|---|
| LID | lid_finetune_subset acc |
0.9944648823787505 |
| LSD | lsd_evaluation acc |
0.9704418789808917 |
| LSD | lsd_evaluation no_switch |
0.973753280839895 |
Files
| File | Role |
|---|---|
model.onnx |
Deploy โ LID + LSD only (no intent) |
model_fp32.onnx |
FP32 reference, LID + LSD only |
label_map.json |
LID / LSD label ids |
tokenizer.json |
Gemma tokenizer (max length 128) |
Inference
import json
from pathlib import Path
import numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer
MODEL_DIR = Path(".") # or snapshot_download("blue-machines/Flow-with-LSD-v1")
MAX_LEN = 128
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)
id2lid = {int(k): v for k, v in maps["head1_lid"]["id2label"].items()}
id2switch = {int(k): v for k, v in maps["head2_switch"]["id2label"].items()}
session = ort.InferenceSession(
str(MODEL_DIR / "model.onnx"),
providers=["CPUExecutionProvider"],
)
def predict(text: str) -> dict:
enc = tokenizer(
text,
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_lid, logits_switch = session.run(None, feed)
lid_id = int(logits_lid[0].argmax())
switch_id = int(logits_switch[0].argmax())
x = logits_lid[0].astype(np.float64)
x = x - x.max()
p = np.exp(x); p = p / p.sum()
return {
"text": text,
"lid": id2lid[lid_id],
"language_switch": id2switch[switch_id],
"lid_confidence": float(p.max()),
}
print(predict("Haan, ye sahi hai. Proceed karo."))
Output tensor names
| Output | Shape | Head |
|---|---|---|
logits_lid |
[batch, 10] |
Sentence LID |
logits_switch |
[batch, 11] |
Language switch |
Inputs: input_ids, attention_mask (int64, pad/truncate to 128).
No
intent_logitsoutput โ useblue-machines/Intent-classifier-v1for intent.
- Downloads last month
- -