1 from transformers import pipeline
2
3 classifier = pipeline (
4 "text-classification" ,
5 model = "./spam_model_quantized" ,
6 tokenizer = "./spam_model"
7 )
8
9 sample = "WINNER!! Claim your $1000 prize now!"
10 result = classifier ( sample )
11 print ( f"Prediction: { result [ 0 ] [ 'label' ] } (confidence: { result [ 0 ] [ 'score' ] : .2% } )" )
1 from optimum . onnxruntime import ORTModelForSequenceClassification
2
3 model = ORTModelForSequenceClassification . from_pretrained (
4 "./spam_model_quantized" ,
5 provider = "CPUExecutionProvider"
6 )
1 import pandas as pd
2
3 df = pd . read_csv ( "messages.csv" )
4 predictions = classifier ( list ( df [ "text" ] ) , batch_size = 32 )
.
├── spam_model/ # Original PyTorch model
│ ├── config.json
│ ├── model.safetensors
│ └── tokenizer.json
├── spam_model_quantized/ # Production-ready quantized model
│ ├── model.onnx
│ ├── quantized_model.onnx
│ └── tokenizer_config.json
├── examples/ # Ready-to-use scripts
│ ├── predict.py # CLI interface
│ └── api_server.py # FastAPI service
├── requirements.txt # Dependencies
└── README.md # This document
1 FROM python:3.9-slim
2 COPY . /app
3 WORKDIR /app
4 RUN pip install -r requirements.txt
5 CMD [ "uvicorn" , "examples.api_server:app" , "--host" , "0.0.0.0" ]
Pull requests and suggestions are welcome! Please open an issue for feature requests or bug reports.