Skip to content
BENIBIX Learn

N-gram

Also known as Bigram, Trigram, N-gram Model

A run of n words in a row, like 'green tea' for n = 2.

Think of it like

Think of it like you look at a line of words through a small hole. Then you slide it along.

Example

From 'I love green tea', the bigrams are 'I love', 'love green' and 'green tea'. A trigram model would see 'love green' and guess 'tea'.

Why it matters

N-grams are the simplest way to see how a computer can guess words from counts alone.

Definition

An n-gram is a run of n words that sit side by side in a piece of text. A bigram is two words, like 'green tea', and a trigram is three. An n-gram model counts how often each run shows up in a corpus. Then it guesses the next word from the last few words alone. These were the main language models before neural networks, and they are still used for quick tasks like spotting phrases.
The same sentence read one word at a time, in pairs, and in threes. Each window is an n-gram.

Common mistake

Thinking a bigger n is always better. Long runs are rare, so most of them never show up in the corpus at all.

Key takeaways

  1. 1
    n words in a row. Two is a bigram, three a trigram.
  2. 2
    Counted in a corpus. How often each run appears.
  3. 3
    Short memory. Only the last few words count.