Topic 5
Lexical similarity: do they look alike?
When exact match is too strict, you can measure how much the output looks like the reference. AI Engineering (Ch. 3, "Similarity Measurements Against Reference Data", "Lexical similarity") describes three common ways:
- Word overlap: split both texts into tokens, here words, and count how many of the reference's words appear in the output.
- n-gram overlap: the same with runs of n words. Pairs (bigrams) start to reward word order.
- Edit distance, also called fuzzy matching: the number of single-character edits needed to turn one text into the other, counting insertions, deletions and substitutions. "bad" is one edit from "bard" and three from "cash". Some matchers also count swapping two letters as one edit.
Predict first
How alike do two texts look?
Computed in your browser · type your own
Exact match
no
Word overlap
5/6
Word-pair overlap
2/5
Edit similarity
76.9%
Word overlap counts the reference's words found in the output; word-pair overlap does the same for adjacent pairs, so word order starts to matter. Edit similarity is 100% minus the share of characters you'd have to insert, delete or change.
Named metrics such as BLEU, ROUGE, METEOR++, TER and CIDEr are variations on this idea, differing in exactly how they count overlap. The book notes they were common before foundation models, especially for translation, and that fewer benchmarks use them now. WMT, COCO Captions and GEMv2 are among those that still do.
Quick check