File size: 12,361 Bytes
ffdff5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<div class="d3-llm-biases"></div>

<style>
  .d3-llm-biases {
    font-family: var(--default-font-family);
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: var(--spacing-4) 0;
    width: 100%;
    margin: 0 auto;
    position: relative;
    box-shadow: none !important;
  }

  .d3-llm-biases svg {
    width: 100%;
    height: auto;
    display: block;
  }

  .d3-llm-biases .card-rect {
    stroke-width: 2;
    transition: all 0.3s ease;
  }

  .d3-llm-biases .bias-title {
    fill: var(--text-color);
    font-size: 12px;
    font-weight: 700;
  }

  .d3-llm-biases .bias-description {
    fill: var(--text-color);
    font-size: 10px;
    font-weight: 400;
    line-height: 1.4;
  }

  .d3-llm-biases .header-text {
    fill: var(--text-color);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .d3-llm-biases .example-label {
    fill: var(--muted-color);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  @media (max-width: 768px) {
    .d3-llm-biases .bias-title {
      font-size: 10px;
    }

    .d3-llm-biases .bias-description {
      font-size: 9px;
    }
  }
</style>

<script>
  (() => {
    const ensureD3 = (cb) => {
      if (window.d3 && typeof window.d3.select === 'function') return cb();
      let s = document.getElementById('d3-cdn-script');
      if (!s) {
        s = document.createElement('script');
        s.id = 'd3-cdn-script';
        s.src = 'https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js';
        document.head.appendChild(s);
      }
      const onReady = () => {
        if (window.d3 && typeof window.d3.select === 'function') cb();
      };
      s.addEventListener('load', onReady, { once: true });
      if (window.d3) onReady();
    };

    const bootstrap = () => {
      const scriptEl = document.currentScript;
      let container = scriptEl ? scriptEl.previousElementSibling : null;
      if (!(container && container.classList && container.classList.contains('d3-llm-biases'))) {
        const candidates = Array.from(document.querySelectorAll('.d3-llm-biases'))
          .filter((el) => !(el.dataset && el.dataset.mounted === 'true'));
        container = candidates[candidates.length - 1] || null;
      }

      if (!container) return;

      if (container.dataset) {
        if (container.dataset.mounted === 'true') return;
        container.dataset.mounted = 'true';
      }

      // Get colors from ColorPalettes or fallback
      const getColors = () => {
        if (window.ColorPalettes && typeof window.ColorPalettes.getColors === 'function') {
          return window.ColorPalettes.getColors('categorical', 8);
        }
        return ['#e74c3c', '#3498db', '#9b59b6', '#f39c12', '#1abc9c', '#e67e22', '#95a5a6', '#34495e'];
      };

      // LLM judge biases - first 4 for row 1, remaining 3 for row 2
      const biases = [
        {
          id: 'internal-consistency',
          title: 'No Internal Consistency',
          description: 'Gives different judgements if prompted multiple times (at T>0)',
          reference: null
        },        {
          id: 'inconsistent-score-range',
          title: 'No Consistent Score Ranges',
          description: 'Model ranking do not follow a consistent scale (e.g: for a task where scores should be 1, 2, 3, 4, ... 10, the model might score 1, 1, 1, 10, 10 ... 10)',
          reference: 'x.com/aparnadhinak/status/1748368364395721128',
          reference2: 'github.com/LeonEricsson/llmjudge'
        },

        {
          id: 'self-preference',
          title: 'Self-Preference',
          description: 'Judge will favor outputs from similar models when scoring',
          reference: 'arxiv.org/abs/2404.13076'
        },
        {
          id: 'input-perturbation',
          title: 'Blindness to Input Perturbation',
          description: 'If input is perturbed, judges don\'t detect quality drops consistently',
          reference: 'arxiv.org/abs/2406.13439'
        },
        {
          id: 'position-bias',
          title: 'Position Bias',
          description: 'When comparing answers, judge favors specific answer positions (e.g: systematically prefers first or second choice)',
          reference: 'arxiv.org/abs/2306.05685'
        },
        {
          id: 'verbosity-bias',
          title: 'Verbosity Bias',
          description: 'Models prefer more verbose answers',
          reference: 'arxiv.org/abs/2404.04475'
        },
        {
          id: 'human-consistency',
          title: 'No Consistency With Human Scoring',
          description: 'LLM ratings diverge from human ratings',
          reference: 'arxiv.org/abs/2308.15812'
        },
        {
          id: 'format-bias',
          title: 'Format Bias',
          description: 'Judge can\'t judge well when their prompt differs from their training prompt format',
          reference: 'arxiv.org/abs/2310.17631'
        }
      ];

      const svg = d3.select(container).append('svg');
      const g = svg.append('g');

      let width = 800;
      let height = 300;

      // Helper function to wrap text
      function wrapText(text, width) {
        text.each(function() {
          const text = d3.select(this);
          const words = text.text().split(/\s+/).reverse();
          let word;
          let line = [];
          let lineNumber = 0;
          const lineHeight = 1.3;
          const y = text.attr('y');
          const x = text.attr('x');
          const dy = parseFloat(text.attr('dy') || 0);
          let tspan = text.text(null).append('tspan')
            .attr('x', x)
            .attr('y', y)
            .attr('dy', dy + 'em');

          while ((word = words.pop())) {
            line.push(word);
            tspan.text(line.join(' '));
            if (tspan.node().getComputedTextLength() > width) {
              line.pop();
              tspan.text(line.join(' '));
              line = [word];
              tspan = text.append('tspan')
                .attr('x', x)
                .attr('y', y)
                .attr('dy', ++lineNumber * lineHeight + dy + 'em')
                .text(word);
            }
          }
        });
      }

      function render() {
        width = container.clientWidth || 800;
        height = Math.max(550, Math.round(width * 0.7));

        svg.attr('width', width).attr('height', height);

        const margin = { top: 40, right: 20, bottom: 20, left: 20 };
        const innerWidth = width - margin.left - margin.right;
        const innerHeight = height - margin.top - margin.bottom;

        g.attr('transform', `translate(${margin.left},${margin.top})`);

        // Clear previous content
        g.selectAll('*').remove();

        const colors = getColors();

        // Header
        g.append('text')
          .attr('class', 'header-text')
          .attr('x', innerWidth / 2)
          .attr('y', -15)
          .attr('text-anchor', 'middle')
          .text('LLM JUDGE BIASES');

        // Calculate card dimensions - 4 rows: 2 cards each
        const cols = 2;
        const rows = 4;
        const cardSpacingX = Math.min(20, innerWidth * 0.03);
        const cardSpacingY = Math.min(18, innerHeight * 0.04);
        const cardWidth = (innerWidth - cardSpacingX * (cols - 1)) / cols;
        const cardHeight = (innerHeight - cardSpacingY * (rows - 1)) / rows;

        // Draw cards in 4 rows (2 + 2 + 2 + 2)
        biases.forEach((bias, i) => {
          const row = Math.floor(i / 2);
          const col = i % 2;

          const x = col * (cardWidth + cardSpacingX);
          const y = row * (cardHeight + cardSpacingY);

          const cardGroup = g.append('g')
            .attr('transform', `translate(${x},${y})`);

          // Card background with frame
          cardGroup.append('rect')
            .attr('class', 'card-rect')
            .attr('width', cardWidth)
            .attr('height', cardHeight)
            .attr('rx', 12)
            .attr('fill', colors[i])
            .attr('fill-opacity', 0.12)
            .attr('stroke', colors[i])
            .attr('stroke-opacity', 0.6)
            .attr('stroke-width', 2);

          // Title
          cardGroup.append('text')
            .attr('class', 'bias-title')
            .attr('x', cardWidth / 2)
            .attr('y', 20)
            .attr('text-anchor', 'middle')
            .text(bias.title);

          // Description with wrapping
          const descText = cardGroup.append('text')
            .attr('class', 'bias-description')
            .attr('x', cardWidth / 2)
            .attr('y', 36)
            .attr('text-anchor', 'middle')
            .attr('dy', 0)
            .text(bias.description);

          wrapText(descText, cardWidth - 20);

          // Example box (only if there's an example)
          if (bias.example) {
            const exampleY = cardHeight - 55;
            const exampleHeight = 24;

            cardGroup.append('rect')
              .attr('x', 8)
              .attr('y', exampleY)
              .attr('width', cardWidth - 16)
              .attr('height', exampleHeight)
              .attr('rx', 4)
              .attr('fill', colors[i])
              .attr('fill-opacity', 0.15)
              .attr('stroke', colors[i])
              .attr('stroke-width', 1)
              .attr('stroke-opacity', 0.4);

            // Example text
            cardGroup.append('text')
              .attr('class', 'bias-description')
              .attr('x', cardWidth / 2)
              .attr('y', exampleY + 13)
              .attr('text-anchor', 'middle')
              .attr('dominant-baseline', 'middle')
              .attr('font-size', 9)
              .text(bias.example);
          }

          // Reference link (if exists)
          if (bias.reference) {
            const refY = bias.example ? cardHeight - 8 : cardHeight - 12;
            const refLink = cardGroup.append('a')
              .attr('href', `https://${bias.reference}`)
              .attr('target', '_blank')
              .attr('rel', 'noopener noreferrer');

            refLink.append('text')
              .attr('class', 'example-label')
              .attr('x', cardWidth - 10)
              .attr('y', bias.reference2 ? refY - 10 : refY)
              .attr('text-anchor', 'end')
              .attr('font-size', 8)
              .attr('fill', colors[i])
              .attr('opacity', 0.7)
              .style('cursor', 'pointer')
              .style('text-decoration', 'underline')
              .text(bias.reference)
              .on('mouseenter', function() {
                d3.select(this).attr('opacity', 1);
              })
              .on('mouseleave', function() {
                d3.select(this).attr('opacity', 0.7);
              });
          }

          // Second reference link (if exists)
          if (bias.reference2) {
            const refY = bias.example ? cardHeight - 8 : cardHeight - 12;
            const refLink2 = cardGroup.append('a')
              .attr('href', `https://${bias.reference2}`)
              .attr('target', '_blank')
              .attr('rel', 'noopener noreferrer');

            refLink2.append('text')
              .attr('class', 'example-label')
              .attr('x', cardWidth - 10)
              .attr('y', refY)
              .attr('text-anchor', 'end')
              .attr('font-size', 8)
              .attr('fill', colors[i])
              .attr('opacity', 0.7)
              .style('cursor', 'pointer')
              .style('text-decoration', 'underline')
              .text(bias.reference2)
              .on('mouseenter', function() {
                d3.select(this).attr('opacity', 1);
              })
              .on('mouseleave', function() {
                d3.select(this).attr('opacity', 0.7);
              });
          }
        });
      }

      render();

      // Responsive handling
      if (window.ResizeObserver) {
        const ro = new ResizeObserver(() => render());
        ro.observe(container);
      } else {
        window.addEventListener('resize', render);
      }
    };

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', () => ensureD3(bootstrap), { once: true });
    } else {
      ensureD3(bootstrap);
    }
  })();
</script>