Update assets/js/calibration.js
Browse files- assets/js/calibration.js +40 -47
assets/js/calibration.js
CHANGED
@@ -20,71 +20,64 @@ $(document).ready(function(){
|
|
20 |
}
|
21 |
});
|
22 |
|
23 |
-
var diagram = document.getElementById("reliability-diagram"),
|
24 |
-
$.getJSON("
|
25 |
$('input[type=radio][name=models]').change(function() {diagram.src = updateFigurePath();});
|
26 |
-
$('input[type=radio][name=
|
27 |
-
if(this.value
|
28 |
-
$("#
|
29 |
-
$("#
|
30 |
}
|
31 |
-
else {
|
32 |
-
$("#
|
33 |
-
$("#
|
|
|
|
|
|
|
34 |
}
|
35 |
diagram.src = updateFigurePath();
|
36 |
});
|
37 |
-
var bin_handle = $("#
|
38 |
-
$( "#
|
39 |
-
step:
|
40 |
-
min:
|
41 |
-
max:
|
42 |
-
value:
|
43 |
create: function() {bin_handle.text($(this).slider("value"));},
|
|
|
44 |
slide: function(event, ui) {bin_handle.text(ui.value);diagram.src = updateFigurePath(ui.value);},
|
45 |
});
|
46 |
-
var ts_handle = $("#
|
47 |
-
$("#
|
48 |
-
step:
|
49 |
-
min:
|
50 |
-
max:
|
51 |
-
value:
|
52 |
disabled: true,
|
53 |
create: function() {ts_handle.text($(this).slider("value"));},
|
54 |
-
slide: function( event, ui ) {ts_handle.text(ui.value);diagram.src = updateFigurePath($('#
|
55 |
});
|
56 |
|
57 |
-
function updateFigurePath(
|
58 |
var cur_model = $("input[type='radio'][name='models']:checked").val(),
|
59 |
-
|
60 |
-
var bin_num_text = (bin_num < 10) ? "0" + bin_num.toString() : bin_num.toString();
|
61 |
var asr_board = document.getElementById("asr-value");
|
62 |
var brr_board = document.getElementById("brr-value");
|
63 |
-
if (
|
64 |
{
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
brr_board.innerText = parseFloat(cifar100_ece_data[cur_model]["none"][bin_num]-0.0001).toFixed(5);
|
69 |
-
return "images/" + "cifar100" + "/" + cur_model + "/none/" + "bin" + bin_num_text + "_actual" + ".png";
|
70 |
-
}
|
71 |
-
else
|
72 |
-
{
|
73 |
-
asr_board.innerText = parseFloat(cifar100_ece_data[cur_model][cur_tool][temp.toString()][bin_num]).toFixed(5);
|
74 |
-
brr_board.innerText = parseFloat(cifar100_ece_data[cur_model][cur_tool][temp.toString()][bin_num]-0.0001).toFixed(5);
|
75 |
-
return "images/"+"cifar100"+"/"+cur_model+"/"+cur_tool+"/"+"bin"+bin_num_text+ts_text+"_actual"+".png";
|
76 |
-
}
|
77 |
}
|
78 |
-
else
|
79 |
{
|
80 |
-
asr_board.innerText = parseFloat(
|
81 |
-
brr_board.innerText = parseFloat(
|
82 |
-
return "
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
}
|
85 |
});
|
86 |
-
|
87 |
-
function figureOption() {
|
88 |
-
var diagram = document.getElementById("reliability-diagram");
|
89 |
-
diagram.src = diagram.src.replace(".png", "_actual.png");
|
90 |
-
}
|
|
|
20 |
}
|
21 |
});
|
22 |
|
23 |
+
var diagram = document.getElementById("reliability-diagram"), jailbreak_results;
|
24 |
+
$.getJSON("demo_results/jailbreak_defense_results.jsonl", function(data) {jailbreak_results = data;});
|
25 |
$('input[type=radio][name=models]').change(function() {diagram.src = updateFigurePath();});
|
26 |
+
$('input[type=radio][name=defense]').change(function() {
|
27 |
+
if(this.value == 'ppl') {
|
28 |
+
$("#ppl-slider").slider('enable');
|
29 |
+
$("#gradient-norm-slider").slider('disable');
|
30 |
}
|
31 |
+
else if (this.value== 'gradient_cuff'){
|
32 |
+
$("#ppl-slider").slider('disable');
|
33 |
+
$("#gradient-norm-slider").slider('enable');
|
34 |
+
}else{
|
35 |
+
$("#ppl-slider").slider('disable');
|
36 |
+
$("#gradient-norm-slider").slider('disable');
|
37 |
}
|
38 |
diagram.src = updateFigurePath();
|
39 |
});
|
40 |
+
var bin_handle = $("#gradient-norm-threshold");
|
41 |
+
$( "#gradient-norm-slider" ).slider({
|
42 |
+
step: 50,
|
43 |
+
min: 0,
|
44 |
+
max: 950,
|
45 |
+
value: 100,
|
46 |
create: function() {bin_handle.text($(this).slider("value"));},
|
47 |
+
disabled: true,
|
48 |
slide: function(event, ui) {bin_handle.text(ui.value);diagram.src = updateFigurePath(ui.value);},
|
49 |
});
|
50 |
+
var ts_handle = $("#ppl_threshold");
|
51 |
+
$("#ppl-slider").slider({
|
52 |
+
step: 5,
|
53 |
+
min: 0,
|
54 |
+
max: 245,
|
55 |
+
value: 5,
|
56 |
disabled: true,
|
57 |
create: function() {ts_handle.text($(this).slider("value"));},
|
58 |
+
slide: function( event, ui ) {ts_handle.text(ui.value);diagram.src = updateFigurePath($('#gradient-norm-slider').slider("option", "value"),ui.value);},
|
59 |
});
|
60 |
|
61 |
+
function updateFigurePath(gradient_norm_threshold=$('#gradient-norm-slider').slider("option", "value"),ppl_threshold=$('#ppl-slider').slider("option", "value")) {
|
62 |
var cur_model = $("input[type='radio'][name='models']:checked").val(),
|
63 |
+
cur_defense = $("input[type='radio'][name='defense']:checked").val();
|
|
|
64 |
var asr_board = document.getElementById("asr-value");
|
65 |
var brr_board = document.getElementById("brr-value");
|
66 |
+
if (cur_defense === "ppl")
|
67 |
{
|
68 |
+
asr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"][ppl_threshold.toString()]["tpr"]).toFixed(5);
|
69 |
+
brr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"][ppl_threshold.toString()]["fpr"]).toFixed(5);
|
70 |
+
return "demo_results/demo_figures/ppl_"+cur_model+"_threshold_"+ppl_threshold.toString()+".png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
+
else if (cur_defense === "gradient_cuff")
|
73 |
{
|
74 |
+
asr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"][gradient_norm_threshold.toString()]["tpr"]).toFixed(5);
|
75 |
+
brr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"][gradient_norm_threshold.toString()]["fpr"]).toFixed(5);
|
76 |
+
return "demo_results/demo_figures/gradient_cuff_"+cur_model+"_threshold_"+gradient_norm_threshold.toString()+".png"
|
77 |
+
}else{
|
78 |
+
asr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"]["tpr"]).toFixed(5);
|
79 |
+
brr_board.innerText = parseFloat(jailbreak_results[cur_defense][cur_model]["pair"]["fpr"]).toFixed(5);
|
80 |
+
return "demo_results/demo_figures/"+cur_defense+"_"+cur_model+".png"
|
81 |
}
|
82 |
}
|
83 |
});
|
|
|
|
|
|
|
|
|
|