R-Judge

R-Judge

R-Judge: Benchmarking Safety Risk Awareness for LLM Agents (EMNLP Findings 2024)

Stars: 58

Visit
 screenshot

R-Judge is a benchmarking tool designed to evaluate the proficiency of Large Language Models (LLMs) in judging and identifying safety risks within diverse environments. It comprises 569 records of multi-turn agent interactions, covering 27 key risk scenarios across 5 application categories and 10 risk types. The tool provides high-quality curation with annotated safety labels and risk descriptions. Evaluation of 11 LLMs on R-Judge reveals the need for enhancing risk awareness in LLMs, especially in open agent scenarios. Fine-tuning on safety judgment is found to significantly improve model performance.

README:

R-Judge: Benchmarking Safety Risk Awareness for LLM Agents

The official repository for R-Judge, containing data and evaluation scripts. Paper Link: https://arxiv.org/abs/2401.10019

The repo is updating with Camera-ready newer version. (2024.10.5)

Large language models (LLMs) have exhibited great potential in autonomously completing tasks across real-world applications. Despite this, these LLM agents introduce unexpected safety risks when operating in interactive environments. Instead of centering on the harmlessness of LLM-generated content in most prior studies, this work addresses the imperative need for benchmarking the behavioral safety of LLM agents within diverse environments. We introduce R-Judge, a benchmark crafted to evaluate the proficiency of LLMs in judging and identifying safety risks given agent interaction records. R-Judge comprises 569 records of multi-turn agent interaction, encompassing 27 key risk scenarios among 5 application categories and 10 risk types. It is of high-quality curation with annotated safety labels and risk descriptions. Evaluation of 11 LLMs on R-Judge shows considerable room for enhancing the risk awareness of LLMs: The best-performing model, GPT-4o, achieves 74.42% while no other models significantly exceed the random. Moreover, we reveal that risk awareness in open agent scenarios is a multi-dimensional capability involving knowledge and reasoning, thus challenging for LLMs. With further experiments, we find that fine-tuning on safety judgment significantly improve model performance while straightforward prompting mechanisms fail.

Overview

Dataset distribution of R-Judge, which contains 27 key risk scenarios among 5 application categories, and spans across 10 risk types. The proportion of each category is shown in the graph.

Illustration of R-Judge by an example. The upper left part is an example in the dataset, i.e., a record of an agent interacting with the user and environment. The lower left part is human annotation involving a binary safety label and high-quality risk description. Following the arrow, we can see the serial evaluation paradigm with two tests: given record and task instruction, LLMs are asked to generate an analysis and a label. An automatic evaluator compares the analysis with the ground truth risk description to assess the effectiveness of risk identification. Correct generated labels are counted to evaluate the performance of safety judgment.

Evaluation

The evaluation scripts are in ./eval.

1. Label Score for Safety Judgment.

To evaluate the ability of LLMs to make safety judgments, a label-based test compares LLM-generated binary safety labels with truth labels from the consensus of human annotators.

python safety_judgment.py

The results will be saved in ./results/standard.

Before running the script, you should specify certain parameters in the code segment below.

# ./eval/safety_judgment.py

# Add models to the variable MODEL2RPM and MODEL2BASE
MODEL2RPM = {
    "gpt-3.5-turbo-0613": 3000,
    "gpt-4-0613": 200,
    "Llama-2-7b-chat-hf": 60,
    "Llama-2-13b-chat-hf": 60,
    "vicuna-7b-v1.5": 60,
    "vicuna-13b-v1.5": 60,
    "vicuna-7b-v1.5-16k": 60,
    "vicuna-13b-v1.5-16k": 60,
}

MODEL2BASE = {
    "gpt-3.5-turbo-0613": None,
    "gpt-4-0613": None,
    # To test locally deployed open-source models, you should specify server address for the model
    "Llama-2-7b-chat-hf": None, 
    "Llama-2-13b-chat-hf": None,
    "vicuna-7b-v1.5": None,
    "vicuna-13b-v1.5": None,
    "vicuna-7b-v1.5-16k": None,
    "vicuna-13b-v1.5-16k": None,
}

API_KEY = os.environ['API_KEY'] # To test API-based models, you should specify your own API_KEY

For models to test, add it to the variable MODEL2RPM and MODEL2BASE.

To test API-based models, you should specify your own API_KEY. For example, OPENAI_KEY for GPT series.

To test locally deployed open-source models, you should specify server address for the model in the MODEL2BASE.

2. Pairwise Evaluation for Risk Identification

To evaluate the effectiveness of LLMs in identifying safety risks, an open-ended test utilizes GPT-4 as an automatic evaluator to assess the open-ended model-generated analysis on unsafe cases.

Before running the test, you should first specify your OPENAI_KEY.

Option 1: Run our results

For the convenience of users, we have saved the results of 8 model performance on unsafe cases in safety judgment in ./eval/results/overall_results_unsafe.json, which is the input for the risk identification test.

You can directly run the script:

python risk_identification.py

Option 2: Run your own results

Before testing Risk Identification, you should first run safety_judgment.py to get model-generated analysis in ./results/standard.

sh risk_identification.sh

The script includes two .py file.

  • extract_analysis.py extract model-generated analysis from ./results/standard/.../results.json in such format(The overall_result_unsafe.json store all results).
    {
        "id": 1,
        "contents": [
            {
                "role": "user",
                "content": "..."
            },
            {
                "role": "assistant",
                "content": "..."
            },
            {
                "role": "user",
                "content": "[ENVIRONMENT]: ..."
            }
        ],
        "label": 1,
        "reference": "...",
        "candidates": {
            "Llama-2-13b-chat-hf": "...",
            "Llama-2-7b-chat-hf": "...",
            "vicuna-13b-v1.5": "...",
            "vicuna-13b-v1.5-16k": "...",
            "vicuna-7b-v1.5": "...",
            "vicuna-7b-v1.5-16k": "...",
            "gpt-3.5-turbo-0613": "...",
            "gpt-4-0613": "..."
        },
        "scenario": "..."
    }
  • risk_identification.py call GPT-4 to evaluate model-generated analysis.

Main Results

Main results(%) of the safety judgment test and risk identification test in R-Judge on two fundamental risk origins: Intended Attacks and Unintended Risks. Safety judgment scores (F1, Recall and Spec as ‘Specificity’) are calculated by counting correct labels and risk identification scores (Effect as ‘effectiveness’) are assigned by an automatic GPT-4 scorer compared with human-annotated risk description. F1 is the main score while the other 3 metrics is for reference. Segment 1: GPT series; Segment 2: Llama 3; Segment 3: Llama 2; Segment 4: Random baseline; Segment 5: Vicuna-1.5; Segment 6: Mistral-7B. The best model results are in bold face, and the second best model results are underlined. F1 scores that exceed random are in italics.

Dataset Introduction

Category & Scenario

Descriptions of 5 common Categories including 27 agent Scenarios in R-Judge.

Risk Type

10 Risk Types of R-Judge, illustrated with risk descriptions.

Statistics

Statistics of R-Judge Datasets, including label count, average turns of interactions, and word counts.

Citation

@article{yuan2024rjudge,
  title={R-Judge: Benchmarking Safety Risk Awareness for LLM Agents},
  author={Tongxin Yuan and Zhiwei He and Lingzhong Dong and Yiming Wang and Ruijie Zhao and Tian Xia and Lizhen Xu and Binglin Zhou and Fangqi Li and Zhuosheng Zhang and Rui Wang and Gongshen Liu},
  journal={arXiv preprint arXiv:2401.10019},
  year={2024}
}

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for R-Judge

Similar Open Source Tools

For similar tasks

For similar jobs