Skip to content

Commit 62ff0b7

Browse files
slister1001allenkim0129
authored andcommitted
Update randomization pattern for Adversarial simulation (Azure#38211)
* Update randomization pattern for Adversarial simulation * update changelog
1 parent 499c99c commit 62ff0b7

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

sdk/evaluation/azure-ai-evaluation/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Other Changes
1414
- Refined error messages for serviced-based evaluators and simulators.
1515
- Introduced environment variable `AI_EVALS_DISABLE_EXPERIMENTAL_WARNING` to disable the warning message for experimental features.
16+
- Changed the randomization pattern for `AdversarialSimulator` such that there is an almost equal number of Adversarial harm categories (e.g. Hate + Unfairness, Self-Harm, Violence, Sex) represented in the `AdversarialSimulator` outputs. Previously, for 200 `max_simulation_results` a user might see 140 results belonging to the 'Hate + Unfairness' category and 40 results belonging to the 'Self-Harm' category. Now, user will see 50 results for each of Hate + Unfairness, Self-Harm, Violence, and Sex.
1617

1718
## 1.0.0b5 (2024-10-28)
1819

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_adversarial_simulator.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import random
99
from typing import Any, Callable, Dict, List, Literal, Optional, Union, cast
10+
from itertools import zip_longest
1011

1112
from tqdm import tqdm
1213

@@ -215,17 +216,18 @@ async def __call__(
215216
ncols=100,
216217
unit="simulations",
217218
)
218-
for template in templates:
219-
parameter_order = list(range(len(template.template_parameters)))
220-
if randomize_order:
221-
# The template parameter lists are persistent across sim runs within a session,
222-
# So randomize a the selection instead of the parameter list directly,
223-
# or a potentially large deep copy.
224-
if randomization_seed is not None:
225-
random.seed(randomization_seed)
226-
random.shuffle(parameter_order)
227-
for index in parameter_order:
228-
parameter = template.template_parameters[index].copy()
219+
220+
if randomize_order:
221+
# The template parameter lists are persistent across sim runs within a session,
222+
# So randomize a the selection instead of the parameter list directly,
223+
# or a potentially large deep copy.
224+
if randomization_seed is not None:
225+
random.seed(randomization_seed)
226+
random.shuffle(templates)
227+
parameter_lists = [t.template_parameters for t in templates]
228+
zipped_parameters = list(zip_longest(*parameter_lists))
229+
for param_group in zipped_parameters:
230+
for template, parameter in zip(templates, param_group):
229231
if _jailbreak_type == "upia":
230232
parameter = self._join_conversation_starter(parameter, random.choice(jailbreak_dataset))
231233
tasks.append(

0 commit comments

Comments
 (0)