22# Licensed under the MIT license.
33
44import logging
5+ import os
56from typing import List , Optional
67
78from datasets import load_dataset
8485
8586
8687def fetch_sorry_bench_dataset (
88+ * ,
8789 cache_dir : Optional [str ] = None ,
8890 categories : Optional [List [str ]] = None ,
8991 prompt_style : Optional [str ] = None ,
92+ token : Optional [str ] = None ,
9093) -> SeedDataset :
9194 """
9295 Fetch Sorry-Bench dataset from Hugging Face (updated 2025/03 version).
@@ -97,23 +100,29 @@ def fetch_sorry_bench_dataset(
97100 Reference: https://arxiv.org/abs/2406.14598
98101
99102 Args:
100- cache_dir: Optional cache directory for Hugging Face datasets
101- categories: Optional list of categories to filter. Full list in:
103+ cache_dir (Optional[str]) : Optional cache directory for Hugging Face datasets.
104+ categories (Optional[List[str]]) : Optional list of categories to filter. Full list in:
102105 https://huggingface.co/datasets/sorry-bench/sorry-bench-202503/blob/main/meta_info.py
103- prompt_style: Optional prompt style to filter. Available styles:
106+ prompt_style (Optional[str]) : Optional prompt style to filter. Available styles:
104107 "base", "ascii", "caesar", "slang", "authority_endorsement", etc.
105108 Default: "base" (only base prompts, no mutations)
106109 Full list: https://huggingface.co/datasets/sorry-bench/sorry-bench-202503
110+ token (Optional[str]): Hugging Face authentication token. If not provided,
111+ will attempt to read from HUGGINGFACE_TOKEN environment variable. This is needed for
112+ accessing gated datasets on Hugging Face.
107113
108114 Returns:
109- SeedDataset containing Sorry-Bench prompts with harm categories.
115+ SeedDataset: SeedDataset containing Sorry-Bench prompts with harm categories.
110116
111117 Raises:
112118 ValueError: If invalid categories or prompt_style are provided.
113119 """
114120 if prompt_style is None :
115121 prompt_style = "base"
116122
123+ if token is None :
124+ token = os .environ .get ("HUGGINGFACE_TOKEN" )
125+
117126 if prompt_style not in VALID_PROMPT_STYLES :
118127 raise ValueError (f"Invalid prompt_style '{ prompt_style } '. Must be one of: { ', ' .join (VALID_PROMPT_STYLES )} " )
119128
@@ -128,7 +137,7 @@ def fetch_sorry_bench_dataset(
128137 try :
129138 source = "sorry-bench/sorry-bench-202503"
130139 logger .info (f"Loading Sorry-Bench dataset from { source } " )
131- data = load_dataset (source , cache_dir = cache_dir )
140+ data = load_dataset (source , cache_dir = cache_dir , token = token )
132141
133142 dataset_split = data ["train" ]
134143
0 commit comments