> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # トーン一貫性 Scorer `createToneScorer()` 関数は、テキストの感情的なトーンと Sentiment の一貫性を評価します。入出力ペア間のトーンを比較するモードと、単一テキスト内のトーンの安定性を分析するモードの2つで動作します。 ## パラメーター `createToneScorer()` 関数はオプションを受け取りません。 この関数は MastraScorer クラスのインスタンスを返します。`.run()` メソッドとその入出力の詳細は、[MastraScorer リファレンス](https://mastra.zisheng.pro/ja/reference/evals/mastra-scorer)を参照してください。 ## `.run()` の戻り値 **runId** (`string`): Run の ID(任意)。 **analyzeStepResult** (`object`): トーン指標を含むオブジェクト:{ responseSentiment: number, referenceSentiment: number, difference: number }(比較モード)または { avgSentiment: number, sentimentVariance: number }(安定性モード) **score** (`number`): トーンの一貫性/安定性スコア(0~1)。 `.run()` は次の形式の結果を返します。 ```typescript { runId: string, analyzeStepResult: { responseSentiment?: number, referenceSentiment?: number, difference?: number, avgSentiment?: number, sentimentVariance?: number, }, score: number } ``` ## スコアリングの詳細 Scorer は、トーンパターンの分析とモード固有のスコアリングによって Sentiment の一貫性を評価します。 ### スコアリング処理 1. トーンパターンを分析します。 - Sentiment の特徴を抽出します - Sentiment スコアを計算します - トーンの変動を測定します 2. モード固有のスコアを計算します。 **トーンの一貫性**(入力と出力): - テキスト間の Sentiment を比較します - Sentiment の差を計算します - スコア = 1 - (sentiment\_difference / max\_difference) **トーンの安定性**(単一入力): - 文ごとの Sentiment を分析します - Sentiment の分散を計算します - スコア = 1 - (sentiment\_variance / max\_variance) 最終スコア:`mode_specific_score * scale` ### スコアの解釈 (0~scale、デフォルトは 0~1) - 1.0:トーンの一貫性/安定性が完全 - 0.7~0.9:軽微な変動はあるが、一貫性が高い - 0.4~0.6:目立つ変化があり、一貫性は中程度 - 0.1~0.3:トーンが大きく変化し、一貫性が低い - 0.0:一貫性がなく、トーンが完全に異なる ### `analyzeStepResult` トーン指標を含むオブジェクトです。 - **responseSentiment**:回答の Sentiment スコア(比較モード)。 - **referenceSentiment**:入力/参照の Sentiment スコア(比較モード)。 - **difference**:Sentiment スコア間の絶対差(比較モード)。 - **avgSentiment**:文全体の Sentiment の平均(安定性モード)。 - **sentimentVariance**:文全体の Sentiment の分散(安定性モード)。 ## 使用例 関連する Agent の回答間でトーンの一貫性を評価します。 ```typescript import { runEvals } from '@mastra/core/evals' import { createToneScorer } from '@mastra/evals/scorers/prebuilt' import { myAgent } from './agent' const scorer = createToneScorer() const result = await runEvals({ data: [ { input: 'How was your experience with our service?', groundTruth: 'The service was excellent and exceeded expectations!', }, { input: 'Tell me about the customer support', groundTruth: 'The support team was friendly and very helpful.', }, ], scorers: [scorer], target: myAgent, onItemComplete: ({ scorerResults }) => { console.log({ score: scorerResults[scorer.id].score, }) }, }) console.log(result.scores) ``` `runEvals` の詳細は、[runEvals リファレンス](https://mastra.zisheng.pro/ja/reference/evals/run-evals)を参照してください。 この Scorer を Agent に追加する方法は、[Scorer の概要](https://mastra.zisheng.pro/ja/docs/evals/overview)ガイドを参照してください。 ## 関連項目 - [コンテンツ類似度 Scorer](https://mastra.zisheng.pro/ja/reference/evals/content-similarity) - [毒性 Scorer](https://mastra.zisheng.pro/ja/reference/evals/toxicity)