rucrf: Conditional Random Fields implemented in pure Rust
rucrf contains a trainer and an estimator for Conditional Random Fields (CRFs). This library supports:
- lattices with variable length edges,
- L1 and L2 regularization, and
- multi-threading during training.
Examples
use NonZeroU32;
use ;
// Train:
// 京(kyo) 都(to)
// 東(to) 京(kyo)
// 京(kei) 浜(hin)
// 京(kyo) の(no) 都(miyako)
//
// Test:
// 水(mizu) の(no) 都(miyako)
//
// 1-gram features:
// 京: 1, 都: 2, 東: 3, 浜: 4, の: 5, 水: 6
// 2-gram features:
// kyo: 1, to: 2, kei: 3, hin: 4, no: 5, miyako: 6, mizu: 7
let mut provider = new;
let label_京kyo = provider.add_feature_set?;
let label_都to = provider.add_feature_set?;
let label_東to = provider.add_feature_set?;
let label_京kei = provider.add_feature_set?;
let label_浜hin = provider.add_feature_set?;
let label_のno = provider.add_feature_set?;
let label_都miyako = provider.add_feature_set?;
let label_水mizu = provider.add_feature_set?;
let mut lattices = vec!;
// 京都 (kyo to)
let mut lattice = new?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattices.push;
// 東京 (to kyo)
let mut lattice = new?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattices.push;
// 京浜 (kei hin)
let mut lattice = new?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattices.push;
// 京の都 (kyo no miyako)
let mut lattice = new?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattices.push;
// Generates a model
let trainer = new;
let model = trainer.train;
// 水の都 (mizu no miyako)
let mut lattice = new?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
lattice.add_edge?;
let = model.search_best_path;
assert_eq!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.