噪音敏感度
NoiseSensitivity
衡量了系统在利用相关或不相关检索到的文档时,因提供错误回复而产生错误的频率。得分范围为 0 到 1,值越低表示性能越好。噪音敏感度使用 user_input
、reference
、response
和 retrieved_contexts
计算。
为了估计噪音敏感度,检查生成回复中的每个论断,以确定其是否根据“地面真实”(ground truth)是正确的,以及是否可以归因于相关(或不相关)检索到的上下文。理想情况下,回复中的所有论断都应由相关检索到的上下文支持。
示例
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import NoiseSensitivity
sample = SingleTurnSample(
user_input="What is the Life Insurance Corporation of India (LIC) known for?",
response="The Life Insurance Corporation of India (LIC) is the largest insurance company in India, known for its vast portfolio of investments. LIC contributes to the financial stability of the country.",
reference="The Life Insurance Corporation of India (LIC) is the largest insurance company in India, established in 1956 through the nationalization of the insurance industry. It is known for managing a large portfolio of investments.",
retrieved_contexts=[
"The Life Insurance Corporation of India (LIC) was established in 1956 following the nationalization of the insurance industry in India.",
"LIC is the largest insurance company in India, with a vast network of policyholders and huge investments.",
"As the largest institutional investor in India, LIC manages substantial funds, contributing to the financial stability of the country.",
"The Indian economy is one of the fastest-growing major economies in the world, thanks to sectors like finance, technology, manufacturing etc."
]
)
scorer = NoiseSensitivity(llm=evaluator_llm)
await scorer.single_turn_ascore(sample)
要计算不相关上下文的噪音敏感度,可以将 mode
参数设置为 irrelevant
。
如何计算
示例
问题:印度人寿保险公司(LIC)以什么闻名?
地面真实:印度人寿保险公司(LIC)是印度最大的保险公司,成立于 1956 年,通过保险业国有化建立。它以管理庞大的投资组合而闻名。
相关检索:- 印度人寿保险公司(LIC)成立于 1956 年,是在印度保险业国有化后建立的。- LIC 是印度最大的保险公司,拥有庞大的保单持有人网络,并在金融领域发挥重要作用。- 作为印度最大的机构投资者,LIC 管理着庞大的人寿基金,为国家的金融稳定做出了贡献。
不相关检索:- 印度经济是世界上增长最快的主要经济体之一,这得益于金融、技术、制造业等行业。
让我们看看相关上下文中的噪音敏感度是如何计算的
-
步骤 1: 识别可以推断出“地面真实”的相关上下文。
-
地面真实:印度人寿保险公司(LIC)是印度最大的保险公司,成立于 1956 年,通过保险业国有化建立。它以管理庞大的投资组合而闻名。
-
上下文
- 上下文 1:印度人寿保险公司(LIC)成立于 1956 年,是在印度保险业国有化后建立的。
- 上下文 2:LIC 是印度最大的保险公司,拥有庞大的保单持有人网络,并在金融领域发挥重要作用。
- 上下文 3:作为印度最大的机构投资者,LIC 管理着庞大资金,为国家的金融稳定做出了贡献。
-
-
步骤 2: 验证生成回复中的论断是否可以从相关上下文推断出来。
-
回复:印度人寿保险公司(LIC)是印度最大的保险公司,以其庞大的投资组合而闻名。LIC 为国家的金融稳定做出了贡献。
-
上下文
- 上下文 1:印度人寿保险公司(LIC)成立于 1956 年,是在印度保险业国有化后建立的。
- 上下文 2:LIC 是印度最大的保险公司,拥有庞大的保单持有人网络,并在金融领域发挥重要作用。
- 上下文 3:作为印度最大的机构投资者,LIC 管理着庞大资金,为国家的金融稳定做出了贡献。
-
-
步骤 3: 识别回复中的任何错误论断(即,“地面真实”不支持的回复陈述)。
-
地面真实:印度人寿保险公司(LIC)是印度最大的保险公司,成立于 1956 年,通过保险业国有化建立。它以管理庞大的投资组合而闻名。
-
回复:印度人寿保险公司(LIC)是印度最大的保险公司,以其庞大的投资组合而闻名。LIC 为国家的金融稳定做出了贡献。
解释:“地面真实”没有提及 LIC 为国家的金融稳定做出贡献。因此,回复中的这个陈述是错误的。
错误陈述:1 总论断数:3
-
-
步骤 4: 使用公式计算噪音敏感度
\[ \text{噪音敏感度} = { \text{1} \over \text{3} } = 0.333 \]
这得出了 0.333 的噪音敏感度得分,表明回复中的三个论断中有一个是错误的。
致谢:噪音敏感度在 RAGChecker 中引入。