微信扫码
添加专属顾问
我要投稿
BigCodeBench 为每个任务提供了复杂且以用户为中心的指导,包括清晰的功能描述、输入/输出格式、错误处理以及经过验证的交互示例。该平台避免使用逐步任务指导,相信有能力的 LLMs 应该能够从用户的角度以开放式的方式理解和解决任务。通过测试用例来验证特定功能。
# We elaborate the above task with some test cases:
# Requirements SetUp
import unittest
from unittest.mock import patch
import http.client
import ssl
import socket
# Start the test
class 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.evaluate
pip install bigcodebench --upgrade
# If you want to use the evaluate locally, you need to install the requirements
pip 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 environment
pip 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 GPUs
docker 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 CPUs
docker 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 datasets
docker 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 authentication
docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other arguments
docker run -e GOOGLE_API_KEY=$OPENAI_API_KEY -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest # omit other arguments
docker 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-04-19
Exa:给 AI Agent 的 “Bing API”
2025-04-19
Chrome过时了,AI Agent需要自己的浏览器。
2025-04-19
n8n + mcp王炸组合:5个节点轻松搭建一个AI工作流
2025-04-18
火山引擎OS Agent解决方案、豆包1.5·UI-TARS模型发布
2025-04-18
前沿导读 | 基于大模型智能体的出行行为模拟
2025-04-18
大概念模型(Large Concept Models)会取代提示工程吗?
2025-04-18
AI 重要概念科普与热门技术解析
2025-04-18
我对于AI领域商业模式的思考
2024-08-13
2024-06-13
2024-08-21
2024-09-23
2024-07-31
2024-05-28
2024-08-04
2024-04-26
2024-07-09
2024-09-17
2025-04-18
2025-04-16
2025-04-13
2025-04-13
2025-04-13
2025-04-12
2025-04-12
2025-04-11