rust-bert is a Rust library that provides ready-to-use NLP pipelines and transformer-based models.
The library addresses the need to run state-of-the-art natural language processing models natively in Rust without depending on Python. It ports Hugging Face's Transformers library using Rust bindings to PyTorch through tch-rs or ONNX Runtime, combined with tokenization from rust-tokenizers. The approach exposes model architectures, task-specific heads, and pre-built pipelines that handle common NLP workflows in just a few lines of code. It supports multi-threaded tokenization and GPU inference.
The tool suits projects requiring NLP capabilities in Rust environments where Python integration is impractical or undesirable. It covers a broad range of tasks including question answering, named entity recognition, translation, summarization, text generation, sentiment analysis, and sentence embeddings. The library supports numerous transformer architectures including BERT, DistilBERT, RoBERTa, GPT-2, T5, BART, and others, each with varying task support. Developers should be aware that pre-trained models are large, typically hundreds of megabytes to gigabytes, and are cached locally in a configurable directory. The library requires libtorch to be available in the environment, which can be downloaded automatically or installed manually.
The project maintains active engagement with issues and pull requests, showing responsiveness to user feedback and bug reports. Development includes regular updates to support new model architectures and task types as they emerge in the transformer ecosystem. The codebase demonstrates consistent refinement of the API surface and performance optimizations for inference workloads.