Nu Appleblossom commited on
Commit
3abb7ea
·
1 Parent(s): 25e0205

updated appliation

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -202,12 +202,13 @@ def process_input(selected_sae, feature_number, weight_type, use_token_centroid,
202
 
203
  return result
204
 
 
205
  def gradio_interface():
206
  with gr.Blocks() as demo:
207
  gr.Markdown("# Gemma-2B SAE Feature Explorer")
208
 
209
  with gr.Row():
210
- with gr.Column():
211
  selected_sae = gr.Dropdown(choices=["Gemma-2B layer 0", "Gemma-2B layer 6", "Gemma-2B layer 10", "Gemma-2B layer 12"], label="Select SAE")
212
  feature_number = gr.Number(label="Select feature number", minimum=0, maximum=16383, value=0)
213
 
@@ -225,22 +226,22 @@ def gradio_interface():
225
  use_pca = gr.Checkbox(label="Introduce first PCA component")
226
  pca_weight = gr.Slider(minimum=0.0, maximum=1.0, value=0.5, label="PCA weight")
227
 
228
- with gr.Column():
 
 
229
  cosine_output = gr.Column(visible=True)
230
  with cosine_output:
231
  gr.Markdown("100 tokens whose embeddings produce the smallest values of the ratio")
232
  gr.Markdown("(cos distance from feature vector)^m/(cos distance from token centroid)^n")
233
- output_100 = gr.Textbox(label="Top 100 tokens")
234
  show_500_btn = gr.Button("Show top 500 tokens and values")
235
- output_500 = gr.Textbox(label="Top 500 tokens and values", visible=False)
236
 
237
  tree_output = gr.Column(visible=False)
238
  with tree_output:
239
  output = gr.Image(label="Tree Diagram Output")
240
  neuronpedia_embed = gr.HTML(label="Neuronpedia Embed")
241
  trim_slider = gr.Slider(minimum=0.00001, maximum=0.1, value=0.00001, label="Trim cutoff for cumulative probability")
242
-
243
- generate_btn = gr.Button("Generate Output")
244
 
245
  def update_output(selected_sae, feature_number, weight_type, use_token_centroid, scaling_factor, use_pca, pca_weight, num_exp, denom_exp, mode):
246
  if mode == "cosine distance token lists":
@@ -268,8 +269,4 @@ def gradio_interface():
268
  generate_btn.click(update_output, inputs=inputs, outputs=[output_100, output_500, cosine_output, tree_output])
269
  show_500_btn.click(show_top_500, outputs=output_500)
270
 
271
- return demo
272
-
273
- if __name__ == "__main__":
274
- iface = gradio_interface()
275
- iface.launch()
 
202
 
203
  return result
204
 
205
+
206
  def gradio_interface():
207
  with gr.Blocks() as demo:
208
  gr.Markdown("# Gemma-2B SAE Feature Explorer")
209
 
210
  with gr.Row():
211
+ with gr.Column(scale=2):
212
  selected_sae = gr.Dropdown(choices=["Gemma-2B layer 0", "Gemma-2B layer 6", "Gemma-2B layer 10", "Gemma-2B layer 12"], label="Select SAE")
213
  feature_number = gr.Number(label="Select feature number", minimum=0, maximum=16383, value=0)
214
 
 
226
  use_pca = gr.Checkbox(label="Introduce first PCA component")
227
  pca_weight = gr.Slider(minimum=0.0, maximum=1.0, value=0.5, label="PCA weight")
228
 
229
+ with gr.Column(scale=3):
230
+ generate_btn = gr.Button("Generate Output")
231
+
232
  cosine_output = gr.Column(visible=True)
233
  with cosine_output:
234
  gr.Markdown("100 tokens whose embeddings produce the smallest values of the ratio")
235
  gr.Markdown("(cos distance from feature vector)^m/(cos distance from token centroid)^n")
236
+ output_100 = gr.Textbox(label="Top 100 tokens", lines=10)
237
  show_500_btn = gr.Button("Show top 500 tokens and values")
238
+ output_500 = gr.Textbox(label="Top 500 tokens and values", visible=False, lines=25)
239
 
240
  tree_output = gr.Column(visible=False)
241
  with tree_output:
242
  output = gr.Image(label="Tree Diagram Output")
243
  neuronpedia_embed = gr.HTML(label="Neuronpedia Embed")
244
  trim_slider = gr.Slider(minimum=0.00001, maximum=0.1, value=0.00001, label="Trim cutoff for cumulative probability")
 
 
245
 
246
  def update_output(selected_sae, feature_number, weight_type, use_token_centroid, scaling_factor, use_pca, pca_weight, num_exp, denom_exp, mode):
247
  if mode == "cosine distance token lists":
 
269
  generate_btn.click(update_output, inputs=inputs, outputs=[output_100, output_500, cosine_output, tree_output])
270
  show_500_btn.click(show_top_500, outputs=output_500)
271
 
272
+ return demo