pub struct Logits {
pub values: Vec<f32>,
}Expand description
A vector of raw unnormalized model logits.
Fields§
§values: Vec<f32>Implementations§
Source§impl Logits
impl Logits
Sourcepub fn new(values: Vec<f32>) -> Logits
pub fn new(values: Vec<f32>) -> Logits
Creates a new Logits instance from a raw vector of floats.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Number of vocabulary items.
Sourcepub fn apply_temperature(&mut self, temperature: f32) -> Result<(), CoreError>
pub fn apply_temperature(&mut self, temperature: f32) -> Result<(), CoreError>
Scales the logits by a positive temperature parameter.
Sourcepub fn apply_top_k(&mut self, k: usize)
pub fn apply_top_k(&mut self, k: usize)
Filters logits to keep only the top-K highest scoring tokens. All other positions are set to -INFINITY.
Sourcepub fn apply_top_p(&mut self, top_p: f32) -> Result<(), CoreError>
pub fn apply_top_p(&mut self, top_p: f32) -> Result<(), CoreError>
Filters logits using nucleus (top-p) sampling. Keeps the smallest set of tokens whose cumulative probability is >= top_p.
Sourcepub fn apply_min_p(&mut self, min_p: f32) -> Result<(), CoreError>
pub fn apply_min_p(&mut self, min_p: f32) -> Result<(), CoreError>
Filters logits using min-p sampling. Retains tokens with probability >= min_p * max_probability.
Sourcepub fn apply_repetition_penalty(
&mut self,
context_tokens: &[u32],
penalty: f32,
) -> Result<(), CoreError>
pub fn apply_repetition_penalty( &mut self, context_tokens: &[u32], penalty: f32, ) -> Result<(), CoreError>
Applies repetition penalty to tokens that have already been generated in the context.
Sourcepub fn apply_presence_and_frequency_penalties(
&mut self,
context_tokens: &[u32],
presence_penalty: f32,
frequency_penalty: f32,
)
pub fn apply_presence_and_frequency_penalties( &mut self, context_tokens: &[u32], presence_penalty: f32, frequency_penalty: f32, )
Applies presence and frequency penalties (OpenAI style).
Sourcepub fn softmax(&self) -> Result<Vec<f32>, CoreError>
pub fn softmax(&self) -> Result<Vec<f32>, CoreError>
Computes numerically stable softmax probabilities.
Sourcepub fn sample<R>(&self, temperature: f32, rng: &mut R) -> Result<u32, CoreError>where
R: Rng,
pub fn sample<R>(&self, temperature: f32, rng: &mut R) -> Result<u32, CoreError>where
R: Rng,
Samples a token from the distribution using standard inverse transform sampling.
Sourcepub fn sample_with_params<R>(
&self,
params: &SamplingParams,
context_tokens: &[u32],
rng: &mut R,
) -> Result<u32, CoreError>where
R: Rng,
pub fn sample_with_params<R>(
&self,
params: &SamplingParams,
context_tokens: &[u32],
rng: &mut R,
) -> Result<u32, CoreError>where
R: Rng,
Samples a token using full sampling parameters (temperature, top_k, top_p, penalties).