kcz358 commited on
Commit
4a38f4a
·
1 Parent(s): bb637e6

Show top 500 explanations

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -79,7 +79,7 @@ def generate_activations(image):
79
  result.scatter_(-1, topk.indices, topk.values)
80
  cached_list.append(result.detach().cpu())
81
  topk_indices = (
82
- latents.squeeze(0).mean(dim=0).topk(k=200).indices.detach().cpu()
83
  )
84
 
85
  handles = [hooked_module.register_forward_hook(hook)]
@@ -101,7 +101,7 @@ def generate_activations(image):
101
 
102
 
103
  torch.cuda.empty_cache()
104
- return topk_indices, cached_list[0], examples
105
 
106
  def visualize_activations(image, feature_num, cached_tensor):
107
  base_img_tokens = 576
@@ -216,8 +216,8 @@ with gr.Blocks() as demo:
216
  with gr.Row():
217
  with gr.Column():
218
  image = gr.Image(type="pil", interactive=True, label="Sample Image")
219
- topk_features = gr.Textbox(value=topk_indices, placeholder="Top 200 Features", label="Top 100 Features", max_lines=5)
220
- known_explanation = gr.DataFrame(headers=["Feature", "Auto Interp Explanation(first 5k neurons)"], label="Auto Interp Explanations(first 5k neurons)")
221
  with gr.Row():
222
  clear_btn = gr.ClearButton([image, topk_features], value="Clear")
223
  submit_btn = gr.Button("Submit", variant="primary")
 
79
  result.scatter_(-1, topk.indices, topk.values)
80
  cached_list.append(result.detach().cpu())
81
  topk_indices = (
82
+ latents.squeeze(0).mean(dim=0).topk(k=500).indices.detach().cpu()
83
  )
84
 
85
  handles = [hooked_module.register_forward_hook(hook)]
 
101
 
102
 
103
  torch.cuda.empty_cache()
104
+ return topk_indices[:200], cached_list[0], examples
105
 
106
  def visualize_activations(image, feature_num, cached_tensor):
107
  base_img_tokens = 576
 
216
  with gr.Row():
217
  with gr.Column():
218
  image = gr.Image(type="pil", interactive=True, label="Sample Image")
219
+ topk_features = gr.Textbox(value=topk_indices, placeholder="Top 200 Features", label="Top 200 Features", max_lines=5)
220
+ known_explanation = gr.DataFrame(headers=["Feature", "Auto Interp Explanation(first 5k neurons)"], label="Auto Interp Explanations(first 5k neurons) for top 500 features")
221
  with gr.Row():
222
  clear_btn = gr.ClearButton([image, topk_features], value="Clear")
223
  submit_btn = gr.Button("Submit", variant="primary")