Skip to content

Commit b2751ba

Browse files
committed
Initial version of the safety benchmark, plus various fixes to the subsets.
Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com>
1 parent 95ad743 commit b2751ba

8 files changed

Lines changed: 51 additions & 11 deletions

File tree

prepare/benchmarks/safety.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from unitxt.benchmark import Benchmark
2+
from unitxt.catalog import add_to_catalog
3+
from unitxt.standard import DatasetRecipe
4+
5+
benchmark = Benchmark(
6+
subsets={
7+
"attaq": DatasetRecipe(card="cards.attaq"),
8+
"provoq": DatasetRecipe(card="cards.safety.provoq"),
9+
"airbench": DatasetRecipe(card="cards.safety.airbench2024"),
10+
"ailuminate": DatasetRecipe(card="cards.safety.mlcommons_ailuminate"),
11+
}
12+
)
13+
14+
add_to_catalog(benchmark, "benchmarks.safety", overwrite=True)

prepare/cards/attaq.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
Shuffle(page_size=2800),
1818
],
1919
task=Task(
20-
input_fields=["input"],
21-
reference_fields=["label"],
20+
input_fields={"input": str},
21+
reference_fields={"label": str},
22+
prediction_type=str,
2223
metrics=["metrics.safety_metric"],
2324
),
2425
templates=[

prepare/cards/safety/airbench2024.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
},
4444
reference_fields={},
4545
prediction_type=str,
46+
# TODO: The current implementation uses Granite Guardian as judge. Future versions could use a custom judge and use the judge_prompt field.
4647
metrics=[
4748
"metrics.granite_guardian.assistant_risk.harm[prediction_type=str,user_message_field=prompt,assistant_message_field=prediction]",
4849
],

prepare/cards/safety/mlcommons_ailuminate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
},
2727
reference_fields={},
2828
prediction_type=str,
29-
metrics=["metrics.llm_as_judge.safety.llamaguard"],
29+
metrics=[
30+
"metrics.granite_guardian.assistant_risk.harm[prediction_type=str,user_message_field=prompt_text,assistant_message_field=prediction]"
31+
],
3032
),
3133
templates=TemplatesDict(
3234
{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"__type__": "benchmark",
3+
"subsets": {
4+
"attaq": {
5+
"__type__": "dataset_recipe",
6+
"card": "cards.attaq"
7+
},
8+
"provoq": {
9+
"__type__": "dataset_recipe",
10+
"card": "cards.safety.provoq"
11+
},
12+
"airbench": {
13+
"__type__": "dataset_recipe",
14+
"card": "cards.safety.airbench2024"
15+
},
16+
"ailuminate": {
17+
"__type__": "dataset_recipe",
18+
"card": "cards.safety.mlcommons_ailuminate"
19+
}
20+
}
21+
}

src/unitxt/catalog/cards/attaq.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
],
1919
"task": {
2020
"__type__": "task",
21-
"input_fields": [
22-
"input"
23-
],
24-
"reference_fields": [
25-
"label"
26-
],
21+
"input_fields": {
22+
"input": "str"
23+
},
24+
"reference_fields": {
25+
"label": "str"
26+
},
27+
"prediction_type": "str",
2728
"metrics": [
2829
"metrics.safety_metric"
2930
]

src/unitxt/catalog/cards/safety/mlcommons_ailuminate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"reference_fields": {},
2323
"prediction_type": "str",
2424
"metrics": [
25-
"metrics.llm_as_judge.safety.llamaguard"
25+
"metrics.granite_guardian.assistant_risk.harm[prediction_type=str,user_message_field=prompt_text,assistant_message_field=prediction]"
2626
]
2727
},
2828
"templates": {

src/unitxt/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def process_value(self, text: Any) -> Any:
326326
try:
327327
return float(match.group(1)) * 0.25 - 0.25
328328
except:
329-
return np.NaN
329+
return np.nan
330330

331331

332332
class ExtractMtBenchLabelJudgment(FieldOperator):

0 commit comments

Comments
 (0)