Generate N-gram

Build overlapping word or character windows of length 1 through 5 and rank repeated windows by count.

freeworks offlinenothing uploaded
ToolN-gram Generator
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Word mode slides across whitespace tokens, while character mode collapses whitespace runs and advances through UTF-16 substring positions. Two-token word windows, case folding, and a 50-row display are the defaults, and every percentage uses the total number of overlapping windows.

  • Overlapping means a six-word sentence contains five bigrams rather than three disjoint pairs.
  • Punctuation stays attached in word mode because only whitespace creates token boundaries.

Worked example

Generate word bigrams
Create word-level bigrams from a sentence
Input
											the cat sat on the mat
										
Output
												Ngram    Count  Percentage
-------  -----  ----------
the cat  1      20
cat sat  1      20
sat on   1      20
on the   1      20
the mat  1      20
											

When to use this

Corpus lessons count common bigrams, language-model demonstrations construct trigram tables, and typo investigations compare character trigrams from product names.

Edge cases

  • A five-token window over four words yields zero rows because no padding or wraparound is invented.
  • hello and hello, form different word-window components due to the attached comma.
  • Character windows can split 😀 between its two UTF-16 surrogate units instead of treating the emoji as one grapheme.