N-grams

N-grams are contiguous sequences of n items, usually words or characters, in a text or speech sample. In Intro to Cognitive Science, they show how language models capture local word order and pattern frequency.

Last updated July 2026

What are n-grams?

In Intro to Cognitive Science, n-grams are a way to break language into short, ordered chunks so a computer can measure patterns in speech or text. A unigram is one item, a bigram is two items, a trigram is three, and the pattern keeps going as n grows.

The big idea is that language is not just a bag of words. Order matters. The phrase “dog bites man” means something very different from “man bites dog,” and n-grams capture that difference by counting sequences instead of isolated words.

A simple example is the sentence “the cat sat on the mat.” Its bigrams include “the cat,” “cat sat,” “sat on,” “on the,” and “the mat.” Those chunks give a model local context, which is useful for predicting the next word, spotting common phrases, or estimating how likely a sentence is.

In cognitive science, n-grams connect language to computation. They are a basic language modeling tool because they approximate how the mind or a machine might use recent context to make predictions. They do not “understand” meaning the way people do, but they can still capture useful regularities in word sequence.

That also explains the main limit: as n gets bigger, the model gets sparse. There are many possible word combinations, so long n-grams appear rarely and become harder to count reliably. Shorter n-grams are easier to estimate, while longer ones give more context but need much more data.

N-grams are not limited to whole words. They can also be built from characters or subwords, which matters when the language has many spelling variations, rare words, or different writing systems. That flexibility makes them a common first step in language analysis before more advanced neural models take over.

Why n-grams matter in Intro to Cognitive Science

N-grams show one of the main ways cognitive science connects language to information processing. If you are studying how computers handle language, n-grams are a clean example of turning messy human speech into counts, probabilities, and patterns.

They also help explain why some language tasks are easier than they look. A machine does not need full human-like understanding to predict a likely next word or recognize a common phrase. It can use local sequence frequency, which is exactly what n-grams measure.

That makes them useful in topics like language modeling, machine translation, and sentiment analysis. A translation system can compare likely phrase sequences, while a sentiment tool can notice whether “not good” appears more often than the separate words might suggest.

For Intro to Cognitive Science, n-grams are a bridge concept. They connect linguistics, computer science, and theories of cognition by showing how much can be done with pattern statistics alone, and where that approach starts to break down.

Keep studying Intro to Cognitive Science Unit 8

How n-grams connect across the course

Tokenization

Tokenization is the step that usually comes before n-grams. You first split text into units, like words or characters, and then build sequences from those units. If tokenization is inconsistent, the n-grams you get will change too, which can affect a model’s counts and predictions.

Language Model

N-grams are one of the simplest kinds of language model. They estimate the chance of a word or phrase based on the recent sequence before it, which is why they work well for prediction tasks. More advanced language models still build on the same idea of using context to predict what comes next.

Bag-of-Words

Bag-of-Words ignores word order, while n-grams keep local order. That difference matters when phrase structure changes meaning, like in negation or fixed expressions. If you need sequence information, n-grams give you more than a bag-of-words approach does.

Machine Translation

Machine translation uses n-grams to estimate which word sequences sound natural in the target language. Even when a system is not translating word-for-word, it still relies on common phrase patterns to choose better output. N-gram statistics help it avoid awkward or unlikely phrasing.

Are n-grams on the Intro to Cognitive Science exam?

A quiz question might give you a short sentence and ask you to identify its bigrams or explain why n-grams are better than single-word counts for language prediction. In a short answer, you may need to trace how a model uses previous words to estimate the next one, or explain why a longer n-gram can capture more context but also becomes sparse. For an essay prompt on NLP, use n-grams as an example of a statistical method that works with local sequence patterns rather than full semantic understanding. If the course includes a lab or problem set, you might compare unigram, bigram, and trigram outputs and describe how the counts change when tokenization or punctuation changes the text.

N-grams vs Bag-of-Words

Bag-of-Words counts words without caring about order, while n-grams preserve short sequences. That means n-grams can capture phrase structure, common collocations, and some effects of negation. If the sequence matters, n-grams give you more information.

Key things to remember about n-grams

  • N-grams are contiguous sequences of n items, usually words or characters, taken from text or speech.

  • A unigram uses one item, a bigram uses two, and a trigram uses three, so bigger n means more context.

  • In Intro to Cognitive Science, n-grams are a basic way to model language statistically instead of relying on full human-like understanding.

  • They are useful for prediction, translation, and text analysis, but they get sparse as n gets larger.

  • N-grams keep local word order, which makes them more informative than bag-of-words when phrasing changes meaning.

Frequently asked questions about n-grams

What is n-grams in Intro to Cognitive Science?

N-grams are ordered chunks of text or speech made of n consecutive items. In Intro to Cognitive Science, they are used to study how language can be modeled with patterns, counts, and probabilities. They show up most often in NLP topics like prediction and machine translation.

What is the difference between unigrams, bigrams, and trigrams?

A unigram is one item, a bigram is two adjacent items, and a trigram is three adjacent items. The bigger the n, the more local context you keep. The tradeoff is that larger n-grams are harder to estimate because they appear less often.

How are n-grams different from bag-of-words?

Bag-of-Words counts words without caring about order, while n-grams preserve short sequences. That means n-grams can capture phrase structure, common collocations, and some effects of negation. If the sequence matters, n-grams give you more information.

Why do n-grams become less useful when n gets too large?

As n increases, the number of possible sequences grows quickly, but each exact sequence appears less often in real data. That creates sparsity, which makes counts less reliable and models harder to compute. Shorter n-grams are simpler, but they also give less context.