Concepts · Map of evalsINTERNALS.md

Exact match and F1

Exact match and F1 compare a model’s answer to a reference answer. The SQuAD reading benchmark scores answers this way.

  • Exact match gives 1 when the answer equals the reference after cleaning, and 0 otherwise.
  • Cleaning means lowercase, no punctuation, and no “a”, “an” or “the”.
  • F1 gives partial credit for the words the answer and the reference share.
  • Both compare words, not meaning.

Try this: change the reference to Austen | Jane Austen and watch Answer C reach 1.

Try it

This page needs JavaScript.

What just happened

  1. Each card cleans the answer first. “Jane Austen.” becomes “jane austen”, which equals the cleaned reference, so exact match is 1 and so is F1.
  2. Orange words are the ones the answer shares with the reference. Answer B, “The author Jane Austen”, keeps one extra word, “author”. Exact match drops to . F1 stays high at , because every reference word was found.
  3. Answer C, “Austen”, has no extra words but misses one: precision 1.00, recall 0.50, F1 . Answer D buries the right name in six other words and gets .
  4. With several accepted answers, the best score wins. That is how SQuAD handles questions that have more than one right way to say it.
Show the formula
precision = shared words / words in the answer recall = shared words / words in the reference F1 = 2 × precision × recall / (precision + recall)

A word counts as shared as many times as it appears in both texts, so repeating a word does not help. F1 is the harmonic mean, which stays low if either precision or recall is low.

Where you meet it

A question-answering team compares two models on a test of short factual questions. One answers in a few words. The other answers in full sentences. The short one wins on exact match, and the sentence writer loses, even when its sentences are right.

Where it breaks

These metrics count words, so they cannot see meaning. A right answer in other words scores 0. A wrong answer that reuses the right words scores high. Each card shows the score next to what a person would say.

“The author of Emma” is right and scores . “Not Jane Austen” is wrong and scores . When meaning matters, people use a judge model or a human, which the next pages cover.

Check yourself

The reference is “the Eiffel Tower”. The answer is “Eiffel Tower!”. What are exact match and F1?

Both are 1. Cleaning removes the “the” and the “!”, so both texts become “eiffel tower”.

An answer has 10 words and contains the 2-word reference. What is its F1?

Shared words: 2. Precision 2/10 = 0.2, recall 2/2 = 1. F1 = 2 × 0.2 × 1 / 1.2 = 0.33. Long answers are punished even when they contain the right words.

Why might a team still use exact match when F1 gives partial credit?

When the answer is a short fixed thing, like a date or an ID, partial credit means nothing. “1813” and “1831” share no word, but a near miss is still wrong.

Used in

Go deeper