Speedtoxify 🚀
Fast 🙊 Detoxify inference with ONNX runtime
⚡ Benchmarks | ⚙️ install | 🌟 Quick Start | 📃 Docs
Speedtoxify is a wrapper around detoxify
that speeds up inference by 2-4x by using ONNX runtime.
Detoxify is a NLP library for detecting toxic / inappropriate / profane texts. Speedtoxify makes use of their pretrained models and runs them in ONNX runtime for much faster inference speeds, which makes it the better option for being used in production.
Speedtoxify provides the same Python API as Detoxify, so it can be used as a drop-in replacement.
However, if your focus is on fine-tuning / re-training the models with your own data, please refer to Detoxify.
⚡ Lightning fast
| Model | Batch size | Device | Detoxify (ms/sample) | Speedtoxify (ms/sample) | Speedup |
|---|---|---|---|---|---|
| original-small | 8 | cpu | 13.34 | 5.43 | 2.46x |
| original-small | 1 | cpu | 31.07 | 13.03 | 2.38x |
| original-small | 8 | cuda | 1.55 | 0.79 | 1.98x |
| original-small | 1 | cuda | 11.17 | 3.24 | 3.44x |
| original | 8 | cpu | 22.99 | 5.39 | 4.26x |
| original | 1 | cpu | 31.48 | 13.11 | 2.40x |
| original | 8 | cuda | 1.60 | 0.75 | 2.12x |
| original | 1 | cuda | 12.13 | 3.37 | 3.60x |
Evaluation script can be found in test_speed.py.
Evaluation is done on my laptop with AMD 4900HS and Nvidia 2060 Max-Q.
⚙️ Installation
Pip
pip install speedtoxify
GPU Inference
Please additionally install onnxruntime-gpu for inference on gpus.
Requires the machine to have CUDA installed.
pip install onnxruntime-gpu
🌟 Quick start
Speedtoxify provides the identical Python API as Detoxify.
from speedtoxify import Speedtoxify
model = Speedtoxify("original-small")
# Exporting to onnx format to ~/.cache/detoxify_onnx/original-small.onnx...
# Using framework PyTorch: 1.11.0+cu102
# Removing shared weights from ~/.cache/detoxify_onnx/original-small.onnx...
# Validating ONNX model...
# -[✓] ONNX model output names match reference model ({'logits'})
# - Validating ONNX Model output "logits":
# -[✓] (2, 6) matches (2, 6)
# -[✓] all values close (atol: 1e-05)
res = model.predict("I hate you!")
print(res)
# {'toxicity': 0.9393415, 'severe_toxicity': 0.015587699, 'obscene': 0.039672945, 'threat': 0.0733101, 'insult': 0.15676126, 'identity_attack': 0.019178415}
Please refer to detoxify for available model types.
The first time Speedtoxify("original-small") is called, an onnx model is
exported and stored at ~/.cache/detoxify_onnx.
This directory can be customized in the cache_dir argument to
Speedtoxify().
📃 Documentation
Please refer to docs.
Metadata
Release files for speedtoxify 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| speedtoxify-0.0.3.tar.gz | 8.9 kB | Without provenance | Details for speedtoxify-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| speedtoxify-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for speedtoxify-0.0.3-py3-none-any.whl |
Total release size: 18.3 kB
Release files / speedtoxify-0.0.3.tar.gz
| Download URL | speedtoxify-0.0.3.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91006bbf85fb884e516649f9cc91e0ff12c8daa6373013c6296da616e9d32211
|
|
BLAKE2b-256 checksum How to use checksums |
26dec30088b097150bfd4f55e95e53bcb65a4957d789649b92e59867eb080572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
|
Release files / speedtoxify-0.0.3-py3-none-any.whl
| Download URL | speedtoxify-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b80d06ab8296fa29aba6fa56bd163a8d29b25af02295629d5308957d61ed08a
|
|
BLAKE2b-256 checksum How to use checksums |
d3ad63e7009b68924035592ab94702cab069f9b99cec1c4f4d3026e3156b820a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
|
Security for speedtoxify 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.