liveBook · Manning

Bigram

As explained in Grokking AI Algorithms, Second Edition

A bigram is a sequence of two adjacent words or tokens used to model the likelihood of one following the other.

A bigram is a pair of adjacent words or tokens. In language prediction, it estimates how likely one item is to follow another by counting each previous–next pairing and dividing by all occurrences of the previous item. section 11.2 section 11.9

Bigrams support two closely related tasks:

  • Next-word prediction: use pairs such as “Alice was” or “White Rabbit” to build a probability table for autocomplete-style completions. section 11.2
  • Tokenization: count neighboring character or subword tokens, then merge the most frequent pair repeatedly as part of byte-pair encoding (BPE). section 11.9

Predicting the next word

Across five sample sentences, “Alice” is followed by “was” twice and “and” once. The model therefore assigns probabilities of 0.67 and 0.33, making “Alice was” the more likely completion. Likewise, “the” leads to “White” twice and “Rabbit” once. section 11.2

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Calculates probabilities with tables, then traces repeated frequency counting and pair merging; it stops short of deeper language-model theory.
Examples
Uses Alice and White Rabbit sentences, autocomplete predictions, character-token tables, and successive BPE merges.
What it assumes
Builds from familiar sentence patterns and introduces word, character, and subword tokens without requiring advanced mathematical background.
What you can do after
Evaluate/understand next-word probabilities and trace how frequent token pairs become merged vocabulary items.
How it connects
Connects bigrams to language models, tokenization, byte-pair encoding, autocomplete, and conditional probability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.