Downloads · 30 days
111
10% of all-time downloads
richardr1126/roberta-base-zeroshot-v2.0-c-ONNX
roberta-base-zeroshot-v2.0-c-ONNX is a zero-shot classification model from richardr1126. Use it when you need labels you did not train the model on. The card lists the license as mit.
This is an ONNX-optimized version of MoritzLaurer/roberta-base-zeroshot-v2.0-c for efficient inference.
Downloads · 30 days
111
10% of all-time downloads
All-time downloads
1.1K
Public
Repo size
624 MB
Likes
0
Public
Click a slice to open those files.
.onnx624 MB · 99%
From the Hugging Face model README
This is an ONNX-optimized version of MoritzLaurer/roberta-base-zeroshot-v2.0-c for efficient inference.
This repository contains:
The model is optimized for zero-shot classification tasks across multiple languages.
from transformers import pipeline, AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification
# Load the quantized model
model = ORTModelForSequenceClassification.from_pretrained(
"richardr1126/roberta-base-zeroshot-v2.0-c-ONNX",
file_name="model_quantized.onnx"
)
tokenizer = AutoTokenizer.from_pretrained(
"richardr1126/roberta-base-zeroshot-v2.0-c-ONNX"
)
# Patch the model's forward method to handle token_type_ids
original_forward = model.forward
def patched_forward(input_ids=None, attention_mask=None, token_type_ids=None, **kwargs):
return original_forward(input_ids=input_ids, attention_mask=attention_mask, **kwargs)
model.forward = patched_forward
# Create zero-shot classification pipeline
classifier = pipeline(
"zero-shot-classification",
model=model,
tokenizer=tokenizer,
device=-1 # CPU inference
)
# Define your labels
labels = ["politics", "technology", "sports", "entertainment", "business"]
# Classify text
text = "Apple announced their new AI chip with impressive performance gains."
result = classifier(
text,
candidate_labels=labels,
hypothesis_template="This text is about {{}}",
multi_label=True # Enable multi-label classification
)
print(f"Text: {{text}}")
for label, score in zip(result['labels'], result['scores']):
print(f" {{label}}: {{score:.2%}}")
For the non-quantized model (larger but potentially slightly more accurate):
model = ORTModelForSequenceClassification.from_pretrained(
"richardr1126/roberta-base-zeroshot-v2.0-c-ONNX",
file_name="model.onnx"
)
# ... rest of the code is the same
The quantized model provides:
This is an optimized version of the original model:
Same as the base model - MIT License
If you use this model, please cite the original model:
@misc{laurer2022roberta,
author = {Laurer, Moritz and Atteveldt, Wouter van and Casas, Andreu Salleras and Welbers, Kasper},
title = {RoBERTa Base Zero-Shot Classification},
year = {2022},
publisher = {Hugging Face},
url = {https://huggingface.co/MoritzLaurer/roberta-base-zeroshot-v2.0-c}
}
This ONNX optimization was created for efficient deployment in production environments. Special thanks to the original model authors and the Hugging Face Optimum team.