pub struct Sampler { /* private fields */ }Implementations§
Source§impl Sampler
impl Sampler
pub fn new(vocab_size: usize, temperature: f32, topp: f32) -> Self
pub fn sample<S: StorageMut<f32, Dyn>>( &mut self, logits: &mut Vector<f32, Dyn, S>, ) -> usize
pub fn sample_argmax<S: StorageMut<f32, Dyn>>( probabilities: &Vector<f32, Dyn, S>, ) -> usize
Sourcepub fn sample_mult<S: StorageMut<f32, Dyn>>(
probabilities: &Vector<f32, Dyn, S>,
coin: f32,
) -> usize
pub fn sample_mult<S: StorageMut<f32, Dyn>>( probabilities: &Vector<f32, Dyn, S>, coin: f32, ) -> usize
Sample index from probabilities.
The probabilities must sum to 1.0.
coin is a random number in [0, 1).
Sourcepub fn sample_topp<S: StorageMut<f32, Dyn>>(
&mut self,
probabilities: &Vector<f32, Dyn, S>,
coin: f32,
) -> usize
pub fn sample_topp<S: StorageMut<f32, Dyn>>( &mut self, probabilities: &Vector<f32, Dyn, S>, coin: f32, ) -> usize
Top-p sampling (or “nucleus sampling”) samples from the smallest set of tokens that exceed probability topp.
This way we never sample token that have very low probabilities and are less likely to go “off the rails”. Coin is a random number in [0, 1).
Auto Trait Implementations§
impl Freeze for Sampler
impl RefUnwindSafe for Sampler
impl Send for Sampler
impl Sync for Sampler
impl Unpin for Sampler
impl UnwindSafe for Sampler
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, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.