gregH commited on
Commit
32419de
·
verified ·
1 Parent(s): e341612

Create example.js

Browse files
Files changed (1) hide show
  1. assets/js/example.js +32 -0
assets/js/example.js ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function selectExample(exampleId) {
2
+ const examples = {
3
+ example1: "High-level speaking, successful jailbreaks share a common principle that they are trying to make the LLMs willing to affirm the user request which will be rejected at the beginning.",
4
+ example2: "Drawing upon this inspiration, our proposed defense aims to find the tokens that are most critical in forcing the LLM to generate such affirmative responses, decrease their importance in the generation, and thereby resolve the potential jailbreak risks brought by these tokens.",
5
+ example3: "To identify these tokens, we propose a new concept called the Affirmation Loss. We then use the loss's gradient norm with respect to each token in the user input prompt to find the jailbreak-critical tokens.",
6
+ example4: "We select those tokens with the larger gradient norm and then apply soft removal on them to mitigate the potential jailbreak risks."
7
+ };
8
+
9
+ const exampleText = document.getElementById('exampleText');
10
+ exampleText.innerHTML = examples[exampleId];
11
+
12
+ // Highlight specific parts of the text
13
+ switch (exampleId) {
14
+ case 'example1':
15
+ highlightText(exampleText, 'successful jailbreaks');
16
+ break;
17
+ case 'example2':
18
+ highlightText(exampleText, 'our proposed defense');
19
+ break;
20
+ case 'example3':
21
+ highlightText(exampleText, 'Affirmation Loss');
22
+ break;
23
+ case 'example4':
24
+ highlightText(exampleText, 'soft removal');
25
+ break;
26
+ }
27
+ }
28
+
29
+ function highlightText(element, keyword) {
30
+ const regex = new RegExp(`(${keyword})`, 'gi');
31
+ element.innerHTML = element.innerHTML.replace(regex, '<span class="highlight">$1</span>');
32
+ }