pub struct GreedyTokenizer<TransTable: TransitionTable, TokenIDType: Clone + Default + PartialEq, SAMRef: Deref<Target = GeneralSAM<TransTable>>> { /* 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<TransTable: TransitionTable, SAMRef: Deref<Target = GeneralSAM<TransTable>>> GreedyTokenizer<TransTable, TrieNodeID, SAMRef>

source

pub fn build_from_trie<TT: TransitionTable<KeyType = TransTable::KeyType>>( sam: SAMRef, trie_state: TrieState<TT, &Trie<TT>> ) -> Self

Available on crate feature trie only.
source§

impl<TransTable: TransitionTable> GreedyTokenizer<TransTable, TrieNodeID, OwnedGeneralSAM<TransTable>>

source

pub fn build_from_sam_and_trie<TT: TransitionTable<KeyType = TransTable::KeyType>>( sam: GeneralSAM<TransTable>, trie_state: TrieState<TT, &Trie<TT>> ) -> Self

Available on crate feature trie only.
source§

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

source

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

source§

impl<TransTable: TransitionTable, TokenIDType: Clone + Default + PartialEq, SAMRef: Deref<Target = GeneralSAM<TransTable>>> GreedyTokenizer<TransTable, TokenIDType, SAMRef>

source

pub fn get_sam_ref(&self) -> &GeneralSAM<TransTable>

source

pub fn inner_as_ref( &self ) -> GreedyTokenizer<TransTable, TokenIDType, &GeneralSAM<TransTable>>

source

pub fn build<TN: TrieNodeAlike<InnerType = TransTable::KeyType>, F: FnMut(&TN) -> TokenIDType>( sam: SAMRef, 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<TransTable: Clone + TransitionTable, TokenIDType: Clone + Clone + Default + PartialEq, SAMRef: Clone + Deref<Target = GeneralSAM<TransTable>>> Clone for GreedyTokenizer<TransTable, TokenIDType, SAMRef>

source§

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

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<TransTable: Debug + TransitionTable, TokenIDType: Debug + Clone + Default + PartialEq, SAMRef: Debug + Deref<Target = GeneralSAM<TransTable>>> Debug for GreedyTokenizer<TransTable, TokenIDType, SAMRef>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TransTable, TokenIDType, SAMRef> RefUnwindSafe for GreedyTokenizer<TransTable, TokenIDType, SAMRef>where SAMRef: RefUnwindSafe, TokenIDType: RefUnwindSafe,

§

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

§

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

§

impl<TransTable, TokenIDType, SAMRef> Unpin for GreedyTokenizer<TransTable, TokenIDType, SAMRef>where SAMRef: Unpin,

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V