トーン一貫性の評価
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.
ToneConsistencyMetric
を使用して、テキスト内の感情トーンのパターンと感情の一貫性を評価します。メトリクスは query
と response
を受け取り、スコアと、感情スコアおよびその差分を含む info
オブジェクトを返します。
インストール
npm install @mastra/evals
ポジティブなトーンの例
この例では、両方のテキストが似たポジティブな感情を示しています。メトリクスはトーンの一貫性を評価し、その結果として高いスコアになります。
import { ToneConsistencyMetric } from "@mastra/evals/nlp";
const metric = new ToneConsistencyMetric();
const query = "This product is fantastic and amazing!";
const response = "The product is excellent and wonderful!";
const result = await metric.measure(query, response);
console.log(result);
ポジティブなトーンの出力
このメトリクスは、感情の強い整合性を反映した高いスコアを返します。info
フィールドには感情値とその差分が示されます。
{
score: 0.8333333333333335,
info: {
responseSentiment: 1.3333333333333333,
referenceSentiment: 1.1666666666666667,
difference: 0.16666666666666652
}
}
安定したトーンの例
この例では、空のレスポンスを渡してテキスト内のトーンの一貫性を解析します。これにより、メトリックは単一の入力テキストにおける感情の安定性を評価し、テキスト全体を通じてトーンがどれほど均一かを示すスコアを算出します。
import { ToneConsistencyMetric } from "@mastra/evals/nlp";
const metric = new ToneConsistencyMetric();
const query = "Great service! Friendly staff. Perfect atmosphere.";
const response = "";
const result = await metric.measure(query, response);
console.log(result);
安定したトーンの出力
このメトリックは、入力テキスト全体で感情が一貫していることを示す高いスコアを返します。info
フィールドには平均感情と感情の分散が含まれ、トーンの安定性を反映します。
{
score: 0.9444444444444444,
info: {
avgSentiment: 1.3333333333333333,
sentimentVariance: 0.05555555555555556
}
}
トーンが混在する例
この例では、入力と応答の感情的なトーンが異なります。メトリクスはこうした違いを検知し、一貫性スコアを低く評価します。
import { ToneConsistencyMetric } from "@mastra/evals/nlp";
const metric = new ToneConsistencyMetric();
const query = "The interface is frustrating and confusing, though it has potential.";
const response = "The design shows promise but needs significant improvements to be usable.";
const result = await metric.measure(query, response);
console.log(result);
混在トーンの出力
感情的トーンに顕著な差があるため、メトリクスは低いスコアを返します。info
フィールドには、センチメントの値とそれらの差の大きさが示されます。
{
score: 0.4181818181818182,
info: {
responseSentiment: -0.4,
referenceSentiment: 0.18181818181818182,
difference: 0.5818181818181818
}
}
メトリクスの設定
ToneConsistencyMetric
インスタンスはデフォルト設定で作成できます。追加の設定は不要です。
const metric = new ToneConsistencyMetric();
設定オプションの詳細は ToneConsistencyMetric を参照してください。
結果の理解
ToneConsistencyMetric
は次の形式の結果を返します:
{
score: number,
info: {
responseSentiment?: number,
referenceSentiment?: number,
difference?: number,
avgSentiment?: number,
sentimentVariance?: number
}
}
トーン一貫性スコア
0〜1 の範囲のトーン一貫性スコア:
- 0.8–1.0: 非常に一貫したトーン。
- 0.6–0.7: おおむね一貫したトーン。
- 0.4–0.5: トーンにばらつきがある。
- 0.0–0.3: トーンが食い違っている。
トーン一貫性に関する情報
スコアの説明(以下を含む):
- 入力と応答の感情極性の整合性。
- 単一テキスト内におけるトーンの安定性。
- 感情極性の差異または分散の程度。