Realm

oa::ml::metric::Perplexity

Additive token-NLL moments behind perplexity. Perplexity is exp(sum(nll × tokens) / sum(tokens)) with the exponential applied only at observation time. Batches contribute their token-weighted mean negative log-likelihood — exactly what cross_entropy_masked returns when its valid_count is the token denominator — so partitioned language evaluation merges exactly. The contract forbids the mean of per-batch perplexities, which is not the corpus perplexity. Empty denominators report NaN.

StRust public API

Declaration

pub struct Perplexity { /* private fields */ }
Public Rust declaration.

Public Methods

pub fn update(&mut self, mean_nll: f64, token_count: u64) -> Result<()>
pub fn update_device( &mut self, mean_nll: &Matrix, token_count: u64, ) -> Result<()>
pub fn merge(&mut self, other: &Self)
pub fn result(&self) -> f64
pub fn mean_nll(&self) -> f64
pub const fn tokens(&self) -> f64
pub fn reset(&mut self)
fn clone(&self) -> Perplexity
fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn eq(&self, other: &Perplexity) -> bool

Associated Functions

pub fn new() -> Self
fn default() -> Perplexity

Public Method Documentation

pub fn update(&mut self, mean_nll: f64, token_count: u64) -> Result<()>
No public source comment is attached to this declaration.
pub fn update_device( &mut self, mean_nll: &Matrix, token_count: u64, ) -> Result<()>
No public source comment is attached to this declaration.
pub fn merge( &mut self, other: &Self )
No public source comment is attached to this declaration.
pub fn result( &self ) -> f64
No public source comment is attached to this declaration.
pub fn mean_nll( &self ) -> f64
No public source comment is attached to this declaration.
pub const fn tokens( &self ) -> f64
No public source comment is attached to this declaration.
pub fn reset( &mut self )
No public source comment is attached to this declaration.
fn clone( &self ) -> Perplexity
No public source comment is attached to this declaration.
fn fmt( &self, f: &mut Formatter<'_> ) -> Result
No public source comment is attached to this declaration.
fn eq( &self, other: &Perplexity ) -> bool
No public source comment is attached to this declaration.
pub fn new() -> Self
No public source comment is attached to this declaration.
fn default() -> Perplexity
No public source comment is attached to this declaration.