# Exact Match, Accuracy and F1 for LLM Tasks

> How exact match, accuracy and F1 score an LLM's answers, where each one misleads, and how to report them, for your AI interview.

**In short:** Exact match checks whether an LLM's answer equals the expected answer word for word, after tidy-up. Accuracy is the share of right labels, and token F1 gives partial credit by balancing precision and recall. Use the score that fits the task, and report two of them.

AI and LLM interview question Q253, Evaluation and observability. Beginner, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/exact-match-accuracy-and-f1-for-llm-tasks

## Say it in 30 seconds

Exact match, accuracy and F1 are three ways to score an LLM's answers against a gold answer. Exact match is strict: the words must match after tidy-up. Accuracy counts the share of right labels, which can look great even when a rare case is always missed. Token F1 gives partial credit for shared words, and balances precision and recall. I'd report at least two of them, and read the gap between them.

## Say it in 2 minutes

Exact match, accuracy and F1 are the three scores I reach for first when an LLM's output has a right answer. Exact match asks whether the answer equals the gold answer after small tidy-ups like case and spaces. It is strict and cheap, so it suits dates, IDs and fixed labels. But a sentence with the right meaning in different words scores zero.

Accuracy is the share of answers that are right. It works for one label from a fixed list, such as billing or refund. Watch the rare cases. If only three in a hundred emails are urgent, a model that never flags anything scores 97 percent, so accuracy alone says nothing about the urgent ones.

F1 is for partial credit. It compares the words in the model's answer with the words in the gold answer, then combines precision and recall into one number. Precision asks how many of its words were right. Recall asks how many of the needed words it found. It is an average that punishes a big gap between the two, so both must be decent for a high score. It is still blind to meaning: 'refundable' and 'not refundable' share a word, so they still get partial credit.

In an interview I'd say which score fits the task and why, and that I report two of them. The gap between exact match and F1 shows where wording fails. When the answer can be worded many ways, I add a judge or people to grade meaning.

## What are exact match, accuracy and F1, in plain words?

When a model answers a test question, you need a rule that says whether the answer is right. Exact match, accuracy and F1 are three common rules. Each one counts a different kind of right.

Exact match asks whether the answer is the same as the expected answer, after small tidy-ups such as case and extra spaces. Accuracy is the share of answers that are right, and it fits when every answer is one label from a list. Token F1 gives partial credit for shared words, so a close answer scores more than a wrong one.

Think of a claims clerk at an insurer checking a settlement letter. A strict check accepts only the exact figure. A fair check gives credit for each line that matches and marks the lines that are missing.

An LLM that reads 500 vendor contracts and returns the notice period needs one of these rules to score it. The rule you pick decides what you think is working.

- **Gold answer:** The answer your team agreed is correct. It is the expected output in a test case.
- **Token:** A unit the scorer compares. In token F1 it is a word here, not the model's sub-word piece.
- **Label:** One choice from a fixed list, such as billing, refund or complaint.
- **F1 score:** One number that combines two checks: precision (the share of the words given that were right) and recall (the share of the needed words that were found).

## How do exact match and accuracy work, and where do they break?

Exact match is the simplest score. For each test case you compare the model's answer with the gold answer. An equal pair scores 1, and anything else scores 0. The score for the whole test set is the share of cases that scored 1.

1. **Tidy both sides:** Lower-case the text and remove extra spaces and stray punctuation, so "60 days." and "60 days" compare as equal.
2. **Compare word for word:** A match scores 1. Anything else scores 0, even when the meaning is right.
3. **Average the test set:** Add the 1s and 0s and divide by the number of cases. That is your exact match rate.

> "Exact match evals measure whether the model's output matches a predefined correct answer, typically after normalizing whitespace and case." (Anthropic)
>
> "Accuracy is the proportion of all classifications that were correct, whether positive or negative." (Google, machine learning course)

Accuracy is the same test counted over labels. It fits one label from a fixed list, such as a ticket's category.

Accuracy has one trap. Suppose only three in every hundred emails in a support inbox are urgent (made-up numbers). A model that never flags anything scores 97 percent accuracy, and it is useless for the urgent ones. That is why accuracy alone is a weak check for rare cases.

Here is a made-up check on five vendor contracts. The model pulls out the notice period, and we score its answers with exact match and with F1.

```python
# Scoring an LLM that pulls the notice period out of five vendor contracts (made-up outputs).
import re
from collections import Counter

def words(s):
    return re.sub(r"[^a-z0-9 ]", "", s.lower()).split()

def exact_match(pred, gold):
    return words(pred) == words(gold)
def token_f1(pred, gold):
    p, g = words(pred), words(gold)
    common = sum((Counter(p) & Counter(g)).values())
    if common == 0:
        return 0.0
    precision, recall = common / len(p), common / len(g)
    return 2 * precision * recall / (precision + recall)

cases = [
    ("60 days", "60 days."),
    ("Sixty (60) days", "60 days"),
    ("90 days after written notice", "90 days"),
    ("30 days", "60 days"),
    ("Not specified", "90 days"),
]
em = [exact_match(p, g) for p, g in cases]
f1 = [token_f1(p, g) for p, g in cases]
print(f"exact match   {sum(em) / len(em):.0%}")
print(f"token F1      {sum(f1) / len(f1):.2f}")
for (p, g), e, f in zip(cases, em, f1):
    print(f"{p!r:32} vs {g!r:12} EM={int(e)} F1={f:.2f}")
```

Output:

```text
exact match   20%
token F1      0.57
'60 days'                        vs '60 days.'   EM=1 F1=1.00
'Sixty (60) days'                vs '60 days'    EM=0 F1=0.80
'90 days after written notice'   vs '90 days'    EM=0 F1=0.57
'30 days'                        vs '60 days'    EM=0 F1=0.50
'Not specified'                  vs '90 days'    EM=0 F1=0.00
```

Exact match scores 20 percent, and token F1 scores 0.57. Exact match credits only the first case. The second means the same thing, and the third is right but adds 'after written notice'. That gap is the lesson: a strict score counts wording, while a partial score counts shared words and can still miss meaning.

*Diagram, One answer, scored two ways: The same answer, scored two ways. Exact match gives 0 because the words differ, while token F1 gives 0.80 for the two words that match. Report both, so the gap shows what to fix.*
1. The answer goes to the strict word-for-word check.
2. The same answer goes to the shared-words check.
3. The strict result, 0, goes into the final report.
4. The 0.80 score goes into the final report.

## What is F1, and when should you use it?

F1 checks how much of the answer is right, in both directions. Classification F1, the score scikit-learn calculates, applies this formula to a model's right and wrong labels. Token F1 is this page's name for the same formula, applied to the words an answer shares with the gold answer. Precision asks: of the words the model wrote, how many were right? Recall asks: of the words the gold answer needs, how many did the model give? F1 combines the two, so it is only high when both are high.

Token F1 suits answers that are spans of a document, such as a clause or a date pulled from a contract. The SQuAD reading benchmark from 2016 used this kind of answer, a segment of text from a passage, and its abstract reports an F1 score of 51.0% for a logistic regression model.

> "The F1 score can be interpreted as a harmonic mean of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0." (scikit-learn, the F1 score)
>
> "This metric balances the importance of precision and recall, and is preferable to accuracy for class-imbalanced datasets." (Google, machine learning course)

- **Exact match: Right or wrong.** Strict. Good for a date, an ID or a fixed phrase. Too harsh for a sentence that says the same thing in other words.
- **Accuracy: Share of labels right.** Fits one label from a list. Misleads when one label is rare.
- **Token F1: Partial credit.** Counts shared words. Still blind to meaning: 'refundable' and 'not refundable' share a word, so they get partial credit.

> **Tip:** Name the metric and why in one breath: for ticket labels, say you track accuracy and per-class recall, since the refund class is rare.

When an answer can be worded many ways, no single string score is enough. Teams then grade meaning with a judge model or with people. See LLM-as-a-judge in this kit.

### How would you report scores for a contract-extraction model?

You have a model that pulls the notice period from vendor contracts. A product owner asks for one number. Here is a plan that keeps the number honest.

1. **Write the tidy-up rules first:** Decide whether "60 days" and "sixty days" count as the same. Write the rule down, or the score moves when the rules move.
2. **Report exact match and token F1 together:** The gap shows where answers differ only in wording. Partial credit can hide a wrong number: '30 days' against '60 days' still scores 0.50 F1, so read the misses by hand.
3. **Read the misses by hand:** Ten misses show whether the model is wrong or the grader is too strict. Fix whichever is the real cause.
4. **Add a meaning check for free text:** Use a judge or people for answers that can be worded many ways.
5. **Keep a hidden test set:** Do not tune prompts on the cases you report. Otherwise the score flatters the model.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] The three scores, each in one plain sentence.
- [ ] Which score fits which task: strict for IDs and dates, F1 for extracted phrases, accuracy for labels.
- [ ] Why accuracy misleads when a case is rare.
- [ ] What exact match and F1 miss: meaning, which needs a judge or people.
- [ ] Reporting two scores and reading the gap between them.
- [ ] Tidy-up rules written down, and a test set kept hidden from tuning.

**Common traps**

- Trap: "Accuracy is the best metric for everything." Better: It hides rare failures. Pair it with recall or F1 when one class is rare.
- Trap: "Exact match is wrong, so ignore it." Better: It is right for dates, IDs and fixed labels. Keep it there, and add a softer score for free text.
- Trap: "An F1 of 0.8 means the model is 80% correct." Better: F1 balances two ratios. It is not a percentage right, so say what it counts.

## Can you spot the scoring problem?

**Spot the scoring problem:** A team reports 97% accuracy for a model that flags urgent emails. Only about 3 in 100 emails are urgent (made-up numbers). What is the problem?

A. Accuracy is fine, because 97% is a high number.
B. Doing nothing would also score about 97%, so measure recall on the urgent class.
C. Exact match should be used for urgent flags.
D. Token F1 should be used, since emails are long.

**Answer:** B. Doing nothing scores about 97% here, so the score hides every urgent email it misses. Measure how many urgent emails the model actually catches.

**Quick check:** A model pulls the due date from invoices. Which score is the best first check?

A. Exact match, after tidying every date into one format
B. Ask the model to rate its own date
C. Ask a second model if the date looks right
D. Token F1 on the whole invoice text

**Answer:** A. A due date is one value once tidied, so exact match checks it strictly and cheaply. A model rating itself, or a second model's opinion, is not a strict check and can be wrong too. Token F1 on the whole invoice would give a near-miss date partial credit.

## Can you answer these from memory?

**Flash cards**

- **What is exact match?** The answer must equal the gold answer after tidy-up. Otherwise it scores 0.
- **What is accuracy?** The share of answers that are right. It misleads when one label is rare.
- **What is F1?** The harmonic mean of precision and recall. It gives partial credit for shared words.
- **Why can 97% accuracy be useless?** A model that never flags the rare class still scores high.
- **Scores for "Sixty (60) days" vs "60 days"?** Exact match 0, token F1 0.80.
- **What does exact match miss?** The same meaning in different words. It scores zero.

## Likely follow-up questions

- Q252 BLEU and ROUGE, and their limits? https://designervenkat.online/interview/ai/bleu-and-rouge-and-their-limits
- Q248 What is a golden dataset, and how do you build one? https://designervenkat.online/interview/ai/what-is-a-golden-dataset
- Q249 What is LLM-as-a-judge? https://designervenkat.online/interview/ai/what-is-llm-as-a-judge
- Q254 Faithfulness vs relevance? https://designervenkat.online/interview/ai/faithfulness-vs-relevance
- Q257 How do you regression-test prompts? https://designervenkat.online/interview/ai/how-to-regression-test-prompts
- Q420 Precision, recall and F1? https://designervenkat.online/interview/ai/precision-recall-and-f1

## Learn it in depth

- [F1-Score: one number for two goals](https://designervenkat.online/learn/machine-learning/f1-score)
