メインコンテンツへ移動

トーン一貫性 Scorer

createToneScorer() 関数は、テキストの感情的なトーンと Sentiment の一貫性を評価します。入出力ペア間のトーンを比較するモードと、単一テキスト内のトーンの安定性を分析するモードの2つで動作します。

パラメーター
パラメーターへの直接リンク

createToneScorer() 関数はオプションを受け取りません。

この関数は MastraScorer クラスのインスタンスを返します。.run() メソッドとその入出力の詳細は、MastraScorer リファレンスを参照してください。

.run() の戻り値
run-returnsへの直接リンク

runId:

string
Run の ID(任意)。

analyzeStepResult:

object
トーン指標を含むオブジェクト:{ responseSentiment: number, referenceSentiment: number, difference: number }(比較モード)または { avgSentiment: number, sentimentVariance: number }(安定性モード)

score:

number
トーンの一貫性/安定性スコア(0~1)。

.run() は次の形式の結果を返します。

{
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
analyzestepresultへの直接リンク

トーン指標を含むオブジェクトです。

  • responseSentiment:回答の Sentiment スコア(比較モード)。
  • referenceSentiment:入力/参照の Sentiment スコア(比較モード)。
  • difference:Sentiment スコア間の絶対差(比較モード)。
  • avgSentiment:文全体の Sentiment の平均(安定性モード)。
  • sentimentVariance:文全体の Sentiment の分散(安定性モード)。

使用例
使用例への直接リンク

関連する Agent の回答間でトーンの一貫性を評価します。

src/example-tone-consistency.ts
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 リファレンスを参照してください。

この Scorer を Agent に追加する方法は、Scorer の概要ガイドを参照してください。