pub struct TemperatureSampler {
pub temperature: f64,
/* private fields */
}Expand description
Samples from a softmax distribution after dividing logits by temperature.
temperature > 1.0: flatter distribution (more randomness).temperature < 1.0: sharper distribution (more peaked).temperature = 1.0: unmodified softmax.
Fields§
§temperature: f64The temperature value used to scale logits.
Implementations§
Source§impl TemperatureSampler
impl TemperatureSampler
Sourcepub fn new(temperature: f64, seed: u64) -> Result<Self, SamplingError>
pub fn new(temperature: f64, seed: u64) -> Result<Self, SamplingError>
Construct a TemperatureSampler.
Returns Err(SamplingError::InvalidTemperature) if 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.
Sourcepub fn sample_batch(
&mut self,
logits: &[Vec<f64>],
) -> Result<Vec<SampledToken>, SamplingError>
pub fn sample_batch( &mut self, logits: &[Vec<f64>], ) -> Result<Vec<SampledToken>, SamplingError>
Sample one token for each row in a batch.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TemperatureSampler
impl RefUnwindSafe for TemperatureSampler
impl Send for TemperatureSampler
impl Sync for TemperatureSampler
impl Unpin for TemperatureSampler
impl UnsafeUnpin for TemperatureSampler
impl UnwindSafe for TemperatureSampler
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