Views
No views yet
distilroberta-sms-spam-detector model. The model has been converted to the ONNX format and its weights have been quantized to 8-bit integers (INT8) for optimal performance on edge devices like mobile phones.distilroberta-base model.version.txt file for use with Over-the-Air (OTA) update systems.onnxruntime.1import onnxruntime as ort
2from transformers import AutoTokenizer
3import numpy as np
4import scipy.special
5
6REPO_ID = "SharpWoofer/distilroberta-sms-spam-detector-onnx-quantized"
7ONNX_MODEL_NAME = "model.quant.onnx"
8
9model_path = hf_hub_download(repo_id=REPO_ID, filename=ONNX_MODEL_NAME)
10
11# Load the tokenizer from the same repository
12tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
13
14session = ort.InferenceSession(model_path)
15
16# Prepare text
17text = "Congratulations! You've won a $1000 gift card. Click now!"
18inputs = tokenizer(text, return_tensors="np", padding="max_length", truncation=True)
19
20# Run inference
21outputs = session.run(None, dict(inputs))
22scores = outputs[0][0] # Get the raw logits
23
24# Convert logits to probabilities
25probabilities = scipy.special.softmax(scores)
26prediction = np.argmax(probabilities)
27
28labels = ["HAM", "SPAM"]
29print(f"Prediction: {labels[prediction]}, Confidence: {probabilities[prediction]:.4f}")
30# >> Prediction: SPAM, Confidence: 0.99...optimum library. Subsequently, dynamic quantization was applied using the onnxruntime.quantization toolkit to convert the model's weights to INT8.onnxruntimequantize_dynamicQuantType.QInt8| Model | Class | Precision | Recall | F1-Score |
|---|---|---|---|---|
| Original (FP32) | HAM | 1.00 | 1.00 | 1.00 |
| SPAM | 1.00 | 0.97 | 0.99 | |
| Overall | 1.00 | 1.00 | 1.00 | |
| Quantized (INT8) | HAM | 0.99 | 1.00 | 1.00 |
| SPAM | 1.00 | 0.96 | 0.98 | |
| Overall | 0.99 | 0.99 | 0.99 |