pub struct TextGenerator {
pub config: GenerationConfig,
}Expand description
Text generator for language models.
Fields§
§config: GenerationConfigGeneration configuration
Implementations§
Source§impl TextGenerator
impl TextGenerator
Sourcepub fn new(config: GenerationConfig) -> Self
pub fn new(config: GenerationConfig) -> Self
Creates a new text generator.
Sourcepub fn apply_temperature(&self, logits: &mut [f32])
pub fn apply_temperature(&self, logits: &mut [f32])
Applies temperature scaling to logits.
Sourcepub fn apply_repetition_penalty(
&self,
logits: &mut [f32],
generated_tokens: &[u32],
)
pub fn apply_repetition_penalty( &self, logits: &mut [f32], generated_tokens: &[u32], )
Applies repetition penalty to logits.
Sourcepub fn apply_top_k(&self, logits: &mut [f32])
pub fn apply_top_k(&self, logits: &mut [f32])
Applies top-k filtering to logits.
Sourcepub fn apply_top_p(&self, logits: &mut [f32])
pub fn apply_top_p(&self, logits: &mut [f32])
Applies top-p (nucleus) filtering to logits.
Sourcepub fn get_next_token(&self, logits: &[f32], generated_tokens: &[u32]) -> u32
pub fn get_next_token(&self, logits: &[f32], generated_tokens: &[u32]) -> u32
Processes logits and returns next token.
Sourcepub fn should_stop(&self, token: u32) -> bool
pub fn should_stop(&self, token: u32) -> bool
Checks if generation should stop.
Auto Trait Implementations§
impl Freeze for TextGenerator
impl RefUnwindSafe for TextGenerator
impl Send for TextGenerator
impl Sync for TextGenerator
impl Unpin for TextGenerator
impl UnwindSafe for TextGenerator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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