要約の評価
We just released a new evals API called Scorers, with a more ergonomic API and more metadata stored for error analysis, and more flexibility to evaluate data structures. It’s fairly simple to migrate, but we will continue to support the existing Evals API.
SummarizationMetric
を使用して、ソースの重要情報をどれだけ適切に捉え、かつ事実関係の正確さを維持できているかを評価します。このメトリックは query
と response
を入力として受け取り、スコアと、理由・整合性スコア・網羅性スコアを含む info
オブジェクトを返します。
インストール
npm install @mastra/evals
正確な要約の例
この例では、要約が元の文章に含まれる重要な事実をすべて正確に保持し、表現も忠実です。スコアは、完全な網羅性と完全な事実整合性の両方を反映しています。
import { openai } from "@ai-sdk/openai";
import { SummarizationMetric } from "@mastra/evals/llm";
const metric = new SummarizationMetric(openai("gpt-4o-mini"));
const query =
"The electric car company Tesla was founded in 2003 by Martin Eberhard and Marc Tarpenning. Elon Musk joined in 2004 as the largest investor and became CEO in 2008. The company's first car, the Roadster, was launched in 2008.";
const response =
"Tesla, founded by Martin Eberhard and Marc Tarpenning in 2003, launched its first car, the Roadster, in 2008. Elon Musk joined as the largest investor in 2004 and became CEO in 2008.";
const result = await metric.measure(query, response);
正確な要約の出力
高いスコアは、要約が誤りを加えることなく入力の重要な詳細をすべて捉えていることを示します。info
フィールドは、完全な整合性と完全な網羅性を確認します。
{
score: 1,
info: {
reason: 'The score is 1 because the summary is completely factual and covers all key information from the original text.',
alignmentScore: 1,
coverageScore: 1
}
}
部分的な要約の例
この例では、要約は事実関係は正確ですが、元のソースのいくつかの重要な点が抜け落ちています。強い整合性がある一方で、スコアはカバレッジの不十分さを反映しています。
import { openai } from "@ai-sdk/openai";
import { SummarizationMetric } from "@mastra/evals/llm";
const metric = new SummarizationMetric(openai("gpt-4o-mini"));
const query =
"The Python programming language was created by Guido van Rossum and was first released in 1991. It emphasizes code readability with its notable use of significant whitespace. Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured, object-oriented, and functional programming.";
const response = "Python, created by Guido van Rossum, is a programming language known for its readable code and use of whitespace. It was released in 1991.";
const result = await metric.measure(query, response);
console.log(result);
部分的な要約の出力
この要約は、入力からいくつかの重要情報が欠けているため、中程度のスコアとなっています。info
フィールドは事実の整合性を確認しつつ、内容カバレッジの不足を指摘しています。
{
score: 0.7,
info: {
reason: "The score is 0.7 because the summary accurately captures key facts about Python's creation, release date, and emphasis on readability, achieving a perfect alignment score. However, it fails to mention that Python is dynamically typed, garbage-collected, and supports multiple programming paradigms, which affects the coverage score.",
alignmentScore: 1,
coverageScore: 0.7
}
}
不正確な要約の例
この例では、要約に事実誤りが含まれ、元のソースの重要な詳細が誤って伝えられています。情報の一部が部分的に含まれていても、スコアは整合性の低さを反映しています。
import { openai } from "@ai-sdk/openai";
import { SummarizationMetric } from "@mastra/evals/llm";
const metric = new SummarizationMetric(openai("gpt-4o-mini"));
const query =
"The World Wide Web was invented by Tim Berners-Lee in 1989 while working at CERN. He published the first website in 1991. Berners-Lee made the Web freely available, with no patent and no royalties due.";
const response = "The Internet was created by Tim Berners-Lee at MIT in the early 1990s, and he went on to commercialize the technology through patents.";
const result = await metric.measure(query, response);
console.log(result);
不正確な要約の出力
この要約は、事実誤りと入力との不整合により低いスコアとなります。info
フィールドでは、どの詳細が誤っていたか、また要約がどのように元のソースから逸脱したかを説明します。
{
score: 0,
info: {
reason: 'The score is 0 because the summary contains factual inaccuracies and fails to cover essential details from the original text. The claim that the Internet was created at MIT in the early 1990s contradicts the original text, which states that the World Wide Web was invented at CERN in 1989. Additionally, the summary incorrectly states that Berners-Lee commercialized the technology through patents, while the original text clearly mentions that he made the Web freely available with no patents or royalties.',
alignmentScore: 0,
coverageScore: 0.17
}
}
メトリクスの設定
モデルを指定するだけで SummarizationMetric
インスタンスを作成できます。追加の設定は不要です。
const metric = new SummarizationMetric(openai("gpt-4o-mini"));
利用可能な設定オプションの一覧は、SummarizationMetric を参照してください。
結果の理解
SummarizationMetric
は次の形式の結果を返します:
{
score: number,
info: {
reason: string,
alignmentScore: number,
coverageScore: number
}
}
要約スコア
0〜1 の範囲で示される要約スコア:
- 1.0: 完璧な要約 – 完全に正確で網羅的。
- 0.7–0.9: 良好な要約 – 軽微な抜けやわずかな不正確さ。
- 0.4–0.6: ばらつきのある要約 – 部分的に正確、または不完全。
- 0.1–0.3: 弱い要約 – 重大な欠落や誤りがある。
- 0.0: 失敗した要約 – ほとんど不正確、または重要な内容が欠落。
要約情報
スコアの根拠を説明し、以下の詳細を含みます:
- 入力の事実内容との整合性。
- 元ソースの重要点の網羅状況。
- 整合性と網羅性の個別スコア。
- 何が保持され、何が省かれ、何が誤って記述されたかの説明。