Skip to content

Commit 9e93b7d

Browse files
authored
Add Airbench (#1730)
* Initial implementation Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> * Remove obsolete Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> * Revised version Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> * Add missing argument. Kudos to @vz-ibm for figuring out the issue. Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> * . Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> * Switch to Granite Guardian as metric. Remove redundant loader fix Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com> --------- Signed-off-by: Jonathan Bnayahu <bnayahu@il.ibm.com>
1 parent 4e918f8 commit 9e93b7d

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from unitxt import add_to_catalog
2+
from unitxt.blocks import InputOutputTemplate, Task, TaskCard
3+
from unitxt.loaders import LoadHF, MultipleSourceLoader
4+
from unitxt.operators import SelectFields
5+
from unitxt.stream_operators import JoinStreams
6+
from unitxt.templates import TemplatesDict
7+
from unitxt.test_utils.card import test_card
8+
9+
dataset_path = "stanford-crfm/air-bench-2024"
10+
11+
card = TaskCard(
12+
loader=MultipleSourceLoader( sources =
13+
[
14+
LoadHF(path=dataset_path, name="default"),
15+
LoadHF(path=dataset_path, data_files={
16+
"judge_prompts": "judge_prompt_final.csv"
17+
})
18+
],
19+
data_classification_policy=["public"],
20+
),
21+
preprocess_steps=[
22+
SelectFields(
23+
fields=["cate-idx", "judge_prompt"], apply_to_streams=["judge_prompts"]
24+
),
25+
JoinStreams(
26+
left_stream="test",
27+
right_stream="judge_prompts",
28+
how="inner",
29+
on=["cate-idx"],
30+
new_stream_name="test",)
31+
],
32+
task=Task(
33+
input_fields={"cate-idx": str, "l2-name": str, "l3-name": str, "l4-name": str, "prompt": str, "judge_prompt": str},
34+
reference_fields={},
35+
prediction_type=str,
36+
metrics=[
37+
"metrics.granite_guardian.assistant_risk.harm[prediction_type=str,user_message_field=prompt,assistant_message_field=prediction]",
38+
],
39+
),
40+
templates=TemplatesDict({"default": InputOutputTemplate(input_format="{prompt}\n", output_format="")}),
41+
__description__="AIRBench 2024 is a AI safety benchmark that aligns with emerging government regulations and company policies. It consists of diverse, malicious prompts spanning categories of the regulation-based safety categories in the AIR 2024 safety taxonomy.",
42+
__tags__={
43+
"languages": ["english"],
44+
"urls": {"arxiv": "https://arxiv.org/abs/2407.17436"},
45+
},
46+
)
47+
48+
test_card(card,strict=False,loader_limit=10000)
49+
50+
add_to_catalog(card, "cards.safety.airbench2024", overwrite=True)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"__type__": "task_card",
3+
"loader": {
4+
"__type__": "multiple_source_loader",
5+
"sources": [
6+
{
7+
"__type__": "load_hf",
8+
"path": "stanford-crfm/air-bench-2024",
9+
"name": "default"
10+
},
11+
{
12+
"__type__": "load_hf",
13+
"path": "stanford-crfm/air-bench-2024",
14+
"data_files": {
15+
"judge_prompts": "judge_prompt_final.csv"
16+
}
17+
}
18+
],
19+
"data_classification_policy": [
20+
"public"
21+
]
22+
},
23+
"preprocess_steps": [
24+
{
25+
"__type__": "select_fields",
26+
"fields": [
27+
"cate-idx",
28+
"judge_prompt"
29+
],
30+
"apply_to_streams": [
31+
"judge_prompts"
32+
]
33+
},
34+
{
35+
"__type__": "join_streams",
36+
"left_stream": "test",
37+
"right_stream": "judge_prompts",
38+
"how": "inner",
39+
"on": [
40+
"cate-idx"
41+
],
42+
"new_stream_name": "test"
43+
}
44+
],
45+
"task": {
46+
"__type__": "task",
47+
"input_fields": {
48+
"cate-idx": "str",
49+
"l2-name": "str",
50+
"l3-name": "str",
51+
"l4-name": "str",
52+
"prompt": "str",
53+
"judge_prompt": "str"
54+
},
55+
"reference_fields": {},
56+
"prediction_type": "str",
57+
"metrics": [
58+
"metrics.granite_guardian.assistant_risk.harm[prediction_type=str,user_message_field=prompt,assistant_message_field=prediction]"
59+
]
60+
},
61+
"templates": {
62+
"__type__": "templates_dict",
63+
"items": {
64+
"default": {
65+
"__type__": "input_output_template",
66+
"input_format": "{prompt}\n",
67+
"output_format": ""
68+
}
69+
}
70+
},
71+
"__description__": "AIRBench 2024 is a AI safety benchmark that aligns with emerging government regulations and company policies. It consists of diverse, malicious prompts spanning categories of the regulation-based safety categories in the AIR 2024 safety taxonomy.",
72+
"__tags__": {
73+
"languages": [
74+
"english"
75+
],
76+
"urls": {
77+
"arxiv": "https://arxiv.org/abs/2407.17436"
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)