HaluEval Benchmark

repository·main·Indexed 20 days ago

https://github.com/rucaibox/halueval

A large-scale benchmark consisting of 35,000 samples designed to evaluate the ability of Large Language Models (LLMs) to recognize hallucinations. It covers general user queries and task-specific scenarios including Question Answering (QA), knowledge-grounded dialogue, and text summarization. The repository provides tools for generating hallucinated samples, evaluating model recognition performance via evaluate.py, and analyzing failure topics using Latent Dirichlet Allocation (LDA).

Tokens
1.2K
Snippets
3
Records
5
Agent score
20%

What's inside HaluEval

  1. Overview of HaluEval Benchmark

    main

    HaluEval is a large-scale hallucination evaluation benchmark for Large Language Models (LLMs). It consists of 35,000 samples designed to test an LLM's ability to recognize hallucinations across different scenarios:

    1. General User Queries (5,000 samples): Human-annotated samples from the Alpaca dataset where ChatGPT responses are labeled for hallucinations (Yes/No).
    2. Task-Specific Examples (30,000 samples): Automatically generated hallucinated samples across three domains:
      • Question Answering (QA): Based on HotpotQA.
      • Knowledge-grounded Dialogue: Based on OpenDialKG.
      • Text Summarization: Based on CNN/Daily Mail.

    Developers can use this benchmark to evaluate how well LLMs detect hallucinations and analyze which topics or content types cause models to fail.

  2. Generate hallucinated samples

    main

    You can use the provided pipeline to generate hallucinated samples on your own datasets. The process involves two main steps: downloading seed data and running the generation/filtering scripts.

    1. Prepare Seed Data

    Download the required training sets (e.g., HotpotQA, OpenDialKG, or CNN/Daily Mail) into the generation directory.

    2. Run Generation

    Use generate.py to create hallucinated counterparts.

    • --seed_data: Path to the downloaded training set.
    • --task: One of qa, dialogue, or summarization.
    • --strategy: Sampling strategy, either one-turn or multi-turn.

    3. Filter Samples

    Use filtering.py to select the most plausible and difficult hallucinated samples.

    • --task: The task to filter (qa, dialogue, or summarization).
    # Step 1: Download seed data
    cd generation
    wget http://curtis.ml.cmu.edu/datasets/hotpot/hotpot_train_v1.1.json
    wget https://raw.githubusercontent.com/facebookresearch/opendialkg/main/data/opendialkg.csv
    wget https://huggingface.co/datasets/ccdv/cnn_dailymail/blob/main/cnn_stories.tgz
    
    # Step 2: Generate samples
    python generate.py --seed_data hotpot_train_v1.1.json --task qa --strategy one-turn
    
    # Step 3: Filter samples
    python filtering.py --task qa
  3. Analyze hallucination topics using LDA

    main

    After evaluation, you can perform topic analysis using Latent Dirichlet Allocation (LDA) to understand which topics LLMs struggle with. This is done via the analyze.py script.

    Arguments:

    • --task: The task to analyze (qa, dialogue, or summarization).
    • --result: Path to the JSON file containing recognition results from the evaluation stage.
    • --category: The subset of data to analyze:
      • all: All task samples.
      • failed: Only the samples where the LLM failed to recognize hallucinations.
    cd analysis
    python analyze.py --task qa --result ../evaluation/qa/qa_gpt-3.5-turbo_result.json --category all
  4. Evaluate LLMs for hallucination recognition

    main

    To evaluate an LLM's ability to recognize hallucinations, use the evaluate.py script. The evaluation logic samples either a ground-truth or a hallucinated output. The LLM is expected to output "Yes" if the text contains a hallucination and "No" if it is a ground-truth answer.

    Arguments:

    • --task: The task being evaluated (qa, dialogue, or summarization).
    • --model: The name of the model to evaluate (e.g., gpt-3.5-turbo, davinci).
    cd evaluation
    python evaluate.py --task qa --model gpt-3.5-turbo
  5. HaluEval Data Formats

    main

    The data/ directory contains four JSON files. Each file follows a specific schema depending on the task:

    qa_data.json (10K samples)

    • knowledge: Wikipedia knowledge.
    • question: The question text.
    • right_answer: Ground-truth answer.
    • hallucinated_answer: The generated hallucinated answer.

    dialogue_data.json (10K samples)

    • knowledge: Wikipedia knowledge.
    • dialogue_history: Dialogue history.
    • right_response: Ground-truth response.
    • hallucinated_response: The generated hallucinated response.

    summarization_data.json (10K samples)

    • document: The source document.
    • right_summary: Ground-truth summary.
    • hallucinated_summary: The generated hallucinated summary.

    general_data.json (5K samples)

    • user_query: The posed user query.
    • chatgpt_response: The ChatGPT response.
    • hallucination_label: Human annotation (Yes or No).