crfrs
Generic structured-perceptron sequence labeler with Viterbi decoding, written in Rust.
Implements the averaged structured perceptron (Collins 2002) with lazy averaging (Daumé 2006) for efficient training. You supply per-token feature vectors and a label set; the crate handles training and inference.
Features
- Averaged structured perceptron training
- Viterbi decoding over label sequences
- Emission and transition scoring
- Save/load models as JSON
- Language-agnostic — works with any feature strings and label set
Usage
[]
= "0.1"
use ;
// Build training data: each example is (features_per_token, gold_labels)
let examples: = vec!;
let labels = vec!;
let config = TrainConfig ;
let model = train;
model.save.unwrap;
// Inference
let loaded = load.unwrap;
let tags = loaded.tag;
println!; // ["DET", "NOUN"]
API
| Item | Description |
|---|---|
train(examples, labels, config) |
Train a model from labeled sequences |
PerceptronTrainer |
Low-level trainer for custom training loops |
TrainConfig |
Training hyperparameters (default: 15 epochs) |
PerceptronModel::tag(&seq_features) |
Viterbi decode a sequence |
PerceptronModel::save(path) |
Persist model to JSON |
PerceptronModel::load(path) |
Load model from JSON |
License
MIT