wellington-roveder/reservabot-nlu-ptbr
Viewer • Updated • 289 • 29
reservabot-nlu-logreg-minilm)
Classificador supervisionado leve (8.80 KB) treinado com Regressão Logística regularizada ($L_2$, C=1.0, class_weight="balanced") sobre embeddings normalizados de 384 dimensões extraídos do sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 (via fastembed).
Comparação controlada contra o baseline zero-shot (SemanticNLU por similaridade de cosseno) e um full fine-tuning do neuralmind/bert-base-portuguese-cased (110M parâmetros):
| Abordagem | Accuracy | F1-Macro | Recall fora_de_escopo |
Latência p50 (CPU) | Tamanho Artefato |
|---|---|---|---|---|---|
Baseline (SemanticNLU Cosseno) |
79,55% | 0,8081 | 60,00% (9/15) | 9,41 ms | 0 KB (JSON) |
LogisticRegression + MiniLM-L12 |
86,36% | 0,8698 | 80,00% (12/15) | 14,67 ms | 8,80 KB |
BERTimbau Fine-Tuned (110M) |
81,82% | 0,7964 | 100,00% (15/15) | 111,92 ms | 416,20 MB |
| Classe | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
fazer_reserva |
1.0000 | 0.7500 | 0.8571 | 8 |
consultar_reserva |
0.8571 | 0.8571 | 0.8571 | 7 |
cancelar_reserva |
1.0000 | 1.0000 | 1.0000 | 7 |
horario_funcionamento |
0.6364 | 1.0000 | 0.7778 | 7 |
fora_de_escopo |
0.9231 | 0.8000 | 0.8571 | 15 |
import joblib
import numpy as np
from fastembed import TextEmbedding
from huggingface_hub import hf_hub_download
caminho = hf_hub_download(
repo_id="wellington-roveder/reservabot-nlu-logreg-minilm",
filename="logreg_nlu.joblib",
)
artefato = joblib.load(caminho)
clf = artefato["model"]
threshold = artefato["threshold"] # 0.35
encoder = TextEmbedding("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
vetor = np.array(list(encoder.embed(["quero reservar uma mesa para 2 hoje às 20h"])))
vetor = vetor / np.linalg.norm(vetor, axis=1, keepdims=True)
probs = clf.predict_proba(vetor)[0]
classes = list(clf.classes_)
idx_fora = classes.index("fora_de_escopo")
melhor_intent, melhor_prob = max(
((c, p) for i, (c, p) in enumerate(zip(classes, probs)) if i != idx_fora),
key=lambda x: x[1],
)
predicao = (
melhor_intent
if (melhor_prob >= threshold and melhor_prob >= probs[idx_fora])
else "fora_de_escopo"
)
print(predicao, round(float(melhor_prob), 4))