AI Engineer Summit 2023
How to evaluate a model for your use case
Read the talk
How to evaluate a language model for your use case
Generic benchmarks describe broad model capabilities. Evaluating your application requires representative inputs, task-specific criteria, and a repeatable way to score the outputs.
From a talk by Emmanuel Turlay
What does good performance mean for your application?
How do you know whether a language model performs well on your particular task? Standard metrics and benchmarks offer useful starting points, but they do not supply a universal evaluation procedure. Emmanuel Turlay, introducing himself as CEO of Sematic, the company behind Airtrain, starts with this gap between general capability and application-specific performance.
Model evaluation is statistical measurement on a dataset independent of the training data. The question is how well a model handles a particular use case across a large collection of examples, rather than whether it produces one convincing answer. Evaluation belongs after training or fine-tuning and should recur throughout development as a check on performance and safety. Turlay compares it to running a test suite in a continuous integration pipeline: a repeatable part of the workflow, rather than a final spot check.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A different answer can still be correct
Traditional supervised learning often provides a well-defined output structure and established ways to measure errors.
| Task | Output | Common metrics |
|---|---|---|
| Regression | Number | Root mean squared error, mean absolute error |
| Classification | Class | Precision, recall, F1 |
| Object localization | Bounding box | Intersection over union |
These metrics give teams a clear way to grade predictions against expected outputs.
Language models generate text, whose acceptable forms are much less constrained. An output that differs from a reference answer is not necessarily wrong. A useful evaluation therefore has to distinguish differences in wording from differences in correctness or suitability for the task.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
What text metrics capture
The first practical distinction is whether you have labeled reference answers. With references, you can compare generated text against expected text using token overlap.
- BLEU: A precision-oriented metric based on matching n-grams—sequences of tokens—between an output and a reference. It is commonly used for translation and can also be applied to summarization. Overlap alone, however, does not establish intelligibility or grammatical correctness.
- ROUGE: A family of metrics presented here through recall: how much of the reference’s token sequences appears in the generated output. Its principal application in this discussion is summarization.
Both provide useful measurements, but their relationship to success depends on what the application actually needs.
Without a reference summary, you can still compare a summary with its source text. Turlay introduces density and coverage for this purpose. The published definitions in Newsroom make the distinction precise: coverage is the fraction of summary tokens belonging to fragments shared with the source; density sums the squared lengths of those fragments and divides by summary length. Longer copied passages therefore contribute more strongly to density. These measures require the source text, but no reference summary, and describe extractiveness rather than overall summary quality.
This leaves a substantial boundary around what the metrics tell you. They are useful for high-level tasks such as translation and summarization, but a measurement tailored to those tasks need not capture success in another application. Public benchmarks broaden the comparison, while retaining their own task boundaries.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Benchmarks map broad capabilities
A benchmark is a standardized test for particular capabilities. GLUE, the General Language Understanding Evaluation benchmark, combines nine language-understanding tasks, including paraphrase detection and sentiment analysis. HellaSwag tests commonsense inference by asking a model to choose a plausible continuation. The slide’s example concerns bathing a dog; Turlay identifies answer C as the reasonable continuation.
TriviaQA tests knowledge and reading comprehension using trivia questions and associated evidence. Its original paper distinguishes 95,000 question-answer pairs from more than 650,000 question-answer-evidence triples; the talk’s description of almost a million questions conflates these units. The questions were written by trivia enthusiasts, with evidence documents collected separately.
ARC tests reasoning through multiple-choice science questions. Its documented scope is grade-school science, rather than the high-school level mentioned in the recording, and it separates questions into Easy and Challenge sets. Together, these benchmarks help map how language models compare across different capabilities.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Bring the evaluation back to your inputs
The application may ask for something much more specific than a benchmark measures:
- Clinical extraction: Extract symptoms from a doctor’s notes.
- Recipe extraction: Extract ingredients from a recipe.
- API interaction: Form a JSON payload to query an API.
A general benchmark score does not tell you how a model performs these operations on the inputs your application will supply. Each application needs an evaluation procedure tied to its own task and data. Building that procedure takes work; the next question is how to make its scoring practical.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Turn task criteria into a scoring prompt
A second language model can grade the first model’s output. Describe what the application is trying to accomplish, specify the properties you want to measure, and ask the grading model for a numerical assessment. This creates a specialized metric whose definition comes from your application’s criteria.
The evaluation pipeline has five steps:
- Run the evaluation dataset through the candidate model.
- Collect the generated outputs, or inferences.
- Place each output inside a scoring prompt that describes the task, the property being graded, and the scale—for example, 1 to 10.
- Send that prompt to a scoring model and obtain a numerical score.
- Repeat across the dataset to produce a distribution of scores for that property.
The distribution connects the grading rule to performance across the evaluation set, extending the assessment beyond an isolated output. The completed diagram shows the entire path through the scoring model to its illustrative result.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
A custom metric for email politeness
Consider a model generating closing words for professional emails. The property to evaluate is politeness, and the grading scale runs from 1 to 10. Turlay contrasts “Please let us know at your earliest convenience,” which scores highly, with “Tell me ASAP,” which scores poorly. The difference is meaningful for this application even though both statements request a response.
A small Python prompt builder makes the components of this scoring step explicit. It keeps the task, property, and scale fixed while changing the closing being evaluated:
python
import json
closings = [
"Please let us know at your earliest convenience",
"Tell me ASAP",
]
def politeness_prompt(closing: str) -> str:
return (
"Task: Generate closing words for a professional email.\n"
"Evaluate the politeness of the closing below.\n"
"Scale: 1 = very impolite; 10 = very polite.\n"
"Return only one integer from 1 to 10.\n"
f"Closing: {json.dumps(closing)}"
)
scoring_prompts = [politeness_prompt(text) for text in closings]
for prompt in scoring_prompts:
print(prompt)
print()
These prompts are ready to send to a scoring model; constructing them does not assign scores. Once the grader returns its judgments, those values can contribute to the dataset-wide politeness distribution.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Choose the grader, then compare distributions
Turlay reports that GPT-4 was the best grading model his team had found at the time, but could be costly for large datasets; Flan-T5 offered a useful trade-off between speed and correctness. He supplies no quantitative comparison or evaluation protocol, so this is a historical account of the team’s experience rather than a current model ranking.
Airtrain packages the workflow around those dataset-wide comparisons: upload a dataset, select candidate models, describe the properties to measure, and visualize the resulting metric distributions. Turlay names Llama 2, Falcon, Flan-T5, and a user’s own model as comparison options. The recording closes with an invitation to Airtrain’s then-early-access offering. The intended decision rests on statistical evidence from your dataset and your criteria—the same application-specific foundation that generic leaderboards cannot supply.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Original reading-comprehension benchmark paper explaining its trivia questions and associated evidence documents.
Grade-school science questions with Easy and Challenge subsets, examples and dataset splits.
Commonsense inference benchmark built around selecting plausible continuations.
Overview of nine language-understanding tasks and their shared evaluation framework.
Further reading
Defines coverage and density using shared fragments between a summary and its source text.
Python examples for calculating extractive coverage, density and compression. The README documents limitations of its separate ROUGE evaluation pipeline.
Research on language-model judges, agreement with human preferences and systematic judging biases.
Read the complete timestamped transcript
- 0:00
[upbeat music] Hi everyone, I'm Emmanuel, CEO of Sematic, the company behind Airtrain.
- 0:23
Today, I want to talk about a difficult problem in the language modeling space, and that is evaluation. Unlike in other areas of machine learning, it is not so straightforward to evaluate language models for a specific use case.
- 0:38
There are metrics and benchmarks, but they mostly apply to generic tasks, and there is no one-size-fits-all process to evaluate the performance of a model for a particular use case.
- 0:49
So first, let's get the basics out of the way. What is model evaluation? Model evaluation is the statistical measurement of the performance of a machine learning model. How well does a model perform on a particular use case, measured on a large dataset independent from the training dataset?
- 1:08
Model evaluation usually comes right after training or fine-tuning and is a crucial part of model development. All ML teams dedicate large resources to establish rigorous evaluation procedures. You need to set up a solid evaluation process as part of your development workflow to guarantee performance and safety.
- 1:28
You can compare evaluation to running a test suite in your continuous integration pipeline.
- 1:33
In traditional supervised machine learning, there is a whole host of well-defined metrics to clearly grade a model's performance. For example, for regressions, we have the root mean squared error or the mean absolute error.
- 1:48
For classifiers, people usually use precision, recall, or F1 score, and so on.
- 1:56
In computer vision, a popular metric is the intersection over union. So what metrics are available to score language models?
- 2:05
Well, unlike other types of models returning structured outputs such as a number, a class, or a bounding box, language models generate text, which is very unstructured. An inference that is different from the ground truth reference is not necessarily incorrect.
- 2:22
Depending on whether you have access to labeled references, there are a number of metrics you can use. For example, BLEU is a precision-based metric. It measures the overlap between n-grams, that is sequences of tokens, between the generated text and the inference.
- 2:39
It's a common metric to evaluate translation between two languages and can also be used to score summarization. It can definitely serve as a good benchmark, but it is not a safe indicator of how a model will perform on your particular task.
- 2:53
For example, it does not take into account intelligibility or grammatical correctness. ROUGE is a set of evaluation metrics that focuses on measuring the recall of sequences of tokens between references and the inference.
- 3:08
It is mostly useful to evaluate for summarization. If you don't have access to labeled references, you can use other standalone metrics. For example, density quantifies how well the summary represents pull fragments from the text, and coverage quantifies the extent to which a summary is derivative of a text.
- 3:30
As you can see, these metrics are only useful to score certain high-level tasks such as translation and summarization. There are also a number of benchmarks and leaderboards that rank various models.
- 3:44
Benchmarks are standardized tests that score model performance for certain tasks. For example, GLUE, or General Language Understanding Evaluation, is a common benchmark to evaluate how well a model understands language through a series of nine tasks.
- 4:01
For example, paraphrase detection and sentiment analysis. HellaSwag measures natural language inference, which is the ability for a model to have common sense and find the most plausible end to a sentence.
- 4:16
In this case, answer C is the most reasonable choice. There are other benchmarks such as TriviaQA, which asks almost a million trivia questions from Wikipedia and other sources and tests the knowledge of the model.
- 4:31
Also, ARC tests models' ability to reason about high school-level science questions. And there are dozens more benchmarks out there.
- 4:39
All these metrics and benchmarks are very useful to draw a landscape of how LLMs compare to one another.
- 4:46
But they do not tell you how they perform for your particular task on the type of input data that will be fed by your application. For example, if you're trying to extract symptoms from a doctor's notes, or extract ingredients from a recipe, or form a JSON payload to query an API, these metrics will not tell you how
- 5:07
each model performs. So each application needs to come up with its own evaluation procedure, which is a lot of work. There is one magic trick, though.
- 5:17
You can use another model to grade the output of your model.
- 5:22
You can describe to an LLM what you're trying to accomplish and what are the grading criteria, and ask it to grade the output of another LLM on a numerical scale.
- 5:33
Essentially, you are crafting your own specialized metrics for your own application. Here's an example of how it works. You can feed your evaluation dataset to the model that you want to evaluate, which is going to generate the inferences that you want to score.
- 5:48
Then you can include those inferences inside a broader scoring prompt in which you've described the task you're trying to accomplish and the properties you're trying to grade, and also you describe the scale across which it, it should be graded, for example, from one to 10.
- 6:03
Then you pass this scoring prompt to a scoring model, which is going to generate a number, a score, to score the actual inference. If you do this on all the inferences generated from your evaluation dataset, you can draw a distribution of that particular metric.
- 6:19
For example, here is a small set of closing words generated for professional emails. We want to evaluate their politeness. We can prompt a model to score the politeness of each statement from one to 10.
- 6:32
For example, "Please let us know at your earliest convenience," scores highly, while, "Tell me ASAP," will score poorly.
- 6:40
We found that the best grading model at this time is still GPT-4, but can be quite costly to use to score large datasets. We have found that Flan-T5 offers a good trade-off of speed and correctness.
- 6:53
Airtrain was designed specifically for this purpose. With Airtrain, you can upload your dataset, select the models you want to compare, describe the properties you want to measure, and visualize metric distribution across your entire dataset.
- 7:07
You can compare Llama 2 with Falcon, Flan-T5, or even your own model. Then you can make an educated decision based on statistical evidence. Sign up today for early access at Airtrain.ai and start making data-driven decision about your choice of LLM.
- 7:24
Thanks. Goodbye. [upbeat music]