Shingling is the process of breaking a document into a set of contiguous subsequences of tokens, known as w-shingles, where w defines the window size. By converting text into overlapping n-gram sequences and applying a hashing function, the technique generates a compact digital fingerprint that represents the document's syntactic structure, enabling efficient large-scale duplicate and near-duplicate detection.
Glossary
Shingling

What is Shingling?
Shingling is a foundational technique in information retrieval that converts a document into a set of contiguous token subsequences, or 'shingles,' which are then hashed into compact fingerprints for efficient similarity comparison.
The resulting set of hashed shingles is often compressed using techniques like minhashing and stored in a locality-sensitive hash index for rapid retrieval. The Jaccard index is then computed between document sets to estimate similarity, allowing search engines and content platforms to identify plagiarized or redundant content without performing costly pairwise string comparisons.
Key Characteristics of Shingling
Shingling transforms documents into sets of contiguous token subsequences (shingles) for efficient hashing and near-duplicate detection. These core properties define its behavior and performance trade-offs.
Contiguous Token Windows
Shingling extracts overlapping sequences of k consecutive tokens from a document. For the phrase 'the quick brown fox', 3-shingles are: ['the quick brown', 'quick brown fox']. This contiguity preserves local word order, making it more robust than bag-of-words models for detecting paraphrased or slightly reordered content. The window slides one token at a time, ensuring comprehensive coverage of all possible subsequences.
Hashing to Fixed-Size Fingerprints
Each shingle is passed through a hash function (e.g., MD5, SHA-1) to produce a fixed-size integer fingerprint. This achieves two goals: dimensionality reduction—a document is represented as a compact set of integers rather than variable-length strings—and uniform distribution across the hash space. The set of hashed shingles becomes the document's sketch, enabling constant-time lookups and set-based comparisons.
Jaccard Similarity Computation
Near-duplicate detection relies on the Jaccard Index: the size of the intersection of two shingle sets divided by the size of their union. A score of 0.85+ typically indicates near-duplicate content.
- Formula:
J(A,B) = |A ∩ B| / |A ∪ B| - Example: If doc A has 100 shingles and doc B shares 92, Jaccard = 0.92
- Threshold tuning: Lower thresholds catch more paraphrases; higher thresholds reduce false positives
Locality-Sensitive Hashing (MinHash)
Pairwise Jaccard computation across millions of documents is computationally prohibitive. MinHash compresses shingle sets into compact signatures of n hash values, where the probability of signature collision equals the Jaccard similarity. Documents are then bucketed using LSH bands, ensuring only candidate pairs within the same bucket are compared exhaustively. This reduces complexity from O(N²) to near-linear.
Parameter Sensitivity: k-Shingle Size
The choice of k (shingle width in tokens) critically impacts detection granularity:
- k=1 (unigrams): Degrades to bag-of-words; loses all word order. High recall, low precision.
- k=3–5: Standard for web documents. Captures short phrases while tolerating minor edits.
- k=8–10: Used for code clone detection or highly structured text. High precision, low recall.
Larger k values increase specificity but miss smaller reused fragments.
Preprocessing and Normalization
Raw text must be normalized before shingling to prevent superficial differences from breaking matches:
- Case folding: Convert all tokens to lowercase
- Punctuation stripping: Remove or normalize punctuation marks
- Stop word handling: Optionally remove high-frequency function words to focus on content-bearing terms
- Stemming/Lemmatization: Reduce words to root forms (e.g., 'running' → 'run')
- Unicode normalization: Apply NFC or NFD to standardize character encodings
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, technical answers to the most common questions about shingling, w-shingling, and its role in near-duplicate detection and document fingerprinting.
Shingling is the algorithmic process of decomposing a document into a set of contiguous subsequences of tokens, known as shingles or n-grams. The process works by sliding a fixed-size window across the tokenized text, extracting every possible sequence of w consecutive tokens. For example, the phrase "the quick brown fox" with a shingle width of 3 yields the set: {"the quick brown", "quick brown fox"}. Each shingle is then typically hashed into a compact integer fingerprint using a hash function like Rabin's fingerprinting or MD5, transforming the document into a set of integers. This set representation enables efficient set-based similarity calculations, such as the Jaccard index, to quantify the overlap between two documents. Shingling is foundational to large-scale duplicate and near-duplicate detection systems, as it captures local word ordering while being robust to minor edits, rephrasing, and sentence reordering.
Related Terms
Shingling is a foundational step in a larger pipeline of algorithms and data structures designed to efficiently identify and manage duplicate or near-duplicate content at scale.
Jaccard Index
The primary statistical measure used to compare two shingled documents. It calculates the similarity between two sets by dividing the size of their intersection by the size of their union. In the context of shingling, a high Jaccard Index indicates a significant overlap of contiguous token subsequences, flagging the documents as near-duplicates.
- Formula: J(A, B) = |A ∩ B| / |A ∪ B|
- Scale: 0 (no overlap) to 1 (identical sets)
Simhash Fingerprinting
A locality-sensitive hashing (LSH) technique that generates a compact, fixed-size fingerprint for a document. Unlike standard hashing, similar documents produce hashes with a small Hamming distance. This allows for efficient near-duplicate detection by comparing fingerprints rather than raw shingle sets, dramatically reducing computational complexity.
- Key Property: Inputs with small differences yield outputs with small differences.
- Use Case: Google's original crawler used Simhash for web-scale deduplication.
MinHash & LSH
An optimization technique used when the set of shingles is too large to compare directly. MinHash compresses large sets into compact signatures while preserving the Jaccard similarity between them. Locality-Sensitive Hashing (LSH) then buckets these signatures so that only candidates within the same bucket are compared, avoiding an O(n²) pairwise comparison.
- Function: Reduces dimensionality while preserving similarity.
- Benefit: Enables sub-linear query time for nearest neighbor search.
Cosine Similarity
A metric that measures the cosine of the angle between two non-zero vectors in a multi-dimensional space. When shingles are vectorized using techniques like TF-IDF, cosine similarity quantifies semantic closeness. A score of 1 indicates identical orientation (and thus high similarity), while 0 indicates orthogonality.
- Contrast: Unlike the Jaccard Index, which operates on discrete sets, cosine similarity operates on continuous vector representations.
- Range: -1 to 1 (typically 0 to 1 for text frequency vectors).
TF-IDF Vectorization
A numerical statistic that reflects the importance of a token to a document within a corpus. Before shingles are hashed or compared, Term Frequency-Inverse Document Frequency (TF-IDF) weighting can be applied to give higher weight to rare, discriminative shingles and lower weight to common ones.
- TF: How often a shingle appears in a document.
- IDF: How rare the shingle is across all documents.
- Effect: Prevents common stop-word shingles from dominating similarity scores.
Bloom Filter
A space-efficient probabilistic data structure used to test whether a shingle is a member of a set. It allows for rapid, memory-efficient duplicate detection with a controllable false positive rate, but guarantees no false negatives. This is useful for quickly discarding documents that definitely do not share shingles with a target set.
- Guarantee: 100% recall (no false negatives).
- Trade-off: Accepts a configurable rate of false positives to save memory.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us