kute_algorithms/lib.rs
1//! Baseline algorithms (FR-002, priority P0 besides BPE):
2//!
3//! * `bytes`: one token per byte. The lossless fallback and the baseline
4//! every other vocabulary is measured against.
5//! * `char`: one token per Unicode character seen in training, with the 256
6//! byte tokens underneath so unseen characters and invalid UTF-8 still
7//! round-trip.
8//! * `dictionary`: a fixed list of entries. Over bytes it matches the longest
9//! entry greedily and falls back to byte tokens; over symbols it is a plain
10//! lookup that refuses unknown symbols.
11
12mod table;
13
14pub use table::{ByteTokenizer, CharTokenizer, DictionaryTokenizer};
15
16pub const BYTES: &str = "bytes";
17pub const CHAR: &str = "char";
18pub const DICTIONARY: &str = "dictionary";
19
20/// Register this crate's algorithms.
21pub fn register(registry: &mut kute_core::Registry) {
22 registry.register_algorithm(BYTES, || Box::new(ByteTokenizer::default()));
23 registry.register_algorithm(CHAR, || Box::new(CharTokenizer::default()));
24 registry.register_algorithm(DICTIONARY, || Box::new(DictionaryTokenizer::default()));
25}