🚀 幻觉检测PEFT适配器模型
本仓库包含我们用于幻觉评估的PEFT适配器模型。该模型旨在检测语言模型输出中的幻觉现象,通过二分类任务评估模型是否产生了与事实不符或无意义的输出。
🚀 快速开始
幻觉检测指标
我们的合并模型在检测语言模型输出幻觉的二分类任务中取得了以下性能:
precision recall f1-score support
0 0.85 0.71 0.77 100
1 0.75 0.87 0.81 100
accuracy 0.79 200
macro avg 0.80 0.79 0.79 200
weighted avg 0.80 0.79 0.79 200
模型使用
为获得最佳效果,我们建议从以下提示策略开始(并鼓励根据需要进行调整):
def format_input(reference, query, response):
prompt = f"""Your job is to evaluate whether a machine learning model has hallucinated or not.
A hallucination occurs when the response is coherent but factually incorrect or nonsensical
outputs that are not grounded in the provided context.
You are given the following information:
####INFO####
[Knowledge]: {reference}
[User Input]: {query}
[Model Response]: {response}
####END INFO####
Based on the information provided is the model output a hallucination? Respond with only "yes" or "no"
"""
return input
text = format_input(query='Based on the follwoing <context>Walrus are the largest mammal</context> answer the question <query> What is the best PC?</query>',
response='The best PC is the mac')
messages = [
{"role": "user", "content": text}
]
pipe = pipeline(
"text-generation",
model=base_model,
model_kwargs={"attn_implementation": attn_implementation, "torch_dtype": torch.float16},
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 2,
"return_full_text": False,
"temperature": 0.01,
"do_sample": True,
}
output = pipe(messages, **generation_args)
print(f'Hallucination: {output[0]["generated_text"].strip().lower()}')
与其他模型的比较
我们将合并模型在幻觉检测基准上的性能与其他几个最先进的语言模型进行了比较:
模型 |
精确率 |
召回率 |
F1分数 |
我们的合并模型 |
0.75 |
0.87 |
0.81 |
GPT - 4 |
0.93 |
0.72 |
0.82 |
GPT - 4 Turbo |
0.97 |
0.70 |
0.81 |
Gemini Pro |
0.89 |
0.53 |
0.67 |
GPT - 3.5 |
0.89 |
0.65 |
0.75 |
GPT - 3.5 - turbo - instruct |
0.89 |
0.80 |
0.84 |
Palm 2 (Text Bison) |
1.00 |
0.44 |
0.61 |
Claude V2 |
0.80 |
0.95 |
0.87 |
如表所示,我们的合并模型在幻觉检测任务中取得了0.81的F1分数,优于其他几个最先进的语言模型。
我们将继续改进和微调合并模型,以在各种基准和任务中实现更好的性能。
引用
分数来自arize/phoenix
📚 详细文档
训练数据
本模型的训练数据引用自以下文献:
@misc{HaluEval,
author = {Junyi Li and Xiaoxue Cheng and Wayne Xin Zhao and Jian - Yun Nie and Ji - Rong Wen },
title = {HaluEval: A Large - Scale Hallucination Evaluation Benchmark for Large Language Models},
year = {2023},
journal={arXiv preprint arXiv:2305.11747},
url={https://arxiv.org/abs/2305.11747}
}
框架版本
- PEFT 0.11.1
- Transformers 4.41.2
- Pytorch 2.3.0+cu121
- Datasets 2.19.2
- Tokenizers 0.19.1
训练超参数
训练期间使用了以下超参数:
- 学习率:0.0001
- 训练批次大小:2
- 评估批次大小:8
- 随机种子:42
- 梯度累积步数:4
- 总训练批次大小:8
- 优化器:Adam(β1 = 0.9,β2 = 0.999,ε = 1e - 08)
- 学习率调度器类型:线性
- 学习率调度器热身步数:10
- 训练步数:150
📄 许可证
本项目采用MIT许可证。