pub struct GreedyTokenizer<'s, TransTable: TransitionTable, TokenIDType: Clone + Default + PartialEq> { /* private fields */ }
Available on crate feature utils only.
Expand description

Greedy tokenizer with a general suffix automaton of the vocabulary.

Assuming that the input length is $n$, the maximum word length is $l$, and querying transitions in the trie takes $\mathcal{O}\left(\log{\Sigma}\right)$ time, then the overall time complexity of this implementation is $\mathcal{O}\left( n \cdot \left( \log{l} + \log{\Sigma} \right) \right)$.

The main optimization is to store suffix-wise information with persistent ropes. For each suffix in a state of the suffix automaton, the longest word matching the prefix of the suffix is stored in the rope. And the information stored in a state will be further merged in the ropes of its successors.

Implementations§

source§

impl<'s, TransTable: TransitionTable> GreedyTokenizer<'s, TransTable, TrieNodeID>

source

pub fn build_from_trie<'t, TT: TransitionTable<KeyType = TransTable::KeyType>>( sam: &'s GeneralSAM<TransTable>, trie_state: TrieState<'t, TT> ) -> Self

Available on crate feature trie only.
source§

impl<'s, TransTable: TransitionTable, TokenIDType: Clone + Default + PartialEq> GreedyTokenizer<'s, TransTable, TokenIDType>

source

pub fn build<TN: TrieNodeAlike<InnerType = TransTable::KeyType>, F: FnMut(&TN) -> TokenIDType>( sam: &'s GeneralSAM<TransTable>, trie_node: TN, f: F ) -> Self

source

pub fn tokenize<Iter: Iterator<Item = TransTable::KeyType>>( &self, iter: Iter, unk_token_id: &TokenIDType ) -> Vec<(TokenIDType, usize)>

Trait Implementations§

source§

impl<'s, TransTable: Clone + TransitionTable, TokenIDType: Clone + Clone + Default + PartialEq> Clone for GreedyTokenizer<'s, TransTable, TokenIDType>

source§

fn clone(&self) -> GreedyTokenizer<'s, TransTable, TokenIDType>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'s, TransTable: Debug + TransitionTable, TokenIDType: Debug + Clone + Default + PartialEq> Debug for GreedyTokenizer<'s, TransTable, TokenIDType>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'s, TransTable, TokenIDType> RefUnwindSafe for GreedyTokenizer<'s, TransTable, TokenIDType>
where TokenIDType: RefUnwindSafe, TransTable: RefUnwindSafe,

§

impl<'s, TransTable, TokenIDType> Send for GreedyTokenizer<'s, TransTable, TokenIDType>
where TokenIDType: Send + Sync, TransTable: Sync,

§

impl<'s, TransTable, TokenIDType> Sync for GreedyTokenizer<'s, TransTable, TokenIDType>
where TokenIDType: Send + Sync, TransTable: Sync,

§

impl<'s, TransTable, TokenIDType> Unpin for GreedyTokenizer<'s, TransTable, TokenIDType>

§

impl<'s, TransTable, TokenIDType> UnwindSafe for GreedyTokenizer<'s, TransTable, TokenIDType>
where TokenIDType: RefUnwindSafe, TransTable: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V