Spaces:
Runtime error
Runtime error
File size: 775 Bytes
190bc8f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
from transformers.onnx import export
from transformers.onnx.features import FeaturesManager
# Load the model and tokenizer
model_name = "cardiffnlp/twitter-roberta-base-sentiment"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Determine the correct export feature
feature = FeaturesManager.get_supported_features_for_model_type("text-classification")
# Define the path where the ONNX model will be saved
onnx_model_path = "https://huggingface.co/spaces/Abineshkumar/demodeploy/sentiment_model.onnx"
# Export the model to ONNX
export(tokenizer, model, feature, onnx_model_path, opset=11, framework="pt")
|