Compare Document Similarity

How to compare document similarity across paragraph revisions: what diffs and similarity scores measure, how to choose a method, and where results can mislead.

When you compare two versions of a document, the tool does not compare what you see. It compares stored characters, words or lines, sometimes after normalizing them first. That difference explains most surprising results: revisions that look identical but register as changed, and rewrites that score as nearly identical even though the meaning changed. This guide covers what a similarity comparison measures, how to choose a method for paragraph revisions, and how to check that the result is usable.

What a similarity comparison actually measures

A comparison takes two texts and either reports the differences (a diff) or condenses them into a single similarity score. In both cases the input is the underlying character sequence, not the rendered page. Fonts, colors, spacing and visual effects matter only if the tool reads formatting data as well as text. A plain-text comparison ignores them entirely.

Several kinds of text transformation look alike on screen but are stored very differently. These distinctions decide whether two passages count as matching:

  • Character-order reversal rewrites the stored sequence, so "budget" becomes "tegdub". A comparison treats the reversed word as a different string.
  • Visual mirroring through CSS or another display transform flips how text is drawn without changing the stored characters. A plain-text comparison of the source sees no change.
  • Unicode character substitution, often sold as fancy fonts or styled text, replaces ordinary letters with separate code points such as mathematical bold letters. A styled "𝐁𝐮𝐝𝐠𝐞𝐭" can look like "Budget" in bold, but every character differs unless the tool applies compatibility normalization.
  • CSS presentation such as bold, italics or capitalization applied through styles changes appearance only. If the stored text is lowercase and a style displays it in capitals, a text comparison sees lowercase.
  • Bidirectional display controls, such as right-to-left override characters, can make the displayed order differ from the stored order. Two passages can look the same on screen while their stored sequences differ, or look different while their stored characters match.

Invisible differences follow the same rule. Zero-width spaces, non-breaking spaces, curly versus straight quotation marks, and different line-ending conventions all show up as changes in a strict comparison, even when nobody edited the wording. When a diff flags a line that looks untouched, check for one of these first.

Labels such as "mirror text" or "font generator" do not tell you which of these mechanisms a tool uses. To find out, paste the output into a plain-text editor or inspect its code points. Do not assume from the name.

Choosing a comparison method for paragraph revisions

Comparison methods differ in the unit they compare and in what they treat as a change. Because each method answers a different question, choose based on what you need to learn about the revision.

Method | What it compares | Best for | Main tradeoff
Character-level diff | Individual characters | Catching typos, punctuation and spacing edits | Noisy on rewritten paragraphs; small edits fragment into many marks
Word-level diff | Words or tokens in order | Reviewing editorial changes to prose | Moved sentences appear as a deletion plus an insertion
Line- or paragraph-level diff | Whole lines or paragraphs | Spotting which paragraphs changed in long documents | Changing one word marks the whole paragraph as changed
Sequence similarity score | Ordered matching runs of characters or words | A quick sense of how much a draft changed | A single number hides where the changes are and whether they matter
Word-overlap (set-based) score | Shared vocabulary, ignoring order | Detecting reuse or near-duplicate passages | Ignores order, so reordered or contradictory text can score high
Semantic similarity | Meaning estimated by a language model | Judging whether a paraphrase preserves intent | Not transparent; results depend on the model and are hard to audit

The two pairs below are illustrative, not output from any particular tool. They show how methods diverge on the same input.

Pair A — Original: "The committee approved the budget on Friday." Revision: "On Friday, the committee approved the budget."

Pair A keeps the meaning and the vocabulary and changes only the order. Ignoring case and punctuation, a word-overlap score treats the two as having the same words. A word-level diff typically shows "On Friday" deleted at the end and inserted at the start. A character-level diff produces many small marks. A semantic comparison would likely rate the two as equivalent.

Pair B — Original: "The committee approved the budget." Revision: "The committee did not approve the budget."

Pair B shares almost all of its wording but reverses the meaning. Overlap and sequence scores stay high because only a few words changed. A word-level diff shows exactly where the change happened, which matters more here than any score. No lexical score reliably catches a reversal of meaning, so treat high similarity as "few words changed," not "same meaning."

In practice, use a word-level diff to review edits to prose, a paragraph-level view to navigate long documents, and a score only as a summary next to the diff. If you need to confirm that a paraphrase preserves intent, a semantic comparison can help, but a person should still review the flagged passages.

Normalization: deciding what counts as a change

Many comparison workflows let you normalize text before comparing. Each option removes a category of differences, so pick only the ones that are noise for your purpose:

  • Case folding: ignore capitalization changes. Useful for content review; wrong if capitalization carries meaning, as with defined terms or code.
  • Whitespace collapsing: ignore extra spaces, tabs and line wrapping. Useful when documents were reflowed or exported from different editors.
  • Line-ending normalization: treat different line-ending conventions as equal. Almost always safe for prose.
  • Punctuation stripping: ignore punctuation entirely. Risky, because a moved comma or an added question mark can change meaning.
  • Unicode normalization: canonical forms (NFC) merge characters that are encoded differently but are the same character, such as an accented letter stored as one code point or as a base letter plus a combining mark. Compatibility forms (NFKC) go further and fold styled letters, ligatures and similar variants into plain equivalents.

Normalization also hides real differences. If one version contains styled Unicode letters and the other plain text, NFKC makes them compare as equal, which is correct when you only care about wording and misleading when the styled characters are themselves the problem, for example because they break search or screen readers. If you are unsure, run the comparison both with and without normalization.

The following Python sketch uses only the standard library to show a normalized word-level comparison. It is an illustration, not a tested recipe for any particular document set. The file names are placeholders.

import difflib
import unicodedata

def normalize(text):
    text = unicodedata.normalize("NFKC", text)
    text = text.replace("\r\n", "\n")
    return " ".join(text.split()).casefold()

with open("draft_v1.txt", encoding="utf-8") as f:
    a = normalize(f.read()).split()
with open("draft_v2.txt", encoding="utf-8") as f:
    b = normalize(f.read()).split()

ratio = difflib.SequenceMatcher(None, a, b).ratio()
print(f"Word-sequence similarity: {ratio:.2f}")

for line in difflib.unified_diff(a, b, lineterm=""):
    print(line)

Remove the NFKC step or the casefold call to make the comparison stricter. The ratio summarizes how much of the word sequence matches. It does not say whether the changes were important.

Will the comparison result be readable and usable where you need it?

A comparison only helps if you can share the result with the people who need it and they can understand it. Check these points before relying on it.

Formatting versus text. A plain-text comparison of exported files does not capture formatting-only changes such as new bold text, heading styles or table layout. If those changes matter, check whether your workflow compares the document's formatting or only its text, and test it on a sample revision before trusting it.

Copying results out. Highlighting in a rendered diff view is presentation, so it may not survive copying into an email, ticket or chat. A unified diff, with plus and minus markers on each line, is plain text and stays intact wherever plain text does. If you need to hand the result to someone, export it in a plain-text form or confirm how the destination renders it.

Accessibility. Diffs that mark insertions and deletions only with color, such as green and red, are hard to read for people with color-vision differences and give screen-reader users nothing to go on. Prefer views that also use text markers, strikethrough with labels, or explicit "added" and "removed" annotations. Styled Unicode letters in either document are a separate problem: they are distinct symbols, so assistive technology may read them oddly or skip them, and search may not match them. Replace them with plain text in any version you plan to publish.

Hidden characters. If the documents may contain bidirectional controls, zero-width characters or look-alike letters from other scripts, use a view that reveals invisible characters or lists code points. Otherwise a reviewer can approve text whose stored content differs from what they saw.

Sensitive documents. Pasting text into an online comparison service sends it to a third party, where it may be logged or retained under that service's policies. For contracts, personal data, unreleased material or anything under confidentiality obligations, compare locally with an offline tool or a script like the one above, or confirm the service's data-handling terms before uploading.

What this guide cannot tell you

There is no universal similarity threshold that marks two documents as "the same" or "substantially different". Any cutoff depends on the method, the normalization settings and your purpose. This guide also does not evaluate or rank specific comparison products, because no tested results for them were available. Test any tool on a few revision pairs where you already know the answer, such as a pure reordering, a single negation and a whitespace-only change, and check whether it reports them the way you need.