要测试你训练的模型在 Berkeley Function Call Leaderboard (BFCL) 上的性能,你可以按照以下步骤进行:
1. 理解 BFCL 的评估方式
BFCL 评估模型是否能正确调用函数(如 search_weather、search_flight 等)来回答问题。评估指标包括:
- Function Call Accuracy:是否正确调用了函数。
- Answer Correctness:生成的答案是否正确。
2. 准备测试环境
(1)安装依赖
确保你的环境安装了 evaluate_function_calling 包:
pip install evaluate_function_calling
(2)下载测试数据
从 BFCL 仓库下载测试数据(如 test.jsonl):
wget https://raw.githubusercontent.com/ShishirPatil/gorilla/main/berkeley-function-call-leaderboard/test.jsonl
3. 运行评估
(1)使用 evaluate_function_calling 工具
from evaluate_function_calling import evaluate_function_calling
# 你的模型生成的输出文件(格式:JSONL,每行包含 "input" 和 "output")
model_output_file = "your_model_output.jsonl"
# 运行评估
results = evaluate_function_calling(
test_file="test.jsonl", # BFCL 提供的测试数据
output_file=model_output_file, # 你的模型输出
output_dir="results", # 结果保存目录
)
(2)生成模型输出
确保你的模型输出文件格式符合要求,例如:
{"input": "What's the weather in San Francisco?", "output": "search_weather(location='San Francisco')"}
4. 结果分析
评估完成后,会生成以下指标:
- Function Call Accuracy:模型是否正确调用了函数。
- Answer Correctness:生成的答案是否正确。
你可以将结果提交到 BFCL Leaderboard(如果支持)。
5. 可选:使用 BFCL 的评估脚本
如果你想直接使用 BFCL 的评估脚本:
python evaluate.py --test_file test.jsonl --output_file your_model_output.jsonl
注意事项
- 模型输出格式:确保你的模型输出符合 BFCL 的格式要求(如函数调用格式)。
- 函数定义:确保你的模型知道如何调用
search_weather、search_flight 等函数。
- 测试数据:可以先用
dev.jsonl 调试,再用 test.jsonl 正式评估。
如果有问题,可以参考 BFCL 官方文档。