Polish Twitter Emotion Classifier (ONNX INT8)
This is the INT8 quantized ONNX version of yazoniak/twitter-emotion-pl-classifier
This model is an INT8 dynamically quantized ONNX version of the Polish Twitter Emotion Classifier, optimized for 2.9x faster inference than ONNX FP32, 9.9x faster than PyTorch, and 51% smaller compared to the original. Perfect for edge deployment and cost-sensitive applications.
Quick Links
Model Description
This model predicts 8 emotion and sentiment labels simultaneously for Polish text:
Emotions : radość (joy), wstręt (disgust), gniew (anger), przeczuwanie (anticipation)
Sentiment : pozytywny (positive), negatywny (negative), neutralny (neutral)
Special : sarkazm (sarcasm)
Model Details
Attribute Value Base Model PKOBP/polish-roberta-8k Original Model yazoniak/twitter-emotion-pl-classifier Architecture RoBERTa for Sequence Classification Task Multi-label text classification Language Polish Format ONNX (INT8 Dynamic Quantization) Quantization AVX512_VNNI ONNX Opset 18 Model Size 825 MB (51% smaller than FP32) License GPL-3.0
Performance
Benchmark Results
Metric PyTorch ONNX FP32 ONNX INT8 INT8 Improvement Mean Latency (CPU) 193.89 ms 56.79 ms 19.48 ms 9.95x faster vs PyTorchP95 Latency 350.16 ms 59.63 ms 23.05 ms 15.19x faster Throughput 5.16/sec 17.61/sec 51.33/sec 9.95x higher Std Deviation 56.04 ms 2.78 ms 1.83 ms Most consistent Model Size 1,690 MB 1,690 MB 825 MB 51% smaller
Summary:
⚡ 2.9x faster than ONNX FP32
🚀 9.9x faster than PyTorch
📦 51% smaller than FP32
🎯 Most consistent latency (std: 1.83ms)
Accuracy (100-sample evaluation)
Evaluated on 100 random samples from
TwitterEmo-PL-Refined (seed=42, threshold=0.5).
ONNX FP32 produces identical predictions to PyTorch (100% agreement, prob diff ~10⁻⁸).
All differences below are INT8 vs PyTorch .
INT8 Quality Difference (vs PyTorch baseline)
Metric INT8 Δ Note F1 Macro −0.0054 Negligible drop Precision Macro +0.0159 Slightly better Recall Macro −0.0140 Slightly lower Exact Match +1.00 pp 52% vs 51%
Per-Label F1 Difference (INT8 − PyTorch)
Label F1 Δ radość 0.0000 wstręt −0.0075 gniew −0.0197 przeczuwanie −0.0506 pozytywny +0.0250 negatywny 0.0000 neutralny +0.0152
INT8 vs PyTorch Agreement
Metric Value Label Agreement (mean) 98.57% Exact Match 92.00% Mean Prob Diff 0.0154 Median Prob Diff 0.0032 Max Prob Diff 0.3546
Key takeaway: INT8 quantization maintains 98.6% label agreement with a negligible F1 macro drop of just 0.005 — well within noise for a 100-sample evaluation.
For reference, the original model accuracy on the full validation set:
F1 Macro: 0.8500
F1 Micro: 0.8900
F1 Weighted: 0.8895
See the
original model card for detailed metrics.
Installation
pip install optimum[onnxruntime] transformers numpy
For GPU support (though INT8 is optimized for CPU):
pip install optimum[onnxruntime-gpu] transformers numpy
Usage
Quick Start (Command Line)
1 # Download the inference scripts
2 wget https://huggingface.co/yazoniak/twitter-emotion-pl-classifier-onnx-int8/resolve/main/predict.py
3 wget https://huggingface.co/yazoniak/twitter-emotion-pl-classifier-onnx-int8/resolve/main/predict_calibrated.py
4
5 # Basic inference
6 python predict.py "Wspaniały dzień! Jestem bardzo szczęśliwy :)"
7
8 # Calibrated inference (recommended for best accuracy)
9 python predict_calibrated.py "Wspaniały dzień! Jestem bardzo szczęśliwy :)"
Python API - Basic Inference
1 from optimum . onnxruntime import ORTModelForSequenceClassification
2 from transformers import AutoTokenizer
3 import numpy as np
4 import re
5
6 # Load model and tokenizer
7 model_name = "yazoniak/twitter-emotion-pl-classifier-onnx-int8"
8 tokenizer = AutoTokenizer . from_pretrained ( model_name )
9 model = ORTModelForSequenceClassification . from_pretrained (
10 model_name ,
11 provider = "CPUExecutionProvider" # INT8 is optimized for CPU
12 )
13
14 # Preprocess text (anonymize @mentions - IMPORTANT!)
15 def preprocess_text ( text ) :
16 return re . sub ( r"@\w+" , "@anonymized_account" , text )
17
18 text = "@user To jest wspaniały dzień!"
19 processed_text = preprocess_text ( text )
20
21 # Tokenize and run inference
22 inputs = tokenizer ( processed_text , return_tensors = "pt" , truncation = True , max_length = 8192 )
23 outputs = model ( ** inputs )
24
25 # Get probabilities (sigmoid for multi-label)
26 logits = outputs . logits . squeeze ( ) . numpy ( )
27 probabilities = 1 / ( 1 + np . exp ( - logits ) )
28
29 # Get labels above threshold
30 labels = [ model . config . id2label [ i ] for i in range ( model . config . num_labels ) ]
31 threshold = 0.5
32 predictions = { labels [ i ] : float ( probabilities [ i ] )
33 for i in range ( len ( labels ) ) if probabilities [ i ] > threshold }
34
35 print ( predictions )
36 # Output: {'radość': 0.9573, 'pozytywny': 0.9721}
Python API - Calibrated Inference (Recommended)
For improved accuracy, use temperature scaling and optimal thresholds:
1 import json
2 from huggingface_hub import hf_hub_download
3
4 # Download calibration artifacts
5 calib_path = hf_hub_download (
6 repo_id = "yazoniak/twitter-emotion-pl-classifier-onnx-int8" ,
7 filename = "calibration_artifacts.json"
8 )
9
10 with open ( calib_path ) as f :
11 calib = json . load ( f )
12
13 temperatures = calib [ "temperatures" ]
14 optimal_thresholds = calib [ "optimal_thresholds" ]
15
16 # Apply temperature scaling and optimal thresholds
17 calibrated_probs = { }
18 for i , label in enumerate ( labels ) :
19 temp = temperatures [ label ]
20 thresh = optimal_thresholds [ label ]
21
22 # Temperature scaling
23 calibrated_logit = logits [ i ] / temp
24 prob = 1 / ( 1 + np . exp ( - calibrated_logit ) )
25
26 if prob > thresh :
27 calibrated_probs [ label ] = float ( prob )
28
29 print ( calibrated_probs )
When to Use This Model
Use ONNX INT8 when:
✅ Edge deployment - Mobile, embedded devices
✅ Cost-sensitive - Reduce cloud inference costs
✅ High throughput - Need 50+ predictions/sec on CPU
✅ Limited storage - 825 MB vs 1.7 GB
✅ CPU inference - AVX512-optimized for modern Intel/AMD CPUs
✅ Slight accuracy loss acceptable
Consider alternatives:
ONNX FP32 : For full precision (same accuracy as PyTorch)
Original PyTorch : For fine-tuning or GPU training
Important Notes
Text Preprocessing
⚠️ The model expects @mentions to be anonymized!
The model was trained with anonymized Twitter mentions. Always preprocess text:
text = re.sub(r"@\w+", "@anonymized_account", text)
The provided scripts (predict.py, predict_calibrated.py) handle this automatically.
Calibration
For best accuracy, use calibrated inference with:
Temperature scaling (per-label)
Optimized thresholds (per-label)
See predict_calibrated.py or the calibrated inference example above.
CPU Optimization
This INT8 model is optimized for CPUs with AVX512_VNNI support. It will work on other CPUs but may not achieve the same speedup.
Limitations
Slight accuracy loss : Some predictions may differ from FP32 (usually minor probability differences)
Twitter-specific : Optimized for informal Polish social media text
Sarcasm detection : Lower performance - inherently difficult
Context length : Optimal for tweet-length texts (up to 8,192 tokens)
Formal text : May not generalize well to news or academic writing
For detailed limitations, see the
original model card .
Files in This Repository
File Size Description model.onnx825 MB INT8 quantized ONNX model config.json2 KB Model configuration tokenizer.json8.2 MB Tokenizer vocabulary tokenizer_config.json12 KB Tokenizer settings calibration_artifacts.json1 KB Temperature scaling & optimal thresholds predict.py4 KB Simple inference script predict_calibrated.py5 KB Calibrated inference script (recommended)
Citation
1 @model{yazoniak2025twitteremotionpl,
2 title={Polish Twitter Emotion Classifier (RoBERTa-8k)},
3 author={yazoniak},
4 year={2025},
5 publisher={Hugging Face},
6 url={https://huggingface.co/yazoniak/twitter-emotion-pl-classifier}
7 }
Also cite the dataset and base model:
1 @dataset{yazoniak_twitteremo_pl_refined_2025,
2 title={TwitterEmo-PL-Refined: Polish Twitter Emotions (8 labels, refined)},
3 author={yazoniak},
4 year={2025},
5 url={https://huggingface.co/datasets/yazoniak/TwitterEmo-PL-Refined}
6 }
7
8 @inproceedings{bogdanowicz2023twitteremo,
9 title={TwitterEmo: Annotating Emotions and Sentiment in Polish Twitter},
10 author={Bogdanowicz, S. and Cwynar, H. and Zwierzchowska, A. and Klamra, C. and Kiera{\'s}, W. and Kobyli{\'n}ski, {\L}.},
11 booktitle={Computational Science -- ICCS 2023},
12 series={Lecture Notes in Computer Science},
13 volume={14074},
14 publisher={Springer, Cham},
15 year={2023},
16 doi={10.1007/978-3-031-36021-3_20}
17 }
License
This model is released under the GNU General Public License v3.0 (GPL-3.0) , inherited from the training dataset.
License Chain:
Base Model (PKOBP/polish-roberta-8k ): Apache-2.0
Training Dataset (TwitterEmo-PL-Refined ): GPL-3.0
Original Model (yazoniak/twitter-emotion-pl-classifier ): GPL-3.0
This ONNX INT8 Model : GPL-3.0
Acknowledgments
Original Model : yazoniak/twitter-emotion-pl-classifier
Base Model : PKOBP/polish-roberta-8k
Dataset : CLARIN-PL TwitterEmo
Conversion & Quantization : Hugging Face Optimum
Model Version : v1.0-onnx-int8
Last Updated : 2026-01-29