Measure Text Similarity Between Documents
How to compare document similarity: what word-level diffs, overlap scores and semantic methods measure, what normalization changes, and when to read plain text.
Measuring how similar two documents are means splitting both texts into comparable units, such as characters, words or meaning vectors, and then scoring or listing what overlaps. The result depends on which units you choose and on how the text is cleaned up first. That cleanup is itself a transformation, and it can make two documents look more alike, or less alike, than a careful reader would judge them.
Is a similarity measure right for your purpose?
Use a word-level diff when you need to know what changed between two revisions of the same document, such as contract drafts, policy updates or edited articles. Use an overlap score or a vector-based score when you need one number to rank, group or triage many document pairs, such as finding near-duplicates in a large collection.
The deciding tradeoff is that a score summarizes and a diff explains. A single number does not show where two texts differ or whether the difference matters. Adding the word "not" to a sentence barely changes a word-overlap score, yet it reverses the meaning. Compare the plain text directly, side by side or with a diff that a person reviews, when the documents are short, when someone must approve the exact wording, or when small changes carry legal, medical or financial weight.
What a comparison actually changes
A comparison does not alter the stored documents. Most tools, however, normalize working copies before scoring them. Common steps include converting text to lowercase, collapsing whitespace, removing punctuation, splitting text into words, and sometimes removing common words or reducing words to their stems. Each step removes differences that the tool treats as noise. If capitalization or punctuation matters for your use, such as defined terms in a contract, check whether the tool removes it.
- Character-level comparison: matches individual characters, so it catches typos and spacing changes but produces noisy output for reworded sentences.
- Word-level comparison: matches whole words in order, which suits revision review because it reports insertions, deletions and substitutions in units people read.
- Order-insensitive overlap: treats each document as a set or count of words and ignores sequence, so rearranged text can still score as highly similar.
- Semantic comparison: maps text to numeric representations produced by a language model, so paraphrases can score as similar even when they share few words.
Here is a small worked example of how the unit and method shape the result. It uses two one-sentence inputs.
A: the cat sat on the mat
B: the cat sat on a mat
Word-level diff: the cat sat on [-the-] {+a+} mat
Unique words in A: the, cat, sat, on, mat (5)
Unique words in B: the, cat, sat, on, a, mat (6)
Shared: the, cat, sat, on, mat (5)
Jaccard overlap: 5 shared / 6 in union ≈ 0.83
The diff reports one substitution in six words. The set-based Jaccard score is about 0.83 for two reasons: it counts "the" only once even though A uses it twice, and it ignores word order. Neither result tells you whether "the mat" and "a mat" mean something different in context. That judgment is left to the reader.
Unicode styling, reversed text and display order
Some text that looks identical is stored differently, and comparisons work on stored characters, not on appearance. Three cases cause most confusion.
Styled "font" text from generators replaces ordinary letters with different Unicode characters, such as mathematical bold or script letters. It is not formatting. A comparison treats these as different characters from plain letters. Unicode compatibility normalization (NFKC) maps many of these characters back to ordinary letters, but not every tool applies it. CSS styling such as bold or italics, by contrast, changes only how text is displayed. The extracted text stays the same, so it does not affect comparison.
Accented letters can be stored as one precomposed character or as a base letter followed by a combining mark. The two forms look the same on screen but differ character by character unless both texts are normalized to the same form, usually NFC. The same issue affects reversed text. Reversing a string character by character can separate a combining mark from its letter or break apart emoji built from several code points. A reversed document also shares almost no words, in order, with the original. Mirrored text that only looks flipped through visual effects leaves the stored characters unchanged.
Right-to-left scripts are stored in logical reading order and arranged for display by the bidirectional algorithm. Comparisons use the logical order. Text copied from a rendered page or a PDF may not always preserve that order, so confirm the extracted text before trusting a score involving mixed-direction content.
Will the results stay readable after copying or sharing?
Diff output often relies on colored highlighting, which is lost when it is pasted into plain-text destinations such as many ticketing systems, terminals or plain-text email. Text markers survive copying. Examples include leading plus and minus signs, bracketed insert and delete labels, or a written list of changes. If the diff will be shared, export or copy a version that carries those markers.
Color alone should not be the only way changes are shown. Accessibility guidance such as WCAG's use-of-color criterion makes this point, because some readers cannot tell the highlight colors apart. HTML diffs may mark changes with insertion and deletion elements, but screen readers do not announce these consistently. Test with the assistive technology your readers actually use rather than assuming one successful rendering holds everywhere. Provide a plain-text summary of the changes whenever the diff goes into a record, an approval workflow or a message to people whose setup you do not control.
A similarity score shared without context is easy to misread. Report the method, the unit of comparison and the normalization steps along with the number. Scores from different methods, or from the same method with different preprocessing, are not comparable.
Choosing between comparison methods
The table below describes how each method is built to work. It is not a measured head-to-head test. No tools were run on equivalent inputs for this article, so any differences in speed, accuracy or output quality between specific products are untested.
| Method | Unit | Respects word order | Best fit | Main limitation |
| Character diff | Characters | Yes | Typos, code, short strings | Noisy on reworded prose |
| Word-level diff | Words | Yes | Reviewing revisions of one document | Gives no single score; rewrites appear as large deletions plus insertions |
| Jaccard overlap | Unique words | No | Quick near-duplicate screening | Ignores repetition and order |
| Cosine on term counts or TF-IDF | Weighted word counts | No | Ranking similarity across many documents | Misses paraphrase; depends on preprocessing |
| Embedding-based similarity | Model-generated vectors | Partly, depending on model | Detecting paraphrase and topical similarity | Opaque; results vary by model and may underweight small meaning changes such as negation |
Three criteria usually decide the choice. If exact wording matters, use a word-level diff and read it. If you need to match reworded content, a semantic method is the only one in the table designed for it, but you should spot-check its high scores by reading the pairs. If you are screening a large collection, use a set-based or count-based score to shortlist candidates and then diff the shortlisted pairs. Many workflows combine methods for this reason.
Gaps to keep in mind
This article has no tested benchmarks, product measurements or validated similarity thresholds, and no universal cutoff applies across methods or document types. To set a threshold, score some pairs from your own documents that you already know are duplicates, revisions or unrelated texts, and see where the scores fall. Before pasting confidential documents into an online comparison tool, read its documented data-handling terms. A tool's appearance or marketing language is not evidence of how it stores or retains text.
- Decide whether you need to see the changes (diff) or rank many pairs (score).
- Check which normalization steps the tool applies and whether any of them remove differences that matter to you.
- Normalize Unicode consistently, NFC for accents or NFKC for styled lookalike letters, when sources may differ.
- Share diffs with text markers and a plain-text summary, not color alone.
- Report the method and preprocessing alongside any score.
- Read the actual text wherever a small change could alter meaning.