Downloads · 30 days
107
78% of all-time downloads
vardhjain20/byte-sized-brain-distilbert-imdb
byte-sized-brain-distilbert-imdb is a text classification model from vardhjain20. Use it when you need a label for a piece of text. The card lists the license as mit.
Two ONNX versions of one DistilBERT model that reads an English movie review and says whether it is positive or negative. They were made by Byte-Sized Brain, a project that measures what quantization does to the size,…
Downloads · 30 days
107
78% of all-time downloads
All-time downloads
137
Public
Repo size
335 MB
Likes
1
Public
Click a slice to open those files.
.onnx335 MB · 100%
From the Hugging Face model README
Two ONNX versions of one DistilBERT model that reads an English movie review and says whether it is positive or negative. They were made by Byte-Sized Brain, a project that measures what quantization does to the size, accuracy, speed and memory of neural networks.
distilbert_imdb_fp32.onnx is the full-precision model, fine-tuned on 3,000 IMDB reviews.distilbert_imdb_int8.onnx is the same model after ONNX Runtime dynamic INT8
quantization, which stores the weights as 8-bit numbers.Try both side by side in the hosted demo.
| File | Size | Accuracy | Mean time per review |
|---|---|---|---|
distilbert_imdb_fp32.onnx | 255.5 MB | 84.6% | 99 ms |
distilbert_imdb_int8.onnx | 64.3 MB | 84.0% | 55 ms |
The model reads at most 128 tokens. Label 0 is negative and label 1 is positive. Both inputs must be int64, which the tokenizer does not guarantee on every platform.
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo = "vardhjain20/byte-sized-brain-distilbert-imdb"
tokenizer = AutoTokenizer.from_pretrained(repo)
session = ort.InferenceSession(hf_hub_download(repo, "distilbert_imdb_int8.onnx"))
enc = tokenizer("A moving, beautifully acted film.", truncation=True, max_length=128,
return_tensors="np")
feed = {name: enc[name].astype(np.int64) for name in ("input_ids", "attention_mask")}
logits = session.run(None, feed)[0]
print(["negative", "positive"][int(np.argmax(logits))])