RACE
收藏资源简介:
RACE数据集由中国信息处理实验室等机构创建,旨在全面评估大型语言模型生成的代码质量。该数据集包含923条数据,涵盖代码的多个维度评估,如可读性、可维护性、正确性和效率。创建过程中,研究者设计了多种用户需求类型,以确保模型生成的代码不仅正确,还能满足特定需求。RACE数据集主要应用于软件开发领域,帮助评估和改进模型在实际应用中的代码生成能力。
The RACE dataset was created by institutions including the China Information Processing Laboratory, aiming to comprehensively evaluate the code quality generated by large language models (LLMs). It comprises 923 data samples, covering multi-dimensional evaluations of code across aspects like readability, maintainability, correctness, and efficiency. During its development, researchers designed multiple types of user requirements to ensure that the code produced by models not only achieves correctness but also fulfills specific targeted needs. The RACE dataset is primarily applied in the software development domain to assist in evaluating and enhancing the code generation capabilities of models in real-world scenarios.
RACEcode
关于
RACE是一个多维度的代码生成基准,专注于R可读性、A可维护性、C正确性和E效率。其目标是评估大型语言模型(LLM)生成正确且符合真实世界开发场景要求的代码的能力。该基准通过不同的需求依赖维度设计,使其更适用于实际场景。为了便于RACE的评估,我们提供了易于使用的评估脚本,并在虚拟化环境中进行评估以确保代码执行的安全性。
快速开始
环境准备
bash pip install -e .
对于vllm,请运行以下命令:
bash pip install -e .[vllm_gen]
代码生成
以Readability为例,使用以下命令从模型生成代码样本,这些样本以JSON Lines(jsonl)格式保存。root指的是输出文件的目录,backend支持openai和vllm。要使用openai后端,请确保配置了环境变量${API_BASE}和${API_KEY}。
bash scripts/gen_readability.sh ${model} ${root} ${backend}
更多维度的命令:
bash
对于Correctness
scripts/gen_correctness.sh ${model} ${root} ${backend}
对于Maintainability
scripts/gen_maintainability.sh ${model} ${root} ${backend}
对于Efficiency
scripts/gen_efficiency.sh ${model} ${root} ${backend}
代码后处理
使用以下命令读取代码样本文件,从模型生成响应中提取有效代码,并将其保存到带有parsed后缀的文件中。
bash python scripts/parse_generated_file.py --generated_file_path ${generated_file_path} --model ${model}
代码评估
生成的代码评估分为两部分:1) 评估生成代码的正确性;2) 评估各种非执行基础的指标。
首先,构建docker镜像作为评估代码执行的环境:
bash docker build --rm -f "./Dockerfile" -t race:latest "."
然后,以代码可读性为例,基于测试用例测试LLM生成代码的正确性。在此上下文中,生成代码在correctness维度的评估分布在代码readability、maintainability和efficiency维度上。
bash scripts/eval_c_readability.sh ${model} ${root}
更多维度的命令:
bash
对于Readability
scripts/eval_c_maintainability.sh ${model} ${root}
对于Efficiency
scripts/eval_c_efficiency.sh ${model} ${root}
进一步详细说明如何在一个单一因素下评估LLM生成代码的正确性:
bash
对于Readability
docker run -v $(pwd):/data race:latest race.codeeval.evaluate_pipeline_evalplus --dataset [humaneval|mbpp] --samples "/data/outputs/${parsed_generated_file}"
对于Maintainability (MI Metric)
docker run -v $(pwd):/data race:latest race.codeeval.evaluate_pipeline_classeval test_pipeline --model_name ${model} --generated_data_path "/data/outputs/${generated_file}" --root "/data/outputs"
对于Maintainability (Modularity)
docker run -v $(pwd):/data race:latest race.codeeval.evaluate_pipeline_leetcode_style test_pipeline_simple --model_name ${model} --evaluation_test_case_path "/data/data/leetcode/evaluation_tests.jsonl" --generated_data_path "/data/outputs/${parsed_generated_file}" --result_path "/data/outputs/${results_file}" --temp_path "/data/outputs"
对于Efficiency
docker run -v $(pwd):/data race:latest race.codeeval.evaluate_pipeline_leetcode_style test_pipeline_complexity --model_name ${model} --evaluation_test_case_path "/data/data/leetcode_efficiency/complexity_evaluation_test_cases.jsonl" --evaluation_efficiency_data_path "/data/data/leetcode_efficiency/complexity_evaluation_data.jsonl" --generated_data_path "/data/outputs/${parsed_generated_file}" --result_path "/data/outputs/${results_file}" --temp_path "/data/outputs"
最后,基于特定指标获取评估结果。以Readability为例:
bash python scripts/get_metric_readability.py --model ${model} --output_path_root ${root}
更多维度的命令:
bash
对于Correctness
python scripts/get_metric_correctness.py --model ${model} --output_path_root ${root}
对于Maintainability
python scripts/get_metric_maintainability.py --model ${model} --output_path_root ${root}
对于Efficiency
python scripts/get_metric_efficiency.py --model ${model} --output_path_root ${root}

- RACE数据集首次发表,由清华大学和微软亚洲研究院共同发布,旨在评估机器阅读理解能力。
- RACE数据集首次应用于多项机器阅读理解竞赛,成为评估模型性能的重要基准。
- RACE数据集被广泛应用于学术研究和工业界,推动了阅读理解技术的发展。
- RACE数据集的扩展版本发布,增加了更多的阅读材料和问题,进一步提升了数据集的挑战性。



