[−][src]Struct grapheme_to_phoneme::Model
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]
directory: &Path
) -> Result<Self, GraphToPhoneError>
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,