silvertext.
All posts
Gloved hands feed printed manuscript strips through a sheet scanner in a document-analysis room with blue-lit equipment.

Engineeringengineering6 min read

N-grams in Similarity Checking: Comparing Overlapping Word Sequences

How n-gram shingles turn text into comparable sequences, why length changes matching behavior, and why overlap needs human review.

SESilvertext EngineeringNovember 8, 2026
0 to 1Jaccard resemblance range 1Set resemblance runs from no shared shingles to identical shingle sets.
$t=k+w-1$Winnowing threshold relation 2A fingerprinting guarantee parameter, not a plagiarism threshold.
5 tokensWorked-example shingle lengthillustrative
1 of 6Worked-example 4-gram resemblanceillustrative

1. Background

Similarity checking asks a limited question: does a draft share enough sequence-level wording with an available text to warrant inspection? It does not answer whether the overlap is plagiarism. A shared passage may be a marked quotation, a bibliography entry, required institutional language, a routine technical phrase, or unattributed reuse. Token overlap cannot determine authorship, permission, chronology, or policy compliance.

An n-gram is a contiguous sequence of nn tokens. In this note, tokens are normalized words or terms. These overlapping sequences are often called shingles. For a method compares overlapping word sequences, the 3-grams are a method compares, method compares overlapping, compares overlapping word, and overlapping word sequences.

Broder defined document resemblance as the Jaccard similarity of shingle sets.1 This representation measures shared distinct sequences, not the intent or meaning of their reuse. Preprocessing choices matter before any comparison: information-retrieval systems commonly tokenize and normalize text, and those operations change the terms that are available for retrieval.3

2. Method

Let T(D)T(D) be the normalized token sequence for document DD. The shingle set Sn(D)S_n(D) contains each contiguous sequence of nn tokens in T(D)T(D). For documents AA and BB, set-based resemblance is:

Sn(D)={(ti,ti+1,…,ti+n−1):1≤i≤∣T(D)∣−n+1}Rn(A,B)=∣Sn(A)∩Sn(B)∣∣Sn(A)∪Sn(B)∣S_n(D)=\{(t_i,t_{i+1},\ldots,t_{i+n-1}) : 1 \leq i \leq |T(D)|-n+1\} R_n(A,B)=\frac{|S_n(A)\cap S_n(B)|}{|S_n(A)\cup S_n(B)|}

RnR_n is zero when the sets share no shingles and one when they are identical. It is a result about this representation. A set collapses repeated wording, so one occurrence of a shingle counts the same as ten. A multiset score or positional alignment measures something else, and may be more useful when a report needs to show repeated passages.

Consider these illustrative normalized passages:

  • A: compare overlapping word sequences before review
  • B: compare overlapping word sequences during human review

The first four tokens match, but the fifth does not. The resulting counts show why nn is a consequential configuration choice.

| Shingle length | ∣Sn(A)∣|S_n(A)| | ∣Sn(B)∣|S_n(B)| | Shared shingles | Rn(A,B)R_n(A,B) | |---|---:|---:|---:|---:| | 4 | 3 | 4 | 1 | See pricing | | 5 | 2 | 3 | 0 | 0 |

Illustrative calculation from the two constructed passages above. At n=4n=4, the shared shingle is compare overlapping word sequences.

Reducing nn recovers more wording after a local edit, but ordinary language will also produce more weak matches. Increasing nn makes a hit more specific, but a small insertion, deletion, or substitution can break a longer sequence. There is no universally correct nn. It should be selected and evaluated for the corpus, language, and reviewer workflow.

Two printed excerpts beneath a copy stand, with corresponding passages marked by coloured transparent strips.
Figure 1. Matched spans should remain attached to surrounding text so a reviewer can inspect meaning and attribution.

At collection scale, comparing every shingle from every document pair is costly. Broder describes representative fingerprints and min-wise independent permutations for estimating resemblance without retaining every comparison.1 Winnowing selects fingerprints from windows of ww consecutive kk-grams. Its detection guarantee concerns matching substrings at the combined threshold t=k+w−1t=k+w-1.2 These techniques reduce candidate-search work. They do not add meaning to a matched passage.

3. Results

The constructed example produces one shared 4-gram and no shared 5-gram. That is not a benchmark result. It demonstrates a behavior that an implementation can test: a four-token common run survives when n=4n=4 and disappears when n=5n=5.

Comparison setting Matching behavior Review consequence
Small $n$, such as 1 or 2 Matches common vocabulary and short phrases Requires close contextual review
Middle $n$, selected for a corpus Finds contiguous reuse with more specificity Can help locate candidate spans
Large $n$ Requires longer unchanged wording Misses interrupted or lightly edited reuse
Fingerprinted shingles Stores or compares selected candidates Must preserve enough evidence to reconstruct spans

A document-level percentage alone hides structure. The same resemblance value can result from one long shared passage, many dispersed stock phrases, a shared bibliography, or repeated template language. A review interface should therefore show matched text, source location when available, shingle length, and preprocessing policy. Those details let a reviewer distinguish a coherent passage from routine vocabulary.

4. Interpretation

For similarity checking, n-grams are most useful as an evidence pipeline:

  1. Use shingles to retrieve candidate overlaps.
  2. Join adjacent or nearby hits into readable passages.
  3. Show both passages with enough surrounding context.
  4. Review attribution, quotation, common language, permission, and the policy that applies.

The indexed corpus bounds the result. A system cannot find a match in material it did not index, could not access, or could not extract into usable text. A found match establishes only that two available texts share selected token sequences after configured preprocessing.

For writers checking their own draft, the next step is to read each substantial highlighted span in context. Confirm that quotations are marked, paraphrases are genuinely in your own wording, citations support the claim being made, and template language is necessary. Silvertext’s features can organize that review, but a person must interpret the evidence.

5. Limitations

N-grams are literal. They are weak when the same idea is expressed with different wording, sentence order changes, text is translated, or a source is substantially paraphrased. They also depend on tokenization. For example, state-of-the-art may be one token or several; names, formulas, code, URLs, and citations need policy decisions appropriate to the document type.3

Set resemblance ignores frequency and position. A high score does not establish which text came first, whether either passage is original, or whether reuse is acceptable. A low score does not establish independence.

Fingerprinting adds another trade-off. It makes candidate retrieval practical for large collections, but selected fingerprints are a compact proxy for the full shingle set.2 Implementations should test known, permissioned material with controlled edits, preserve inspectable spans, and avoid presenting a score as a verdict. The output is evidence for review.

References

  1. 1. Andrei Z. Broder. 1997. On the Resemblance and Containment of Documents. Proceedings of the Compression and Complexity of Sequences 1997, pages 21-29. IEEE Computer Society. https://doi.org/10.1109/SEQUEN.1997.666900 https://doi.org/10.1109/SEQUEN.1997.666900
  2. 2. Saul Schleimer, Daniel S. Wilkerson, and Alex Aiken. 2003. Winnowing: Local Algorithms for Document Fingerprinting. Proceedings of the 2003 ACM SIGMOD International Conference on Management of Data, pages 76-85. ACM. https://doi.org/10.1145/872757.872770 https://doi.org/10.1145/872757.872770
  3. 3. Christopher D. Manning, Prabhakar Raghavan, and Hinrich Schütze. 2008. Introduction to Information Retrieval. Cambridge University Press. https://nlp.stanford.edu/IR-book/ https://nlp.stanford.edu/IR-book/