78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
|
|
// metric_presenter.js — 统一维护指标语义(高分好 / 低分好)、颜色阈值与简要说明。
|
||
|
|
|
||
|
|
(function attachMetricPresenter(globalObj) {
|
||
|
|
const METRIC_META = {
|
||
|
|
faithfulness: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "回答是否被检索内容直接支持,越高越可靠。",
|
||
|
|
},
|
||
|
|
answer_relevancy: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "回答与问题是否紧密相关,越高越切题。",
|
||
|
|
},
|
||
|
|
context_recall: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "检索片段覆盖标准答案关键信息的程度,越高越完整。",
|
||
|
|
},
|
||
|
|
context_precision: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "检索片段中有效信息的占比,越高越精准。",
|
||
|
|
},
|
||
|
|
noise_sensitivity: {
|
||
|
|
direction: "lower_better",
|
||
|
|
description: "对噪声上下文的敏感程度,越低说明抗干扰能力越强。",
|
||
|
|
},
|
||
|
|
factual_correctness: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "回答与标准答案在事实层面的吻合程度,越高越准确。",
|
||
|
|
},
|
||
|
|
semantic_similarity: {
|
||
|
|
direction: "higher_better",
|
||
|
|
description: "回答与标准答案在语义上的相似程度,越高越接近。",
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
function isLowerBetter(metricName) {
|
||
|
|
return METRIC_META[metricName]?.direction === "lower_better";
|
||
|
|
}
|
||
|
|
|
||
|
|
function scoreClass(metricName, value) {
|
||
|
|
if (value === null || value === undefined || Number.isNaN(Number(value))) return "na";
|
||
|
|
const numeric = Number(value);
|
||
|
|
if (isLowerBetter(metricName)) {
|
||
|
|
if (numeric <= 0.15) return "good";
|
||
|
|
if (numeric <= 0.35) return "warn";
|
||
|
|
return "bad";
|
||
|
|
}
|
||
|
|
if (numeric >= 0.85) return "good";
|
||
|
|
if (numeric >= 0.65) return "warn";
|
||
|
|
return "bad";
|
||
|
|
}
|
||
|
|
|
||
|
|
function describeMetric(metricName) {
|
||
|
|
return METRIC_META[metricName]?.description || "该指标用于衡量当前问答样本的评估表现。";
|
||
|
|
}
|
||
|
|
|
||
|
|
function binColor(metricName, lower) {
|
||
|
|
const numeric = Number(lower);
|
||
|
|
if (isLowerBetter(metricName)) {
|
||
|
|
if (numeric < 0.2) return "#16a34a";
|
||
|
|
if (numeric < 0.4) return "#84cc16";
|
||
|
|
if (numeric < 0.6) return "#eab308";
|
||
|
|
if (numeric < 0.8) return "#f97316";
|
||
|
|
return "#dc2626";
|
||
|
|
}
|
||
|
|
if (numeric >= 0.8) return "#16a34a";
|
||
|
|
if (numeric >= 0.6) return "#84cc16";
|
||
|
|
if (numeric >= 0.4) return "#eab308";
|
||
|
|
if (numeric >= 0.2) return "#f97316";
|
||
|
|
return "#dc2626";
|
||
|
|
}
|
||
|
|
|
||
|
|
globalObj.MetricPresenter = {
|
||
|
|
scoreClass,
|
||
|
|
describeMetric,
|
||
|
|
binColor,
|
||
|
|
};
|
||
|
|
})(window);
|