stevekor commited on
Commit
5849182
·
1 Parent(s): 5b413ef

Make t-SNE always render (embedding fallback)

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -459,18 +459,28 @@ def plot_tsne(
459
 
460
  if representation == "LWM Embedding":
461
  embed_mask = sampled_df["tech_embedding"].apply(lambda x: x is not None)
462
- if embed_mask.sum() < 5:
463
- fig = go.Figure()
464
- fig.update_layout(
465
- title="No per-technology embeddings found for the selected filters.",
466
- xaxis=dict(visible=False),
467
- yaxis=dict(visible=False),
468
- )
469
- return fig
470
- sampled_df = sampled_df.loc[embed_mask].reset_index(drop=True)
471
- features = np.stack(sampled_df["tech_embedding"].values)
 
 
 
 
 
 
 
 
 
472
  else:
473
  features = build_tsne_raw_vectors(sampled_df["spectrogram"])
 
474
 
475
  if features.size == 0:
476
  fig = go.Figure()
@@ -510,7 +520,7 @@ def plot_tsne(
510
  y="y",
511
  color=color_column,
512
  hover_data=["tech", "snr", "mod", "mob"],
513
- title=f"t-SNE of {representation} ({len(sampled_df)} samples)",
514
  template="plotly_white",
515
  category_orders=category_orders,
516
  )
 
459
 
460
  if representation == "LWM Embedding":
461
  embed_mask = sampled_df["tech_embedding"].apply(lambda x: x is not None)
462
+ if embed_mask.sum() >= 5:
463
+ sampled_df = sampled_df.loc[embed_mask].reset_index(drop=True)
464
+ features = np.stack(sampled_df["tech_embedding"].values)
465
+ title_prefix = "t-SNE of LWM Embedding"
466
+ else:
467
+ # Fallback: use the full embedding vector so the UI doesn't go blank when
468
+ # per-expert metadata is missing in the artifact.
469
+ base_mask = sampled_df["embedding"].apply(lambda x: x is not None)
470
+ if base_mask.sum() < 5:
471
+ fig = go.Figure()
472
+ fig.update_layout(
473
+ title="No embeddings available for the selected filters.",
474
+ xaxis=dict(visible=False),
475
+ yaxis=dict(visible=False),
476
+ )
477
+ return fig
478
+ sampled_df = sampled_df.loc[base_mask].reset_index(drop=True)
479
+ features = np.stack(sampled_df["embedding"].values)
480
+ title_prefix = "t-SNE of LWM Embedding (full vector)"
481
  else:
482
  features = build_tsne_raw_vectors(sampled_df["spectrogram"])
483
+ title_prefix = "t-SNE of Raw Spectrogram"
484
 
485
  if features.size == 0:
486
  fig = go.Figure()
 
520
  y="y",
521
  color=color_column,
522
  hover_data=["tech", "snr", "mod", "mob"],
523
+ title=f"{title_prefix} ({len(sampled_df)} samples)",
524
  template="plotly_white",
525
  category_orders=category_orders,
526
  )