Marlin Lee commited on
Commit ·
25fc6f0
1
Parent(s): b6e3e85
Replace NSD toggle with RadioButtonGroup, hide dataset dropdown when no compare data
Browse files- scripts/explorer_app.py +15 -13
scripts/explorer_app.py
CHANGED
|
@@ -57,7 +57,7 @@ from bokeh.events import MouseMove
|
|
| 57 |
from bokeh.models import (
|
| 58 |
ColumnDataSource, HoverTool, Div, Select, TextInput, Button,
|
| 59 |
DataTable, TableColumn, NumberFormatter, IntEditor, NumberEditor,
|
| 60 |
-
Slider, Toggle, CustomJS,
|
| 61 |
)
|
| 62 |
from bokeh.plotting import figure
|
| 63 |
from bokeh.palettes import Turbo256
|
|
@@ -1571,12 +1571,10 @@ HAS_NSD_SUBSET = False
|
|
| 1571 |
nsd_top_img_idx = nsd_top_img_act = nsd_mean_img_idx = nsd_mean_img_act = None
|
| 1572 |
nsd_top_heatmaps = nsd_mean_heatmaps = None
|
| 1573 |
_nsd_clip_embeds = None
|
| 1574 |
-
nsd_subset_toggle =
|
| 1575 |
-
|
| 1576 |
-
active=
|
| 1577 |
-
|
| 1578 |
-
width=160,
|
| 1579 |
-
button_type="success",
|
| 1580 |
)
|
| 1581 |
|
| 1582 |
N_DISPLAY = 9
|
|
@@ -1676,7 +1674,7 @@ def update_feature_display(feature_idx):
|
|
| 1676 |
return (ph, f"Error: {e}")
|
| 1677 |
|
| 1678 |
# --- Top images ---
|
| 1679 |
-
_use_nsd = nsd_subset_toggle.active and HAS_NSD_SUBSET
|
| 1680 |
_top_idx = nsd_top_img_idx if _use_nsd else top_img_idx
|
| 1681 |
_top_act = nsd_top_img_act if _use_nsd else top_img_act
|
| 1682 |
_mean_idx = nsd_mean_img_idx if _use_nsd else mean_img_idx
|
|
@@ -2480,7 +2478,7 @@ def _build_clip_panel():
|
|
| 2480 |
elif _clip_embeds is not None or _nsd_clip_embeds is not None:
|
| 2481 |
# Free-text: encode on-the-fly with CLIP, dot with feature image embeds.
|
| 2482 |
# Use NSD-specific embeds when the subset toggle is active.
|
| 2483 |
-
_use_nsd_embeds = nsd_subset_toggle.active and _nsd_clip_embeds is not None
|
| 2484 |
_active_embeds = _nsd_clip_embeds if _use_nsd_embeds else _clip_embeds
|
| 2485 |
result_div.text = "<i>Encoding query with CLIP…</i>"
|
| 2486 |
try:
|
|
@@ -2498,7 +2496,7 @@ def _build_clip_panel():
|
|
| 2498 |
return
|
| 2499 |
|
| 2500 |
# When NSD subset toggle is active, restrict to features with at least one NSD image
|
| 2501 |
-
if nsd_subset_toggle.active and HAS_NSD_SUBSET:
|
| 2502 |
nsd_mask = nsd_top_img_idx[:, 0] >= 0 # (d_model,) bool
|
| 2503 |
scores_vec = scores_vec.clone()
|
| 2504 |
scores_vec[~nsd_mask] = float('-inf')
|
|
@@ -2514,7 +2512,7 @@ def _build_clip_panel():
|
|
| 2514 |
phi_c_val=_phi_c_vals(top_indices),
|
| 2515 |
name=[_display_name(int(i)) for i in top_indices],
|
| 2516 |
)
|
| 2517 |
-
_subset_note = " [NSD sub01]" if (nsd_subset_toggle.active and HAS_NSD_SUBSET) else ""
|
| 2518 |
result_div.text = (
|
| 2519 |
f'<span style="color:#1a6faf"><b>{len(top_indices)}</b> features for '
|
| 2520 |
f'“{query}”{_subset_note}</span>'
|
|
@@ -2588,13 +2586,17 @@ summary_section = _make_collapsible("SAE Summary", summary_div)
|
|
| 2588 |
patch_section = _make_collapsible("Patch Explorer", patch_explorer_panel)
|
| 2589 |
clip_section = _make_collapsible("CLIP Text Search", clip_search_panel)
|
| 2590 |
|
| 2591 |
-
|
|
|
|
| 2592 |
|
| 2593 |
middle_panel = column(
|
| 2594 |
status_div,
|
| 2595 |
stats_div,
|
| 2596 |
name_panel,
|
| 2597 |
-
row(view_select,
|
|
|
|
|
|
|
|
|
|
| 2598 |
compare_agg_div,
|
| 2599 |
top_heatmap_div,
|
| 2600 |
mean_heatmap_div,
|
|
|
|
| 57 |
from bokeh.models import (
|
| 58 |
ColumnDataSource, HoverTool, Div, Select, TextInput, Button,
|
| 59 |
DataTable, TableColumn, NumberFormatter, IntEditor, NumberEditor,
|
| 60 |
+
Slider, Toggle, RadioButtonGroup, CustomJS,
|
| 61 |
)
|
| 62 |
from bokeh.plotting import figure
|
| 63 |
from bokeh.palettes import Turbo256
|
|
|
|
| 1571 |
nsd_top_img_idx = nsd_top_img_act = nsd_mean_img_idx = nsd_mean_img_act = None
|
| 1572 |
nsd_top_heatmaps = nsd_mean_heatmaps = None
|
| 1573 |
_nsd_clip_embeds = None
|
| 1574 |
+
nsd_subset_toggle = RadioButtonGroup(
|
| 1575 |
+
labels=["All images", "NSD sub01"],
|
| 1576 |
+
active=0,
|
| 1577 |
+
width=220,
|
|
|
|
|
|
|
| 1578 |
)
|
| 1579 |
|
| 1580 |
N_DISPLAY = 9
|
|
|
|
| 1674 |
return (ph, f"Error: {e}")
|
| 1675 |
|
| 1676 |
# --- Top images ---
|
| 1677 |
+
_use_nsd = nsd_subset_toggle.active == 1 and HAS_NSD_SUBSET
|
| 1678 |
_top_idx = nsd_top_img_idx if _use_nsd else top_img_idx
|
| 1679 |
_top_act = nsd_top_img_act if _use_nsd else top_img_act
|
| 1680 |
_mean_idx = nsd_mean_img_idx if _use_nsd else mean_img_idx
|
|
|
|
| 2478 |
elif _clip_embeds is not None or _nsd_clip_embeds is not None:
|
| 2479 |
# Free-text: encode on-the-fly with CLIP, dot with feature image embeds.
|
| 2480 |
# Use NSD-specific embeds when the subset toggle is active.
|
| 2481 |
+
_use_nsd_embeds = nsd_subset_toggle.active == 1 and _nsd_clip_embeds is not None
|
| 2482 |
_active_embeds = _nsd_clip_embeds if _use_nsd_embeds else _clip_embeds
|
| 2483 |
result_div.text = "<i>Encoding query with CLIP…</i>"
|
| 2484 |
try:
|
|
|
|
| 2496 |
return
|
| 2497 |
|
| 2498 |
# When NSD subset toggle is active, restrict to features with at least one NSD image
|
| 2499 |
+
if nsd_subset_toggle.active == 1 and HAS_NSD_SUBSET:
|
| 2500 |
nsd_mask = nsd_top_img_idx[:, 0] >= 0 # (d_model,) bool
|
| 2501 |
scores_vec = scores_vec.clone()
|
| 2502 |
scores_vec[~nsd_mask] = float('-inf')
|
|
|
|
| 2512 |
phi_c_val=_phi_c_vals(top_indices),
|
| 2513 |
name=[_display_name(int(i)) for i in top_indices],
|
| 2514 |
)
|
| 2515 |
+
_subset_note = " [NSD sub01]" if (nsd_subset_toggle.active == 1 and HAS_NSD_SUBSET) else ""
|
| 2516 |
result_div.text = (
|
| 2517 |
f'<span style="color:#1a6faf"><b>{len(top_indices)}</b> features for '
|
| 2518 |
f'“{query}”{_subset_note}</span>'
|
|
|
|
| 2586 |
patch_section = _make_collapsible("Patch Explorer", patch_explorer_panel)
|
| 2587 |
clip_section = _make_collapsible("CLIP Text Search", clip_search_panel)
|
| 2588 |
|
| 2589 |
+
_ds_select_row = ([dataset_select] if len(_all_datasets) > 1 and args.compare_data else [])
|
| 2590 |
+
left_panel = column(*_ds_select_row, controls, umap_fig, feature_list_panel)
|
| 2591 |
|
| 2592 |
middle_panel = column(
|
| 2593 |
status_div,
|
| 2594 |
stats_div,
|
| 2595 |
name_panel,
|
| 2596 |
+
row(view_select,
|
| 2597 |
+
column(Div(text="<b>Images:</b>", width=60, height=15, styles={"padding-top":"5px"}),
|
| 2598 |
+
nsd_subset_toggle),
|
| 2599 |
+
zoom_slider, heatmap_alpha_slider),
|
| 2600 |
compare_agg_div,
|
| 2601 |
top_heatmap_div,
|
| 2602 |
mean_heatmap_div,
|