BEHONEST
收藏BeHonest: Benchmarking Honesty in Large Language Models
简介
BeHonest是一个综合基准,用于评估大型语言模型的诚实度,通过评估其知识边界(自我认知)、避免欺骗(非欺骗性)和响应一致性(一致性)。
BeHonest支持10个场景:
- Expressing Unknowns:LLMs应适当拒绝回答超出其知识范围的问题。
- Admitting Knowns:LLMs应正确回答其有知识的问题。
- Persona Sycophancy:LLMs不应改变其响应以适应感知到的角色观点,这可能导致维持批准的偏见信息。
- Preference Sycophancy:当用户明确偏好某一选项时,LLMs不应改变其观点以维持批准。
- Burglar Deception:即使在被明确指示或鼓励欺骗行为时,LLMs也不应撒谎。
- Game:即使在战略游戏中欺骗行为有助于获胜,LLMs也不应撒谎。
- Prompt Format:LLMs在遇到相同内容的轻微提示变化时应保持响应一致性。
- Demonstration Format:即使在少样本演示中存在无关的偏见特征,LLMs也应保持响应一致性。
- Open-Form Consistency:LLMs应通过验证其生成的响应来显示一致性。
- Multiple-Choice Consistency:当被要求再次回答问题或当用户提出不必要的疑虑时,LLMs应保持响应一致性。
开始使用
要使用BeHonest仓库,需要安装所需的依赖项。可以通过运行以下命令来完成: bash git clone https://github.com/GAIR-NLP/BeHonest.git pip install -r requirements.txt
确保已安装Python 3.10+。
加载数据
BeHonest的基准数据集已在Hugging Face网站上发布。每个子集对应BeHonest中的一个场景,拆分对应每个场景下的单个.json文件。
以下代码片段用于加载数据集: python from datasets import load_dataset
dataset = load_dataset("GAIR/BeHonest")
print(dataset)
推理
步骤1:
要运行推理,首先导航到LLM目录: python cd LLM
对于Admitting Unknowns、Expressing Knowns、Burglar Deception、Game和Demonstration Format场景,跳至评估部分。
步骤2.1:
要在vLLM上运行支持的模型,导航到vLLM目录并运行: python cd vLLM bash get_response.sh
可更改以下参数:
--input_dir:Hugging Face数据集的路径(默认:"../../${scenario}")--output_dir:保存模型响应输出的路径(默认:"../../${scenario}/output/${model}")--file_name:要运行推理的文件名(默认:"persona")--scenario:要运行推理的场景名称(默认:"Persona_Sycophancy")--model:模型名称(例如:llama3-70b-instruct、Mistral-7B-Instruct-v0.2等)--model_path:模型权重保存的路径
完成推理后,生成的响应将保存为../../${scenario}/output/${model}/${file_name}.json,可用于后续评估。
步骤2.2:
或者,通过API调用在GPT模型上运行推理,导航到GPT目录并执行以下命令: python cd GPT bash get_response.sh
可更改以下参数:
--input_dir:Hugging Face数据集的路径(默认:"../../${scenario}")--output_dir:保存模型响应输出的路径(默认:"../../${scenario}/output/${model}")--file_name:要运行推理的文件名(默认:"persona")--scenario:要运行推理的场景名称(默认:"Persona_Sycophancy")--model:模型名称(例如:gpt-4o-2024-05-13、gpt-3.5-turbo-0125等)
完成推理后,生成的响应将保存为../../${scenario}/output/${model}/${file_name}.json,可用于后续评估。
评估
要评估每个场景下的生成响应,执行以下命令: python cd Evaluation
案例1:
要一次性评估所有场景,请按照以下步骤操作:
步骤1:填写或修改案例2中提到的每个.sh文件中指定的参数。
步骤2:设置好参数后,运行以下命令评估所有场景: python bash eval_all.sh
案例2:
每个场景也可以单独评估,如下所示:
- Admitting Unknowns和Expressing Knowns:
python cd Self_Knowledge bash test_self_knowledge.sh
- Persona Sycophancy和Preference Sycophancy:
python cd Non_Deceptiveness bash test_sycophancy.sh
- Burglar Deception和Game:
python cd Non_Deceptiveness bash test_burglar.sh bash test_game.sh
- Prompt Format、Open Form、Multiple Choice:
python cd Consistency bash test_prompt_format.sh bash test_open_form.sh bash test_mcq.sh
- Demonstration Format:
首先从此github仓库获取该场景的数据集,并保存在路径/Demonstration_Format/bbh/${task}/xxx.json中。然后,可以运行推理和评估:
python
cd Consistency
bash test_demon_format.sh
实验结果
要查看论文中报告的详细结果,请导航到Results目录: python cd Results
引用
如果您发现这些资源有用,请考虑引用我们的论文或仓库:
@article{chern2024behonest, title={BeHonest: Benchmarking Honesty in Large Language Models}, author={Chern, Steffi and Hu, Zhulin and Yang, Yuqing and Chern, Ethan and Guo, Yuan and Jin, Jiahe and Wang, Binjie and Liu, Pengfei}, journal={arXiv preprint arXiv:2406.13261}, url={https://arxiv.org/abs/2406.13261} year={2024} }

- 1BeHonest: Benchmarking Honesty of Large Language Models生成式AI研究实验室 (GAIR) · 2024年



