rust-bert exposes ready-made Rust pipelines and transformer architectures for tasks such as QA, NER, translation, and text generation, ported from Hugging Face Transformers via tch-rs or ONNX.
Overview
rust-bert is a Rust crate that brings transformer-based NLP models and end-to-end pipelines into native applications. It mirrors much of Hugging Face Transformers, using tch-rs bindings to Libtorch or optional ONNX runtime support, with tokenization from rust-tokenizers and support for multi-threaded tokenization and GPU inference.
Task-specific heads and pretrained pipelines cover translation, summarization, dialogue, zero-shot classification, sentiment, named entity recognition, part-of-speech tagging, question answering, language generation, masked language modeling, sentence embeddings, and keyword extraction. Many encoder, decoder, and encoder–decoder architectures appear in the supported model matrix.
Setup requires Libtorch (manual install or download-libtorch feature) or ONNX libraries when the onnx feature is enabled. Pretrained weights download to a configurable cache directory defaulting under the user home.
Optional ONNX paths aim for compatibility with models exported through Optimum, with separate encoder and decoder artifacts where needed. Base model APIs remain available for custom checkpoints imported from PyTorch with aligned parameter naming.
Key features
- Ready-to-use NLP pipelines
- Libtorch via tch-rs
- Optional ONNX inference
- Multi-threaded tokenization
- GPU inference support
- Many BERT-family architectures
- Pretrained weight cache
- Custom model head APIs
Use cases
- Rust services needing local NLP
- Embedding and retrieval pipelines
- On-device translation or QA
- ONNX-deployed transformer models
- Comparing Rust vs Python inference paths