[][src]Struct grapheme_to_phoneme::Model

pub struct Model { /* fields omitted */ }

Holds the g2p model for repeated evaluations.

Implementations

impl Model[src]

pub fn load_in_memory() -> Result<Self, GraphToPhoneError>[src]

Load the model that comes bundled in-memory with the library. This is baked into the library at compile time, and it cannot be updated without re-releasing the library.

pub fn load_from_npz_file(filepath: &Path) -> Result<Self, GraphToPhoneError>[src]

Load a model from a NumPy '.npz' file.

If you wish to retrain the model (without changing its structure), you can use this function to load it.

pub fn load_from_npy_directory(
    directory: &Path
) -> Result<Self, GraphToPhoneError>
[src]

Load a model from a directory containing '.npy' files of the expected names.

If you wish to retrain the model (without changing its structure), you can use this function to load it.

This is provided in the event native NumPy '.npz' serialization fails with this library. (I was unable to get 'checkpoint20.npz to work without unzipping and manually rebundling it.)

This looks for the individual model weights files 'enc_emb.npy', 'enc_w_ih.npy', 'enc_w_hh.npy', 'enc_b_ih.npy', 'enc_b_hh.npy', 'dec_emb.npy', 'dec_w_ih.npy', 'dec_w_hh.npy', 'dec_b_ih.npy', 'dec_b_hh.npy', 'fc_w.npy', 'fc_b.npy'.

They must be located together in a single directory.

It's a bit heavy-handed, but may help if it's difficult to rebundle as an 'npz'.

pub fn predict(&self, grapheme: &str) -> Result<Vec<String>, GraphToPhoneError>[src]

Predict phonemes from single-word grapheme input.

To predict multiple words, make multiple calls to this function, once per word. This should only be relied upon as a last resort. You should be using CMUDict to look up words and use this as a fallback for the OOV case.

Usage:

extern crate grapheme_to_phoneme;
use grapheme_to_phoneme::Model;

let model = Model::load_in_memory()
  .expect("should load");

assert_eq!(model.predict("test").expect("should encode"),
  vec!["T", "EH1", "S", "T"].iter()
    .map(|s| s.to_string())
    .collect::<Vec<String>>());

Auto Trait Implementations

impl RefUnwindSafe for Model

impl Send for Model

impl Sync for Model

impl Unpin for Model

impl UnwindSafe for Model

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.