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")