File size: 13,997 Bytes
76b5743
f25ae00
76b5743
 
 
 
 
 
 
 
 
 
 
 
 
f25ae00
76b5743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f25ae00
 
 
 
 
 
 
 
 
76b5743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f25ae00
 
 
 
 
 
 
 
 
 
 
 
 
76b5743
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="attribution.css">
</head>

<body>

    <main class="main_frame">
        <section class="left_panel">
            <div class="floating_content">
                <!-- INCLUDE partials/app-header.html -->

                <div class="chat-cached-history-bar">
                    <div class="semantic-search-input-wrapper chat-prompt-history-wrapper">
                        <button type="button" id="attribution_cached_history_btn" class="text-action-btn" data-i18n>Cached history</button>
                        <ul id="attribution_cached_history_dropdown" class="semantic-search-history-dropdown"></ul>
                    </div>
                </div>

                <section id="attribution_examples" class="page-examples-section"></section>

                <section class="input-section">
                    <div class="chat-prompt-panel">
                        <div class="input-header">
                            <span data-i18n>Context</span>
                            <div class="text-action-buttons-top">
                                <div class="textarea-counter" id="context_count_display">
                                    <span id="context_count_value">0</span> <span data-i18n>chars</span>
                                </div>
                                <button type="button" id="clear_context_btn" class="text-action-btn" data-i18n>Clear</button>
                                <button type="button" id="paste_context_btn" class="text-action-btn" data-i18n>Paste</button>
                                <button type="button" id="context_history_btn" class="text-action-btn" data-i18n>History</button>
                            </div>
                        </div>
                        <div class="textarea-wrapper chat-prompt-textarea-block">
                            <div class="semantic-search-input-wrapper chat-prompt-history-wrapper">
                                <textarea id="context_text"></textarea>
                                <ul id="context_history_dropdown" class="semantic-search-history-dropdown"></ul>
                            </div>
                        </div>
                    </div>

                    <div class="chat-prompt-panel attribution-target-panel">
                        <div class="input-header">
                            <span data-i18n>Target prediction</span>
                            <div class="text-action-buttons-top">
                                <div class="textarea-counter" id="target_count_display">
                                    <span id="target_count_value">0</span> <span data-i18n>chars</span>
                                </div>
                                <button type="button" id="clear_target_btn" class="text-action-btn" data-i18n>Clear</button>
                                <button type="button" id="paste_target_btn" class="text-action-btn" data-i18n>Paste</button>
                                <button type="button" id="target_history_btn" class="text-action-btn" data-i18n>History</button>
                            </div>
                        </div>
                        <div class="textarea-wrapper chat-prompt-textarea-block">
                            <div class="semantic-search-input-wrapper chat-prompt-history-wrapper">
                                <textarea id="target_text"></textarea>
                                <ul id="target_history_dropdown" class="semantic-search-history-dropdown"></ul>
                            </div>
                        </div>
                    </div>

                    <div class="textarea-wrapper chat-prompt-actions-row">
                        <div class="semantic-submode-row chat-completion-options-row attribution-model-variant-row">
                            <span class="semantic-submode-group">
                                <label class="semantic-submode-label" for="attribution_model_variant" data-i18n>Model</label>
                                <select id="attribution_model_variant" class="semantic-submode-select" aria-label="Attribution model slot" data-i18n="aria-label">
                                    <option value="base">base</option>
                                    <option value="instruct">instruct</option>
                                </select>
                            </span>
                            <span class="semantic-submode-group">
                                <label class="semantic-submode-label" for="attribution_method" data-i18n>Method</label>
                                <select id="attribution_method" class="semantic-submode-select" aria-label="Attribution method" data-i18n="aria-label">
                                    <option value="gradient" data-i18n>Gradient</option>
                                    <option value="ablation" data-i18n>Ablation</option>
                                    <option value="both" data-i18n>Both</option>
                                </select>
                            </span>
                        </div>
                        <div class="button-group">
                            <div class="button-left">
                                <div class="button-left-primary">
                                    <button type="button" id="analyze_btn" class="primary-btn inactive" disabled data-i18n>Analyze attribution</button>
                                    <div class="loadersmall loader-small-container"></div>
                                </div>
                            </div>
                            <div id="attribution_result_info" class="text-metrics is-hidden"></div>
                            <div class="button-right">
                                <button type="button" id="force_retry_btn" class="primary-btn inactive" disabled title="Fetch again without using cached result" data-i18n="text,title">Force retry</button>
                            </div>
                        </div>
                    </div>

                    <div class="semantic-submode-row attribution-max-score-row">
                        <span class="semantic-submode-group">
                            <label class="attribution-use-mapping-label">
                                <input type="checkbox" id="attribution_use_mapping">
                                <span></span>
                            </label>
                        </span>
                        <span class="semantic-submode-group attribution-max-score-slider-group">
                            <label class="semantic-submode-label" for="attribution_max_score_range" data-i18n>Max score</label>
                            <input type="range" id="attribution_max_score_range" class="attribution-max-score-range"
                                min="0.01" max="1" step="0.01" value="1"
                                title="For threshold x∈(0,1]: map normalized scores in [0,x] linearly to display intensities [0,1]; scores above x saturate at maximum intensity. At x=1, equivalent to disabling mapping."
                                data-i18n="title"
                                disabled>
                            <span id="attribution_max_score_value" class="attribution-max-score-value" aria-live="polite">1.00</span>
                        </span>
                    </div>

                    <div class="attribution-exclude-prompt-patterns-row">
                        <div class="semantic-submode-row attribution-exclude-prompt-patterns-header">
                            <span class="semantic-submode-group">
                                <label class="attribution-use-mapping-label"
                                    title="When enabled, each line below is a regex with the global flag, matched only within the context field below. If a token offset lies fully inside a match, its score is treated as 0."
                                    data-i18n="title">
                                    <input type="checkbox" id="attribution_exclude_prompt_patterns_enable" checked>
                                    <span></span>
                                </label>
                            </span>
                            <span class="semantic-submode-group">
                                <label class="semantic-submode-label" for="attribution_exclude_prompt_patterns" data-i18n>Exclude prompt patterns</label>
                            </span>
                        </div>
                        <textarea id="attribution_exclude_prompt_patterns" class="attribution-exclude-prompt-patterns-input" rows="1"
                            placeholder="One regex per line (context only)"
                            spellcheck="false"
                            autocomplete="off"
                            title="One regex per line (global flag), matched only within the context text; if a token offset lies fully inside a match, its score is treated as 0."
                            data-i18n="placeholder,title"></textarea>
                    </div>
                </section>
            </div>
        </section>

        <div class="resizer" id="resizer"></div>

        <section class="right_panel">
            <div class="empty-state empty-state-dashed">
                <svg class="empty-state-icon" viewBox="0 0 48 48" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
                    <circle cx="24" cy="24" r="16"/>
                    <path d="M24 8 L24 40 M8 24 L40 24"/>
                    <circle cx="24" cy="24" r="6"/>
                </svg>
                <div class="empty-state-title" data-i18n>No attribution yet</div>
                <div class="empty-state-description" data-i18n>Enter context and target text on the left, then click Analyze to see which words drive the prediction.</div>
            </div>
            <div class="attribution-method-panels">
                <div class="attribution-gradient-panel">
                    <div class="attribution-panel-label" data-i18n>Gradient</div>
                    <div id="results" class="attribution-inspector-surface">
                        <div id="major_tooltip" class="tooltip">
                            <div class="currentToken"></div>
                            <div class="myDetail"></div>
                            <br />
                            <div class="predictions predictions-table"></div>
                        </div>
                    </div>
                    <div id="attribution_debug_container"></div>
                </div>
                <div class="attribution-ablation-panel">
                    <div class="attribution-panel-label" data-i18n>Ablation</div>
                    <div id="ablation_results" class="attribution-inspector-surface">
                        <div id="ablation_major_tooltip" class="tooltip">
                            <div class="currentToken"></div>
                            <div class="myDetail"></div>
                            <br />
                            <div class="predictions predictions-table"></div>
                        </div>
                    </div>
                    <div id="ablation_debug_container"></div>
                    <div class="attribution-ablation-disclaimer" data-i18n>
                        Occlusion-based causal attribution. Positive = supports target; negative = suppresses target.
                    </div>
                </div>
            </div>
            <div id="attribution_both_legend" class="attribution-both-legend" style="display:none;">
                <span class="attribution-legend-item">
                    <span class="attribution-legend-swatch attribution-legend-positive"></span>
                    <span data-i18n>Supports target</span>
                </span>
                <span class="attribution-legend-item">
                    <span class="attribution-legend-swatch attribution-legend-negative"></span>
                    <span data-i18n>Suppresses target</span>
                </span>
                <span class="attribution-legend-item">
                    <span class="attribution-legend-swatch attribution-legend-neutral"></span>
                    <span data-i18n>Neutral</span>
                </span>
            </div>
            <div id="attribution_consistency_readout" class="attribution-consistency-readout"></div>
            <div class="attr-ae-panel" id="attr_ae_panel" style="display:none;">
                <div class="attribution-panel-label" data-i18n>Activation Explainer</div>
                <div class="ae-trigger-row">
                    <span class="ae-trigger-hint" data-i18n>Click a context token above, then explain its activation</span>
                    <button type="button" id="attr_ae_trigger" class="text-action-btn" disabled data-i18n>Explain activation</button>
                </div>
                <div id="attr_ae_loading" class="ae-loading" style="display:none" data-i18n>Loading activation explanation…</div>
                <div id="attr_ae_result" class="ae-result" style="display:none">
                    <div class="ae-field"><span class="ae-label" data-i18n>Explanation</span><span id="attr_ae_explanation" class="ae-value"></span></div>
                    <div class="ae-field"><span class="ae-label" data-i18n>Confidence</span><span id="attr_ae_cosine" class="ae-cosine"></span><span>&nbsp;(roundtrip cosine)</span></div>
                </div>
                <div id="attr_ae_error" class="ae-error" style="display:none"></div>
            </div>
        </section>
    </main>

    <div id="toast" class="toast"></div>

    <script src="vendor.js"></script>
    <script src="attribution.js"></script>

</body>

</html>