Downloads · 30 days
40
10% of all-time downloads
rchuluc/bertimbau-large-inferbr-nli-onnx
bertimbau-large-inferbr-nli-onnx is a zero-shot classification model from rchuluc. Use it when you need labels you did not train the model on. It is set up for transformers.js. The card lists the license as mit.
This is an ONNX conversion of felipesfpaula/bertimbau-large-InferBr-NLI for use with Transformers.js (v3+) and ONNX Runtime.
Downloads · 30 days
40
10% of all-time downloads
All-time downloads
385
Public
Repo size
1.7 GB
Likes
0
Public
Click a slice to open those files.
.onnx1.7 GB · 100%
From the Hugging Face model README
This is an ONNX conversion of felipesfpaula/bertimbau-large-InferBr-NLI for use with Transformers.js (v3+) and ONNX Runtime.
No changes to the encoder weights. The config.json is patched so the id2label map uses the canonical NLI names (contradiction / entailment / neutral) — required by the zero-shot-classification pipeline in Transformers.js. Semantics of each class index are preserved from the upstream checkpoint.
Conversion pipeline: rchuluc/bertimbau-large-inferbr-nli-onnx on GitHub (scripts, parity check, reproduction steps).
Not affiliated with the original authors. Please cite the original work in any publication.
contradiction, entailment, neutral
Index mapping is preserved from the upstream checkpoint:
| index | upstream label | this repo label |
|---|---|---|
| 0 | LABEL_0 (Contradiction) | contradiction |
| 1 | LABEL_1 (Entailment) | entailment |
| 2 | LABEL_2 (Neutral) | neutral |
config.json # id2label patched: contradiction / entailment / neutral
tokenizer.json
tokenizer_config.json
special_tokens_map.json
vocab.txt
onnx/
model.onnx # fp32 — 1.34 GB
model_quantized.onnx # dynamic int8 (QUInt8) — 336 MB
The zero-shot-classification pipeline handles the NLI premise/hypothesis pair internally via the hypothesis_template.
import { pipeline } from '@huggingface/transformers';
const clf = await pipeline(
'zero-shot-classification',
'rchuluc/bertimbau-large-inferbr-nli-onnx',
{ dtype: 'q8' }, // or 'fp32'
);
const result = await clf(
'Os bailes funks nas favelas paulistanas são fundamentais para a juventude local.',
[
'anglicismo',
'neologismo',
'gíria de nicho',
'termo técnico apropriado',
'marcador identitário',
'estrangeirismo não-inglês',
],
{ hypothesis_template: 'Este texto é sobre {}.' },
);
console.log(result);
// { sequence: '...', labels: [...], scores: [...] } — sorted desc
⚠️ pipeline('text-classification') in Transformers.js v3 does not implement text_pair — to run NLI directly, drop to the tokenizer + model API:
import {
AutoTokenizer,
AutoModelForSequenceClassification,
softmax,
} from '@huggingface/transformers';
const tokenizer = await AutoTokenizer.from_pretrained(
'rchuluc/bertimbau-large-inferbr-nli-onnx',
);
const model = await AutoModelForSequenceClassification.from_pretrained(
'rchuluc/bertimbau-large-inferbr-nli-onnx',
{ dtype: 'q8' },
);
const enc = await tokenizer(
'O baile da DZ7 reunia milhares de pessoas em Paraisópolis.',
{
text_pair: 'Existia um baile funk grande em Paraisópolis.',
truncation: true,
padding: 'max_length',
max_length: 128,
return_tensors: 'pt',
},
);
const out = await model(enc);
const probs = softmax(Array.from(out.logits.data));
const id2label = model.config.id2label;
// probs[0] = contradiction, probs[1] = entailment, probs[2] = neutral
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer
import torch
model = ORTModelForSequenceClassification.from_pretrained(
"rchuluc/bertimbau-large-inferbr-nli-onnx",
file_name="onnx/model_quantized.onnx", # or "onnx/model.onnx"
)
tok = AutoTokenizer.from_pretrained("rchuluc/bertimbau-large-inferbr-nli-onnx")
inputs = tok(
"O baile da DZ7 reunia milhares de pessoas em Paraisópolis.",
"Existia um baile funk grande em Paraisópolis.",
return_tensors="pt", truncation=True, padding="max_length", max_length=128,
)
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)[0]
print({model.config.id2label[i]: float(probs[i]) for i in range(3)})
12 PT-BR NLI control pairs (cultural / civic domain), reference = PyTorch fp32 BertForSequenceClassification:
| dtype | parity vs PyTorch fp32 | accuracy vs ground truth | latency (onnxruntime-node, CPU) | size |
|---|---|---|---|---|
| fp32 | (not benchmarked) | (not benchmarked) | — | 1.34 GB |
| q8 | 12/12 (100%) | 12/12 (100%) | 48 ms/pair | 336 MB |
Maximum absolute logit divergence reported by Optimum during export: 0.00011 (well within practical tolerance).
id2label patch. Upstream ships labels as LABEL_0/LABEL_1/LABEL_2. The Transformers.js zero-shot-classification pipeline requires the entailment label to be discoverable by case-insensitive substring match — so this repo patches config.json to use contradiction/entailment/neutral (preserving the original index order documented by the upstream model card).text_pair on the JS pipeline. Transformers.js v3 pipeline('text-classification') ignores text_pair. For NLI direct, use AutoTokenizer + AutoModelForSequenceClassification. The zero-shot-classification pipeline is unaffected — it builds the pair internally from the hypothesis_template.onnxruntime.quantization.quantize_dynamic with weight_type=QUInt8. No static calibration; q8 matched fp32 PyTorch perfectly on the 12-pair control set.onnxruntime-node ≥ 1.21 / @huggingface/transformers ≥ 3.8).@misc{felipesfpaula2025bertimbau-inferbr-nli,
author = {Paula, Felipe S. F.},
title = {bertimbau-large-InferBr-NLI},
year = {2025},
url = {https://huggingface.co/felipesfpaula/bertimbau-large-InferBr-NLI}
}
@inproceedings{souza2020bertimbau,
author = {Fábio Souza and Rodrigo Nogueira and Roberto Lotufo},
title = {{BERT}imbau: Pretrained {BERT} Models for {B}razilian {P}ortuguese},
booktitle = {9th Brazilian Conference on Intelligent Systems (BRACIS)},
year = {2020}
}