Skip to main content

Library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs). Re-implementation of OpenFst in Rust.

Project description

Rustfst

License: MIT/Apache-2.0 Maintenance macOS Linux Github tag

Rust

rustc >= 1.49.0 Native Linux test status Documentation

Python

PyPI version PyPI download month PyPI pyversions

This repo contains a Rust implementation of Weighted Finite States Transducers. Along with a Python binding.

Rustfst is a library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs). Weighted finite-state transducers are automata where each transition has an input label, an output label, and a weight. The more familiar finite-state acceptor is represented as a transducer with each transition's input and output label equal. Finite-state acceptors are used to represent sets of strings (specifically, regular or rational sets); finite-state transducers are used to represent binary relations between pairs of strings (specifically, rational transductions). The weights can be used to represent the cost of taking a particular transition.

FSTs have key applications in speech recognition and synthesis, machine translation, optical character recognition, pattern matching, string processing, machine learning, information extraction and retrieval among others. Often a weighted transducer is used to represent a probabilistic model (e.g., an n-gram model, pronunciation model). FSTs can be optimized by determinization and minimization, models can be applied to hypothesis sets (also represented as automata) or cascaded by finite-state composition, and the best results can be selected by shortest-path algorithms.

fst

References

Implementation heavily inspired from Mehryar Mohri's, Cyril Allauzen's and Michael Riley's work :

Example

use anyhow::Result;
use rustfst::prelude::*;
use rustfst::algorithms::determinize::{DeterminizeType, determinize};
use rustfst::algorithms::rm_epsilon::rm_epsilon;

fn main() -> Result<()> {
    // Creates a empty wFST
    let mut fst = VectorFst::<TropicalWeight>::new();

    // Add some states
    let s0 = fst.add_state();
    let s1 = fst.add_state();
    let s2 = fst.add_state();

    // Set s0 as the start state
    fst.set_start(s0)?;

    // Add a transition from s0 to s1
    fst.add_tr(s0, Tr::new(3, 5, 10.0, s1))?;

    // Add a transition from s0 to s2
    fst.add_tr(s0, Tr::new(5, 7, 18.0, s2))?;

    // Set s1 and s2 as final states
    fst.set_final(s1, 31.0)?;
    fst.set_final(s2, 45.0)?;

    // Iter over all the paths in the wFST
    for p in fst.paths_iter() {
         println!("{:?}", p);
    }

    // A lot of operations are available to modify/optimize the FST.
    // Here are a few examples :

    // - Remove useless states.
    connect(&mut fst)?;

    // - Optimize the FST by merging states with the same behaviour.
    minimize(&mut fst)?;

    // - Copy all the input labels in the output.
    project(&mut fst, ProjectType::ProjectInput);

    // - Remove epsilon transitions.
    rm_epsilon(&mut fst)?;

    // - Compute an equivalent FST but deterministic.
    fst = determinize(&fst)?;

    Ok(())
}

Benchmark with OpenFST

I did a benchmark some time ago on almost every linear fst algorithm and compared the results with OpenFst. You can find the results here :

Spoiler alert: Rustfst is faster on all those algorithms 😅

Documentation

The documentation of the last released version is available here : https://docs.rs/rustfst

Release process

  1. Use the script update_version.sh to update the version of every package.
  2. Push
  3. Push a new tag with the prefix rustfst-v

Example :

./update_version.sh 0.9.1-alpha.6
git commit -am "Release 0.9.1-alpha.6"
git push
git tag -a rustfst-v0.9.1-alpha.6 -m "Release rustfst 0.9.1-alpha.6"  
git push --tags

Optionally, if this is a major release, create a GitHub release in the UI.

Projects contained in this repository

This repository contains two main projects:

  • rustfst is the Rust re-implementation.
    • Crate available on crates.io here
    • Documentation available on docs.rs here
  • rustfst-python is the python binding of rustfst.
    • Package available on Pypi here
    • Documentation available on Github Pages here

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rustfst_python-0.11.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (619.2 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

rustfst_python-0.11.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (619.2 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

rustfst_python-0.11.4-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (619.2 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

rustfst_python-0.11.4-cp310-cp310-musllinux_1_1_x86_64.whl (965.8 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

rustfst_python-0.11.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-cp310-cp310-macosx_11_0_arm64.whl (571.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rustfst_python-0.11.4-cp310-cp310-macosx_10_9_x86_64.whl (619.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

rustfst_python-0.11.4-cp310-cp310-macosx_10_9_universal2.whl (1.2 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

rustfst_python-0.11.4-cp39-cp39-musllinux_1_1_x86_64.whl (965.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

rustfst_python-0.11.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-cp39-cp39-macosx_11_0_arm64.whl (571.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rustfst_python-0.11.4-cp39-cp39-macosx_10_9_x86_64.whl (619.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

rustfst_python-0.11.4-cp39-cp39-macosx_10_9_universal2.whl (1.2 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

rustfst_python-0.11.4-cp38-cp38-musllinux_1_1_x86_64.whl (965.8 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

rustfst_python-0.11.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-cp38-cp38-macosx_11_0_arm64.whl (571.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

rustfst_python-0.11.4-cp38-cp38-macosx_10_9_x86_64.whl (619.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

rustfst_python-0.11.4-cp38-cp38-macosx_10_9_universal2.whl (1.2 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

rustfst_python-0.11.4-cp37-cp37m-musllinux_1_1_x86_64.whl (965.8 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

rustfst_python-0.11.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (932.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

rustfst_python-0.11.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (952.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

rustfst_python-0.11.4-cp37-cp37m-macosx_10_9_x86_64.whl (619.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page