微信扫码
添加专属顾问
我要投稿
BigCodeBench 为每个任务提供了复杂且以用户为中心的指导,包括清晰的功能描述、输入/输出格式、错误处理以及经过验证的交互示例。该平台避免使用逐步任务指导,相信有能力的 LLMs 应该能够从用户的角度以开放式的方式理解和解决任务。通过测试用例来验证特定功能。
# We elaborate the above task with some test cases:# Requirements SetUpimport unittestfrom unittest.mock import patchimport http.clientimport sslimport socket# Start the testclass TestCases(unittest.TestCase):# Mock the successful connection and assess the response content@patch('http.client.HTTPSConnection')def test_response_content(self, mock_conn):""" Test the content of the response. """mock_conn.return_value.getresponse.return_value.read.return_value = b'Expected Content'result = task_func('www.example.com', 443, '/content/path')self.assertEqual(result, 'Expected Content')# Mock the failed connection and assess the error handling@patch('socket.create_connection')@patch('http.client.HTTPSConnection')def test_ssl_handshake_error_handling(self, mock_conn, mock_socket):""" Test handling of SSL handshake errors. """mock_socket.side_effect = ssl.SSLError('SSL handshake failed')with self.assertRaises(ssl.SSLError):task_func('badssl.com', 443, '/test/path')# More test cases...
为了深入理解实现的复杂性以及工具使用的多样性,BigCodeBench 与包括 APPS、DS-1000、ODEX、APIBench、MBPP、NumpyEval、PandasEval、HumanEval 和 TorchDataEval 等代表性基准测试中的任务进行了比较。结果显示,BigCodeBench 在实现全面功能方面需要更复杂的推理和问题解决能力。
如图中所示的任务,主要目标场景是代码补全(标记为 BigCodeBench-Complete),在此场景中,LLMs 需要根据文档字符串中详细的指令完成函数的实现。然而,考虑到下游应用,例如多轮对话,用户可能会以更会话化、更简洁的方式描述需求。这正是经过指令调整的 LLMs 显示出优势的地方,因为它们被训练以遵循自然语言指令并相应生成代码片段。为了测试模型是否真正理解人类的意图并将其转化为代码,我们创建了 BigCodeBench-Instruct,这是一个更具挑战性的 BigCodeBench 变体,旨在评估经过指令调整的 LLMs。
开始之前,请先设置环境:
# Install to use bigcodebench.evaluatepip install bigcodebench --upgrade# If you want to use the evaluate locally, you need to install the requirementspip install -I -r https://raw.githubusercontent.com/bigcode-project/bigcodebench/main/Requirements/requirements-eval.txt# Install to use bigcodebench.generate# You are strongly recommended to install the generate dependencies in a separate environmentpip install bigcodebench[generate] --upgrade
建议使用flash-attn来生成代码示例。
pip install -U flash-attn
要从模型生成代码示例,可以使用以下命令:
bigcodebench.generate \--model [model_name] \--subset [complete|instruct] \--greedy \--bs [bs] \--temperature [temp] \--n_samples [n_samples] \--resume \--backend [vllm|hf|openai|mistral|anthropic|google] \--tp [gpu_number] \[--trust_remote_code] \[--base_url [base_url]]
生成的代码样本将存储在一个名为 [model_name]--bigcodebench-[instruct|complete]--[backend]-[temp]-[n_samples].jsonl 的文件中。或者,可以使用以下命令来利用我们预先构建的 Docker 镜像来生成代码样本:
# If you are using GPUsdocker run --gpus '"device=$CUDA_VISIBLE_DEVICES"' -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest \--model [model_name] \--subset [complete|instruct] \[--greedy] \--bs [bs] \--temperature [temp] \--n_samples [n_samples] \--resume \--backend [vllm|hf|openai|mistral|anthropic|google] \--tp [gpu_number]# ...Or if you are using CPUsdocker run -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest \--model [model_name] \--subset [complete|instruct] \[--greedy] \--bs [bs] \--temperature [temp] \--n_samples [n_samples] \--resume \--backend [vllm|hf|openai|mistral|anthropic|google]
# If you wish to use gated or private HuggingFace models and datasetsdocker run -e HUGGING_FACE_HUB_TOKEN=$token -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other arguments4# Similarly, to use other backends that require authenticationdocker run -e OPENAI_API_KEY=$OPENAI_API_KEY -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other argumentsdocker run -e GOOGLE_API_KEY=$OPENAI_API_KEY -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other argumentsdocker run -e ANTHROPIC_KEY=$ANTHROPIC_KEY -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other arguments
LLM 生成的文本可能无法包含自然语言行或不完整的额外代码的可编译代码。我们提供了一个名为 bigcodebench.sanitize 的工具来清理代码:
# ? If you want to get the calibrated results:bigcodebench.sanitize --samples samples.jsonl --calibrate# Sanitized code will be produced to `samples-sanitized-calibrated.jsonl`# ? If you want to get the original results:bigcodebench.sanitize --samples samples.jsonl# Sanitized code will be produced to `samples-sanitized.jsonl`# ? If you are storing codes in directories:bigcodebench.sanitize --samples /path/to/vicuna-[??]b_temp_[??]# Sanitized code will be produced to `/path/to/vicuna-[??]b_temp_[??]-sanitized`
强烈建议您使用沙箱,例如docker:
# Mount the current directory to the containerdocker run -v $(pwd):/app bigcodebench/bigcodebench-evaluate:latest --subset [complete|instruct] --samples samples-sanitized-calibrated# ...Or locally ⚠️bigcodebench.evaluate --subset [complete|instruct] --samples samples-sanitized-calibrated# ...If the ground truth is working locally (due to some flaky tests)bigcodebench.evaluate --subset [complete|instruct] --samples samples-sanitized-calibrated --no-gt
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-30
Cursor 2.0的一些有趣的新特性
2025-10-30
Anthropic 发布最新研究:LLM 展现初步自省迹象
2025-10-30
让Agent系统更聪明之前,先让它能被信任
2025-10-30
Rag不行?谷歌DeepMind同款,文档阅读新助手:ReadAgent
2025-10-29
4大阶段,10个步骤,助你高效构建企业级智能体(Agent)
2025-10-29
DocReward:让智能体“写得更专业”的文档奖励模型
2025-10-29
沃尔沃RAG实战:企业级知识库,早就该放弃小分块策略
2025-10-29
大模型的Funcation Calling是什么?
2025-08-21
2025-08-21
2025-08-19
2025-09-16
2025-10-02
2025-09-08
2025-09-17
2025-08-19
2025-09-29
2025-08-20
2025-10-29
2025-10-29
2025-10-28
2025-10-28
2025-10-27
2025-10-26
2025-10-25
2025-10-23