ArcWeight
A high-performance Rust library for weighted finite-state transducers with comprehensive semiring support.
ArcWeight provides efficient algorithms for constructing, combining, and optimizing weighted finite-state transducers (WFSTs), making it suitable for natural language processing, speech recognition, and computational linguistics applications.
Features
- Core FST Operations: Composition, determinization, minimization, closure, union, concatenation
- Advanced Algorithms: Shortest path, weight pushing, epsilon removal, pruning, synchronization
- High-Performance Minimization: Hopcroft's O(n log n) algorithm and Brzozowski's algorithm
- Rich Semiring Support: Tropical, log, probability, boolean, integer, product, and Gallic weights
- Multiple FST Implementations: Vector-based, constant, compact, lazy evaluation, CSR format, and cached
- Type-Safe Design: Zero-cost abstractions with trait-based polymorphism
- OpenFST Compatible: Read and write OpenFST format files
- Python Bindings: Full-featured Python API via PyO3 for easy integration
- Pure Rust: Memory-safe implementation with no C++ dependencies
- Parallel Processing: Rayon-based parallelization with work-stealing for large FSTs
- SIMD Optimizations: AVX2/AVX-512 vectorized weight operations (where available)
- Custom Allocators: Optional mimalloc support via
fast-allocfeature
Quick Start
Add ArcWeight to your Cargo.toml:
[]
= "0.3"
Basic Example
use *;
Python Bindings
ArcWeight also provides Python bindings for easy integration into Python projects:
# Create a new FST
=
# Add states
=
=
# Set start state
# Add an arc: from s0 to s1, input=1, output=1, weight=1.0
# Set final state
# Perform operations
=
=
The Python API provides full access to all FST operations and algorithms. See the Python bindings documentation for more details.
Examples
ArcWeight includes comprehensive examples demonstrating real-world applications:
# String edit distance
# Spell checking and correction
# Morphological analysis
# Phonological rules
# Text normalization
See the examples/ directory for complete implementations with detailed explanations.
Documentation
- API Documentation - Complete API reference with examples
- Examples - Real-world applications and usage patterns
Minimum Supported Rust Version (MSRV)
ArcWeight requires Rust 1.85.0 or later.
The MSRV is explicitly tested in CI and will only be increased in minor version updates. When the MSRV is increased, the previous two stable releases will still be supported for six months.
Performance
ArcWeight is designed for high performance:
- Zero-copy arc iteration minimizes allocations
- Cache-friendly data structures optimize memory access (CSR format, SmallVec inline storage)
- Optional parallel algorithms leverage multi-core processors with work-stealing
- Automatic algorithm selection based on FST properties
- SIMD-accelerated weight operations (AVX2/AVX-512)
- Custom allocator support (mimalloc via
fast-allocfeature) - FxHashMap for faster hash operations in composition and determinization
- LTO and single-codegen-unit builds for release optimization
Run benchmarks on your system:
Performance Features
Enable additional optimizations:
[]
= { = "0.3", = ["fast-alloc", "parallel"] }
Available performance features:
fast-alloc- Use mimalloc allocator for reduced allocation overheadparallel- Enable Rayon-based parallel algorithms (enabled by default)gpu- Experimental GPU acceleration via wgpu
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Quick checklist:
- Follow existing code style (run
cargo fmt) - Add tests for new functionality (run
cargo test) - Update documentation for public APIs (run
cargo doc) - Ensure all CI checks pass (run
cargo clippy)
Getting Help
- Documentation - API reference and guides
- Issues - Bug reports and feature requests
- Discussions - Questions and community support
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Citation
If you use ArcWeight in your research, please cite:
References
ArcWeight implements algorithms based on:
- Mehryar Mohri. 1997. Finite-State Transducers in Language and Speech Processing. Computational Linguistics 23(2):269-311.
- Mehryar Mohri. 2002. Semiring Frameworks and Algorithms for Shortest-Distance Problems. Journal of Automata, Languages and Combinatorics 7(3):321-350.
- Mehryar Mohri. 2009. Weighted Automata Algorithms. In Handbook of Weighted Automata, pages 213-254. Springer.
Acknowledgments
This library was architected and implemented with the help of Claude Code.