LanguageModelMetrics<T>
Helpers & Utilities · AiDotNet.Metrics
Static helpers for evaluating language-model / classification predictions over a vocabulary: perplexity (how surprised the model is by the true tokens) and top-k accuracy (how often the true token is among the model’s k most likely guesses).
For Beginners
A language model outputs, for each position, a score for every word in its vocabulary. Two standard ways to grade those outputs:
How It Works
These live next to the other AiDotNet.Metrics helpers and are the standard signals
for gating a language-model training run (e.g. “abort if perplexity stops falling”).
Methods
| Method | Summary |
|---|---|
T CrossEntropy(Tensor<T> predictions, int[] targets, bool fromLogits) |
Computes the mean cross-entropy (average negative log-likelihood, in nats) of the true tokens. |
T Perplexity(Tensor<T> predictions, int[] targets, bool fromLogits) |
Computes perplexity = exp(mean negative-log-likelihood) of the true tokens under the model’s predicted distributions. |
T TopKAccuracy(Tensor<T> predictions, int[] targets, int k) |
Computes top-k accuracy: the fraction of positions whose true token is among the model’s k highest-scoring vocabulary entries. |