pierrefdz commited on
Commit
e4409fa
·
1 Parent(s): 8e6cbe9

added helpers

Browse files
wm_interactive/static/styles.css CHANGED
@@ -354,4 +354,98 @@ h1 {
354
 
355
  .floating-btn.generating .stop-icon {
356
  display: block;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  }
 
354
 
355
  .floating-btn.generating .stop-icon {
356
  display: block;
357
+ }
358
+
359
+ /* Help documentation styles */
360
+ .param-help-icon {
361
+ color: #6e6e80;
362
+ font-size: 14px;
363
+ cursor: pointer;
364
+ }
365
+
366
+ .help-modal-body {
367
+ max-height: 70vh;
368
+ overflow-y: auto;
369
+ }
370
+
371
+ .help-modal-body h4 {
372
+ margin-top: 1.5rem;
373
+ margin-bottom: 0.75rem;
374
+ font-size: 1.1rem;
375
+ font-weight: 600;
376
+ color: #10a37f;
377
+ }
378
+
379
+ .help-modal-body h4:first-child {
380
+ margin-top: 0;
381
+ }
382
+
383
+ .help-modal-body p {
384
+ margin-bottom: 1rem;
385
+ line-height: 1.6;
386
+ }
387
+
388
+ .help-modal-body ol, .help-modal-body ul {
389
+ margin-bottom: 1rem;
390
+ padding-left: 1.5rem;
391
+ }
392
+
393
+ .help-modal-body li {
394
+ margin-bottom: 0.5rem;
395
+ }
396
+
397
+ .help-description-list dt {
398
+ font-weight: 600;
399
+ margin-bottom: 0.25rem;
400
+ }
401
+
402
+ .help-description-list dd {
403
+ margin-bottom: 1rem;
404
+ margin-left: 1rem;
405
+ }
406
+
407
+ .paper-references {
408
+ list-style: none;
409
+ padding-left: 0;
410
+ }
411
+
412
+ .paper-references li {
413
+ margin-bottom: 0.75rem;
414
+ padding-left: 1rem;
415
+ border-left: 3px solid #e5e5e5;
416
+ }
417
+
418
+ .paper-references a {
419
+ display: block;
420
+ color: #10a37f;
421
+ font-weight: 500;
422
+ margin-bottom: 0.25rem;
423
+ }
424
+
425
+ .paper-authors {
426
+ display: block;
427
+ color: #6e6e80;
428
+ font-size: 0.9rem;
429
+ font-style: italic;
430
+ }
431
+
432
+ /* Tooltip adjustments for parameter help icons */
433
+ .tooltip {
434
+ --bs-tooltip-max-width: 300px;
435
+ --bs-tooltip-opacity: 1;
436
+ --bs-tooltip-padding-y: 0.5rem;
437
+ --bs-tooltip-padding-x: 0.75rem;
438
+ --bs-tooltip-bg: rgba(26, 26, 26, 0.95);
439
+ font-size: 13px;
440
+ line-height: 1.4;
441
+ }
442
+
443
+ @media (max-width: 768px) {
444
+ .help-modal-body {
445
+ max-height: 60vh;
446
+ }
447
+
448
+ .tooltip {
449
+ --bs-tooltip-max-width: 200px;
450
+ }
451
  }
wm_interactive/templates/index.html CHANGED
@@ -11,9 +11,97 @@
11
  <div class="container">
12
  <div class="d-flex justify-content-between align-items-center">
13
  <h1>Interactive watermark detector</h1>
14
- <button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#paramsModal">
15
- <i class="bi bi-gear"></i>
16
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  </div>
18
 
19
  <!-- Advanced Parameters Modal -->
@@ -26,7 +114,10 @@
26
  </div>
27
  <div class="modal-body">
28
  <div class="mb-3">
29
- <label for="detectorType" class="form-label">Detector Type</label>
 
 
 
30
  <select class="form-select" id="detectorType">
31
  <option value="maryland">Maryland</option>
32
  <option value="marylandz">Maryland Z-score</option>
@@ -36,22 +127,34 @@
36
  <div class="form-text">Type of watermark detection algorithm</div>
37
  </div>
38
  <div class="mb-3">
39
- <label for="seed" class="form-label">Seed</label>
 
 
 
40
  <input type="number" class="form-control" id="seed" value="0">
41
  <div class="form-text">Random seed for the watermark detector</div>
42
  </div>
43
  <div class="mb-3">
44
- <label for="ngram" class="form-label">N-gram Size</label>
 
 
 
45
  <input type="number" class="form-control" id="ngram" value="1">
46
  <div class="form-text">Size of the n-gram window used for detection</div>
47
  </div>
48
  <div class="mb-3">
49
- <label for="delta" class="form-label">Delta</label>
 
 
 
50
  <input type="number" step="0.1" class="form-control" id="delta" value="2.0">
51
  <div class="form-text">Bias added to greenlist tokens (for Maryland method)</div>
52
  </div>
53
  <div class="mb-3">
54
- <label for="temperature" class="form-label">Temperature</label>
 
 
 
55
  <input type="number" step="0.1" class="form-control" id="temperature" value="0.8">
56
  <div class="form-text">Temperature for sampling (higher = more random)</div>
57
  </div>
@@ -137,6 +240,20 @@
137
  const deltaInput = document.getElementById('delta');
138
  const temperatureInput = document.getElementById('temperature');
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  function startGeneration() {
141
  const prompt = promptArea.value.trim();
142
  if (!prompt) {
@@ -439,13 +556,6 @@
439
  });
440
  });
441
 
442
- // Initial tokenization with error handling
443
- document.addEventListener('DOMContentLoaded', function() {
444
- updateTokenization().catch(error => {
445
- console.error('Error during initial tokenization:', error);
446
- });
447
- });
448
-
449
  // Add this helper function for formatting p-values
450
  function formatPValue(value) {
451
  if (value >= 0.001) {
 
11
  <div class="container">
12
  <div class="d-flex justify-content-between align-items-center">
13
  <h1>Interactive watermark detector</h1>
14
+ <div class="d-flex gap-2">
15
+ <button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#helpModal">
16
+ <i class="bi bi-question-circle"></i>
17
+ </button>
18
+ <button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#paramsModal">
19
+ <i class="bi bi-gear"></i>
20
+ </button>
21
+ </div>
22
+ </div>
23
+
24
+ <!-- Help Modal -->
25
+ <div class="modal fade" id="helpModal" tabindex="-1">
26
+ <div class="modal-dialog modal-lg">
27
+ <div class="modal-content">
28
+ <div class="modal-header">
29
+ <h5 class="modal-title">Watermark Detection Help</h5>
30
+ <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
31
+ </div>
32
+ <div class="modal-body help-modal-body">
33
+ <h4>What is LLM watermarking?</h4>
34
+ <p>LLM watermarking is a technique that slightly modifies how language models generate text, making it possible to detect if text was generated by a specific AI model without visibly changing the text quality.</p>
35
+
36
+ <h4>How to use this demo</h4>
37
+ <ol>
38
+ <li>Enter a prompt in the top text area to generate watermarked text</li>
39
+ <li>The generated text will appear in the second text box</li>
40
+ <li>The text will be automatically analyzed to show which tokens (parts of text) were influenced by the watermark</li>
41
+ <li>The statistics at the bottom show the detection results</li>
42
+ <li>You can also paste any text in the second box to test if it contains a watermark</li>
43
+ </ol>
44
+
45
+ <h4>Detection Methods</h4>
46
+ <p><strong>Maryland</strong>: A token-level detection algorithm that analyzes how unexpected each token is, based on the paper "<a href="https://arxiv.org/abs/2301.10226" target="_blank">A Watermark for Large Language Models</a>" by Kirchenbauer et al.</p>
47
+ <p><strong>Maryland Z-score</strong>: A variant of the Maryland detector that uses z-scores for better statistical interpretation.</p>
48
+ <p><strong>OpenAI</strong>: A watermarking method similar to what was described in "<a href="https://arxiv.org/abs/2306.04634" target="_blank">A Watermark for Large Language Models</a>" by Kirchenbauer et al., inspired by initial reports from OpenAI.</p>
49
+ <p><strong>OpenAI Z-score</strong>: A variant of the OpenAI detector that uses z-scores for better statistical interpretation.</p>
50
+
51
+ <h4>Parameters Explained</h4>
52
+ <dl class="help-description-list">
53
+ <dt>Detector Type</dt>
54
+ <dd>The algorithm used to detect watermarks in the text. Different detectors perform better in different scenarios.</dd>
55
+
56
+ <dt>Seed</dt>
57
+ <dd>The random seed used for watermarking. The detector must use the same seed that was used when generating the text. In a real-world scenario, this would be kept private by the model provider.</dd>
58
+
59
+ <dt>N-gram Size</dt>
60
+ <dd>The number of previous tokens considered when choosing "greenlist" tokens. Larger values make the watermark more robust against edits but may reduce text quality.</dd>
61
+
62
+ <dt>Delta</dt>
63
+ <dd>The bias added to "greenlist" tokens during generation. Higher values make the watermark stronger but might affect text quality. Typical values range from 1.0 to 5.0.</dd>
64
+
65
+ <dt>Temperature</dt>
66
+ <dd>Controls randomness in text generation. Higher values (e.g., 1.0) produce more diverse outputs; lower values (e.g., 0.2) make outputs more focused and deterministic.</dd>
67
+ </dl>
68
+
69
+ <h4>Understanding Results</h4>
70
+ <dl class="help-description-list">
71
+ <dt>Tokens</dt>
72
+ <dd>The total number of tokens in the analyzed text. Tokens are units of text that may represent words, parts of words, or punctuation.</dd>
73
+
74
+ <dt>Scored Tokens</dt>
75
+ <dd>The number of tokens that were actually evaluated by the detector (excludes first few tokens that don't have enough context).</dd>
76
+
77
+ <dt>Final Score</dt>
78
+ <dd>A measure of how likely the text contains a watermark. Higher scores indicate stronger evidence of watermarking.</dd>
79
+
80
+ <dt>P-value</dt>
81
+ <dd>The statistical significance of the detection. Lower values (especially p &lt; 0.05) indicate strong evidence that the text was watermarked. Values close to 0.5 suggest no watermark is present.</dd>
82
+ </dl>
83
+
84
+ <h4>Related Papers</h4>
85
+ <ul class="paper-references">
86
+ <li>
87
+ <a href="https://arxiv.org/abs/2301.10226" target="_blank">A Watermark for Large Language Models</a>
88
+ <span class="paper-authors">Kirchenbauer, Geiping, et al. (2023)</span>
89
+ </li>
90
+ <li>
91
+ <a href="https://arxiv.org/abs/2306.04634" target="_blank">Robust Distortion-free Watermarks for Language Models</a>
92
+ <span class="paper-authors">Kuditipudi, Thickstun, et al. (2023)</span>
93
+ </li>
94
+ <li>
95
+ <a href="https://arxiv.org/abs/2305.08883" target="_blank">Provable Robust Watermarking for AI-Generated Text</a>
96
+ <span class="paper-authors">Christ, Mireshghallah, et al. (2023)</span>
97
+ </li>
98
+ </ul>
99
+ </div>
100
+ <div class="modal-footer">
101
+ <button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
102
+ </div>
103
+ </div>
104
+ </div>
105
  </div>
106
 
107
  <!-- Advanced Parameters Modal -->
 
114
  </div>
115
  <div class="modal-body">
116
  <div class="mb-3">
117
+ <div class="d-flex align-items-center">
118
+ <i class="bi bi-info-circle param-help-icon me-2" data-bs-toggle="tooltip" title="The algorithm used to detect watermarks in the text. Different algorithms have different strengths and weaknesses."></i>
119
+ <label for="detectorType" class="form-label mb-0">Detector Type</label>
120
+ </div>
121
  <select class="form-select" id="detectorType">
122
  <option value="maryland">Maryland</option>
123
  <option value="marylandz">Maryland Z-score</option>
 
127
  <div class="form-text">Type of watermark detection algorithm</div>
128
  </div>
129
  <div class="mb-3">
130
+ <div class="d-flex align-items-center">
131
+ <i class="bi bi-info-circle param-help-icon me-2" data-bs-toggle="tooltip" title="The random seed used for watermarking. For detection to work, this must match the seed used during generation."></i>
132
+ <label for="seed" class="form-label mb-0">Seed</label>
133
+ </div>
134
  <input type="number" class="form-control" id="seed" value="0">
135
  <div class="form-text">Random seed for the watermark detector</div>
136
  </div>
137
  <div class="mb-3">
138
+ <div class="d-flex align-items-center">
139
+ <i class="bi bi-info-circle param-help-icon me-2" data-bs-toggle="tooltip" title="The number of previous tokens considered when determining the token distribution. Higher values are more secure but may affect quality."></i>
140
+ <label for="ngram" class="form-label mb-0">N-gram Size</label>
141
+ </div>
142
  <input type="number" class="form-control" id="ngram" value="1">
143
  <div class="form-text">Size of the n-gram window used for detection</div>
144
  </div>
145
  <div class="mb-3">
146
+ <div class="d-flex align-items-center">
147
+ <i class="bi bi-info-circle param-help-icon me-2" data-bs-toggle="tooltip" title="The bias added to greenlist tokens during generation. Higher values (2.0-5.0) make watermarks easier to detect but might affect text quality."></i>
148
+ <label for="delta" class="form-label mb-0">Delta</label>
149
+ </div>
150
  <input type="number" step="0.1" class="form-control" id="delta" value="2.0">
151
  <div class="form-text">Bias added to greenlist tokens (for Maryland method)</div>
152
  </div>
153
  <div class="mb-3">
154
+ <div class="d-flex align-items-center">
155
+ <i class="bi bi-info-circle param-help-icon me-2" data-bs-toggle="tooltip" title="Controls randomness in generation. Higher values (closer to 1.0) create more diverse outputs but might make watermarks harder to detect."></i>
156
+ <label for="temperature" class="form-label mb-0">Temperature</label>
157
+ </div>
158
  <input type="number" step="0.1" class="form-control" id="temperature" value="0.8">
159
  <div class="form-text">Temperature for sampling (higher = more random)</div>
160
  </div>
 
240
  const deltaInput = document.getElementById('delta');
241
  const temperatureInput = document.getElementById('temperature');
242
 
243
+ // Initialize tooltips
244
+ document.addEventListener('DOMContentLoaded', function() {
245
+ // Initialize Bootstrap tooltips
246
+ const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
247
+ const tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
248
+ return new bootstrap.Tooltip(tooltipTriggerEl);
249
+ });
250
+
251
+ // Initialize our tokenization
252
+ updateTokenization().catch(error => {
253
+ console.error('Error during initial tokenization:', error);
254
+ });
255
+ });
256
+
257
  function startGeneration() {
258
  const prompt = promptArea.value.trim();
259
  if (!prompt) {
 
556
  });
557
  });
558
 
 
 
 
 
 
 
 
559
  // Add this helper function for formatting p-values
560
  function formatPValue(value) {
561
  if (value >= 0.001) {