pub trait Model {
// Required methods
fn tokenize(&self, sequence: &str) -> Result<Vec<Token>>;
fn token_to_id(&self, token: &str) -> Option<u32>;
fn id_to_token(&self, id: u32) -> Option<String>;
fn vocab(&self) -> HashMap<String, u32>;
fn vocab_size(&self) -> usize;
}Expand description
Maps a piece of text to tokens.
Required Methods§
Sourcefn tokenize(&self, sequence: &str) -> Result<Vec<Token>>
fn tokenize(&self, sequence: &str) -> Result<Vec<Token>>
Tokenize sequence. Token offsets are byte offsets into
sequence.
Sourcefn token_to_id(&self, token: &str) -> Option<u32>
fn token_to_id(&self, token: &str) -> Option<u32>
Id of token, if it is in the vocabulary.
Sourcefn id_to_token(&self, id: u32) -> Option<String>
fn id_to_token(&self, id: u32) -> Option<String>
Token for id, if it is in the vocabulary.
Sourcefn vocab_size(&self) -> usize
fn vocab_size(&self) -> usize
Vocabulary size.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".