N-gram generator

You can use this page to generate n-grams for your texts. This site was made by Alex Reuneker. For a little demonstration and how to, see https://youtu.be/4aRD_NwuHW4. For questions, see contact details at http://www.reuneker.nl. If you use this site for your research, please cite it as follows.

Reuneker, A. (2019). N-gram generator. Retrieved ..., from https://www.reuneker.nl/files/ngram.


Steps

  1. Copy a text (from a website, a book, a larger corpus, et cetera).
  2. Paste the text into the input area below. You don't have to remove weird characters, tags, white spaces and new lines — the script does it for you.
  3. Set 'ngram' to the desired number of words or leave at 2 (bigrams) and set the number of results wanted (or leave at 50). If you're going to sort on probablity (see 'explanation'), it can be useful to set a minimal frequency for the n-grams included in the list.
  4. Click 'Generate ngrams' and wait a bit.

Input and settings

Choose preferred settings, or leave at default.

N-gram: Top: Sort: Minimal frequency:

Paste a text to analyze below.



Results

Results will be presented here after you clicked 'generate n-grams'...

About

The ngram function used was written using Vanilla Javascript, and your text is not uploaded to any server. Your computer itself does all the work. Small texts are processed very quickly. Longer texts take a bit longer, although getting all bigrams from the King James Bible (4.2MB; almost 800.000 words) took my laptop three seconds with multiple tabs and other applications open.

Update: Added feature to export results to CSV. (2022-08-31)
Update: Added feature to exclude words before processing text. (2022-08-31)
Update: Fixed newline problem resulting in n+1-grams. (2021-01-17)
Update: Added strength measure. (2019-12-11)
Update: Added conditional probabilities. (2019-12-10)

Short explanation

An n-gram is just a sequence of n words. So, 'cat' is a unigram, 'my cat' is a bi-gram, and 'my sleepy cat' is a tri-gram. There's more interesting things to know about n-grams. For a short explanation of frequencies, probabilities and my (rather unusual) 'strength' measure, click here.