pub struct Engine { /* private fields */ }Expand description
The engine: a registry plus the common workflows.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn with_registry(registry: Registry) -> Self
pub fn with_registry(registry: Registry) -> Self
An engine around a caller-built registry.
pub fn registry(&self) -> &Registry
Sourcepub fn registry_mut(&mut self) -> &mut Registry
pub fn registry_mut(&mut self) -> &mut Registry
Add algorithms or adapters without touching KUTE’s own crates.
Sourcepub fn train(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
documents: &[Vec<u8>],
config: &TrainingConfig,
) -> Result<Vocabulary>
pub fn train( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, documents: &[Vec<u8>], config: &TrainingConfig, ) -> Result<Vocabulary>
Train algorithm on raw documents read through adapter.
The adapter and its options are recorded in the vocabulary, so encoding and decoding later go through the same adapter without being told.
Sourcepub fn train_stream<'a>(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
config: &TrainingConfig,
documents: &mut dyn FnMut() -> Result<Option<Cow<'a, Vec<u8>>>>,
) -> Result<Vocabulary>
pub fn train_stream<'a>( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, config: &TrainingConfig, documents: &mut dyn FnMut() -> Result<Option<Cow<'a, Vec<u8>>>>, ) -> Result<Vocabulary>
Train on documents that are produced one at a time. Only the document being read is held, so a corpus larger than memory can be trained on as long as each document fits.
Sourcepub fn train_paths(
&self,
algorithm: &str,
adapter: &str,
adapter_config: &AdapterConfig,
paths: &[PathBuf],
config: &TrainingConfig,
) -> Result<Vocabulary>
pub fn train_paths( &self, algorithm: &str, adapter: &str, adapter_config: &AdapterConfig, paths: &[PathBuf], config: &TrainingConfig, ) -> Result<Vocabulary>
Train on files. A directory is read recursively, in sorted path order.
Sourcepub fn tokenizer(&self, vocabulary: Vocabulary) -> Result<Box<dyn Tokenizer>>
pub fn tokenizer(&self, vocabulary: Vocabulary) -> Result<Box<dyn Tokenizer>>
A tokenizer with vocabulary installed.
Sourcepub fn encode_raw(
&self,
tokenizer: &dyn Tokenizer,
raw: &[u8],
) -> Result<TokenSequence>
pub fn encode_raw( &self, tokenizer: &dyn Tokenizer, raw: &[u8], ) -> Result<TokenSequence>
Raw bytes to tokens, through the vocabulary’s adapter.
Sourcepub fn encode_raw_open(
&self,
tokenizer: &dyn Tokenizer,
raw: &[u8],
policy: UnknownPolicy,
) -> Result<TokenSequence>
pub fn encode_raw_open( &self, tokenizer: &dyn Tokenizer, raw: &[u8], policy: UnknownPolicy, ) -> Result<TokenSequence>
Raw bytes to tokens under an explicit policy for unknown symbols.
Sourcepub fn decode_raw_bounded(
&self,
tokenizer: &dyn Tokenizer,
tokens: &TokenSequence,
max_units: u64,
) -> Result<Vec<u8>>
pub fn decode_raw_bounded( &self, tokenizer: &dyn Tokenizer, tokens: &TokenSequence, max_units: u64, ) -> Result<Vec<u8>>
Like Engine::decode_raw, but refuses before decoding when the
sequence would expand to more than max_units bytes or symbols.
For a symbol vocabulary this bounds the number of symbols and not
their size: a symbol can be a kilobyte long, and an escaped one is
chosen by whoever made the sequence. For a sequence from a party you
do not trust, use Engine::decode_raw_within.
Sourcepub fn decode_raw_within(
&self,
tokenizer: &dyn Tokenizer,
tokens: &TokenSequence,
max_units: u64,
max_bytes: u64,
) -> Result<Vec<u8>>
pub fn decode_raw_within( &self, tokenizer: &dyn Tokenizer, tokens: &TokenSequence, max_units: u64, max_bytes: u64, ) -> Result<Vec<u8>>
Like Engine::decode_raw_bounded, and also refuses before
decoding when the decoded content comes to more than max_bytes:
the bytes of a byte vocabulary, or the names of the symbols of a
symbol vocabulary. What an adapter writes around each name (a few
bytes of JSON, and escapes inside it) cannot be known before it is
written, so the result is checked again afterwards: nothing longer
than max_bytes is returned. While decoding, memory is bounded by
the two limits together (at most six bytes written per byte of a
name, plus the framing of max_units symbols), not by max_bytes
alone.
Sourcepub fn decode_raw(
&self,
tokenizer: &dyn Tokenizer,
tokens: &TokenSequence,
) -> Result<Vec<u8>>
pub fn decode_raw( &self, tokenizer: &dyn Tokenizer, tokens: &TokenSequence, ) -> Result<Vec<u8>>
Tokens back to raw bytes, through the vocabulary’s adapter.
Sourcepub fn encode_batch(
&self,
tokenizer: &dyn Tokenizer,
documents: &[Vec<u8>],
) -> Result<Vec<TokenSequence>>
pub fn encode_batch( &self, tokenizer: &dyn Tokenizer, documents: &[Vec<u8>], ) -> Result<Vec<TokenSequence>>
Encode many documents in parallel. Output order matches input order.
Sourcepub fn verify(&self, vocabulary: &Vocabulary) -> Result<VerifyReport>
pub fn verify(&self, vocabulary: &Vocabulary) -> Result<VerifyReport>
Run the vocabulary’s embedded test vectors: each input must encode to the recorded ids and decode back to the input.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Engine
impl !UnwindSafe for Engine
impl Forget for Engine
impl Freeze for Engine
impl Move for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more