pub struct MaskGenerator { /* private fields */ }Expand description
Generates logit masks from TØR-G builder state.
This struct combines a token mapping with a vocabulary size to
produce LogitMask instances from Builder::valid_next_tokens().
Implementations§
Source§impl MaskGenerator
impl MaskGenerator
Sourcepub fn new(mapping: TokenMapping, vocab_size: usize) -> Self
pub fn new(mapping: TokenMapping, vocab_size: usize) -> Self
Create a new mask generator.
§Arguments
mapping- Token mapping from TØR-G tokens to LLM vocab IDsvocab_size- Size of the LLM vocabulary
Sourcepub fn mapping(&self) -> &TokenMapping
pub fn mapping(&self) -> &TokenMapping
Get the token mapping.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get the vocabulary size.
Sourcepub fn generate(&self, valid_tokens: &[Token]) -> LogitMask
pub fn generate(&self, valid_tokens: &[Token]) -> LogitMask
Generate a logit mask from a list of valid tokens.
Tokens that cannot be mapped are silently ignored.
Sourcepub fn generate_from_builder(&self, builder: &Builder) -> LogitMask
pub fn generate_from_builder(&self, builder: &Builder) -> LogitMask
Generate a logit mask from builder state.
This is a convenience method that calls builder.valid_next_tokens()
and then generates the mask.
Trait Implementations§
Source§impl Clone for MaskGenerator
impl Clone for MaskGenerator
Source§fn clone(&self) -> MaskGenerator
fn clone(&self) -> MaskGenerator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MaskGenerator
impl RefUnwindSafe for MaskGenerator
impl Send for MaskGenerator
impl Sync for MaskGenerator
impl Unpin for MaskGenerator
impl UnwindSafe for MaskGenerator
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
Mutably borrows from an owned value. Read more