Skip to main content

Crate crfs

Crate crfs 

Source
Expand description

Pure Rust implementation of Conditional Random Fields (CRF)

This library provides both training and prediction capabilities for linear-chain CRFs.

§Examples

§Training

use crfs::train::Trainer;
use crfs::Attribute;
use std::path::Path;

let mut trainer = Trainer::lbfgs();
trainer.verbose(true);

let xseq = vec![
    vec![Attribute::new("walk", 1.0)],
    vec![Attribute::new("shop", 1.0)],
];
let yseq = vec!["sunny", "rainy"];
trainer.append(&xseq, &yseq)?;

trainer.params_mut().set_c2(1.0)?;
trainer.train(Path::new("model.crfsuite"))?;

§Prediction

use crfs::{Attribute, Model};

let model_data = std::fs::read("model.crfsuite")?;
let model = Model::new(&model_data)?;
let tagger = model.tagger()?;

let xseq = vec![
    vec![Attribute::new("walk", 1.0)],
    vec![Attribute::new("shop", 1.0)],
];
let result = tagger.tag(&xseq)?;

Re-exports§

pub use self::train::Trainer;

Modules§

train
Training module containing all components for training CRF models Training module for CRF models

Structs§

Attribute
Tuple of attribute and its value
Model
The CRF model
Tagger
The tagger provides the functionality for predicting label sequences for input sequences using a model