N-Gram Analyzer
Count bigrams and trigrams with PMI collocation scoring, sortable and exportable.
Corpus
N-grams
No n-grams yet
Paste a corpus or load an example.
N-Gram Analyzer tokenizes a corpus, builds sliding windows for selected sizes from 2 to 5, and counts every n-gram. Alongside raw counts it computes frequency and pointwise mutual information (PMI), a collocation score that shows which word combinations occur more often than chance. Case folding, stopword removal, sentence boundaries, minimum counts, term filters and add-0.25 smoothing are all controllable, and results export as CSV.
Examples
Repeated pair
cat dog cat dog cat dogcat dog — count 3, freq 60%Three of the five bigram windows are the same pair.
No cross-sentence windows
One two. Three four.one two · three fourThe pair two three is not emitted because a sentence boundary separates them.
Stopword removal
the cat and the dog with stopwords removedcat and · and dog · dog withRemoving the and with-type stopwords changes which sequences can be counted.
PMI sorting
the cat sat on the mat the dog sat on the rugsat on ranks above the cat by PMIPMI favors distinctive combinations rather than the most frequent function words.
About this tool
N-Gram Analyzer explores repeated word sequences in pasted text. It extracts bigrams, trigrams and custom sizes from 2 to 5, counts occurrences, and shows each n-gram's share of all windows of that size. Sliding windows never cross sentence boundaries unless you turn that guard off.
The headline metric is pointwise mutual information (PMI): log2 of the observed n-gram probability divided by the product of its individual token probabilities. High PMI means the words co-occur more often than chance, which is useful for finding collocations that raw frequency counts hide behind common stopwords. An optional add-0.25 smoothing variant tames zero-count cases.
Case folding, stopword removal, minimum token length, minimum count, term filters and sort order are all adjustable. Results display up to 200 rows with the full set available as CSV. Analysis runs locally in the browser; the corpus is never uploaded.
What this tool does not do
- Input is capped at 5 MB and the on-screen table displays at most 200 rows; export CSV for the full result.
- PMI is computed for a single document, so there is no document-frequency measure.
- Tokenization is Unicode-aware but does not perform language-specific word segmentation for CJK text.
- Stopword removal uses a small built-in English list and cannot be extended in the browser UI.
- N-gram sizes are limited to 2 through 5 to bound the number of generated windows.
How to use this tool
Paste a corpus
A few paragraphs are enough to explore; load an example if you want a quick demonstration.
Choose sizes
Toggle 2-gram, 3-gram, 4-gram or 5-gram. Multiple sizes can be analyzed at once.
Tune tokenization
Use case fold, stopwords and sentence-boundary controls to match your research question.
Sort and export
Sort by count, PMI or length, filter by term, then copy or download the CSV.
Use cases
Linguistic research
Find collocations and phrase patterns in a small corpus without installing statistical software.
SEO phrase research
Inspect which multi-word phrases repeat in competitor copy.
Quality checks
Spot accidentally repeated phrases in drafts and generated text.
Teaching statistics
Show the difference between raw frequency and association measures such as PMI.
Columns and metrics
| Column | Meaning |
|---|---|
| N-gram | Tokens joined with spaces |
| n | Number of tokens in the window |
| Count | Occurrences in the corpus |
| Freq % | Count divided by all windows of that size |
| PMI | log2( p(ngram) / product of p(token) ) |
| Add-0.25 smoothing | Adds a quarter count to numerator and denominators before scoring |
PMI can be negative when words occur less often together than chance would predict.
Common mistakes
Mistake:Expecting PMI to rank the most frequent phrases first.
Fix:PMI measures surprise, not frequency. Sort by count when you want raw repetition.
Mistake:Running n-grams across sentence boundaries.
Fix:Leave Respect sentences on unless you intentionally want cross-sentence windows.
Mistake:Forgetting that stopword removal changes n-gram counts.
Fix:Compare both settings; common pairs like of the dominate counts when stopwords stay.
Mistake:Drawing conclusions from a tiny corpus.
Fix:The tool warns below ten tokens; add more text before interpreting PMI.
Mistake:Assuming CJK text is split into words.
Fix:The Unicode tokenizer groups runs of CJK letters as one token; use a dedicated segmenter for CJK word analysis.
Frequently asked questions
What is PMI and why use it?
Pointwise mutual information compares how often words appear together with how often they would appear together by chance. A high PMI marks a distinctive collocation, while a low or negative score means the combination is unremarkable. The formula is shown on the results panel.
How are words tokenized?
Text is lowercased when case folding is on, then split on non-letter and non-digit characters. Apostrophes inside words are kept, so don't remains one token. CJK runs without spaces are treated as a single token because the tokenizer does not do word segmentation.
Can I exclude stopwords from n-grams?
Yes. Turn on Remove stopwords to drop a built-in list of common English function words before windows are built. This changes both counts and PMI, so compare both settings for your analysis.
Do n-grams cross sentence boundaries?
Not by default. The tokenizer splits on . ! and ? so a window never spans two sentences. Turn off Respect sentences if you want a continuous stream of tokens.
What corpus size works?
A few paragraphs are enough to see patterns; thousands of words give more stable PMI. Below ten tokens the tool warns that counts are not statistically meaningful. Input is capped at 5 MB.
Does my text leave the browser?
No. Tokenization, counting, PMI scoring and CSV export all happen locally. Nothing is uploaded or persisted.
References & standards
Related tools
Anagram Solver & Palindrome
Normalize text for palindrome checks and privacy-preserving anagram analysis.
Binary Text Translator
Convert text to binary or hex bytes and decode it back
Braille Translator
Translate text to Unicode Braille and back with UEB Grade 1 letters, numbers, punctuation and a per-cell dot breakdown.
Caesar Cipher Tool
Encrypt, decrypt and brute-force Caesar shifts with English-frequency ranking and a one-click ROT13 shortcut.
Case Converter & Text Formatter
Convert text between 14 different case formats including camelCase, snake_case, kebab-case with batch processing and advanced options
Character Frequency Analyzer
Count character, letter and word frequencies for text analysis