N-Grams

The words immediately before a position give us clues about what might come next. An n-gram model uses counts of short sequences to make that prediction, with adjustments for sequences missing from its training data.

15 sections · 15 questions · 3 coding challenges

1 / 15

Could a Short Memory Capture Some of a Language's Structure?

BOTIE

Counting single words tells us that they are common, but not which ones tend to occur together. A short phrase can carry information that disappears when its words are considered separately. We need some memory of neighbouring items without storing every possible sentence.

Shannon's 1948 communication paper illustrated increasingly structured approximations to English by incorporating dependencies between successive symbols and words. Short-context models offered a manageable way to represent some of the order in language.

An n-gram is a consecutive group of a chosen length. Counting these groups preserves local order, whether the units are characters or words. The representation remains limited by its window: distant relationships fall outside it, and longer groups quickly become rare. This explains both the usefulness of short recurring phrases and the need to handle sequences that were absent from training.

Sources for this history