Skip to content

NLP (Concepts & Pipeline)

N-gram (Unigram, Bigram, Trigram)

In shortA contiguous sequence of n words or characters from a text: unigrams (1), bigrams (2), trigrams (3) and so on, used to find recurring patterns.

Updated 24 Oct 2026· 2 min read

An n-gram is a sequence of n consecutive items taken from text, where the items are usually words and sometimes characters. One word is a unigram, two are a bigram and three a trigram. Counting n-grams across a keyword list or set of pages is one of the simplest ways to see which phrases and patterns keep coming up.

How it works

You slide a window of n items across the text. The query “how to fix iphone camera” gives the word bigrams “how to”, “to fix”, “fix iphone” and “iphone camera”, and the trigrams “how to fix”, “to fix iphone” and “fix iphone camera”. Character n-grams work the same way on letters: “shoes” gives the character trigrams “sho”, “hoe” and “oes”.

Most text tools let you choose the range. scikit-learn’s CountVectorizer takes an ngram_range setting, and KeyBERT’s keyphrase_ngram_range controls whether it extracts single words, pairs or longer phrases.

How it’s used in SEO and marketing

  • Modifier mining. Count the most frequent bigrams and trigrams in your keyword universe to find modifiers such as “how to fix”, “best … for” or “near me”.
  • Micro-intents. Combine n-grams with extracted entities to reverse-engineer how people phrase specific needs.
  • Content gaps. Compare n-grams on the ranking pages with those on your page.
  • Keyphrase extraction. Use KeyBERT with a bigram range to label keyword clusters with two-word phrases.
  • Fuzzy matching. Character trigrams with TF-IDF make string matching tolerant of typos, and are the default model in PolyFuzz.

Example

MLforSEO’s query sequence guide combines entity extraction with n-gram analysis. Suppose your entities include iPhone, Samsung Galaxy and camera, and the common trigrams in your keyword set include “how to fix”, “best tutorial for” and “review of”. Putting them together reveals real query constructions such as “how to fix iPhone camera” and “review of iPhone camera features”, which become sections or pages in your plan.

Limitations and things to watch

  • Frequency is not meaning: a common n-gram may be filler, so remove stop words thoughtfully (keep “how to” if you care about questions).
  • Larger n means sparser counts; most long n-grams appear only once.
  • N-grams only see neighbouring words, so relationships across a sentence are missed.
  • Inflected languages need lemmatisation first, or variants of the same word split the counts.

Learn it on MLforSEO

Where N-gram (Unigram, Bigram, Trigram) shows up on MLforSEO

Sources and further reading

Other terms from NLP (Concepts & Pipeline)

See all 17 NLP (Concepts & Pipeline) terms →