Skip to main content

Crate crfrs

Crate crfrs 

Source
Expand description

§crfrs

Generic structured-perceptron sequence labeler with Viterbi decoding.

Implements the averaged structured perceptron (Collins 2002) with lazy averaging (Daumé 2006). You supply feature vectors (Vec<String> per position) and a label set; the crate handles training and Viterbi decoding.

§Usage

use crfrs::{PerceptronModel, train, TrainConfig};

// Each example: (features_per_token, labels_per_token)
let examples: Vec<(Vec<Vec<String>>, Vec<String>)> = vec![];
let labels = vec!["NOUN".into(), "VERB".into(), "ADJ".into()];
let model = train(&examples, labels, TrainConfig::default());
model.save(std::path::Path::new("model.json")).unwrap();

let loaded = PerceptronModel::load(std::path::Path::new("model.json")).unwrap();
let tags = loaded.tag(&[vec!["word=hello".into(), "suffix-1=o".into()]]);

Re-exports§

pub use error::Error;
pub use error::Result;
pub use model::PerceptronModel;
pub use trainer::train;
pub use trainer::PerceptronTrainer;
pub use trainer::TrainConfig;

Modules§

error
Error types for crfrs.
model
Trained perceptron model — weights storage and Viterbi decoding.
trainer
Online structured-perceptron trainer with averaged weights.