Spaces:
Sleeping
Sleeping
Ajaykanth Maddi commited on
Commit ·
1921c0a
1
Parent(s): 3e0e5e4
Code Changes - Reranking Implementation
Browse files
app.py
CHANGED
|
@@ -114,7 +114,56 @@ def get_info_from_sample_questions(subset, question):
|
|
| 114 |
return orig_ans, y_metrics
|
| 115 |
return "No answer found.", "No metrics found."
|
| 116 |
|
| 117 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
"""Generate a bar plot of key metrics for a given subset with proper title display."""
|
| 119 |
try:
|
| 120 |
summary = ragbench_details[subset_name]["summary"]
|
|
@@ -169,61 +218,11 @@ def plot_subset_metrics(subset_name):
|
|
| 169 |
)
|
| 170 |
|
| 171 |
return fig
|
| 172 |
-
|
| 173 |
-
except KeyError:
|
| 174 |
-
print(f"Error: Subset '{subset_name}' not found")
|
| 175 |
except Exception as e:
|
| 176 |
print(f"Plotting error: {str(e)}")
|
| 177 |
|
| 178 |
-
def plot_subset_metrics_old(subset_name):
|
| 179 |
-
summary = ragbench_details[subset_name]["summary"]
|
| 180 |
-
|
| 181 |
-
# Create a DataFrame for plotting
|
| 182 |
-
keys = ['Entries', 'TotalDocs', 'TotalUniqueIds', 'TotalUniqueDocs', 'UniqueDocsPercent']
|
| 183 |
-
values = [summary.get(k, 0) for k in keys]
|
| 184 |
-
|
| 185 |
-
fig, ax = plt.subplots(figsize=(8, 4))
|
| 186 |
-
bars = ax.bar(keys, values, color='skyblue')
|
| 187 |
-
plt.tight_layout() # Apply tight layout after plotting
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
# ✅ Add count on top of bars
|
| 191 |
-
ax.bar_label(bars, fmt='%.0f', padding=3)
|
| 192 |
-
|
| 193 |
-
# ax.bar(keys, values, color="mediumseagreen")
|
| 194 |
-
ax.set_title(f"Metrics for Subset: {subset_name}, Domain: {summary.get('Domain')}", fontsize=14)
|
| 195 |
-
ax.set_ylabel("Value")
|
| 196 |
-
ax.grid(axis='y')
|
| 197 |
-
ax.set_xticks(range(len(keys)))
|
| 198 |
-
ax.set_xticklabels(keys, rotation=21, ha='right')
|
| 199 |
-
return fig
|
| 200 |
-
|
| 201 |
-
def plot_chunking_strategies_old(subset_name):
|
| 202 |
-
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 203 |
-
|
| 204 |
-
plt.figure(figsize=(8, 4))
|
| 205 |
-
strategies = list(chunking_data.keys())
|
| 206 |
-
counts = list(chunking_data.values())
|
| 207 |
-
|
| 208 |
-
bars = plt.bar(strategies, counts, color="skyblue")
|
| 209 |
-
|
| 210 |
-
# Add value labels on top of bars
|
| 211 |
-
for bar in bars:
|
| 212 |
-
yval = bar.get_height()
|
| 213 |
-
plt.text(bar.get_x() + bar.get_width()/2, yval + 20, int(yval), ha='center', va='bottom', fontsize=10)
|
| 214 |
-
|
| 215 |
-
# plt.xlabel("Chunking Strategies")
|
| 216 |
-
plt.tight_layout() # Apply tight layout after plotting
|
| 217 |
-
|
| 218 |
-
plt.ylabel("Number of Chunks")
|
| 219 |
-
plt.title(f"Chunking Strategy Distribution - {subset_name}")
|
| 220 |
-
plt.xticks(rotation=30)
|
| 221 |
-
plt.tight_layout()
|
| 222 |
-
|
| 223 |
-
# Return plot as figure (Gradio accepts it)
|
| 224 |
-
return plt.gcf()
|
| 225 |
|
| 226 |
-
def
|
| 227 |
"""Visualize chunking strategy distribution with enhanced formatting."""
|
| 228 |
try:
|
| 229 |
chunking_data = ragbench_details[subset_name]["chunking"]
|
|
@@ -235,9 +234,6 @@ def plot_chunking_strategies(subset_name):
|
|
| 235 |
strategies = list(chunking_data.keys())
|
| 236 |
counts = list(chunking_data.values())
|
| 237 |
|
| 238 |
-
# # Create color gradient based on count values
|
| 239 |
-
# colors = plt.cm.Blues(np.linspace(0.4, 1, len(strategies)))
|
| 240 |
-
|
| 241 |
# Plot bars with different colors
|
| 242 |
bars = ax.bar(strategies, counts, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 243 |
|
|
@@ -277,11 +273,121 @@ def plot_chunking_strategies(subset_name):
|
|
| 277 |
# Auto-scale y-axis with 10% headroom
|
| 278 |
ax.set_ylim(0, max(counts) * 1.1)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
return fig
|
| 281 |
|
| 282 |
except Exception as e:
|
| 283 |
print(f"Error plotting chunking strategies: {str(e)}")
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
# Initialize with first subset's summary
|
| 286 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 287 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|
|
|
|
| 114 |
return orig_ans, y_metrics
|
| 115 |
return "No answer found.", "No metrics found."
|
| 116 |
|
| 117 |
+
def plot_subset_metrics_old(subset_name):
|
| 118 |
+
summary = ragbench_details[subset_name]["summary"]
|
| 119 |
+
|
| 120 |
+
# Create a DataFrame for plotting
|
| 121 |
+
keys = ['Entries', 'TotalDocs', 'TotalUniqueIds', 'TotalUniqueDocs', 'UniqueDocsPercent']
|
| 122 |
+
values = [summary.get(k, 0) for k in keys]
|
| 123 |
+
|
| 124 |
+
fig, ax = plt.subplots(figsize=(8, 4))
|
| 125 |
+
bars = ax.bar(keys, values, color='skyblue')
|
| 126 |
+
plt.tight_layout() # Apply tight layout after plotting
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
# ✅ Add count on top of bars
|
| 130 |
+
ax.bar_label(bars, fmt='%.0f', padding=3)
|
| 131 |
+
|
| 132 |
+
# ax.bar(keys, values, color="mediumseagreen")
|
| 133 |
+
ax.set_title(f"Metrics for Subset: {subset_name}, Domain: {summary.get('Domain')}", fontsize=14)
|
| 134 |
+
ax.set_ylabel("Value")
|
| 135 |
+
ax.grid(axis='y')
|
| 136 |
+
ax.set_xticks(range(len(keys)))
|
| 137 |
+
ax.set_xticklabels(keys, rotation=21, ha='right')
|
| 138 |
+
return fig
|
| 139 |
+
|
| 140 |
+
def plot_chunking_strategies_old(subset_name):
|
| 141 |
+
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 142 |
+
|
| 143 |
+
plt.figure(figsize=(8, 4))
|
| 144 |
+
strategies = list(chunking_data.keys())
|
| 145 |
+
counts = list(chunking_data.values())
|
| 146 |
+
|
| 147 |
+
bars = plt.bar(strategies, counts, color="skyblue")
|
| 148 |
+
|
| 149 |
+
# Add value labels on top of bars
|
| 150 |
+
for bar in bars:
|
| 151 |
+
yval = bar.get_height()
|
| 152 |
+
plt.text(bar.get_x() + bar.get_width()/2, yval + 20, int(yval), ha='center', va='bottom', fontsize=10)
|
| 153 |
+
|
| 154 |
+
# plt.xlabel("Chunking Strategies")
|
| 155 |
+
plt.tight_layout() # Apply tight layout after plotting
|
| 156 |
+
|
| 157 |
+
plt.ylabel("Number of Chunks")
|
| 158 |
+
plt.title(f"Chunking Strategy Distribution - {subset_name}")
|
| 159 |
+
plt.xticks(rotation=30)
|
| 160 |
+
plt.tight_layout()
|
| 161 |
+
|
| 162 |
+
# Return plot as figure (Gradio accepts it)
|
| 163 |
+
return plt.gcf()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def plot_subset_metrics_old1(subset_name):
|
| 167 |
"""Generate a bar plot of key metrics for a given subset with proper title display."""
|
| 168 |
try:
|
| 169 |
summary = ragbench_details[subset_name]["summary"]
|
|
|
|
| 218 |
)
|
| 219 |
|
| 220 |
return fig
|
|
|
|
|
|
|
|
|
|
| 221 |
except Exception as e:
|
| 222 |
print(f"Plotting error: {str(e)}")
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
+
def plot_chunking_strategies_old1(subset_name):
|
| 226 |
"""Visualize chunking strategy distribution with enhanced formatting."""
|
| 227 |
try:
|
| 228 |
chunking_data = ragbench_details[subset_name]["chunking"]
|
|
|
|
| 234 |
strategies = list(chunking_data.keys())
|
| 235 |
counts = list(chunking_data.values())
|
| 236 |
|
|
|
|
|
|
|
|
|
|
| 237 |
# Plot bars with different colors
|
| 238 |
bars = ax.bar(strategies, counts, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 239 |
|
|
|
|
| 273 |
# Auto-scale y-axis with 10% headroom
|
| 274 |
ax.set_ylim(0, max(counts) * 1.1)
|
| 275 |
|
| 276 |
+
return fig
|
| 277 |
+
except Exception as e:
|
| 278 |
+
print(f"Error plotting chunking strategies: {str(e)}")
|
| 279 |
+
|
| 280 |
+
def plot_chunking_strategies(subset_name):
|
| 281 |
+
"""Visualize chunking strategy distribution with consistent formatting."""
|
| 282 |
+
try:
|
| 283 |
+
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 284 |
+
|
| 285 |
+
# Create figure with constrained layout
|
| 286 |
+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)
|
| 287 |
+
|
| 288 |
+
# Prepare data
|
| 289 |
+
strategies = list(chunking_data.keys())
|
| 290 |
+
counts = list(chunking_data.values())
|
| 291 |
+
|
| 292 |
+
# Plot bars with consistent styling
|
| 293 |
+
bars = ax.bar(strategies, counts, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 294 |
+
|
| 295 |
+
# Add value labels (consistent with plot_subset_metrics)
|
| 296 |
+
ax.bar_label(bars, fmt='%d', padding=3, fontsize=9)
|
| 297 |
+
|
| 298 |
+
# Customize plot (aligned with plot_subset_metrics style)
|
| 299 |
+
ax.set_title(
|
| 300 |
+
f"Chunking Strategy Distribution - {subset_name}",
|
| 301 |
+
fontsize=12,
|
| 302 |
+
pad=20,
|
| 303 |
+
loc='left'
|
| 304 |
+
)
|
| 305 |
+
ax.set_ylabel("Number of Chunks", fontsize=10)
|
| 306 |
+
|
| 307 |
+
# Rotate x-labels (consistent angle)
|
| 308 |
+
ax.set_xticks(range(len(strategies)))
|
| 309 |
+
ax.set_xticklabels(
|
| 310 |
+
strategies,
|
| 311 |
+
rotation=25, # Matches 25° from plot_subset_metrics
|
| 312 |
+
ha='right',
|
| 313 |
+
fontsize=9,
|
| 314 |
+
rotation_mode='anchor'
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
# Consistent grid and spines
|
| 318 |
+
ax.grid(axis='y', linestyle=':', alpha=0.6)
|
| 319 |
+
ax.spines[['top', 'right']].set_visible(False)
|
| 320 |
+
|
| 321 |
+
# Auto-scale with same headroom
|
| 322 |
+
ax.set_ylim(0, max(counts) * 1.1)
|
| 323 |
+
|
| 324 |
return fig
|
| 325 |
|
| 326 |
except Exception as e:
|
| 327 |
print(f"Error plotting chunking strategies: {str(e)}")
|
| 328 |
|
| 329 |
+
def plot_subset_metrics(subset_name):
|
| 330 |
+
"""Generate a bar plot of key metrics with consistent formatting."""
|
| 331 |
+
try:
|
| 332 |
+
summary = ragbench_details[subset_name]["summary"]
|
| 333 |
+
|
| 334 |
+
# Metrics to plot
|
| 335 |
+
metrics = {
|
| 336 |
+
'Entries': 'Total Entries',
|
| 337 |
+
'TotalDocs': 'Total Documents',
|
| 338 |
+
'TotalUniqueIds': 'Unique IDs',
|
| 339 |
+
'TotalUniqueDocs': 'Unique Documents',
|
| 340 |
+
'UniqueDocsPercent': '% Unique Docs'
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
# Prepare data
|
| 344 |
+
display_names = list(metrics.values())
|
| 345 |
+
values = [summary.get(metric, 0) for metric in metrics.keys()]
|
| 346 |
+
|
| 347 |
+
# Create figure with same layout
|
| 348 |
+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)
|
| 349 |
+
|
| 350 |
+
# Plot bars with same style
|
| 351 |
+
bars = ax.bar(display_names, values, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 352 |
+
|
| 353 |
+
# Consistent value labels
|
| 354 |
+
ax.bar_label(bars, fmt='%d', padding=3, fontsize=9)
|
| 355 |
+
|
| 356 |
+
# Title with same style
|
| 357 |
+
title = f"Dataset Metrics - {subset_name}"
|
| 358 |
+
if 'Domain' in summary:
|
| 359 |
+
title += f" (Domain: {summary['Domain']})"
|
| 360 |
+
|
| 361 |
+
ax.set_title(title, fontsize=12, pad=20, loc='left')
|
| 362 |
+
|
| 363 |
+
# Consistent axis styling
|
| 364 |
+
ax.set_ylabel("Count", fontsize=10)
|
| 365 |
+
ax.grid(axis='y', linestyle=':', alpha=0.6)
|
| 366 |
+
ax.spines[['top', 'right']].set_visible(False)
|
| 367 |
+
|
| 368 |
+
# Same label rotation
|
| 369 |
+
ax.set_xticks(range(len(display_names)))
|
| 370 |
+
ax.set_xticklabels(display_names, rotation=25, ha='right', fontsize=9)
|
| 371 |
+
|
| 372 |
+
# Special percentage handling (now matches chunking plot's y-limit logic)
|
| 373 |
+
if 'UniqueDocsPercent' in summary:
|
| 374 |
+
current_ylim = ax.get_ylim()
|
| 375 |
+
ax.set_ylim(current_ylim[0], max(current_ylim[1], summary['UniqueDocsPercent'] * 1.2))
|
| 376 |
+
ax.text(
|
| 377 |
+
len(metrics)-1,
|
| 378 |
+
summary['UniqueDocsPercent'],
|
| 379 |
+
f"{summary['UniqueDocsPercent']}%",
|
| 380 |
+
ha='center',
|
| 381 |
+
va='bottom',
|
| 382 |
+
fontsize=10,
|
| 383 |
+
bbox=dict(facecolor='white', alpha=0.8, edgecolor='none')
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
return fig
|
| 387 |
+
|
| 388 |
+
except Exception as e:
|
| 389 |
+
print(f"Error plotting metrics: {str(e)}")
|
| 390 |
+
|
| 391 |
# Initialize with first subset's summary
|
| 392 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 393 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|