Dynamic methods - accept any method from user submissions
Browse files
app.py
CHANGED
|
@@ -15,9 +15,7 @@ server = app.server
|
|
| 15 |
# Load leaderboard data
|
| 16 |
DATA_FILE = "leaderboard.csv"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
VALID_METHODS = ["none", "abliteration", "steering", "finetuning", "prompting", "other"]
|
| 20 |
-
|
| 21 |
METHOD_DESCRIPTIONS = {
|
| 22 |
"none": "Baseline (no modification)",
|
| 23 |
"abliteration": "Abliteration technique",
|
|
@@ -27,6 +25,7 @@ METHOD_DESCRIPTIONS = {
|
|
| 27 |
"other": "Other methods",
|
| 28 |
}
|
| 29 |
|
|
|
|
| 30 |
METHOD_COLORS = {
|
| 31 |
"none": "#9E9E9E",
|
| 32 |
"abliteration": "#E91E63",
|
|
@@ -36,6 +35,9 @@ METHOD_COLORS = {
|
|
| 36 |
"other": "#9C27B0",
|
| 37 |
}
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def load_data():
|
| 41 |
"""Load leaderboard data from CSV."""
|
|
@@ -55,18 +57,39 @@ def load_data():
|
|
| 55 |
])
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def calculate_method_stats(df):
|
| 59 |
"""Calculate statistics for each method including delta from baseline."""
|
| 60 |
if len(df) == 0:
|
| 61 |
-
return pd.DataFrame()
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Get baseline average (method = "none")
|
| 64 |
baseline_df = df[df["method"] == "none"]
|
| 65 |
baseline_avg = baseline_df["uncensored_rate"].mean() if len(baseline_df) > 0 else 0
|
| 66 |
|
| 67 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
method_stats = []
|
| 69 |
-
for method in
|
| 70 |
method_df = df[df["method"] == method]
|
| 71 |
if len(method_df) > 0:
|
| 72 |
avg_rate = method_df["uncensored_rate"].mean()
|
|
@@ -78,9 +101,12 @@ def calculate_method_stats(df):
|
|
| 78 |
# Find best model for this method
|
| 79 |
best_model = method_df.loc[method_df["uncensored_rate"].idxmax(), "model"]
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
method_stats.append({
|
| 82 |
"method": method,
|
| 83 |
-
"description":
|
| 84 |
"num_models": len(method_df),
|
| 85 |
"avg_uncensored_rate": avg_rate,
|
| 86 |
"max_uncensored_rate": max_rate,
|
|
@@ -90,7 +116,7 @@ def calculate_method_stats(df):
|
|
| 90 |
"best_model": best_model,
|
| 91 |
})
|
| 92 |
|
| 93 |
-
return pd.DataFrame(method_stats)
|
| 94 |
|
| 95 |
|
| 96 |
# Column definitions for Models AG Grid
|
|
@@ -447,7 +473,7 @@ def render_tab_content(tab, n):
|
|
| 447 |
|
| 448 |
elif tab == "methods":
|
| 449 |
# Methods comparison view
|
| 450 |
-
method_df = calculate_method_stats(df)
|
| 451 |
row_data = method_df.to_dict("records") if len(method_df) > 0 else []
|
| 452 |
|
| 453 |
# Sort by delta from baseline descending
|
|
@@ -455,6 +481,22 @@ def render_tab_content(tab, n):
|
|
| 455 |
method_df = method_df.sort_values("delta_from_baseline", ascending=False)
|
| 456 |
row_data = method_df.to_dict("records")
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
return html.Div([
|
| 459 |
# Method comparison description
|
| 460 |
html.Div([
|
|
@@ -482,19 +524,13 @@ def render_tab_content(tab, n):
|
|
| 482 |
className="ag-theme-alpine",
|
| 483 |
),
|
| 484 |
|
| 485 |
-
# Method legend
|
| 486 |
html.Div([
|
| 487 |
html.H4("Method Definitions", style={"marginTop": "30px", "marginBottom": "15px"}),
|
| 488 |
-
html.Div(
|
| 489 |
-
html.
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
style={"color": METHOD_COLORS.get(method, "#666"), "fontWeight": "bold", "marginRight": "10px"}
|
| 493 |
-
),
|
| 494 |
-
html.Span(desc, style={"color": "#666"}),
|
| 495 |
-
], style={"marginBottom": "8px"})
|
| 496 |
-
for method, desc in METHOD_DESCRIPTIONS.items()
|
| 497 |
-
], style={"columns": "2", "columnGap": "40px"}),
|
| 498 |
], style={
|
| 499 |
"backgroundColor": "#f9f9f9",
|
| 500 |
"padding": "20px",
|
|
|
|
| 15 |
# Load leaderboard data
|
| 16 |
DATA_FILE = "leaderboard.csv"
|
| 17 |
|
| 18 |
+
# Known method descriptions (for display purposes, but we accept any method)
|
|
|
|
|
|
|
| 19 |
METHOD_DESCRIPTIONS = {
|
| 20 |
"none": "Baseline (no modification)",
|
| 21 |
"abliteration": "Abliteration technique",
|
|
|
|
| 25 |
"other": "Other methods",
|
| 26 |
}
|
| 27 |
|
| 28 |
+
# Colors for known methods, dynamic methods get auto-assigned colors
|
| 29 |
METHOD_COLORS = {
|
| 30 |
"none": "#9E9E9E",
|
| 31 |
"abliteration": "#E91E63",
|
|
|
|
| 35 |
"other": "#9C27B0",
|
| 36 |
}
|
| 37 |
|
| 38 |
+
# Fallback colors for dynamically discovered methods
|
| 39 |
+
DYNAMIC_COLORS = ["#00BCD4", "#795548", "#607D8B", "#3F51B5", "#009688", "#CDDC39", "#FF5722", "#673AB7"]
|
| 40 |
+
|
| 41 |
|
| 42 |
def load_data():
|
| 43 |
"""Load leaderboard data from CSV."""
|
|
|
|
| 57 |
])
|
| 58 |
|
| 59 |
|
| 60 |
+
def get_method_color(method, method_index=0):
|
| 61 |
+
"""Get color for a method, using predefined or dynamic colors."""
|
| 62 |
+
if method in METHOD_COLORS:
|
| 63 |
+
return METHOD_COLORS[method]
|
| 64 |
+
# Assign a dynamic color based on index
|
| 65 |
+
return DYNAMIC_COLORS[method_index % len(DYNAMIC_COLORS)]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
def calculate_method_stats(df):
|
| 69 |
"""Calculate statistics for each method including delta from baseline."""
|
| 70 |
if len(df) == 0:
|
| 71 |
+
return pd.DataFrame(), {}
|
| 72 |
+
|
| 73 |
+
# Get all unique methods from the actual data
|
| 74 |
+
all_methods = df["method"].dropna().unique().tolist()
|
| 75 |
|
| 76 |
# Get baseline average (method = "none")
|
| 77 |
baseline_df = df[df["method"] == "none"]
|
| 78 |
baseline_avg = baseline_df["uncensored_rate"].mean() if len(baseline_df) > 0 else 0
|
| 79 |
|
| 80 |
+
# Build dynamic color mapping for any new methods
|
| 81 |
+
dynamic_method_colors = {}
|
| 82 |
+
dynamic_idx = 0
|
| 83 |
+
for method in all_methods:
|
| 84 |
+
if method in METHOD_COLORS:
|
| 85 |
+
dynamic_method_colors[method] = METHOD_COLORS[method]
|
| 86 |
+
else:
|
| 87 |
+
dynamic_method_colors[method] = DYNAMIC_COLORS[dynamic_idx % len(DYNAMIC_COLORS)]
|
| 88 |
+
dynamic_idx += 1
|
| 89 |
+
|
| 90 |
+
# Group by method - iterate over actual methods in the data
|
| 91 |
method_stats = []
|
| 92 |
+
for method in all_methods:
|
| 93 |
method_df = df[df["method"] == method]
|
| 94 |
if len(method_df) > 0:
|
| 95 |
avg_rate = method_df["uncensored_rate"].mean()
|
|
|
|
| 101 |
# Find best model for this method
|
| 102 |
best_model = method_df.loc[method_df["uncensored_rate"].idxmax(), "model"]
|
| 103 |
|
| 104 |
+
# Get description - use predefined or just capitalize the method name
|
| 105 |
+
description = METHOD_DESCRIPTIONS.get(method, method.replace("_", " ").title())
|
| 106 |
+
|
| 107 |
method_stats.append({
|
| 108 |
"method": method,
|
| 109 |
+
"description": description,
|
| 110 |
"num_models": len(method_df),
|
| 111 |
"avg_uncensored_rate": avg_rate,
|
| 112 |
"max_uncensored_rate": max_rate,
|
|
|
|
| 116 |
"best_model": best_model,
|
| 117 |
})
|
| 118 |
|
| 119 |
+
return pd.DataFrame(method_stats), dynamic_method_colors
|
| 120 |
|
| 121 |
|
| 122 |
# Column definitions for Models AG Grid
|
|
|
|
| 473 |
|
| 474 |
elif tab == "methods":
|
| 475 |
# Methods comparison view
|
| 476 |
+
method_df, method_colors = calculate_method_stats(df)
|
| 477 |
row_data = method_df.to_dict("records") if len(method_df) > 0 else []
|
| 478 |
|
| 479 |
# Sort by delta from baseline descending
|
|
|
|
| 481 |
method_df = method_df.sort_values("delta_from_baseline", ascending=False)
|
| 482 |
row_data = method_df.to_dict("records")
|
| 483 |
|
| 484 |
+
# Build method legend from actual data
|
| 485 |
+
method_legend_items = []
|
| 486 |
+
for _, row in method_df.iterrows():
|
| 487 |
+
method = row["method"]
|
| 488 |
+
desc = row["description"]
|
| 489 |
+
color = method_colors.get(method, "#666")
|
| 490 |
+
method_legend_items.append(
|
| 491 |
+
html.Div([
|
| 492 |
+
html.Span(
|
| 493 |
+
f"● {method}",
|
| 494 |
+
style={"color": color, "fontWeight": "bold", "marginRight": "10px"}
|
| 495 |
+
),
|
| 496 |
+
html.Span(desc, style={"color": "#666"}),
|
| 497 |
+
], style={"marginBottom": "8px"})
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
return html.Div([
|
| 501 |
# Method comparison description
|
| 502 |
html.Div([
|
|
|
|
| 524 |
className="ag-theme-alpine",
|
| 525 |
),
|
| 526 |
|
| 527 |
+
# Method legend - dynamically built from actual data
|
| 528 |
html.Div([
|
| 529 |
html.H4("Method Definitions", style={"marginTop": "30px", "marginBottom": "15px"}),
|
| 530 |
+
html.Div(
|
| 531 |
+
method_legend_items if method_legend_items else [html.P("No methods submitted yet.", style={"color": "#666"})],
|
| 532 |
+
style={"columns": "2", "columnGap": "40px"} if len(method_legend_items) > 3 else {}
|
| 533 |
+
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
], style={
|
| 535 |
"backgroundColor": "#f9f9f9",
|
| 536 |
"padding": "20px",
|