How openai/human-eval works
Main Components
• Data Files: Represent the input/output artifacts (the JSONL files in the data folder such as HumanEval.jsonl.gz, example_problem.jsonl, example_samples.jsonl). These serve as the raw problem definitions and samples that fuel the evaluation.
• Core Library Module ("human_eval" directory): This contains several sub-components:
• data.py: Handles reading and writing JSON Lines files (i.e., loading the problems and saving generated samples).
• evaluation.py: Takes care of calculating pass rates (pass@1, pass@10, etc.) and other metrics.
• execution.py: Responsible for executing the generated code safely; note that it has explicit warnings about untrusted code execution.
• evaluate_functional_correctness.py: Acts as the main entry point when evaluating the completions. It coordinates reading samples, executing tests and writing back the evaluation results.
• Dependencies and Setup: Files like setup.py and requirements.txt represent the project’s installation and dependency management. Although not drawn as major runtime elements, they are important for understanding how the system is put together.
Relationships and Interactions
• Next, include a “Sample Generation” block (as indicated in the example code, though it is provided to users for generating completions) which uses an external function (generate_one_completion) to produce completions.
• Then, the “Code Execution Engine” from execution.py should be depicted. This engine is designed to run untrusted code in a sandboxed environment (even though the code is commented out by default, its presence is critical).
• Follow this with the “Evaluator” component (evaluation.py) that runs test suites against the execution results and computes pass metrics.
Architectural Patterns and Design Principles
• Modularity: The system is separated into clear modules (data handling, execution, evaluation) that each encapsulate a specific functionality.
• Command-line Driven: The evaluation script (evaluate_functional_correctness.py) acts as a CLI entry point that orchestrates the process.
• Security Awareness: There is a distinct emphasis on safe execution of untrusted code (documented in execution.py and shown as a safety disclaimer in the README).
Relevant Technologies
• Python (version 3.7+), which underpins the entire system.
• JSON Lines format for data storage and exchange.
• The use of pip for installation and conda for virtual environment management.
• From data files (e.g., HumanEval.jsonl.gz, example_problem.jsonl) to the Data Loader component.
• From Data Loader to the Sample Generation process (which might be shown as an external/process boundary since users supply the generate_one_completion function).
• From generated samples to the Code Execution Engine.
• From Code Execution to the Evaluation component where they run test suites.
• From Evaluation to the final Results Writer (writing to files with _results.jsonl suffix).
• Notes or annotations on key components that explain the importance of safe code execution and the dependency on the Python environment.