JoFrost commited on
Commit
8330b1d
·
1 Parent(s): 155a7fa

feat: add text

Browse files
Files changed (1) hide show
  1. app.py +93 -52
app.py CHANGED
@@ -24,6 +24,44 @@ params = {
24
  "filename" : "layer_31/width_16k/average_l0_76/params.npz"
25
  }
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  C = 0.01
28
 
29
  model_name = params["model_name"]
@@ -168,58 +206,61 @@ def get_feature_iframe(feature):
168
  html = gr.HTML(html_content)
169
  return html
170
 
171
- with gr.Blocks() as demo:
172
- with gr.Row():
173
- with gr.Column(scale=4):
174
- input_text = gr.Textbox(label="Input", show_label=False, value=DEFAULT_EXAMPLE)
175
- gr.Examples(
176
- examples=examples,
177
- inputs=input_text,
178
- )
179
- with gr.Column(scale=1):
180
- run_button = gr.Button("Run")
181
-
182
- with gr.Row():
183
- label = gr.Label(label="Scores")
184
-
185
- with gr.Row():
186
- with gr.Column(scale=1):
187
- plot = gr.Plot(label="Plot")
188
- dropdown = gr.Dropdown(choices=["Option 1"], label="Features")
189
-
190
- with gr.Column(scale=1):
191
- highlighted_text = gr.HighlightedText(
192
- label="Activating Tokens",
193
- combine_adjacent=True,
194
- show_legend=True,
195
- color_map={"+": "red", "-": "green"})
196
-
197
- with gr.Row():
198
- html = gr.HTML()
199
-
200
- # Connect the components
201
- run_button.click(
202
- fn=get_features,
203
- inputs=[input_text],
204
- outputs=[label, plot, dropdown],
205
- ).then(
206
- fn=get_highlighted_text,
207
- inputs=[input_text, dropdown],
208
- outputs=[highlighted_text]
209
- ).then(
210
- fn=get_feature_iframe,
211
- inputs=[dropdown],
212
- outputs=[html]
213
- )
214
-
215
- dropdown.change(
216
  fn=get_highlighted_text,
217
- inputs=[input_text, dropdown],
218
- outputs=[highlighted_text]
219
- ).then(
220
- fn=get_feature_iframe,
221
- inputs=[dropdown],
222
- outputs=[html]
223
- )
 
 
 
 
 
 
 
 
 
 
224
 
225
  demo.launch(share=True)
 
24
  "filename" : "layer_31/width_16k/average_l0_76/params.npz"
25
  }
26
 
27
+ title = """
28
+ <div class='parent' align="center">
29
+ <div class='child' style="display: inline-block !important; margin-bottom: 20px;">
30
+ <h1 style="margin-bottom: 30px;">🔍Interpretable Classifier for movie ratings using Gemma 2 with SAEs</h1>
31
+ </div>
32
+ </div>
33
+ <div class='parent' align="center">
34
+ <p>This space demonstrates how a linear classifier trained on top of features learned by Sparse Auto Encoders (SAEs) can be used to create interpretable natural language classifiers.</p>
35
+ <p>We leverage the interpretability API of <b>Neuronpedia</b> to provide more information about the features used by the LLM (like what tokens activate it the most and their distribution).</p>
36
+ <p><b>More resources on interpretability for LLMs using SAEs:</b></p>
37
+ </div>
38
+ <ul>
39
+ <li><a href="https://transformer-circuits.pub/2024/scaling-monosemanticity/">Anthropic: Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet</a></li>
40
+ <li><a href="https://blog.eleuther.ai/autointerp/">EleutherAI: Open Source Automated Interpretability for Sparse Autoencoder Features</a></li>
41
+ <li><a href="https://www.gemma.ai/gemma-scope">Gemma Scope: Open Sparse Autoencoders Everywhere All At Once on Gemma 2</a></li>
42
+ </ul>
43
+ <div class='parent' align="center">
44
+ <p>About us: <b> 🌊 LaVague</b> is an open-source framework to build AI Web Agents. Check out our <a href="https://github.com/lavague-ai/LaVague">GitHub</a> or join our <a href="https://discord.com/invite/SDxn9KpqX9">Discord</a>.</p>
45
+ </div>
46
+ """
47
+
48
+ css = """
49
+ .my-button {
50
+ height: 100px; /* Increase the height of the buttons */
51
+ width: 100%; /* Make sure the button takes the full width */
52
+ max-width: 300px; /* Optional: set a max width */
53
+ max-height: 80px;
54
+ font-size: 1.1rem; /* Increase font size */
55
+ }
56
+ .button-container {
57
+ display: flex;
58
+ justify-content: center; /* Center buttons horizontally */
59
+ align-items: center; /* Center buttons vertically */
60
+ height: 100%; /* Ensure it takes up the full height */
61
+ width: 100%; /* Ensure it takes up the full width */
62
+ }
63
+ """
64
+
65
  C = 0.01
66
 
67
  model_name = params["model_name"]
 
206
  html = gr.HTML(html_content)
207
  return html
208
 
209
+ with gr.Blocks(gr.themes.Default(primary_hue="blue", secondary_hue="neutral"), css=css) as demo:
210
+ with gr.Tab(""):
211
+ with gr.Row():
212
+ gr.HTML(title)
213
+ with gr.Row():
214
+ with gr.Column(scale=4):
215
+ input_text = gr.Textbox(label="Input", show_label=False, value=DEFAULT_EXAMPLE)
216
+ gr.Examples(
217
+ examples=examples,
218
+ inputs=input_text,
219
+ )
220
+ with gr.Column(scale=1):
221
+ run_button = gr.Button("Run")
222
+
223
+ with gr.Row():
224
+ label = gr.Label(label="Scores")
225
+
226
+ with gr.Row():
227
+ with gr.Column(scale=1):
228
+ plot = gr.Plot(label="Plot")
229
+ dropdown = gr.Dropdown(choices=["Option 1"], label="Features")
230
+
231
+ with gr.Column(scale=1):
232
+ highlighted_text = gr.HighlightedText(
233
+ label="Activating Tokens",
234
+ combine_adjacent=True,
235
+ show_legend=True,
236
+ color_map={"+": "red", "-": "green"})
237
+
238
+ with gr.Row():
239
+ html = gr.HTML()
240
+
241
+ # Connect the components
242
+ run_button.click(
243
+ fn=get_features,
244
+ inputs=[input_text],
245
+ outputs=[label, plot, dropdown],
246
+ ).then(
 
 
 
 
 
 
 
247
  fn=get_highlighted_text,
248
+ inputs=[input_text, dropdown],
249
+ outputs=[highlighted_text]
250
+ ).then(
251
+ fn=get_feature_iframe,
252
+ inputs=[dropdown],
253
+ outputs=[html]
254
+ )
255
+
256
+ dropdown.change(
257
+ fn=get_highlighted_text,
258
+ inputs=[input_text, dropdown],
259
+ outputs=[highlighted_text]
260
+ ).then(
261
+ fn=get_feature_iframe,
262
+ inputs=[dropdown],
263
+ outputs=[html]
264
+ )
265
 
266
  demo.launch(share=True)