Skip to main content

BaseHiddenMarkovModelSegmenter

Trait BaseHiddenMarkovModelSegmenter 

Source
pub trait BaseHiddenMarkovModelSegmenter: Sized + Clone {
    // Required methods
    fn hmm(&self) -> &HiddenMarkovModel;
    fn hmm_mut(&mut self) -> &mut HiddenMarkovModel;
    fn from_hmm(hmm: HiddenMarkovModel) -> Self;

    // Provided methods
    fn fit_segmented(&mut self, sents: Vec<Vec<String>>) { ... }
    fn fit_unsegmented(&mut self, sent_strs: Vec<String>) { ... }
    fn save_to_path(&self, path: &str) -> Result<(), ModelError> { ... }
    fn load_from_path(&mut self, path: &str) -> Result<(), ModelError> { ... }
    fn save_to_writer<W: Write>(&self, writer: &mut W) -> Result<(), ModelError> { ... }
    fn load_from_reader<R: Read>(&mut self, reader: R) -> Result<(), ModelError> { ... }
    fn score(&self, sents: Vec<Vec<String>>) -> Result<Vec<f64>, ModelError> { ... }
    fn predict(&self, sent_strs: Vec<String>) -> Vec<Vec<String>> { ... }
    fn predict_with_offsets(
        &self,
        sent_strs: Vec<String>,
    ) -> Vec<Vec<(String, (usize, usize))>> { ... }
}
Expand description

Core HMM segmenter behavior with default implementations.

The segmenter delegates vocabulary building, parameter estimation, Viterbi decoding, and save/load to BaseHiddenMarkovModel. It provides the word↔char↔BMES conversion layer on top.

Required Methods§

Provided Methods§

Source

fn fit_segmented(&mut self, sents: Vec<Vec<String>>)

Train the segmenter from supervised segmented sentences.

Source

fn fit_unsegmented(&mut self, sent_strs: Vec<String>)

Train the segmenter from unsegmented sentences using Baum-Welch EM.

Each string in sent_strs is an unsegmented sentence. Characters are extracted and passed to the underlying HMM’s Baum-Welch algorithm. If the model was previously fitted (e.g., via fit_segmented), the existing parameters serve as EM initialization (warm start).

Source

fn save_to_path(&self, path: &str) -> Result<(), ModelError>

Source

fn load_from_path(&mut self, path: &str) -> Result<(), ModelError>

Source

fn save_to_writer<W: Write>(&self, writer: &mut W) -> Result<(), ModelError>

Save the model to a FlatBuffers binary stream.

Source

fn load_from_reader<R: Read>(&mut self, reader: R) -> Result<(), ModelError>

Load the model from a FlatBuffers byte slice.

Source

fn score(&self, sents: Vec<Vec<String>>) -> Result<Vec<f64>, ModelError>

Compute log-likelihood of segmented sentences under the model.

Each sentence is a list of words (same format as fit_segmented input). Returns one log-likelihood per sentence using the Forward algorithm.

Source

fn predict(&self, sent_strs: Vec<String>) -> Vec<Vec<String>>

Segment unsegmented sentence strings.

Source

fn predict_with_offsets( &self, sent_strs: Vec<String>, ) -> Vec<Vec<(String, (usize, usize))>>

Segment unsegmented sentences and return words with character offsets.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§