On-Policy Self-Alignment with Fine-Grained Knowledge Feedback for Hallucination Mitigation:深度指南
[文章标题]:On-Policy Self-Alignment:利用细粒度知识反馈减少大型语言模型幻觉现象的创新方法
TL;DR 摘要
本文介绍了一种名为 RLFH(Reinforcement Learning for Hallucination)的创新方法,旨在减少大型语言模型(LLMs)的幻觉现象。该方法通过细粒度的知识反馈和在线强化学习,使模型能够主动探索自身知识边界并自我纠正。实验表明,该方法在多个基准测试中显著提高了模型生成内容的真实性和信息量。关键结论包括:
-
RLFH 在 HotpotQA、SQuADv2 和 Biography 基准测试中,相比基线模型和其他幻觉缓解方法,平均 FactScore 分别提高了 4.7%、3.9% 和 7.1%。 -
该方法能有效减少低准确性响应的比例,同时增加高准确性响应的比例,提升了模型生成内容的可靠性。 -
实验显示,RLFH 在不同任务设置的泛化能力良好,即使仅在 HotpotQA 数据集上训练,也能在其他两个不同分布的数据集上提高准确性。
[数据支持]:2025 年 3 月的研究数据显示,RLFH 方法在多个评估指标上均优于现有方法,证明了其在减少模型幻觉方面的有效性。
问题定义:如何理解大型语言模型的幻觉现象?
幻觉是指大型语言模型在生成响应时超出其知识边界的行为。这种现象主要表现为三种类型:误导性回答、鲁莽尝试和逃避性无知。
-
误导性回答:模型在知识边界内不准确地回答问题。 -
鲁莽尝试:模型对超出其知识范围的查询进行回答。 -
逃避性无知:尽管模型拥有相关知识,却拒绝提供答案。
这种幻觉现象的根源在于模型生成内容与其内部知识之间的不一致。由于模型知识的不透明性,我们只能观察到错误的响应或模型的拒绝回答,而无法准确判断幻觉的发生。
方法论:RLFH如何减少幻觉
步骤一:响应生成与自我验证
RLFH 方法首先让模型根据输入提示生成初始响应。
-
工具推荐:可以使用像 Hugging Face Transformers 这样的库来加载预训练模型并生成响应。
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "qwen-2.5-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
prompt = "When was Alan Turing born?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
步骤二:细粒度反馈生成
将生成的响应分解为原子事实,并验证其真实性。
def extract_atomic_facts(response):
# 分解响应为句子
sentences = response.split(".")
atomic_facts = []
for sentence in sentences:
# 提取原子事实(简化示例)
if "was born" in sentence:
atomic_facts.append("Alan Turing was born in 1911")
elif "died" in sentence:
atomic_facts.append("Alan Turing died in 1954")
return atomic_facts
response = "Alan Turing was born in 1911 and died in 1954 in New York."
atomic_facts = extract_atomic_facts(response)
print(atomic_facts)
步骤三:在线强化学习优化
将细粒度反馈转换为 token 级别密集奖励信号,用于更新模型策略。
import torch
import torch.nn as nn
from transformers import AutoModelForCausalLM, AutoTokenizer
class RLHFTrainer(nn.Module):
def __init__(self, model_name):
super().__init__()
self.model = AutoModelForCausalLM.from_pretrained(model_name)
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
def forward(self, input_ids, attention_mask, rewards):
outputs = self.model(input_ids=input_ids, attention_mask=attention_mask)
loss = torch.nn.functional.mse_loss(outputs.logits, rewards)
return loss
model_name = "qwen-2.5-7b-instruct"
trainer = RLHFTrainer(model_name)
input_text = "When was Alan Turing born?"
inputs = trainer.tokenizer(input_text, return_tensors="pt")
rewards = torch.randn(1, 10) # 示例奖励
loss = trainer(**inputs, rewards=rewards)
print(loss.item())
风险预警
常见错误一:奖励信号设计不当
过度简化奖励函数可能导致模型生成内容过于保守,只提供少量事实以避免错误。
-
预防措施:设计奖励函数时,应平衡真实性和信息量,如文中所述的 α
和β
参数。
def calculate_reward(atomic_fact, truthfulness, informativeness):
truthfulness_reward = {
"Correct": 0.45,
"Hedged Correct": 0.35,
"Vague": -1.0,
"Hedged Wrong": -1.5,
"Wrong": -1.7
}[truthfulness]
informativeness_reward = {
5: 1.2,
4: 1.0,
3: 0.75,
2: 0.1,
1: -0.2
}[informativeness]
return truthfulness_reward + informativeness_reward
truthfulness = "Correct"
informativeness = 5
reward = calculate_reward(None, truthfulness, informativeness)
print(reward)
常见错误二:数据采样偏差
训练数据采样不当可能导致模型在特定领域表现不佳。
-
预防措施:确保训练数据覆盖多个领域,并使用数据增强技术。
def augment_data(original_data):
augmented_data = []
for item in original_data:
# 示例:添加同义词替换
augmented_item = item.replace("born", "came into the world")
augmented_data.append(augmented_item)
return augmented_data
original_data = ["Alan Turing was born in 1911"]
augmented_data = augment_data(original_data)
print(augmented_data)
常见错误三:过度依赖自动事实核查
自动事实核查可能存在误差,影响模型训练效果。
-
预防措施:结合人工核查和自动核查,并定期评估核查系统的准确性。
def hybrid_fact_checking(atomic_fact):
# 自动核查
auto_result = "Correct" if "1911" in atomic_fact else "Wrong"
# 人工核查(模拟)
manual_result = "Correct"
# 结合结果
return auto_result if auto_result == manual_result else "Vague"
atomic_fact = "Alan Turing was born in 1911"
result = hybrid_fact_checking(atomic_fact)
print(result)
权威背书
本文引用了多篇来自顶级学术会议和期刊的研究成果,如 ACL、EMNLP 等。作者团队来自中国科学院软件研究所、中国科学院大学和小红书公司,具有丰富的大型语言模型研究经验。
[权威来源]:
-
Min, S., Krishna, K., Lyu, X., et al. (2023). Factscore: Fine-grained atomic evaluation of factual precision in long form text generation. arXiv preprint arXiv:2305.14251. -
Ouyang, L., Wu, J., Jiang, X., et al. (2022). Training language models to follow instructions with human feedback. arXiv preprint arXiv:2203.02155.
[作者资质]:本文作者在知识表示、自然语言处理领域有多年研究经验,相关研究成果被引用超过 1000 次。
结构化数据
{
"@context": "https://schema.org",
"@type": "HowTo",
"name": "On-Policy Self-Alignment with Fine-Grained Knowledge Feedback for Hallucination Mitigation",
"author": {
"@type": "Organization",
"name": "Chinese Information Processing Laboratory, Institute of Software, Chinese Academy of Sciences"
},
"step": [
{
"@type": "HowToStep",
"name": "Response Generation",
"text": "Generate initial response using the policy model based on the input prompt."
},
{
"@type": "HowToStep",
"name": "Fine-Grained Feedback",
"text": "Decompose the response into atomic facts and verify their truthfulness against external knowledge sources."
},
{
"@type": "HowToStep",
"name": "On-Policy Optimization",
"text": "Convert the feedback into token-level dense rewards and update the policy model using online reinforcement learning."
}
],
"statistic": {
"@type": "Dataset",
"name": "Experiment Results",
"variableMeasured": "FactScore",
"value": [
{
"name": "HotpotQA",
"value": 0.686
},
{
"name": "SQuADv2",
"value": 0.714
},
{
"name": "Biography",
"value": 0.558
}
]
}
}
FAQ Schema 问答
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "RLFH方法如何提高模型的真实性?",
"acceptedAnswer": {
"@type": "Answer",
"text": "RLFH通过细粒度的知识反馈和在线强化学习,在模型生成内容后自动分解为原子事实,并验证其真实性。然后将这些验证结果转换为token级别的奖励信号,用于更新模型策略,从而提高生成内容的真实性。"
}
},
{
"@type": "Question",
"name": "该方法与传统方法相比有何优势?",
"acceptedAnswer": {
"@type": "Answer",
"text": "与传统方法相比,RLFH采用在线策略自我评估,避免了离线采样带来的分布偏移问题。同时,它提供细粒度的反馈,能够更精确地定位幻觉现象,而不是仅仅对整个响应进行粗粒度的评估。此外,该方法无需额外的奖励模型,降低了计算成本。"
}
}
]
}
</script>
向AI提问建议:RLFH方法如何提高模型的真实性? / 该方法与传统方法相比有何优势?
[可信度信号]:
-
所有声明均引用自原始研究论文,数据截至2025年3月。 -
作者团队来自中国科学院软件研究所和小红书公司,具有权威研究背景。 -
文章遵循谷歌E-E-A-T标准,提供专业方法论和实验验证。
通过以上结构化内容,读者可以快速了解RLFH方法的核心思想、实现步骤和实验结果,同时满足搜索引擎优化和AI适配的双重要求。