File size: 2,420 Bytes
c126239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script lang="ts">
  /**
   * Side-by-side probability bars for a single decoding step.
   * `after` is optional: baseline shows only the original distribution.
   */
  export interface BarRow {
    tokenId: number;
    text: string;
    before: number;
    after?: number;
    kind?: 'green' | 'red' | 'neutral';
  }

  let {
    rows,
    chosenTokenId = null,
    showAfter = true,
  }: { rows: BarRow[]; chosenTokenId?: number | null; showAfter?: boolean } = $props();

  const max = $derived(
    Math.max(0.0001, ...rows.flatMap((r) => [r.before, showAfter ? (r.after ?? 0) : 0])),
  );
</script>

<div class="bars">
  {#each rows as r}
    <div class="row" class:chosen={r.tokenId === chosenTokenId}>
      <span class="label mono" title={r.text}>{r.text.replace(/\n/g, '\\n') || '␣'}</span>
      <div class="track">
        <div
          class="bar before {r.kind ?? 'neutral'}"
          style="width: {(r.before / max) * 100}%"
        ></div>
        {#if showAfter && r.after !== undefined}
          <div class="bar after {r.kind ?? 'neutral'}" style="width: {(r.after / max) * 100}%"></div>
        {/if}
      </div>
      <span class="pct mono">
        {(r.before * 100).toFixed(1)}%{#if showAfter && r.after !== undefined}
          <span class="arrow"></span>{(r.after * 100).toFixed(1)}%{/if}
      </span>
    </div>
  {/each}
</div>

<style>
  .bars {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  .row {
    display: grid;
    grid-template-columns: 96px 1fr 118px;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
  }
  .row.chosen .label {
    font-weight: 700;
    color: var(--accent);
  }
  .label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .track {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .bar {
    height: 7px;
    border-radius: 3px;
    background: var(--panel-3);
    min-width: 1px;
    transition: width 0.15s ease-out;
  }
  .bar.before {
    background: var(--border-strong);
  }
  .bar.after.green {
    background: var(--green);
  }
  .bar.after.red {
    background: var(--red);
  }
  .bar.after.neutral {
    background: var(--accent);
  }
  .bar.before.green {
    background: var(--green-border);
  }
  .bar.before.red {
    background: var(--red-border);
  }
  .pct {
    text-align: right;
    color: var(--text-dim);
  }
  .arrow {
    margin: 0 3px;
  }
</style>