N-Gram Generator

Turn text into unigrams, bigrams, trigrams or any N-grams - instantly.

Online N-Gram Generator

Split your text into word or letter N-grams of size 1 to 10.

Load an example

Summary
0 Characters
0 Without spaces
0 Words
Statistics
0 Words
0 N-grams generated
0 Unique n-grams
Gram Size
Pick a preset size or choose N-gram and enter a value between 1 and 10.
Settings
Build grams from words or from single letters.
Replaces spaces in the output. Letters mode only.

Placed between the words inside each gram.
Placed after every gram in the list.

In corpus mode the last word of a sentence joins with the first word of the next. Bigrams and larger only.

Counts mode lists each gram once with how often it appears.
Frequency sort groups repeated grams together.
Hide grams that appear fewer times. Counts mode only.

Convert every gram to lowercase.
Deletes the punctuation symbols listed here.
Symbols deleted when Remove punctuation is on. Apostrophes are kept so words like don't stay whole.
Enter some text to generate n-grams.


Overview

The N-Gram Generator is a free online tool that breaks any text into its n-grams - single units (unigrams), pairs (bigrams), triples (trigrams) or a custom run of up to ten units. Choose whether a unit is a whole word or a single letter, and the list appears instantly as you type.

N-grams are the building blocks behind search engines, autocomplete and language models, so this tool is handy for SEO keyphrase research, linguistics study, text analysis homework and preparing language-model training data - all entirely in your browser.


What this Tool Does

An n-gram is a short sequence of consecutive units taken from text, and each name tells you its length. A unigram is a single unit on its own - one word such as rain, or one letter such as r. A bigram joins two neighbouring units into one pair, so in "heavy rain" the words form a single bigram. A trigram links three units in a row, turning "in heavy rain" into one trigram. Beyond that you simply pick your own N with the N-gram option.

To generate them, the tool slides a window N units wide across your text one unit at a time and records every window it sees. With List every gram you get the full sequence in reading order; with Unique grams with counts you get each distinct gram once together with the number of times it occurs. The statistics panel under the output shows the total units processed, how many grams were produced, and how many of them are unique.


Features and Settings

Gram size: Pick Unigrams, Bigrams or Trigrams, or choose N-gram and enter any N between 1 and 10. For example, the sentence "The cat sat on the mat." produces the unigrams the, cat, sat, on, the, mat, the bigrams the cat, cat sat, sat on, on the, the mat and the trigrams the cat sat, cat sat on, sat on the, on the mat.

Units - Words / Letters: Word mode treats each word as one unit. Letters mode makes every character a unit and replaces spaces with your space symbol, so "Hi there." becomes the units h, i, _, t, h, e, r, e and the bigrams hi, i_, _t, th, he, er, re.

Sentence handling: Sentences are detected from full stops, question marks, exclamation marks and line breaks. By default the tool stops at each sentence, so the last word of one sentence never pairs with the first word of the next. In corpus mode sentences are joined: "I like rain. Rain is good." gains the cross-boundary bigrams rain rain and is good alongside the normal ones.

Separators: The inside-gram separator joins words within a gram (space by default, or underscore, hyphen, comma or pipe), and the between-grams separator separates grams from each other (new line by default).

Unique grams with counts: Switching the output style to counts turns "The cat sat on the mat. The cat was happy." into the cat: 2, cat sat: 1, .... Combine it with Min occurrences set to 2 to keep only the cat: 2, and with Sort order: Most frequent first to bring repeated phrases to the top - ideal for finding the phrases an article repeats most.

Lowercase & punctuation: Lowercase output normalises "The" and "the" into the same gram. Remove punctuation deletes the symbols listed in the punctuation box before the grams are built, while apostrophes are always kept so contractions like isn't stay whole.

Copy & Download: Copy the results to your clipboard or download them as a ngrams.txt file with one click. You can also load a .txt or .csv file instead of pasting.


How to Use this Tool?

Step 1 - Enter your text: Type or paste your text into the left-hand box, or click Upload a file to load a .txt or .csv file. You can also press Load an example to insert some sample sentences. The Summary panel under the input counts your characters (with and without spaces) and words as you type.

Step 2 - Choose a gram size: In the Gram Size section pick Unigrams, Bigrams or Trigrams, or select N-gram and type any value from 1 to 10 into the field that appears next to it. Bigrams are pre-selected, so pairs appear straight away.

Step 3 - Adjust the settings (optional): Under Settings choose whether the units are Words or Letters, set the inside-gram and between-grams separators, and decide whether grams stop at each sentence or treat the text as one corpus. Then pick an output style: list every gram in order, or show unique grams with counts together with a sort order and a minimum occurrence filter. Turn on Lowercase output to merge "The" and "the", and edit the punctuation symbols that should be stripped before counting.

Step 4 - Read the results: The output updates automatically on the right as you type or change any setting; you can also press Generate N-grams to recalculate. The statistics panel under it shows how many units were processed and how many grams were generated in total and uniquely - the labels follow your chosen size (unigrams, bigrams, trigrams).

Step 5 - Save or start over: Use the Copy link under the output to copy the results to your clipboard, or Download to save them as a ngrams.txt file. Use Clear input under the input box to empty just the text, or the red Clear button for a fresh start.


FAQs

FAQ 1: What is the difference between unigrams, bigrams and trigrams?
Answer: They differ only in window size: a unigram is a single unit ("rain"), a bigram is two consecutive units ("heavy rain") and a trigram is three ("in heavy rain"). Bigger windows capture more context but appear fewer times in a text.

FAQ 2: How does the custom N-gram option work?
Answer: Select the N-gram radio option in the Gram Size section and enter any value between 1 and 10 in the field that appears. The tool then generates grams of exactly that many words or letters.

FAQ 3: Why does "the cat" appear twice in my bigram list?
Answer: In List every gram mode the output follows your text exactly, so repeated phrases repeat. Switch the output style to Unique grams with counts to see each phrase once with its occurrence count.

FAQ 4: What is corpus mode for?
Answer: Corpus mode ignores sentence boundaries and threads the whole text together, which mirrors how language models read a training corpus. Stop-at-sentence keeps phrases within their own sentence, which is usually better for SEO and readability analysis.

FAQ 5: Can I use it on languages other than English?
Answer: Yes. Splitting is based on spaces and characters, not English grammar, so accented and non-Latin text works. Punctuation removal uses the editable symbol list, and the lowercase option applies to letters of any alphabet.

FAQ 6: Is my text saved or uploaded anywhere?
Answer: No. All processing happens in your browser. We do not store or transmit the text you enter.

TextToolz

The Ultimate Text Tools

TextToolz works seamlessly to let you convert and design your text. It is fast, reliable and secure. Trusted by thousands of users.