🤖 AI/ML

HumanEval

HumanEval

A benchmark that evaluates LLMs' code generation ability. Developed by OpenAI.

📖 Detailed Explanation

HumanEval is a benchmark for evaluating code generation ability, released by OpenAI in 2021 together with the Codex paper. It consists of 164 Python programming problems and evaluates whether a model can generate correctly working code given a function signature and docstring.

The evaluation metric is pass@k. It refers to the probability that, when a model generates k code samples, at least one of them passes all test cases. Typically, pass@1 (success on the first attempt), pass@10, and pass@100 are reported.

HumanEval problems range in difficulty from basic ones like "finding the sum of two numbers" to "string parsing" and "list manipulation." Each problem has hidden test cases that verify correct implementation.

Today's latest LLMs record a pass@1 of over 90% on HumanEval. Accordingly, more difficult benchmarks such as HumanEval+, MBPP, and SWE-bench have emerged. However, HumanEval is still used as the standard for quickly checking the basic capabilities of code generation models.

💻 Code Example

from human_eval.data import read_problems
from human_eval.evaluation import evaluate_functional_correctness
import openai

# HumanEval 벤치마크 실행 예제
def run_humaneval_benchmark(model_name="gpt-4"):
    # 1. 문제 로드
    problems = read_problems()

    # 2. 각 문제에 대해 코드 생성
    samples = []
    for task_id, problem in problems.items():
        prompt = problem["prompt"]

        # LLM으로 코드 생성
        response = openai.chat.completions.create(
            model=model_name,
            messages=[{
                "role": "user",
                "content": f"Complete the following Python function:\n\n{prompt}"
            }],
            temperature=0.2,
            max_tokens=500
        )

        completion = response.choices[0].message.content
        samples.append({
            "task_id": task_id,
            "completion": completion
        })

    # 3. 결과 저장
    with open("samples.jsonl", "w") as f:
        for sample in samples:
            f.write(json.dumps(sample) + "\n")

    # 4. 테스트 실행 및 pass@k 계산
    results = evaluate_functional_correctness(
        sample_file="samples.jsonl",
        k=[1, 10, 100]
    )

    print(f"pass@1: {results['pass@1']:.2%}")
    print(f"pass@10: {results['pass@10']:.2%}")
    print(f"pass@100: {results['pass@100']:.2%}")

    return results

🗣️ Say It Like This in Practice

In a code generation model comparison meeting

"GPT-4o has a HumanEval pass@1 of 92%, while Claude 3.5 Sonnet has 94%. However, HumanEval consists of relatively easy problems, so the difference in actual coding ability can be seen more accurately with SWE-bench."

In a technical interview

"HumanEval's pass@k metric is a sampling-based evaluation. If pass@1 is low but pass@100 is high, it means the model does know the correct answer but lacks consistency. In production, pass@1 is what matters."

In a model fine-tuning discussion

"After fine-tuning a code generation model, verify it with HumanEval first. If pass@1 drops compared to the original model, catastrophic forgetting has occurred, so you need to adjust the training data or hyperparameters."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

1
Possibility of data contamination

Some models may have inflated scores because HumanEval problems were included in their training data. Do not judge actual capability by benchmark scores alone.

2
Python-centric evaluation

HumanEval evaluates Python only. Capability in other languages needs to be checked separately with extended benchmarks such as MultiPL-E.

3
Gap with real-world practice

HumanEval focuses mainly on algorithm problems. Skills needed in real development, such as API usage, debugging, and refactoring, should be evaluated with other benchmarks.

🔗 Related Terms

📚 Learn More