> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # テキスト差分スコアラー `createTextualDifferenceScorer()` 関数は、シーケンス照合を使って 2 つの文字列間のテキスト差分を測定します。あるテキストを別のテキストへ変換するために必要な操作数など、変更に関する詳細情報を提供します。 ## パラメーター `createTextualDifferenceScorer()` 関数はオプションを受け取りません。 この関数は MastraScorer クラスのインスタンスを返します。`.run()` メソッドとその入出力の詳細については、[MastraScorer リファレンス](https://mastra.zisheng.pro/ja/reference/evals/mastra-scorer)を参照してください。 ## `.run()` の戻り値 **runId** (`string`): 実行 ID(任意)。 **analyzeStepResult** (`object`): 差分指標を持つオブジェクト: { confidence: number, changes: number, lengthDiff: number } **score** (`number`): 類似度(0〜1)。1 はテキストが同一であることを示します。 `.run()` は次の形式の結果を返します。 ```typescript { runId: string, analyzeStepResult: { confidence: number, ratio: number, changes: number, lengthDiff: number }, score: number } ``` ## スコアリングの詳細 スコアラーは複数の指標を計算します。 - **類似度**: テキスト間のシーケンス照合に基づく値(0〜1) - **変更数**: 必要な不一致操作の数 - **長さの差**: テキストの長さの差を正規化した値 - **信頼度**: 長さの差に反比例する値 ### スコアリング処理 1. テキストの差分を分析します。 - 入力と出力の間でシーケンス照合を実行 - 必要な変更操作の数をカウント - 長さの差を測定 2. 指標を計算します。 - 類似度を計算 - 信頼度スコアを決定 - 重み付きスコアに統合 最終スコア: `(similarity_ratio * confidence) * scale` ### スコアの解釈 テキスト差分スコアは 0〜1 です。 - **1.0**: テキストは同一です。 - **0.7〜0.9**: わずかな違いがあり、必要な変更は少数です。 - **0.4〜0.6**: 中程度の違いがあり、明確な変更が必要です。 - **0.1〜0.3**: 大きな違いがあり、多数の変更が必要です。 - **0.0**: テキストはまったく異なります。 ## 例 期待される Agent の出力と実際の出力のテキスト差分を測定します。 ```typescript 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 リファレンス](https://mastra.zisheng.pro/ja/reference/evals/run-evals)を参照してください。 このスコアラーを Agent に追加する方法については、[スコアラーの概要](https://mastra.zisheng.pro/ja/docs/evals/overview)ガイドを参照してください。 ## 関連項目 - [コンテンツ類似度スコアラー](https://mastra.zisheng.pro/ja/reference/evals/content-similarity) - [完全性スコアラー](https://mastra.zisheng.pro/ja/reference/evals/completeness) - [キーワードカバレッジスコアラー](https://mastra.zisheng.pro/ja/reference/evals/keyword-coverage)