Concepts / Reference-Free Evaluation Metrics

Reference-Free Evaluation Metrics

Lexical similarity measures how much two texts overlap, most simply by counting how many tokens they share with a reference.

  • Programming

Judging a Response Against a Reference

Suppose you need to judge whether a generated response is good. A tempting shortcut is to hold it up against a reference response, a trusted answer written in advance, and ask how much the two texts look alike on the surface. In evaluation work that shortcut has a name: lexical similarity. It is one of the most common ways to score generated text, and it is easy to apply. It is also easy to misread, and this article is built around one of the most common misreadings.

What do you think happens?

The reference is 'My cats scare the mice'. How many tokens does it contain if each word counts as one token?

Reveal answer
Answer:

5

Each word is one token in the simplest form of the measure: My, cats, scare, the, and mice. Every later percentage in this article is calculated against this count of 5.

The belief many learners start with is this: if a generated response shares more words with the reference, it must be the better response. The reasoning sounds sensible. Overlap seems like evidence of correctness, and a score is a number that can be ranked. The trouble is that the measurement only sees matching surface material. It does not see whether the meaning is right, whether the answer is useful, or whether a different but correct wording was phrased differently from the reference. The rest of this article shows how the score is counted, what each variant of the count can notice, and where the score stops being trustworthy.

Counting Shared Tokens

Lexical similarity measures how much two texts overlap. The first step is to break each text into smaller units called tokens. In the simplest form of the measure, you count how many tokens two texts have in common and express that count relative to the reference. Each token in the reference can be matched at most once against the generated response, and the result is a percentage of the reference's tokens that appear in the response.

Worked example

Scoring two candidates against one reference

Reference: 'My cats scare the mice' (5 tokens). Response A: 'My cats frighten the mice'. Response B: 'My dogs chase the mice'. Which response has the higher token overlap, and what are the scores?

  1. 1
    Tokenize the reference

    The reference has five word tokens: my, cats, scare, the, mice. The reference count is the denominator for every score.

  2. 2
    Match Response A

    Response A contains my, cats, the, and mice. It does not contain scare, so it shares 4 of the 5 reference tokens. 4 out of 5 is 80 percent.

  3. 3
    Match Response B

    Response B contains my, the, and mice. It does not contain cats or scare, so it shares 3 of the 5 reference tokens. 3 out of 5 is 60 percent.

  4. 4
    Compare the scores

    Response A scores higher at 80 percent, and Response B scores 60 percent. The score alone says nothing about whether frighten means the same as scare or whether dogs changes the meaning of the sentence.

Result

Response A has the higher overlap at 80 percent, and Response B has 60 percent. These two candidate responses are generated examples, not texts from the source, and they are used to show the counting procedure.

Reference: My catsscare the mice5 tokensResponse A4 of 5 shared, 80 percentResponse B3 of 5 shared, 60 percentmy, cats, the, mice matchmy, the, mice match
Which tokens are shared between each generated response and the reference, and how does matching them produce the overlap count?

Counting whole shared words is coarse. The overlap count treats each reference token as either present or absent, so a scare that becomes scarce earns no credit at all. The next section covers a measure that gives partial credit for near-matches, and the one after that covers a measure that looks at pairs of words rather than single words.

Edit Distance and Fuzzy Matching

Approximate string matching, sometimes called fuzzy matching, handles the coarseness of whole-word counts by measuring similarity through the number of edits needed to turn one text into another. That number is called the edit distance. A smaller edit distance means the texts are more similar. Edit distance is defined by counting edits, so two strings that are one edit apart are very close, and two strings that need many edits are far apart.

  • Deletion removes a character from one text.
  • Insertion adds a character to one text.
  • Substitution replaces one character with another.

The diagram below walks the word 'cats' into the word 'cars' one character at a time. Each position is compared in order, and the one position that differs is changed by a substitution. Changing t to r costs one edit, so the edit distance between 'cats' and 'cars' is 1. The same counting works for the other two operations: turning 'scare' into 'scarce' takes one insertion of a c, and turning 'mices' into 'mice' takes one deletion of an s.

cunchangedckeptaunchangedakepttto be replacedrsubstituted insunchangedskeptsubstitution, 1 edit
What changes in the text when one character is substituted, and how many edits does that take?

Bigrams and Local Word Order

N-gram similarity changes the unit of comparison. Instead of checking single tokens, it checks sequences of tokens, called n-grams. A 1-gram, also called a unigram, is a single token. A 2-gram, or bigram, is a set of two consecutive tokens. Larger n-grams follow the same pattern with longer windows. Because the unit is a sequence, n-gram similarity notices when words appear in the same order, which single-word counting does not.

To find the bigrams in a sentence, slide a window of size two across the tokens one position at a time. Each window position produces one bigram. For the reference sentence 'My cats scare the mice', the window starts at 'My' and 'cats', then moves one step to 'cats' and 'scare', then to 'scare' and 'the', and finally to 'the' and 'mice'. The four bigrams are 'my cats', 'cats scare', 'scare the', and 'the mice'. A sentence with five tokens always produces four bigrams, because the window has four possible starting positions.

my catswindow at tokens 0 and 1cats scarewindow at tokens 1 and 2scare thewindow at tokens 2 and 3the micewindow at tokens 3 and 4window moves one tokenwindow moves one tokenwindow moves one token
Which adjacent token pairs appear in the sentence, and how does the window move from one position to the next to produce each bigram?

The measure works by checking what percentage of the n-grams in the reference also appear in the generated response. Bigram overlap therefore rewards phrases that match the reference's local word order. Consider a generated response that uses the same five words in a scrambled order. It would still share all five unigrams with the reference, but it would share few or none of the bigrams. That is the difference bigrams add: the unigram count sees the same words, while the bigram count sees whether those words sit next to each other in the same way.

MeasureWhat gets comparedWhat it can noticeWhat it still misses
Token overlapWhole tokens shared with the referenceWhich words matchWord order, and meaning
Edit distanceCharacter edits needed to change one text into anotherHow close a misspelled or altered word is to its targetWhether the altered word means the same thing
Bigram similarityPairs of consecutive tokensShared words in local word orderMeaning, and order beyond the pair

Three lexical similarity approaches, what each compares, and what each still misses

Where Overlap Misleads

The misconception breaks down for two separate reasons, and both come from the reference data rather than from the generated text. The first reason is that a good response can receive a low similarity score when the reference set does not contain anything that looks like it. Lexical similarity can only reward resemblance to the references that were written. If a correct answer uses different words, it has nothing to match against.

A real case from the source shows this. Adept's model Fuyu performed poorly on some benchmark examples, not because its outputs were wrong, but because some correct answers were missing from the reference data. In one image-captioning example, Fuyu generated a correct caption and still received a low score. The reference captions described a fast moving image of cars on a busy street with a tower clock, and a city building lit up with traffic. None of the reference captions mentioned Big Ben or Parliament, so the caption that named them received a CIDEr score of 0.4. The caption was right, and the reference set simply did not contain its wording.

The second reason is that references can be wrong. The organizers of the WMT 2023 Metrics shared task, which examines evaluation metrics for machine translation, reported that they found many bad reference translations in their data. Low-quality reference data is one of the reasons that reference-free metrics were strong contenders against reference-based metrics for correlation with human judgment (Freitag et al., 2023). When the yardstick itself is flawed, a high or low score tells you less than it seems to.

A third limit appears in code generation. On HumanEval, a code generation benchmark, OpenAI found that BLEU scores for incorrect and correct solutions were similar. The source concludes that optimizing for BLEU scores is not the same as optimizing for functional correctness (Chen et al., 2021). A code solution can look textually close to the reference while failing to work, and a working solution can look different from the reference. Overlap does not measure whether code runs correctly.

Reference: My catsscare the micethe correct claimMy cats do not scarethe mice100 percent tokens, 75percent bigrams, wrongmeaningMy cats frighten themice80 percent tokens, 50percent bigrams, samemeaninghigher surface overlaplower surface overlap
How can a response with more shared tokens still be the worse answer when its overlap comes from matching words that do not carry the same meaning?
  • Common mistake

    Treating the higher overlap score as the better response

    What it looks like

    The candidate 'My cats do not scare the mice' shares all five reference tokens and scores 100 percent on unigrams, while 'My cats frighten the mice' scores 80 percent. The first candidate reverses the claim.

    Why it fails

    The score counts matching surface tokens against one reference. It does not check whether the meaning is right, whether the answer is useful, or whether a correct answer was worded differently.

    Do this instead

    Read the score as evidence of surface resemblance only, and judge meaning separately.

  • Common mistake

    Assuming unigram overlap captures word order

    What it looks like

    The candidate 'Mice the cats scare my' shares all five reference tokens and so scores 100 percent on unigrams, but it shares only the bigram 'cats scare', which is 1 of 4 reference bigrams, or 25 percent.

    Why it fails

    Single-token counts ignore sequence. A scrambled sentence can match every word and still read differently from the reference.

    Do this instead

    Add a bigram comparison to check whether the local word order matches the reference.

  • Common mistake

    Giving a misspelled word no credit in every sense

    What it looks like

    The word 'scarce' compared with the reference word 'scare' gets no credit under whole-word matching.

    Why it fails

    Whole-word matching is coarse. The two words are one insertion apart, so an edit-distance measure would register them as very close.

    Do this instead

    Use approximate string matching when near-spellings should count for something, and remember that a small edit distance still says nothing about meaning.

  • Common mistake

    Treating a low score as proof that a response is wrong

    What it looks like

    The Fuyu caption naming Big Ben and Parliament received a CIDEr score of 0.4 even though it was correct.

    Why it fails

    The reference set may lack the correct wording, and references themselves can be wrong.

    Do this instead

    Check the reference data before concluding that a low score reflects a bad response.

Practice Comparing Two Candidates

MEDIUM

Reference: 'My cats scare the mice'. Candidate X: 'The mice fear my cats'. Candidate Y: 'My cats scare the rats'. Compute the unigram overlap for each candidate, list the bigrams of each candidate, and decide which candidate you would trust more and why. Remember that a higher score is not automatically a better answer.

Hints
  • Count how many of the five reference tokens each candidate contains. Remember that 'rats' is not the same token as 'mice'.
  • Candidate X contains my, cats, the, mice, and fear. Check which reference tokens it is missing.
  • List the four bigrams of the reference first. Then check which of them appear as adjacent pairs in each candidate.

Key Takeaways

  • Lexical similarity measures overlap between two texts, most simply by counting the reference tokens that a generated response shares, expressed as a percentage of the reference.
  • Edit distance counts the deletions, insertions, and substitutions needed to turn one text into another, so a smaller edit distance means closer strings, and it gives partial credit for near-spellings.
  • N-gram similarity compares sequences such as unigrams and bigrams; bigrams are consecutive token pairs and capture local word order that single-token counts miss.
  • A higher overlap score does not always mean a better response, because surface matches ignore meaning, correct answers can score low when the reference lacks their wording, and references themselves can be wrong.

Related concepts

More concepts starting with R