Skip to content

Fully automatic censorship removal for language models

fix: skip non-metrics in benchmark output (#486)

Philipp Emanuel Weidmann49b56e5af43f
diff --git a/src/heretic/main.py b/src/heretic/main.py
index fabfde3..f9c2823 100644
--- a/src/heretic/main.py
+++ b/src/heretic/main.py
@@ -1327,6 +1327,15 @@ def run():
else:
table.add_column("Value", justify="right")
+ def format_value(value: Any) -> str:
+ if isinstance(
+ value,
+ (float, np.floating),
+ ):
+ return f"{value:.4f}"
+ else:
+ return f"{value}"
+
try:
first_benchmark = True
@@ -1350,37 +1359,29 @@ def run():
first_row = True
for metric, value in results.items():
- if metric != "alias":
- if first_row and not first_benchmark:
- if benchmark_original_model:
- table.add_row("", "", "", "")
- else:
- table.add_row("", "", "")
-
- def format_value(value: Any) -> str:
- if isinstance(
- value,
- (float, np.floating),
- ):
- return f"{value:.4f}"
- else:
- return f"{value}"
-
- cells = [
- benchmark.name if first_row else "",
- metric,
- format_value(value),
- ]
+ # Skip non-metrics.
+ if metric in ["name", "alias", "sample_len"]:
+ continue
+
+ if first_row and not first_benchmark:
if benchmark_original_model:
- cells.append(
- format_value(
- original_results[metric]
- )
- )
- table.add_row(*cells)
+ table.add_row("", "", "", "")
+ else:
+ table.add_row("", "", "")
+
+ cells = [
+ benchmark.name if first_row else "",
+ metric,
+ format_value(value),
+ ]
+ if benchmark_original_model:
+ cells.append(
+ format_value(original_results[metric])
+ )
+ table.add_row(*cells)
- first_row = False
- first_benchmark = False
+ first_row = False
+ first_benchmark = False
except KeyboardInterrupt:
pass