Skip to main content

softmax

Function softmax 

Source
pub fn softmax(logprobs: &[f64], temperature: f64) -> Vec<f64>
Expand description

Softmax over logprobs, with temperature scaling applied first.

Scaling before the exponential is plain temperature scaling: T = 1 reproduces the model’s own distribution, T > 1 flattens it. Small instruct-tuned models answer clear cases at a probability of 1.0000, so flattening is usually what a caller wants — but it is their call, which is why the raw logprobs travel back in every answer.

Subtracting the maximum before exponentiating keeps the sum finite for the very negative logprobs a truncated distribution produces (values around -25 are routine).