PromptBench

repository·main·Indexed 25 days ago

https://github.com/microsoftarchive/promptbench

A PyTorch-based Python library for the unified evaluation and understanding of Large Language Models (LLMs). It provides tools for model performance assessment, prompt engineering testing, and dynamic evaluation (DyVal) to mitigate data contamination. PromptBench implements four levels of adversarial attacks—character, word, sentence, and semantic—to evaluate LLM robustness, using the Performance Drop Rate (PDR) as a unified metric to quantify performance decline.

Tokens
59.2K
Snippets
56
Records
386
Agent score
81%

What's inside PromptBench

  1. Overview of the Prompt Engineering Benchmark

    main

    The Prompt Engineering Module in promptbench evaluates various prompting methods across multiple datasets. It is designed to compare different prompting strategies like Chain-of-Thought (CoT), Zero-shot CoT, Expert Prompting, Emotion Prompt, and Least-to-Most prompting.

    Currently supported models include:

    • GPT-3.5-turbo
    • GPT-4-1106
  2. Introduction to PromptBench

    main
    PromptBench is a unified library designed for evaluating and understanding the performance of large language models (LLMs). It provides tools for model performance benchmarking, prompt engineering, adversarial prompt attack simulation, and dynamic evaluation to mitigate test data contamination.
  3. Understand the 4 levels of Prompt Attacks

    main

    PromptBench implements four levels of adversarial attacks to evaluate LLM robustness:

    • Character-level: Uses TextBugger and DeepWordBug to introduce typos or errors (adding, deleting, repeating, replacing, or permuting characters).
    • Word-level: Uses BertAttack and TextFooler to replace words with synonyms or contextually similar words.
    • Sentence-level: Uses StressTest and CheckList to append distracting information:
      • StressTest: Appends and true is true, and false is not true, or and true is true five times.
      • CheckList: Appends 50 random sequences of alphabets and digits (length 10 each).
    • Semantic-level: Simulates linguistic nuances by translating prompts into 6 languages (Chinese, French, Arabic, Spanish, Japanese, and Korean) and back to English.
  4. Understand the DyVal Dynamic Evaluation Benchmark

    main

    DyVal (Graph-informed Dynamic Evaluation of Large Language Models) is a dynamic evaluation protocol for LLMs. It measures model performance across various reasoning tasks categorized by complexity levels.

    Key reasoning tasks evaluated include:

    • Arithmetic
    • Linear Equation
    • Boolean Logic
    • Deductive Logic
    • Abductive Logic
    • Reachability
    • Max Sum Path

    If you wish to have your model's results included in the PromptBench DyVal leaderboard, you must contact the project maintainers.

  5. Understand the Adversarial Prompt Leaderboard

    main

    PromptBench provides a leaderboard to evaluate the adversarial robustness of Large Language Models (LLMs) against various prompt attacks. The leaderboard tracks how different models perform across multiple datasets when subjected to adversarial prompts.

    For detailed methodology, refer to the paper: PromptBench: Towards Evaluating the Robustness of Large Language Models on Adversarial Prompts.

  6. Add new datasets to PromptBench

    main

    To add a custom dataset, follow these two steps:

    1. Implement a New Dataset Class: Create a class in dataload/dataset.py that inherits from the Dataset class. Implement the __init__ method to handle your dataset loading. It is recommended to organize data samples as dictionaries to simplify the input process.
    2. Register the Interface: Register your new dataset class in the DataLoader class within dataload.py to make it accessible via the framework.
  7. Install promptbench from source via GitHub

    main

    To make changes to the codebase or experiment with the source, follow these steps to clone the repository and install dependencies manually:

    1. Clone the repository:
      git clone git@github.com:microsoft/promptbench.git
      cd promptbench
    2. Create a Conda environment (recommended):
      conda create --name promptbench python=3.9
    3. Install the required Python packages:
      pip install -r requirements.txt

    Note: This only installs basic Python packages. If you intend to use Prompt Attacks, you must also install textattacks.

    git clone git@github.com:microsoft/promptbench.git
    cd promptbench
    conda create --name promptbench python=3.9
    pip install -r requirements.txt
  8. PromptBench Usage Tutorials

    main

    PromptBench provides several specialized notebooks for different evaluation tasks:

    • Basic Model Evaluation: Construct an evaluation pipeline for existing benchmarks using examples/basic.ipynb.
    • Multi-modal Evaluation: Evaluate multi-modal models and datasets using examples/multimodal.ipynb.
    • Prompt Attack Robustness: Examine how models handle adversarial attacks using examples/prompt_attack.ipynb.
    • Dynamic Evaluation (DyVal): Construct DyVal datasets to mitigate test data contamination using examples/dyval.ipynb.
    • Efficient Multi-prompt Evaluation (PromptEval): Use the PromptEval method for efficient evaluation using examples/efficient_multi_prompt_eval.ipynb.