Spaces:
Running
Running
Remove Paper stats tab; explain F_n/M_n in Factor poster; show mode-label preview in factor dropdown
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +40 -14
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -1329,10 +1329,26 @@ def _gallery_axes(figsize=(10, 9)):
|
|
| 1329 |
# ---------- (1) Factor decomposition poster ----------
|
| 1330 |
|
| 1331 |
def factor_options(sibling: str):
|
|
|
|
| 1332 |
m = MODELS[sibling]
|
| 1333 |
-
|
| 1334 |
-
|
| 1335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1336 |
|
| 1337 |
def render_factor_poster(sibling: str, factor_id: str):
|
| 1338 |
"""Reference-screenshot style: dark teal background, faint contour texture,
|
|
@@ -2162,28 +2178,38 @@ Three sibling ingredient embeddings from [arXiv:2605.22391](https://arxiv.org/ab
|
|
| 2162 |
label="Try one of these baskets",
|
| 2163 |
)
|
| 2164 |
|
| 2165 |
-
# ---------- Tab: PAPER STATS ----------
|
| 2166 |
-
with gr.Tab("Paper stats"):
|
| 2167 |
-
gr.Markdown("Headline numbers from the paper §3.2. The Cooc < Core < Chem ordering on every probe stratum.")
|
| 2168 |
-
dq_plot = gr.Plot(value=render_direction_quality_heatmap(), label="")
|
| 2169 |
-
|
| 2170 |
# ---------- Tab 5: GALLERY ----------
|
| 2171 |
with gr.Tab("Gallery"):
|
| 2172 |
gr.Markdown("Six aesthetic views of the model. All rendered in the Kaikaku palette.")
|
| 2173 |
with gr.Tabs():
|
| 2174 |
# --- Factor poster ---
|
| 2175 |
with gr.Tab("Factor poster"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2176 |
with gr.Row():
|
| 2177 |
fp_sib = gr.Radio(choices=["cooc","core","chem"], value="chem",
|
| 2178 |
label="Sibling", scale=1)
|
| 2179 |
-
fp_factor = gr.Dropdown(choices=
|
| 2180 |
-
value=
|
| 2181 |
-
label="Factor", scale=
|
| 2182 |
fp_btn = gr.Button("Render", variant="primary", scale=1)
|
| 2183 |
-
fp_plot = gr.Plot(label="", value=render_factor_poster("chem",
|
| 2184 |
fp_btn.click(render_factor_poster, inputs=[fp_sib, fp_factor], outputs=fp_plot, show_progress="full")
|
| 2185 |
-
|
| 2186 |
-
|
|
|
|
|
|
|
|
|
|
| 2187 |
|
| 2188 |
# --- Cuisine compass ---
|
| 2189 |
with gr.Tab("Cuisine compass"):
|
|
|
|
| 1329 |
# ---------- (1) Factor decomposition poster ----------
|
| 1330 |
|
| 1331 |
def factor_options(sibling: str):
|
| 1332 |
+
"""Return list of (descriptive_label, factor_id) tuples for the factor dropdown."""
|
| 1333 |
m = MODELS[sibling]
|
| 1334 |
+
by_fid: dict[str, list] = {}
|
| 1335 |
+
for md in m.modes:
|
| 1336 |
+
if md.kind != "factor": continue
|
| 1337 |
+
by_fid.setdefault(md.property, []).append(md.label)
|
| 1338 |
+
def sort_key(fid):
|
| 1339 |
+
last = fid.split("_")[-1]
|
| 1340 |
+
return int(last) if last.isdigit() else 999
|
| 1341 |
+
out = []
|
| 1342 |
+
for fid in sorted(by_fid.keys(), key=sort_key):
|
| 1343 |
+
labels = by_fid[fid]
|
| 1344 |
+
# Take first 2-3 mode-label keywords as a preview
|
| 1345 |
+
preview = " · ".join(lab[:32] for lab in labels[:2])
|
| 1346 |
+
out.append((f"{fid} — {preview}", fid))
|
| 1347 |
+
return out
|
| 1348 |
+
|
| 1349 |
+
def factor_id_list(sibling: str):
|
| 1350 |
+
"""Just the bare F_n IDs, for the actual handler input."""
|
| 1351 |
+
return [fid for _, fid in factor_options(sibling)]
|
| 1352 |
|
| 1353 |
def render_factor_poster(sibling: str, factor_id: str):
|
| 1354 |
"""Reference-screenshot style: dark teal background, faint contour texture,
|
|
|
|
| 2178 |
label="Try one of these baskets",
|
| 2179 |
)
|
| 2180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2181 |
# ---------- Tab 5: GALLERY ----------
|
| 2182 |
with gr.Tab("Gallery"):
|
| 2183 |
gr.Markdown("Six aesthetic views of the model. All rendered in the Kaikaku palette.")
|
| 2184 |
with gr.Tabs():
|
| 2185 |
# --- Factor poster ---
|
| 2186 |
with gr.Tab("Factor poster"):
|
| 2187 |
+
gr.Markdown(
|
| 2188 |
+
"**How to read this.** Each sibling has **20 emergent ICA factors** (`F_0` to `F_19`), "
|
| 2189 |
+
"ranked by stability across random seeds (`F_0` is most reproducible). "
|
| 2190 |
+
"A factor is an unsupervised latent dimension discovered by FastICA on the embedding "
|
| 2191 |
+
"with food-group variance projected out. "
|
| 2192 |
+
"Each factor's top-quartile ingredients are partitioned into **3-7 GMM modes** "
|
| 2193 |
+
"(`M0`, `M1`, ...) — culinary neighbourhoods along that factor. "
|
| 2194 |
+
"Mode labels (e.g. *Chinese Wok Essentials*) are Claude-generated from member contents. "
|
| 2195 |
+
"Pick a factor below; the dropdown shows a preview of its mode labels."
|
| 2196 |
+
)
|
| 2197 |
+
_fp_choices = factor_options("chem")
|
| 2198 |
+
_fp_default = _fp_choices[0][1] if _fp_choices else ""
|
| 2199 |
with gr.Row():
|
| 2200 |
fp_sib = gr.Radio(choices=["cooc","core","chem"], value="chem",
|
| 2201 |
label="Sibling", scale=1)
|
| 2202 |
+
fp_factor = gr.Dropdown(choices=_fp_choices,
|
| 2203 |
+
value=_fp_default,
|
| 2204 |
+
label="Factor (preview of mode labels shown)", scale=3)
|
| 2205 |
fp_btn = gr.Button("Render", variant="primary", scale=1)
|
| 2206 |
+
fp_plot = gr.Plot(label="", value=render_factor_poster("chem", _fp_default))
|
| 2207 |
fp_btn.click(render_factor_poster, inputs=[fp_sib, fp_factor], outputs=fp_plot, show_progress="full")
|
| 2208 |
+
def _refresh_factor_choices(s):
|
| 2209 |
+
choices = factor_options(s)
|
| 2210 |
+
return gr.Dropdown(choices=choices, value=choices[0][1] if choices else None)
|
| 2211 |
+
fp_sib.change(_refresh_factor_choices, inputs=fp_sib, outputs=fp_factor)
|
| 2212 |
+
fp_factor.change(render_factor_poster, inputs=[fp_sib, fp_factor], outputs=fp_plot, show_progress="minimal")
|
| 2213 |
|
| 2214 |
# --- Cuisine compass ---
|
| 2215 |
with gr.Tab("Cuisine compass"):
|