How it Works
PromptBench is a Python-based library built on PyTorch designed to evaluate the performance and robustness of large language models (LLMs). It provides a standardized framework for researchers to assess model capabilities across multiple dimensions, including standard evaluation, adversarial robustness, prompt engineering effectiveness, and dynamic evaluation techniques. The library is structured to support quick model assessment, integration of new datasets and models, and extension through user-friendly APIs.
The core functionality of PromptBench revolves around five key components: model performance assessment, prompt engineering, adversarial prompt evaluation, dynamic evaluation, and efficient multi-prompt evaluation. For instance, researchers can evaluate models on existing benchmarks, test the impact of different prompting techniques, or simulate adversarial attacks to measure robustness.
The library integrates a variety of datasets spanning language and multi-modal tasks, including GLUE benchmarks (e.g., SST-2, QNLI), MMLU, BIG-Bench Hard, GSM8K, and multi-modal datasets like VQAv2 and ChartQA. This breadth of support enables comprehensive evaluations across diverse model architectures and tasks.
PromptBench also incorporates adversarial attack methods at multiple levels: character-level (e.g., DeepWordBug, TextBugger), word-level (e.g., TextFooler, BertAttack), sentence-level (e.g., CheckList, StressTest), and semantic-level (e.g., human-crafted attacks). These attacks simulate real-world scenarios where LLMs might encounter malicious or deceptive inputs, helping researchers identify vulnerabilities in model responses.
Dynamic evaluation is another critical feature, implemented through the DyVal framework. DyVal generates evaluation samples on-the-fly with controlled complexity, mitigating issues related to test data contamination. Additionally, PromptBench includes PromptEval, an efficient multi-prompt evaluation method that reduces the need for extensive data sampling by predicting performance on unseen data using a small subset of examples.
Detailed documentation and tutorials guide users through the process of integrating custom components, such as constructing evaluation pipelines for multi-modal models or testing adversarial robustness. Installation is straightforward via pip or by cloning the GitHub repository, with support for conda environments to manage dependencies.
PromptBench’s architecture emphasizes modularity and ease of use. Users can import the library directly via import promptbench as pb after installation, and tutorials cover common workflows, including basic model evaluation, prompt engineering experiments, adversarial attack simulations, and dynamic evaluation using DyVal.
Use Cases
PromptBench is primarily used for testing and red teaming LLMs to identify weaknesses in their robustness, accuracy, and reliability. One of its key applications is in evaluating the resilience of LLMs against adversarial prompts. By simulating attacks at character, word, sentence, and semantic levels, researchers can assess how models respond to manipulated or deceptive inputs.
The library also supports the evaluation of prompt engineering techniques, allowing researchers to compare the effectiveness of methods like chain-of-thought prompting, emotion prompting, and expert prompting. By integrating these methods into PromptBench, users can systematically test how different prompting strategies influence model outputs.
Dynamic evaluation through DyVal addresses a significant challenge in LLM assessment: test data contamination. Traditional static benchmarks may become outdated or biased as models are trained on leaked evaluation data. DyVal mitigates this by generating evaluation samples dynamically, ensuring that assessments remain relevant and unbiased.
PromptBench’s support for multi-modal models extends its applicability to tasks requiring both textual and visual inputs, such as image captioning (e.g., NoCaps) or visual question answering (e.g., VQAv2). By providing a unified framework for both language and multi-modal evaluations, PromptBench enables comprehensive assessments across diverse AI applications.
Another notable use case is efficient multi-prompt evaluation via PromptEval. This method reduces the computational overhead of large-scale evaluations by using a small subset of data to predict performance on unseen examples. Tests on benchmarks like MMLU and BBH demonstrate that PromptEval can achieve high accuracy with minimal data sampling, making it ideal for resource-constrained environments or rapid prototyping.
The library’s integration with a wide range of datasets and models makes it a versatile tool for benchmarking and comparative analysis.
Key Features & Capabilities
- Language datasets cover benchmarks like GLUE (e.g., SST-2, MNLI), MMLU, BIG-Bench Hard, and specialized tasks such as mathematical reasoning (GSM8K) and commonsense QA (CSQA).
- Adversarial Prompt Attacks: The library implements adversarial attacks at multiple granularities—character-level (e.g., DeepWordBug), word-level (e.g., TextFooler), sentence-level (e.g., CheckList), and semantic-level (e.g., human-crafted attacks). These attacks help identify vulnerabilities in LLMs by simulating malicious or deceptive inputs. Researchers can use these tools to red-team models and improve their robustness against real-world threats, such as jailbreaking or prompt injection.
- Prompt Engineering Methods: PromptBench integrates several advanced prompt engineering techniques, including chain-of-thought (COT) prompting, emotion prompting, expert prompting, and least-to-most prompting. By evaluating these techniques within the same framework, users can determine which approaches are most effective for specific applications.
- Dynamic Evaluation with DyVal: The DyVal framework generates evaluation samples dynamically, reducing the risk of test data contamination. DyVal’s graph-informed sampling method controls the complexity of generated samples, allowing researchers to assess model performance under varying conditions without relying on static benchmarks.
- Efficient Multi-Prompt Evaluation with PromptEval: PromptEval enables efficient evaluation by predicting model performance on unseen data using a small subset of examples. This method leverages an Item Response Theory (IRT)-like model to estimate accuracy with minimal sampling, reducing computational costs. Benchmark tests on MMLU and BBH show that PromptEval achieves high accuracy with only 5% of the data, making it ideal for large-scale or resource-limited evaluations.
- The library provides detailed documentation and examples for integrating custom components, such as new adversarial attack methods or multi-modal datasets.
- The ability to compare performance across different model types is critical for identifying strengths and weaknesses in AI systems.
- Benchmarking and Visualization Tools: PromptBench includes tools for benchmarking model performance across various tasks and protocols, such as standard evaluation, adversarial robustness, and dynamic assessment.
