Expand description
§cufflink-model
Run small trained text classifiers inside Cufflink services. Training
happens offline (the Python toolkit in ml/); a service embeds the
exported file and classifies with it, natively or in WASM, without
calling out to anything.
ⓘ
use cufflink_model::Model;
static GENRES: &[u8] = include_bytes!("../models/genre.cflm");
let model = Model::from_bytes(GENRES)?;
let p = model.predict("The Dragon of Ember Hill");
if p.confidence >= model.threshold().unwrap_or(0.9) {
// use p.label
}A WASM guest is a fresh instance on every call, so Model::from_bytes
reads the file in place: it checks the layout once and keeps borrowed
slices, with no tables rebuilt. Every offset is bounds-checked at load,
and nothing in this crate panics on a malformed file or unusual input.
The file format is described in docs/design-notes/models.md.
Modules§
- featurise
- Turning text into the n-gram features a model scores.
Structs§
- Model
- A loaded model, borrowing the file it was read from.
- Prediction
- A model’s answer for one text.
Enums§
- Kind
- The kind of model a file holds.
- Model
Error - Why a model file couldn’t be read.
Constants§
- FORMAT_
VERSION - The file layout this crate reads.
- MAGIC
- The first four bytes of every model file.