Skip to main content

crfs/
lib.rs

1//! Pure Rust implementation of Conditional Random Fields (CRF)
2//!
3//! This library provides both training and prediction capabilities for linear-chain CRFs.
4//!
5//! # Examples
6//!
7//! ## Training
8//!
9//! ```no_run
10//! use crfs::train::Trainer;
11//! use crfs::Attribute;
12//! use std::path::Path;
13//!
14//! let mut trainer = Trainer::lbfgs();
15//! trainer.verbose(true);
16//!
17//! let xseq = vec![
18//!     vec![Attribute::new("walk", 1.0)],
19//!     vec![Attribute::new("shop", 1.0)],
20//! ];
21//! let yseq = vec!["sunny", "rainy"];
22//! trainer.append(&xseq, &yseq)?;
23//!
24//! trainer.params_mut().set_c2(1.0)?;
25//! trainer.train(Path::new("model.crfsuite"))?;
26//! # Ok::<(), std::io::Error>(())
27//! ```
28//!
29//! ## Prediction
30//!
31//! ```no_run
32//! use crfs::{Attribute, Model};
33//!
34//! let model_data = std::fs::read("model.crfsuite")?;
35//! let model = Model::new(&model_data)?;
36//! let tagger = model.tagger()?;
37//!
38//! let xseq = vec![
39//!     vec![Attribute::new("walk", 1.0)],
40//!     vec![Attribute::new("shop", 1.0)],
41//! ];
42//! let result = tagger.tag(&xseq)?;
43//! # Ok::<(), std::io::Error>(())
44//! ```
45
46mod attribute;
47mod context;
48mod dataset;
49mod feature;
50mod model;
51mod tagger;
52
53/// Training module containing all components for training CRF models
54pub mod train;
55
56// Re-export main types
57pub use self::attribute::Attribute;
58pub use self::model::Model;
59pub use self::tagger::Tagger;
60
61// Re-export training types for convenience
62pub use self::train::Trainer;