テキスト差分スコアラー
createTextualDifferenceScorer() 関数は、シーケンス照合を使って 2 つの文字列間のテキスト差分を測定します。あるテキストを別のテキストへ変換するために必要な操作数など、変更に関する詳細情報を提供します。
パラメーターパラメーターへの直接リンク
createTextualDifferenceScorer() 関数はオプションを受け取りません。
この関数は MastraScorer クラスのインスタンスを返します。.run() メソッドとその入出力の詳細については、MastraScorer リファレンスを参照してください。
.run() の戻り値run-returnsへの直接リンク
runId:
string
実行 ID(任意)。
analyzeStepResult:
object
差分指標を持つオブジェクト: { confidence: number, changes: number, lengthDiff: number }
score:
number
類似度(0〜1)。1 はテキストが同一であることを示します。
.run() は次の形式の結果を返します。
{
runId: string,
analyzeStepResult: {
confidence: number,
ratio: number,
changes: number,
lengthDiff: number
},
score: number
}
スコアリングの詳細スコアリングの詳細への直接リンク
スコアラーは複数の指標を計算します。
- 類似度: テキスト間のシーケンス照合に基づく値(0〜1)
- 変更数: 必要な不一致操作の数
- 長さの差: テキストの長さの差を正規化した値
- 信頼度: 長さの差に反比例する値
スコアリング処理スコアリング処理への直接リンク
- テキストの差分を分析します。
- 入力と出力の間でシーケンス照合を実行
- 必要な変更操作の数をカウント
- 長さの差を測定
- 指標を計算します。
- 類似度を計算
- 信頼度スコアを決定
- 重み付きスコアに統合
最終スコア: (similarity_ratio * confidence) * scale
スコアの解釈スコアの解釈への直接リンク
テキスト差分スコアは 0〜1 です。
- 1.0: テキストは同一です。
- 0.7〜0.9: わずかな違いがあり、必要な変更は少数です。
- 0.4〜0.6: 中程度の違いがあり、明確な変更が必要です。
- 0.1〜0.3: 大きな違いがあり、多数の変更が必要です。
- 0.0: テキストはまったく異なります。
例例への直接リンク
期待される Agent の出力と実際の出力のテキスト差分を測定します。
src/example-textual-difference.ts
import { runEvals } from '@mastra/core/evals'
import { createTextualDifferenceScorer } from '@mastra/evals/scorers/prebuilt'
import { myAgent } from './agent'
const scorer = createTextualDifferenceScorer()
const result = await runEvals({
data: [
{
input: 'Summarize the concept of recursion',
groundTruth:
'Recursion is when a function calls itself to solve a problem by breaking it into smaller subproblems.',
},
{
input: 'What is the capital of France?',
groundTruth: 'The capital of France is Paris.',
},
],
scorers: [scorer],
target: myAgent,
onItemComplete: ({ scorerResults }) => {
console.log({
score: scorerResults[scorer.id].score,
groundTruth: scorerResults[scorer.id].groundTruth,
})
},
})
console.log(result.scores)
runEvals の詳細については、runEvals リファレンスを参照してください。
このスコアラーを Agent に追加する方法については、スコアラーの概要ガイドを参照してください。