Registry / ai-ml / human-eval

human-eval

JSON →
library1.0.3pypypi✓ verified 27d ago

HumanEval is a benchmark developed by OpenAI for assessing the code generation capabilities of Large Language Models (LLMs). It comprises 164 hand-written Python programming problems, each with a function signature, docstring, and comprehensive unit tests, designed to evaluate functional correctness. The library uses the `pass@k` metric for evaluation. The current version is 1.0.3, released on July 24, 2023. As a benchmark dataset and evaluation harness, it has an infrequent release cadence, with updates typically driven by new research or significant improvements to the benchmark itself.

pip install human-eval
INSTALL
IMPORT
SIG · HUMAN-EVAL
H
human-eval
ai-mlpythonv1.0.3
Install
3.9s avg
Import
16ms
Disk
91MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.016s · 91MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.9s · import 0.016s · 87MB
91MB installed
● package 91MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

read_problems
✓ from human_eval.data import read_problems
write_jsonl
✓ from human_eval.data import write_jsonl
evaluate_functional_correctness (command-line)
✓ evaluate_functional_correctness samples.jsonl
This is a command-line utility, not a Python import.

This quickstart demonstrates the core workflow: reading HumanEval problems, generating code completions using a placeholder function (which you would replace with your LLM integration), saving these completions to a JSONL file, and finally, instructing how to run the `evaluate_functional_correctness` command-line tool to assess the functional correctness of the generated code.

import os import json from human_eval.data import write_jsonl, read_problems def generate_one_completion(prompt: str) -> str: """A placeholder for your LLM's code generation function. Replace this with actual API calls to your LLM. It should take a problem prompt and return a generated code string. """ # Example: A simple dummy completion for demonstration if "def multiply" in prompt: return "def multiply(a, b):\n return a * b" elif "def add" in prompt: return "def add(a, b):\n return a + b" else: return "def solution():\n pass # Your LLM generated code here" # 1. Read the HumanEval problems problems = read_problems() # 2. Generate completions for each problem num_samples_per_task = 1 # For quick demonstration, typically >100 for robust eval samples = [] for task_id in problems: prompt = problems[task_id]["prompt"] for _ in range(num_samples_per_task): completion = generate_one_completion(prompt) samples.append(dict(task_id=task_id, completion=completion)) # 3. Save the generated samples to a JSON Lines file samples_filepath = "samples.jsonl" write_jsonl(samples_filepath, samples) print(f"Generated samples saved to {samples_filepath}") # 4. Evaluate functional correctness (typically run as a separate command-line step) print("\nTo evaluate, run the following from your terminal (after installing human-eval):") print(f"$ evaluate_functional_correctness {samples_filepath}") print("\nWARNING: This command executes untrusted model-generated code. Ensure you are in a robust security sandbox.") # Example of output from evaluate_functional_correctness (if run separately): # {'pass@1': ..., 'pass@10': ..., 'pass@100': ...}
Debug
Known issues
breakingExecuting model-generated code carries significant security risks. The `execution.py` module in the `human-eval` library deliberately comments out the actual code execution call.
fix
Users are *strongly encouraged* to run the `evaluate_functional_correctness` tool within a robust security sandbox (e.g., Docker, a dedicated VM, or an isolated environment like Riza). Review `human_eval/execution.py` and uncomment the execution line only after understanding the risks and implementing proper sandboxing.
affects: All versions
gotchaBase language models (not instruction-tuned) might produce repetitive or malformed outputs that can break benchmark scores. This is particularly common with chat completion APIs.
fix
For optimal results, use instruction-tuned models. If using base models, a post-generation filtering step (`filter_code`) might be necessary to clean up outputs before evaluation.
affects: All versions
gotchaThe HumanEval benchmark can be susceptible to 'contamination' where test problems or similar solutions might have been part of an LLM's training data, leading to artificially inflated scores.
fix
To mitigate contamination, use time-split datasets, rigorously audit potential overlap sources, and compare `pass@k` scores on fresh, internal tasks.
affects: All versions
gotchaEvaluating a large number of samples or using the `--test-details` flag for `evaluate_functional_correctness` can be computationally intensive and slow.
fix
To speed up evaluation: utilize the `--parallel` flag (e.g., `--parallel $(nproc)`), avoid `--test-details` if only `pass@k` scores are needed (as it runs all tests even after failure), and consider using specialized versions like HumanEval+ Mini for faster checks.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'human_eval'
This error occurs when the 'human-eval' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install human-eval'.
ImportError: cannot import name 'read_problems' from 'human_eval.data'
This error occurs when attempting to import 'read_problems' from 'human_eval.data' without the package being installed or due to an incorrect installation.
fix
Ensure the 'human-eval' package is installed correctly: 'pip install human-eval'.
AttributeError: module 'human_eval' has no attribute 'data'
This error occurs when trying to access the 'data' module within 'human_eval', possibly due to an incomplete or incorrect installation.
fix
Verify the installation of 'human-eval' and reinstall if necessary: 'pip install --force-reinstall human-eval'.
FileNotFoundError: [Errno 2] No such file or directory: 'samples.jsonl'
This error occurs when the 'samples.jsonl' file is missing or the path is incorrect during evaluation.
fix
Ensure that 'samples.jsonl' is generated and located in the correct directory before running the evaluation command.
TypeError: 'NoneType' object is not subscriptable
This error occurs when 'read_problems()' returns None, possibly due to issues with reading the problem dataset.
fix
Check the integrity of the problem dataset and ensure 'read_problems()' is functioning correctly.
Upgrade
Version history
1.0.3latest on PyPI · released Jul 24, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources