pub struct TopKSampler {
pub k: usize,
pub temperature: f64,
/* private fields */
}Expand description
Zeroes out all logits except the top-k, then applies temperature sampling.
Fields§
§k: usizeNumber of top tokens to keep.
temperature: f64Temperature applied after the top-k filter.
Implementations§
Source§impl TopKSampler
impl TopKSampler
Sourcepub fn new(k: usize, temperature: f64, seed: u64) -> Result<Self, SamplingError>
pub fn new(k: usize, temperature: f64, seed: u64) -> Result<Self, SamplingError>
Construct a TopKSampler.
Fails if k == 0 or temperature <= 0.0.
Sourcepub fn sample(&mut self, logits: &[f64]) -> Result<SampledToken, SamplingError>
pub fn sample(&mut self, logits: &[f64]) -> Result<SampledToken, SamplingError>
Sample one token from logits using the top-k filter.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TopKSampler
impl RefUnwindSafe for TopKSampler
impl Send for TopKSampler
impl Sync for TopKSampler
impl Unpin for TopKSampler
impl UnsafeUnpin for TopKSampler
impl UnwindSafe for TopKSampler
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> 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