Spaces:
Running
Running
File size: 6,814 Bytes
ff3bc98 474491f ff3bc98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use("Agg")
def load_evaluation_data(data_path) -> pd.DataFrame:
"""Load evaluation results from CSV"""
eval_file = data_path / "evaluation_results.csv"
if eval_file.exists():
return pd.read_csv(eval_file)
return None
def get_model_style(model_name):
"""
Get color and hatch pattern for a model
Color scheme:
- GPT models: Gray (#808080)
- Qwen2.5-VL-32B: Light purple (#9B87E8) - BASE solid, SFT with pattern
- Qwen2-VL-72B: Medium blue (#5B7FD8) - BASE solid, SFT with pattern
Returns:
tuple: (color, hatch_pattern)
"""
if "GPT" in model_name or "gpt" in model_name:
return "#808080", None
if "Qwen2.5" in model_name or "qwen2p5" in model_name or "32B" in model_name:
if "SFT" in model_name:
return "#9B87E8", "///"
else:
return "#9B87E8", None
if "Qwen2" in model_name or "72B" in model_name:
if "SFT" in model_name:
return "#5B7FD8", "///"
else:
return "#5B7FD8", None
if "Qwen3" in model_name or "qwen3" in model_name or "32B" in model_name:
if "SFT" in model_name:
return "#6B4DB8", "///"
else:
return "#6B4DB8", None
return "#6B4DC1", None
def create_accuracy_plot(
eval_df: pd.DataFrame,
selected_models: list = None,
selected_categories: list = None,
):
"""
Create bar chart of accuracy by category, colored by model
Args:
eval_df: DataFrame with evaluation results
selected_models: List of models to display (None for all)
selected_categories: List of categories to display (None for all)
Returns:
matplotlib figure
"""
if eval_df is None:
return None
# Filter data
df_filtered = eval_df.copy()
if selected_models:
df_filtered = df_filtered[df_filtered["model"].isin(selected_models)]
if selected_categories:
df_filtered = df_filtered[df_filtered["category"].isin(selected_categories)]
# Create figure
fig, ax = plt.subplots(figsize=(12, 6))
# Get unique categories and models
categories = df_filtered["category"].unique()
models = df_filtered["model"].unique()
# Set up bar positions
x = range(len(categories))
width = 0.8 / len(models)
for i, model in enumerate(models):
model_data = df_filtered[df_filtered["model"] == model]
accuracies = [
model_data[model_data["category"] == cat]["accuracy"].values[0]
for cat in categories
]
color, hatch = get_model_style(model)
offset = (i - len(models) / 2) * width + width / 2
ax.bar(
[xi + offset for xi in x],
accuracies,
width,
label=model,
color=color,
hatch=hatch,
alpha=0.8,
edgecolor="white",
linewidth=1.2,
)
# Customize plot
ax.set_xlabel("Category", fontsize=12, fontweight="bold")
ax.set_ylabel("Accuracy", fontsize=12, fontweight="bold")
ax.set_title("Model Accuracy by Category", fontsize=14, fontweight="bold")
ax.set_xticks(x)
ax.set_xticklabels(categories, rotation=0)
ax.set_ylim(0, 1.0)
ax.legend(loc="lower right", framealpha=0.9)
ax.grid(axis="y", alpha=0.3, linestyle="--")
plt.tight_layout()
return fig
def create_precision_recall_plot(
eval_df: pd.DataFrame,
selected_models: list = None,
selected_categories: list = None,
):
"""
Create subplot with precision and recall by category, colored by model
Args:
eval_df: DataFrame with evaluation results
selected_models: List of models to display (None for all)
selected_categories: List of categories to display (None for all)
Returns:
matplotlib figure
"""
if eval_df is None:
return None
# Filter data
df_filtered = eval_df.copy()
if selected_models:
df_filtered = df_filtered[df_filtered["model"].isin(selected_models)]
if selected_categories:
df_filtered = df_filtered[df_filtered["category"].isin(selected_categories)]
# Create figure with subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))
# Get unique categories and models
categories = df_filtered["category"].unique()
models = df_filtered["model"].unique()
# Set up bar positions
x = range(len(categories))
width = 0.8 / len(models)
# Plot precision bars
for i, model in enumerate(models):
model_data = df_filtered[df_filtered["model"] == model]
precisions = [
model_data[model_data["category"] == cat]["precision"].values[0]
for cat in categories
]
# Get color and pattern for this model
color, hatch = get_model_style(model)
offset = (i - len(models) / 2) * width + width / 2
ax1.bar(
[xi + offset for xi in x],
precisions,
width,
label=model,
color=color,
hatch=hatch,
alpha=0.8,
edgecolor="white",
linewidth=1.2,
)
# Customize precision plot
ax1.set_xlabel("Category", fontsize=12, fontweight="bold")
ax1.set_ylabel("Precision", fontsize=12, fontweight="bold")
ax1.set_title("Model Precision by Category", fontsize=14, fontweight="bold")
ax1.set_xticks(x)
ax1.set_xticklabels(categories, rotation=0)
ax1.set_ylim(0, 1.0)
ax1.legend(loc="lower right", framealpha=0.9)
ax1.grid(axis="y", alpha=0.3, linestyle="--")
# Plot recall bars
for i, model in enumerate(models):
model_data = df_filtered[df_filtered["model"] == model]
recalls = [
model_data[model_data["category"] == cat]["recall"].values[0]
for cat in categories
]
# Get color and pattern for this model
color, hatch = get_model_style(model)
offset = (i - len(models) / 2) * width + width / 2
ax2.bar(
[xi + offset for xi in x],
recalls,
width,
label=model,
color=color,
hatch=hatch,
alpha=0.8,
edgecolor="white",
linewidth=1.2,
)
ax2.set_xlabel("Category", fontsize=12, fontweight="bold")
ax2.set_ylabel("Recall", fontsize=12, fontweight="bold")
ax2.set_title("Model Recall by Category", fontsize=14, fontweight="bold")
ax2.set_xticks(x)
ax2.set_xticklabels(categories, rotation=0)
ax2.set_ylim(0, 1.0)
ax2.legend(loc="lower right", framealpha=0.9)
ax2.grid(axis="y", alpha=0.3, linestyle="--")
plt.tight_layout()
return fig
|