Text Similarity Calculator
Measure how similar two texts are using cosine, Jaccard, and Levenshtein metrics.
关于此工具
Paste two pieces of text and calculate three complementary similarity metrics: cosine similarity on TF-IDF word vectors (ideal for comparing documents), Jaccard similarity on word sets (measures vocabulary overlap), and Levenshtein distance at the character level (useful for near-duplicate strings). Results include a percentage score for each metric, the list of shared words, and words unique to each text — helping you decide how alike two documents truly are.
使用方法
- 1 Paste the first text into the left text area.
- 2 Paste the second text into the right text area.
- 3 Click Compare to compute all three similarity metrics.
- 4 Review the percentage scores, shared words, and unique words panels.
Three ways to measure "alike," and why you need all three
The word "similar" hides a lot of ambiguity. Two texts can share almost every word yet say opposite things, or share no individual letters yet mean the same thing. There is no single correct number for similarity, so this tool computes three different metrics side by side. Each answers a different question, and reading them together tells you far more than any one alone. Everything runs in your browser on the text you paste — nothing is uploaded.
Cosine similarity — do the two texts talk about the same things?
Cosine similarity treats each text as a bag of words. It counts how often each word appears, builds a frequency vector for each text, and measures the angle between those two vectors. Identical word distributions point in the same direction (100%); texts with no shared words are perpendicular (0%). Because it uses the cosine of the angle rather than raw distance, document length barely matters — a 50-word abstract and a 5,000-word paper on the same topic can still score high. The formula is the dot product of the two word-count vectors divided by the product of their magnitudes.
Jaccard similarity — how much vocabulary overlaps?
Jaccard ignores frequency entirely. It builds the set of unique words in each text and divides the number of words they share by the total number of distinct words across both. A word that appears once counts the same as a word that appears thirty times. This makes Jaccard excellent for spotting near-duplicate vocabulary and detecting whether one text is a rewording of another.
Levenshtein similarity — how many edits separate the raw characters?
Levenshtein works at the character level, not the word level. It counts the minimum number of single-character insertions, deletions, or substitutions needed to turn one string into the other — the "edit distance." This tool converts that distance into a percentage: 1 − distance / length of the longer string. It is the right tool for catching typos, version drift, and tiny mechanical changes. (To stay fast, the edit-distance calculation uses the first 2,000 characters; cosine and Jaccard use the full text.)
A worked example
Suppose Text A is the cat sat on the mat and Text B is the cat sat on the hat.
- Cosine: Both share
the(twice),cat,sat,on. Onlymatversushatdiffer. The frequency vectors are nearly parallel, so cosine is roughly 92%. - Jaccard: The shared word set is {the, cat, sat, on} = 4 words; the union adds {mat, hat} = 6 total. So Jaccard = 4 / 6 ≈ 67%. Notice it drops faster than cosine, because a single different word is a larger fraction of a tiny vocabulary.
- Levenshtein: Only one character differs (
mversush) out of 22, giving an edit distance of 1 and a similarity near 95%.
The spread between these three numbers is itself the signal. When cosine is high but Jaccard is low, one text repeats a few keywords heavily. When Levenshtein is high but cosine is lower, the texts are mechanically close but use different word counts.
Genuine use cases
- Duplicate and near-duplicate detection: Flag support tickets, product reviews, or catalog descriptions that are reworded copies of each other.
- Editing and revision tracking: Compare a draft against its rewrite to see how much actually changed (high Levenshtein = light edit).
- Plagiarism screening: A high Jaccard plus high cosine between two essays is a strong prompt to investigate further.
- Deduplicating training data: Strip near-identical entries before feeding a dataset into a model.
How the tokenizer affects your results
Before any metric runs, the text is lowercased and split into words using the pattern [a-z']+. That has consequences worth knowing. Numbers and most punctuation are dropped from the word-based metrics, so Order #5012 and Order #9988 look identical to cosine and Jaccard (the digits vanish). Case is ignored, so Apple and apple match. Hyphenated terms split into separate words. The shared-words and unique-words panels below your scores show exactly which tokens the tool saw, which is the fastest way to sanity-check a surprising result.
Common mistakes
- Trusting one number. A single metric can mislead. Always read all three plus the shared/unique word lists.
- Expecting semantic understanding. These are surface metrics.
cheapandinexpensiveare synonyms to a human but score zero overlap here — none of the three methods understand meaning, only words and characters. - Comparing texts in different languages or with heavy formatting. Markdown symbols, code, and non-Latin scripts are stripped by the tokenizer and will skew word-based scores.
- Reading Levenshtein on very long, reordered texts. Moving a paragraph to the top counts as a huge number of edits even though no words changed; lean on cosine or Jaccard for reordered content.