AWS-113 · Lesson 9 of 12 · 19 min

Evaluating foundation model output

▶ Video coming soon A video version of this lesson is on the way.

Jonah had a habit Noor wanted to break. After each change to Front Desk Helper, he typed three or four questions into the sandbox, read the answers, and declared the new version "better". At the ninth AI hour, Noor asked him how much better, on which kinds of questions, and whether anything had got worse. He did not know.

"Reading a few answers is a demo, not an evaluation," she said. "Generative models can be fluent and wrong in the same sentence. We need a fixed set of test cases, measures we can repeat, and a way to compare versions fairly. Then 'better' means something."

This lesson covers how to evaluate foundation model output: building a test set, the automatic metrics the exam names (ROUGE, BLEU, BERTScore and LLM-as-a-judge), Amazon Bedrock evaluations, and how to evaluate whole applications such as RAG systems and agents. Lesson 10 covers human evaluation and benchmark datasets in more depth.

Why evaluating generative output is hard

Evaluating a classifier, as in AWS-111, is relatively simple: each prediction is right or wrong, and accuracy, precision and recall follow. Generative output is different. A question can have many good answers worded differently, and an answer can be mostly right with one wrong detail. Evaluation therefore uses several kinds of measure, each catching different problems:

  • Reference-based metrics compare the output with a human-written reference answer.
  • Model-based judgement uses another model to score outputs against criteria.
  • Human evaluation asks people, often experts, to rate or compare outputs.
  • Task and business measures check whether the application achieves its purpose, such as staff finding the right answer faster.

All of them start with a test set, sometimes called a golden dataset: a fixed collection of realistic inputs, each with a reference answer or the facts a good answer must contain. Jonah and the clinic managers wrote 200 Front Desk Helper questions covering every SOP area, including 25 deliberately hard ones: questions with no answer in the documents, questions that should be refused because they are clinical, and questions whose answers had changed in the latest policy revision. Night Notes got 150 invented call notes with veterinarian-approved summaries, including the houseplant note from lesson 2.

Reference-based metrics

The exam guide names two classic metrics that compare words in the output with words in a reference.

  • ROUGE (Recall-Oriented Understudy for Gisting Evaluation) measures how much of the reference appears in the output, by overlapping words or word sequences. It is recall-oriented: it asks whether the output captured what the reference said. It is most often used for summarization. ROUGE-1 counts single words, ROUGE-2 counts pairs of consecutive words, and ROUGE-L uses the longest common sequence.
  • BLEU (Bilingual Evaluation Understudy) measures how much of the output appears in the reference, using overlapping word sequences of several lengths, with a penalty for outputs that are too short. It is precision-oriented and was designed for machine translation.

The code below computes simple versions of these ideas for one Night Notes summary. Real evaluations use standard libraries, but the counting is the same in spirit.

Python Example
def words(t):
    return t.lower().replace(",", "").replace(".", "").split()

reference = "Dog ate one packet of sugar-free gum about 30 minutes ago and is drooling and unsteady."
output    = "Dog ate a packet of sugar-free gum 30 minutes ago, now drooling."

ref, out = words(reference), words(output)
overlap = sum(min(ref.count(w), out.count(w)) for w in set(out))

rouge1_recall = overlap / len(ref)       # share of the reference captured
unigram_precision = overlap / len(out)   # share of the output found in the reference
f1 = 2 * rouge1_recall * unigram_precision / (rouge1_recall + unigram_precision)

print("Overlapping words:", overlap)
print("ROUGE-1 recall:", round(rouge1_recall, 2))
print("Unigram precision (BLEU-style):", round(unigram_precision, 2))
print("F1:", round(f1, 2))
print("Exact match:", reference == output)
Output
Overlapping words: 10
ROUGE-1 recall: 0.62
Unigram precision (BLEU-style): 0.83
F1: 0.71
Exact match: False

What this code does

It compares a model's summary with a reference summary word by word. It counts the shared words, then calculates ROUGE-1 recall (how much of the reference the output covers), unigram precision (how much of the output appears in the reference) and their combined F1 score, and checks for an exact match. The scores show the output is close but incomplete, and an exact-match test would wrongly call it a total failure.

The summary scored well on precision, since almost everything it said was in the reference, but lower on recall: it dropped "unsteady", which a vet would want. That is useful. The weakness of word-overlap metrics is equally clear: "a packet" and "one packet" mean the same thing, but only exact words count. And a summary that said "Dog did NOT eat sugar-free gum" would share most of its words with the reference while meaning the opposite.

BERTScore

BERTScore addresses part of that weakness. Instead of matching exact words, it uses embeddings from a language model to compare the meaning of words in context, so "unsteady" and "wobbly" can count as a match. It correlates better with human judgement than pure word overlap for many tasks, but it still compares against a reference and still cannot judge facts it cannot see.

Chart placing evaluation methods by what they compare, from exact words on the left to meaning on the right, and by whether they use a reference answer, near the top, or criteria, near the bottom. ROUGE and BLEU sit top left, BERTScore top centre, LLM-as-a-judge on the right in the middle, and human evaluation lower centre.
Automatic evaluation metrics compared. No single metric is enough; teams use several.

LLM-as-a-judge

LLM-as-a-judge uses a second foundation model to score each output against criteria written in plain language, such as correctness, completeness, faithfulness to the source, helpfulness and harmfulness. The judge can also explain its score. This scales much better than human review and can assess qualities that word overlap cannot, such as whether an answer stays within the provided passages.

Judges have weaknesses that must be managed. They can prefer longer answers, prefer outputs written in their own style, or be inconsistent. Good practice is to write clear scoring criteria with examples, check a sample of the judge's scores against human ratings, and avoid using the same model as both the system under test and its judge where possible.

Evaluation methods named in the exam guide.
MethodStrengthWeaknessTypical use
ROUGESimple, repeatable, recall-orientedExact words only; ignores meaningSummarization
BLEUSimple, precision-oriented, standard for translationExact words only; needs good referencesTranslation
BERTScoreCompares meaning with embeddingsStill needs a reference; cannot check factsParaphrase-tolerant comparison
LLM-as-a-judgeScales; scores criteria like faithfulnessCan be biased or inconsistent; must be checkedQuality, faithfulness, helpfulness
Human evaluationMost trusted for nuance and riskSlow and expensiveHigh-stakes checks and calibration

Amazon Bedrock evaluations

Amazon Bedrock Model Evaluation runs these kinds of assessment as managed jobs. A team chooses the model, or a knowledge base, to test and the dataset, which can be its own prompt dataset in Amazon S3 or a built-in dataset, and the job produces a report. Evaluation types include:

  • Automatic (programmatic) evaluation, which computes metrics such as accuracy, robustness and toxicity for common tasks like summarization, question answering and classification.
  • Model as a judge, in which a judge model scores responses against chosen criteria and explains each score.
  • Human evaluation, in which your own employees or a managed team rate responses through a work interface. Lesson 10 covers this.
  • RAG evaluation for knowledge bases, which assesses both retrieval (did it find relevant passages?) and generation (is the answer correct, complete and faithful to them?).

Because evaluations can compare several models or prompt versions on the same dataset, they turn model selection from guesswork into a measured decision. Noor reran the Small, Medium and Large comparison from lesson 1 as an evaluation job on the 150-note test set. The Medium model still led, and the Small model's main failure was omitting secondary symptoms, a pattern the job's report made obvious.

Evaluating whole applications

An application can fail even when its model is good, so the exam guide also asks how to evaluate applications built with foundation models, such as RAG systems, agents and workflows.

  • RAG applications: measure retrieval and generation separately. Context relevance asks whether the retrieved passages relate to the question; context coverage asks whether they contain what the answer needs; faithfulness (or groundedness) asks whether the answer sticks to those passages; and answer correctness compares with the reference. A wrong answer with irrelevant passages points to retrieval; a wrong answer with the right passages points to the prompt or model.
  • Agents: check whether the task was completed, whether the right tools were called with valid arguments, how many steps it took, and whether any unsafe action was attempted.
  • Workflows: test each step and the end-to-end result, because an error early in a chain is passed to every later step.
Python Example
# Front Desk Helper test results (illustrative): one row per question.
results = [
    # (retrieved the right SOP section?, answer judged correct?)
    *[(True, True)] * 164, *[(True, False)] * 9, *[(False, False)] * 19, *[(False, True)] * 8,
]
n = len(results)
retrieval_hit = sum(r for r, _ in results) / n
correct = sum(a for _, a in results) / n
wrong_with_right_context = sum(1 for r, a in results if r and not a)
wrong_with_wrong_context = sum(1 for r, a in results if not r and not a)
print("Questions:", n)
print("Retrieval hit rate:", round(retrieval_hit, 3))
print("Answer correctness:", round(correct, 3))
print("Wrong despite right passages (prompt/model issue):", wrong_with_right_context)
print("Wrong with wrong passages (retrieval issue):", wrong_with_wrong_context)
Output
Questions: 200
Retrieval hit rate: 0.865
Answer correctness: 0.86
Wrong despite right passages (prompt/model issue): 9
Wrong with wrong passages (retrieval issue): 19

What this code does

It summarizes illustrative test results for 200 questions, each recording whether retrieval found the right policy section and whether the answer was judged correct. It prints the retrieval hit rate and the answer correctness. It then separates the wrong answers into those with the right passages, which points to a prompt or model problem, and those with the wrong passages, which points to a retrieval problem, so the team knows which part to fix.

Most of the wrong answers came with the wrong passages, so the next improvement belonged in retrieval, not the prompt. Jonah looked at the 19 failures and found that most were questions using clinic slang, such as "no-show fee", for a policy titled "missed appointment charge". Adding the common synonyms to each SOP's metadata and turning on hybrid search fixed most of them on the next run.

Common mistakes

  • MistakeJudging a new version by reading a few answers.

    InsteadRun the same fixed test set on every version and compare scores.

  • MistakeRelying on one metric such as ROUGE.

    InsteadCombine reference metrics, model judgement, human review and task measures.

  • MistakeTrusting an LLM judge without checking it.

    InsteadCalibrate the judge against a sample of human ratings, with clear criteria.

  • MistakeEvaluating only the final answer of a RAG system.

    InsteadMeasure retrieval and generation separately to find where failures start.

Building and maintaining a test set

A test set is only as good as its cases, and building one is real work. Noor gave Jonah four rules. Cover the real mix: draw questions from what staff actually ask, in proportion, not just the questions that are easy to write. Include hard and edge cases: questions with no answer, questions that must be refused, ambiguous questions and questions about recently changed policies. Write references carefully: for each question, record the correct answer and the SOP section it comes from, checked by someone who knows the policy. Keep it growing: every real failure becomes a new test case, so the same mistake is caught automatically next time.

The test set also needs protecting. If its questions and answers leaked into prompts as examples, or into any fine-tuning data, scores would rise without the application getting better. Cascade Ridge kept the test set in its own S3 bucket, readable only by the evaluation role, and the few-shot examples in prompts were written separately.

Finally, results need context. A correctness score of 0.86 means little on its own. Compared with the previous version, the cheaper model and the target agreed with the clinic managers, it becomes a decision.

Evaluation is also a conversation with the people who own the work. Jonah shared the failure list with the clinic managers each week. They often spotted patterns he had missed, such as a cluster of wrong answers that all came from one clinic's local variation of a policy.

Worked problem

Choosing metrics for two tasks

Andre wants to evaluate two features: automatic translation of reminder letters into French, and summaries of after-hours calls. Which reference-based metric suits each, and what should be added?

Show solution
  1. Translation: BLEU was designed for machine translation and compares the output with reference translations.
  2. Summaries: ROUGE is recall-oriented and widely used for summarization, checking that the summary captures the reference content.
  3. Add BERTScore or an LLM judge to both, so correct paraphrases are not penalized.
  4. Add human review by fluent speakers for the letters and by veterinarians for a sample of summaries, because errors in either can matter.

Answer: BLEU for translation, ROUGE for summaries, plus meaning-based scoring and human review of samples.

Summary and key terms

  • Evaluating generative output needs a fixed test set of realistic inputs with reference answers, including hard cases, and several kinds of measure.
  • ROUGE is recall-oriented word overlap, common for summarization; BLEU is precision-oriented word overlap designed for translation; BERTScore compares meaning using embeddings; LLM-as-a-judge uses a model to score outputs against criteria and must be calibrated against humans.
  • Amazon Bedrock Model Evaluation runs automatic, model-as-a-judge, human and RAG evaluation jobs on your datasets or built-in ones and compares models or prompts.
  • Applications need their own evaluation: for RAG, measure retrieval relevance and coverage separately from faithfulness and correctness; for agents, measure task completion, tool use, steps and safety; for workflows, test each step and the end-to-end result.
Test set (golden dataset)
A fixed set of realistic inputs with reference answers used to compare versions.
ROUGE
Recall-oriented metric of word overlap with a reference, common for summarization.
BLEU
Precision-oriented metric of word overlap with a reference, designed for translation.
BERTScore
A metric that compares meaning using embeddings from a language model.
LLM-as-a-judge
Using a foundation model to score outputs against criteria.
Faithfulness
Whether an answer is supported by the provided source passages.
Amazon Bedrock Model Evaluation
A Bedrock feature that runs managed evaluation jobs on models and knowledge bases.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which metric is recall-oriented and common for summarization?

    Show answer

    ROUGE.

  2. What weakness of ROUGE and BLEU does BERTScore address?

    Show answer

    They match exact words; BERTScore compares meaning.

  3. A RAG answer is wrong but the retrieved passages were correct. Where is the problem likely to be?

    Show answer

    In the prompt or the model, not retrieval.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz