From a24cade714cd20ed9b485ee381e1b3fd72ce98f2 Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sun, 23 Mar 2025 09:15:43 +0100 Subject: [PATCH 1/4] fix: replace `eval` with `ast.literal_eval` in `fetch_aya_redteaming_dataset` --- pyrit/datasets/aya_redteaming_dataset.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrit/datasets/aya_redteaming_dataset.py b/pyrit/datasets/aya_redteaming_dataset.py index 47bb0d60fd..a7136684a4 100644 --- a/pyrit/datasets/aya_redteaming_dataset.py +++ b/pyrit/datasets/aya_redteaming_dataset.py @@ -1,6 +1,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT license. +import ast + from pathlib import Path from typing import List, Literal, Optional @@ -77,7 +79,7 @@ def fetch_aya_redteaming_dataset( seed_prompts = [] for example in examples: - categories = eval(example["harm_category"]) + categories = ast.literal_eval(example["harm_category"]) if harm_categories is None or any(cat in categories for cat in harm_categories): if harm_scope is None or example["global_or_local"] == harm_scope: seed_prompts.append( From e0d692232a3ba5e328db20fd864b0b543476d204 Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sun, 23 Mar 2025 13:48:54 +0100 Subject: [PATCH 2/4] feat: add fetch function for DarkBench dataset --- doc/api.rst | 1 + pyrit/datasets/__init__.py | 2 ++ pyrit/datasets/aya_redteaming_dataset.py | 1 - pyrit/datasets/darkbench_dataset.py | 35 +++++++++++++++++++ .../datasets/test_fetch_datasets.py | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 pyrit/datasets/darkbench_dataset.py diff --git a/doc/api.rst b/doc/api.rst index 9c004dbe1e..0d99494815 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -114,6 +114,7 @@ API Reference fetch_adv_bench_dataset fetch_aya_redteaming_dataset fetch_babelscape_alert_dataset + fetch_darkbench_dataset fetch_decoding_trust_stereotypes_dataset fetch_examples fetch_forbidden_questions_dataset diff --git a/pyrit/datasets/__init__.py b/pyrit/datasets/__init__.py index c5484bde31..f230f61726 100644 --- a/pyrit/datasets/__init__.py +++ b/pyrit/datasets/__init__.py @@ -4,6 +4,7 @@ from pyrit.datasets.adv_bench_dataset import fetch_adv_bench_dataset from pyrit.datasets.aya_redteaming_dataset import fetch_aya_redteaming_dataset from pyrit.datasets.babelscape_alert_dataset import fetch_babelscape_alert_dataset +from pyrit.datasets.darkbench_dataset import fetch_darkbench_dataset from pyrit.datasets.decoding_trust_stereotypes_dataset import fetch_decoding_trust_stereotypes_dataset from pyrit.datasets.dataset_helper import fetch_examples from pyrit.datasets.forbidden_questions_dataset import fetch_forbidden_questions_dataset @@ -24,6 +25,7 @@ "fetch_adv_bench_dataset", "fetch_aya_redteaming_dataset", "fetch_babelscape_alert_dataset", + "fetch_darkbench_dataset", "fetch_decoding_trust_stereotypes_dataset", "fetch_examples", "fetch_forbidden_questions_dataset", diff --git a/pyrit/datasets/aya_redteaming_dataset.py b/pyrit/datasets/aya_redteaming_dataset.py index a7136684a4..214a93806d 100644 --- a/pyrit/datasets/aya_redteaming_dataset.py +++ b/pyrit/datasets/aya_redteaming_dataset.py @@ -2,7 +2,6 @@ # Licensed under the MIT license. import ast - from pathlib import Path from typing import List, Literal, Optional diff --git a/pyrit/datasets/darkbench_dataset.py b/pyrit/datasets/darkbench_dataset.py new file mode 100644 index 0000000000..bab554e363 --- /dev/null +++ b/pyrit/datasets/darkbench_dataset.py @@ -0,0 +1,35 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +from datasets import load_dataset + +from pyrit.models import SeedPromptDataset +from pyrit.models.seed_prompt import SeedPrompt + + +def fetch_darkbench_dataset() -> SeedPromptDataset: + """ + Fetch DarkBench examples and create a SeedPromptDataset. + + Returns: + SeedPromptDataset: A SeedPromptDataset containing the examples. + """ + data = load_dataset("anonymous152311/darkbench", "default") + + prompts = [item["Example"] for item in data["train"]] + + seed_prompts = [ + SeedPrompt( + value=prompt, + data_type="text", + name="anonymous152311/darkbench", + dataset_name="anonymous152311/darkbench", + description="""DarkBench dataset on dark patterns from HuggingFace, + created by anonymous152311 (https://huggingface.co/anonymous152311).""", + source="https://huggingface.co/datasets/anonymous152311/darkbench", + ) + for prompt in prompts + ] + + seed_prompt_dataset = SeedPromptDataset(prompts=seed_prompts) + return seed_prompt_dataset diff --git a/tests/integration/datasets/test_fetch_datasets.py b/tests/integration/datasets/test_fetch_datasets.py index 4757c52ceb..97d4cb3295 100644 --- a/tests/integration/datasets/test_fetch_datasets.py +++ b/tests/integration/datasets/test_fetch_datasets.py @@ -7,6 +7,7 @@ fetch_adv_bench_dataset, fetch_aya_redteaming_dataset, fetch_babelscape_alert_dataset, + fetch_darkbench_dataset, fetch_decoding_trust_stereotypes_dataset, fetch_forbidden_questions_dataset, fetch_harmbench_dataset, @@ -29,6 +30,7 @@ (fetch_adv_bench_dataset, True), (fetch_aya_redteaming_dataset, True), (fetch_babelscape_alert_dataset, True), + (fetch_darkbench_dataset, True), (fetch_decoding_trust_stereotypes_dataset, True), (fetch_forbidden_questions_dataset, True), (fetch_harmbench_dataset, True), From b8e4113a530e19514872e83817c27ff9846c2dda Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:20:03 +0100 Subject: [PATCH 3/4] change `name` and `dataset_name` --- pyrit/datasets/darkbench_dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrit/datasets/darkbench_dataset.py b/pyrit/datasets/darkbench_dataset.py index bab554e363..50faead19a 100644 --- a/pyrit/datasets/darkbench_dataset.py +++ b/pyrit/datasets/darkbench_dataset.py @@ -22,8 +22,8 @@ def fetch_darkbench_dataset() -> SeedPromptDataset: SeedPrompt( value=prompt, data_type="text", - name="anonymous152311/darkbench", - dataset_name="anonymous152311/darkbench", + name="", + dataset_name="DarkBench", description="""DarkBench dataset on dark patterns from HuggingFace, created by anonymous152311 (https://huggingface.co/anonymous152311).""", source="https://huggingface.co/datasets/anonymous152311/darkbench", From a44c9551f652200f3d589827e724c389db370eb5 Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sun, 23 Mar 2025 21:00:34 +0100 Subject: [PATCH 4/4] include "Deceptive Pattern" column --- pyrit/datasets/darkbench_dataset.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pyrit/datasets/darkbench_dataset.py b/pyrit/datasets/darkbench_dataset.py index 50faead19a..f740ba96c7 100644 --- a/pyrit/datasets/darkbench_dataset.py +++ b/pyrit/datasets/darkbench_dataset.py @@ -16,19 +16,21 @@ def fetch_darkbench_dataset() -> SeedPromptDataset: """ data = load_dataset("anonymous152311/darkbench", "default") - prompts = [item["Example"] for item in data["train"]] - seed_prompts = [ SeedPrompt( - value=prompt, + value=item["Example"], data_type="text", name="", dataset_name="DarkBench", - description="""DarkBench dataset on dark patterns from HuggingFace, - created by anonymous152311 (https://huggingface.co/anonymous152311).""", + harm_categories=[item["Deceptive Pattern"]], + description="""The DarkBench dataset focuses on dark patterns and is available on Hugging Face, + created by anonymous152311 (https://huggingface.co/anonymous152311). The dataset includes + 660 examples, each labeled with a 'Deceptive Pattern' category. These categories indicate + different types of deceptive strategies used in the data, such as: + Anthropomorphization, Brand bias, Harmful generation, Sneaking, Sycophancy, or User retention.""", source="https://huggingface.co/datasets/anonymous152311/darkbench", ) - for prompt in prompts + for item in data["train"] ] seed_prompt_dataset = SeedPromptDataset(prompts=seed_prompts)