Fit a probability
A Bernoulli variable is one with probability and zero with probability Suppose we observe ones in independent trials with the same unknown The likelihood of a particular ordered observation is It is a function of with the data held fixed. If we only observe the count, the binomial factor multiplies the likelihood and leaves its maximiser unchanged.
For the log-likelihood is Setting its derivative to zero gives The second derivative is negative on If all trials agree, the maximum occurs at or
A fixed prompt is sampled independently ten times and the first token is seven times. The maximum-likelihood estimate of the probability of is
Measure on fresh examples
When training a model, use training data for fitting, validation data for selecting models or settings, and held-out test data for the final evaluation. For tasks with near duplicates or many items from the same source, split by source, such as document or user. Otherwise, the reported performance may reflect memorisation of related items. If the test result is used to select another model, an independently held-out set is needed for the same kind of final comparison.
Let be independent scores from the same population, with variance The mean has variance Replacing by the sample standard deviation using denominator in gives the estimated standard error The formula does not account for correlation between tokens in the same document. For document-level evaluation, use independently sampled documents as the units and define explicitly whether the score weights documents or tokens equally.
For four independent document scores, print the mean and the estimated standard error. Four observations demonstrate the arithmetic and provide limited evidence about the population.
from math import sqrt
from statistics import mean, stdev
scores = [0.6, 0.8, 1.0, 0.8]
print(f"{mean(scores):.3f}")
print(f"{stdev(scores) / sqrt(len(scores)):.3f}")0.800
0.082Exercises
Find the Bernoulli maximum-likelihood estimate for two successes in eight independent trials.
Show solution✓ Checked
The estimate is
If the population standard deviation is find the standard deviation of the mean for 9 and 36 independent observations.
Show solution✓ Checked
Divide by The two values are and
Twelve documents each supply four paragraphs. Set aside four whole documents for test and two whole documents for validation. How many paragraphs remain for training?
Show solution✓ Checked
Six documents remain for training, so there are paragraphs. Keep all paragraphs from each document in the same split.