Skip to content

Witten–Bell

WittenBell · discounting · estimates the unseen mass from the number of types

Witten–Bell smoothing (Witten & Bell, 1991) reserves mass for unseen elements in proportion to how often a new element has been observed: each of the \(V\) distinct elements was new once, out of \(N + V\) events of "seeing an element" or "seeing a new element". It has no parameters beyond the support size.

Definition

\[ P(w) = \frac{c(w)}{N + V}, \qquad p_0 = \frac{V}{N + V}, \qquad P(\text{unseen}) = \frac{p_0}{B - V}, \]

where \(B\) = bins. With the default (bins unset, or equal to \(V\)), the whole reserved mass goes to a single unseen bin, so every unseen element scores \(p_0\).

Example

With the example counts, \(V = 10\) and \(N = 30\):

>>> import freqprob
>>> counts = dict(the=10, cat=5, sat=4, on=3, mat=2, a=2, dog=1, ran=1, far=1, away=1)
>>> wb = freqprob.WittenBell(counts, bins=100, logprob=False)
>>> [round(wb(w), 4) for w in ("the", "dog", "zebra")]
[0.25, 0.025, 0.0028]

The observed words keep \(30/40\) of the mass, and the 90 unseen words share the remaining \(10/40\).

Properties

  • Parameter-free and assumption-light. It needs no fit, so it works where Simple Good–Turing's assumptions fail.
  • Discounts all observed elements by the same factor, \(N/(N + V)\), unlike Good–Turing, which discounts rare elements more.
  • Reserves more mass when the vocabulary grows quickly: a sample in which most observations are new types predicts more new types.
  • Pass bins to share the unseen mass among the possible elements; see Pitfalls.

API

freqprob.WittenBell

WittenBell(freqdist: FrequencyDistribution, bins: int | None = None, logprob: bool = True)

Bases: ScoringMethod

Witten-Bell smoothing.

Reserves probability mass for unseen elements based on how many distinct types were observed, treating each new type as evidence that more unseen types exist. The reserved mass is T / (N + T), where T is the number of observed types and N the total number of observations; the remaining mass is discounted proportionally so all estimates sum to one:

  • p = T / (Z * (N + T)) for an unobserved element, and
  • p = c / (N + T) for an element observed c times.

Useful as a lightweight discounting method when a simple, parameter-free way to handle unseen elements is needed.

Parameters:

Name Type Description Default
freqdist FrequencyDistribution

Mapping of elements to observed counts.

required
bins int | None

Optional total number of possible sample bins for the experiment. If None (the default), it defaults to the number of observed types, so the full reserved mass is assigned to a single unseen bin.

None
logprob bool

Return log-probabilities if True (the default), otherwise plain probabilities. Counts are corrected to avoid domain errors when taking logarithms.

True

Examples:

Observed elements are scored by relative frequency over N + T, and unseen elements share the reserved mass:

>>> from freqprob import WittenBell
>>> freqdist = {"the": 100, "a": 50, "cat": 3, "dog": 2, "rare": 1}
>>> wb = WittenBell(freqdist, logprob=False)
>>> round(wb("the"), 3)
0.621
>>> round(wb("rare"), 3)
0.006
>>> round(wb("unicorn"), 3)  # unobserved
0.031

Initialize Witten-Bell smoothing.

References