gregH commited on
Commit
82428f3
1 Parent(s): 0730956

Update assets/js/calibration.js

Browse files
Files changed (1) hide show
  1. 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"), cifar100_ece_data;
24
- $.getJSON("images/cifar100/cifar100_ece_value.json", function(data) {cifar100_ece_data = data;});
25
  $('input[type=radio][name=models]').change(function() {diagram.src = updateFigurePath();});
26
- $('input[type=radio][name=calibration_tool]').change(function() {
27
- if(this.value !== 'ts') {
28
- $("#ts-slider").slider('disable');
29
- $("#bin-slider").slider('enable');
30
  }
31
- else {
32
- $("#bin-slider").slider('disable');
33
- $("#ts-slider").slider('enable');
 
 
 
34
  }
35
  diagram.src = updateFigurePath();
36
  });
37
- var bin_handle = $("#bin-num");
38
- $( "#bin-slider" ).slider({
39
- step: 1,
40
- min: 4,
41
- max: 40,
42
- value: 15,
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 = $("#temp-scale");
47
- $("#ts-slider").slider({
48
- step: 0.2,
49
- min: 1.0,
50
- max: 1.8,
51
- value: 1.0,
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($('#bin-slider').slider("option", "value"),ui.value);},
55
  });
56
 
57
- function updateFigurePath(bin_num=$('#bin-slider').slider("option", "value"),temp=$('#ts-slider').slider("option", "value")) {
58
  var cur_model = $("input[type='radio'][name='models']:checked").val(),
59
- cur_tool = $("input[type='radio'][name='calibration_tool']:checked").val();
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 (cur_tool === "ts")
64
  {
65
- var ts_text = "_t" + (temp*100).toString();
66
- if (ts_text === "_t100") {
67
- asr_board.innerText = parseFloat(cifar100_ece_data[cur_model]["none"][bin_num]).toFixed(5);
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(cifar100_ece_data[cur_model][cur_tool][bin_num]).toFixed(5);
81
- brr_board.innerText = parseFloat(cifar100_ece_data[cur_model][cur_tool][bin_num]-0.0001).toFixed(5);
82
- return "images/"+"cifar100"+"/"+cur_model+"/"+cur_tool+"/"+"bin"+bin_num_text+"_actual"+".png";
 
 
 
 
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
  });