@@ -331,14 +331,6 @@ def plot_layer_auc(
331331# Transfer table (cross-dataset generalisation)
332332# ---------------------------------------------------------------------------
333333
334- TRANSFER_ROW_LABELS = {
335- "in_dist_verified" : "In-distribution (Verified)" ,
336- "in_dist_pro" : "In-distribution (Pro)" ,
337- "verified_to_pro" : "Verified $\\ rightarrow$ Pro" ,
338- "pro_to_verified" : "Pro $\\ rightarrow$ Verified" ,
339- }
340-
341-
342334def build_transfer_table (
343335 verified_results_dir : Path ,
344336 pro_results_dir : Path ,
@@ -351,26 +343,35 @@ def build_transfer_table(
351343) -> str :
352344 """Return a LaTeX table comparing in-distribution vs cross-dataset transfer AUC.
353345
354- Rows: in-dist Verified, in-dist Pro, Verified→Pro, Pro→Verified.
355- Columns: probe × layer.
346+ Layout per probe:
347+ - Two compact gray reference rows: in-dist Verified / in-dist Pro
348+ - Two main rows showing transfer AUC and delta vs. the corresponding in-dist
349+ baseline (same evaluation set):
350+ Verified→Pro value (±Δ vs. Pro in-dist)
351+ Pro→Verified value (±Δ vs. Verified in-dist)
356352 """
357353 n_layer_cols = len (layers )
358354 col_spec = "l" + "c" * n_layer_cols
359355 layer_header = " & " .join (f"Layer { l } " for l in layers )
360356
361- rows = [
362- ("in_dist_verified" , verified_results_dir , verified_pooled_run_id ),
363- ("in_dist_pro" , pro_results_dir , pro_pooled_run_id ),
364- ("verified_to_pro" , pro_results_dir , verified_to_pro_run_id ),
365- ("pro_to_verified" , verified_results_dir , pro_to_verified_run_id ),
366- ]
357+ def _fmt_delta (delta : float ) -> str :
358+ sign = "+" if delta >= 0 else "−"
359+ return rf"{{\scriptsize { sign } { abs (delta ):.3f} }}"
360+
361+ def _get_aucs (res_dir , run_id , probe ):
362+ res = _load (res_dir , run_id , probe )
363+ if res is None :
364+ return {l : float ("nan" ) for l in layers }
365+ return {l : _weighted_mean (res .get (l , []), "test_auc" ) for l in layers }
367366
368367 lines = [
369368 r"\begin{table*}[h]" ,
370369 r"\centering" ,
371370 r"\caption{Cross-dataset transfer AUC-ROC for Laguna-XS2. "
372- r"\emph{In-distribution} probes are trained and evaluated on the same dataset. "
373- r"\emph{Transfer} probes use weights trained on one dataset and evaluated on the other.}" ,
371+ r"Gray rows show in-distribution (in-dist) reference performance. "
372+ r"Transfer rows show the AUC when probe weights trained on one dataset are "
373+ r"evaluated on the other; the subscript shows the difference relative to the "
374+ r"in-dist baseline on the \emph{same evaluation set}.}" ,
374375 r"\label{tab:transfer}" ,
375376 rf"\begin{{tabular}}{{{ col_spec } }}" ,
376377 r"\toprule" ,
@@ -382,33 +383,43 @@ def build_transfer_table(
382383 probe_label = PROBE_LABELS .get (probe , probe )
383384 lines .append (rf"\multicolumn{{{ 1 + n_layer_cols } }}{{l}}{{\textit{{{ probe_label } }}}} \\" )
384385
385- # Find global best AUC across all rows for bolding
386- best : dict [int , float ] = {}
387- for _ , res_dir , run_id in rows :
388- res = _load (res_dir , run_id , probe )
389- if res is None :
390- continue
391- for l in layers :
392- v = _weighted_mean (res .get (l , []), "test_auc" )
393- if not math .isnan (v ) and v > best .get (l , float ("-inf" )):
394- best [l ] = v
386+ # Load all four result sets
387+ v_aucs = _get_aucs (verified_results_dir , verified_pooled_run_id , probe ) # in-dist Verified
388+ p_aucs = _get_aucs (pro_results_dir , pro_pooled_run_id , probe ) # in-dist Pro
389+ vp_aucs = _get_aucs (pro_results_dir , verified_to_pro_run_id , probe ) # Verified→Pro
390+ pv_aucs = _get_aucs (verified_results_dir , pro_to_verified_run_id , probe ) # Pro→Verified
395391
396- for row_key , res_dir , run_id in rows :
397- res = _load (res_dir , run_id , probe )
398- row_label = TRANSFER_ROW_LABELS [row_key ]
399- cells = []
400- for l in layers :
401- if res is None :
402- cells .append ("—" )
403- continue
404- v = _weighted_mean (res .get (l , []), "test_auc" )
405- if math .isnan (v ):
406- cells .append ("—" )
407- elif not math .isnan (best .get (l , float ("nan" ))) and abs (v - best [l ]) < 1e-9 :
408- cells .append (rf"\textbf{{{ v :.3f} }}" )
409- else :
410- cells .append (f"{ v :.3f} " )
411- lines .append (f"\\ quad { row_label } & " + " & " .join (cells ) + r" \\" )
392+ # --- compact gray reference rows ---
393+ def _ref_cell (v ):
394+ return rf"\textcolor{{gray}}{{\small { v :.3f} }}" if not math .isnan (v ) else "—"
395+
396+ lines .append (
397+ r"\quad\textcolor{gray}{\small In-dist (Verified)} & "
398+ + " & " .join (_ref_cell (v_aucs [l ]) for l in layers ) + r" \\"
399+ )
400+ lines .append (
401+ r"\quad\textcolor{gray}{\small In-dist (Pro)} & "
402+ + " & " .join (_ref_cell (p_aucs [l ]) for l in layers ) + r" \\"
403+ )
404+
405+ # --- transfer rows with deltas ---
406+ def _transfer_cell (transfer_v , ref_v ):
407+ if math .isnan (transfer_v ):
408+ return "—"
409+ delta = transfer_v - ref_v if not math .isnan (ref_v ) else float ("nan" )
410+ delta_str = _fmt_delta (delta ) if not math .isnan (delta ) else ""
411+ return rf"{ transfer_v :.3f} \,{ delta_str } "
412+
413+ lines .append (
414+ r"\quad Verified $\rightarrow$ Pro & "
415+ + " & " .join (_transfer_cell (vp_aucs [l ], p_aucs [l ]) for l in layers )
416+ + r" \\"
417+ )
418+ lines .append (
419+ r"\quad Pro $\rightarrow$ Verified & "
420+ + " & " .join (_transfer_cell (pv_aucs [l ], v_aucs [l ]) for l in layers )
421+ + r" \\"
422+ )
412423
413424 lines .append (r"\midrule" )
414425
0 commit comments