Inferensys

Glossary

Shingling

Shingling is the process of decomposing a document into a set of overlapping, contiguous subsequences of tokens (words or characters), which are then hashed to create compact fingerprints for scalable duplicate and near-duplicate content detection.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
NEAR-DUPLICATE DETECTION

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.

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.

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.

FINGERPRINTING FUNDAMENTALS

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.

01

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.

02

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.

03

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
04

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.

05

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.

06

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
SHINGLING EXPLAINED

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.

Prasad Kumkar

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.