Spaces:
Sleeping
Sleeping
Ajaykanth Maddi commited on
Commit ·
617e568
1
Parent(s): 1921c0a
Code Changes - Reranking Implementation
Browse files
app.py
CHANGED
|
@@ -278,12 +278,16 @@ def plot_chunking_strategies_old1(subset_name):
|
|
| 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())
|
|
@@ -292,10 +296,10 @@ def plot_chunking_strategies(subset_name):
|
|
| 292 |
# Plot bars with consistent styling
|
| 293 |
bars = ax.bar(strategies, counts, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 294 |
|
| 295 |
-
# Add value labels
|
| 296 |
ax.bar_label(bars, fmt='%d', padding=3, fontsize=9)
|
| 297 |
|
| 298 |
-
# Customize plot
|
| 299 |
ax.set_title(
|
| 300 |
f"Chunking Strategy Distribution - {subset_name}",
|
| 301 |
fontsize=12,
|
|
@@ -304,11 +308,11 @@ def plot_chunking_strategies(subset_name):
|
|
| 304 |
)
|
| 305 |
ax.set_ylabel("Number of Chunks", fontsize=10)
|
| 306 |
|
| 307 |
-
# Rotate x-labels
|
| 308 |
ax.set_xticks(range(len(strategies)))
|
| 309 |
ax.set_xticklabels(
|
| 310 |
strategies,
|
| 311 |
-
rotation=25,
|
| 312 |
ha='right',
|
| 313 |
fontsize=9,
|
| 314 |
rotation_mode='anchor'
|
|
@@ -317,17 +321,19 @@ def plot_chunking_strategies(subset_name):
|
|
| 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 |
|
|
@@ -340,13 +346,15 @@ def plot_subset_metrics(subset_name):
|
|
| 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 |
|
|
@@ -360,16 +368,19 @@ def plot_subset_metrics(subset_name):
|
|
| 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
|
| 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))
|
|
@@ -384,7 +395,6 @@ def plot_subset_metrics(subset_name):
|
|
| 384 |
)
|
| 385 |
|
| 386 |
return fig
|
| 387 |
-
|
| 388 |
except Exception as e:
|
| 389 |
print(f"Error plotting metrics: {str(e)}")
|
| 390 |
|
|
|
|
| 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 and border."""
|
| 282 |
try:
|
| 283 |
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 284 |
|
| 285 |
+
# Create figure with constrained layout and white background
|
| 286 |
+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True, facecolor='white')
|
| 287 |
+
|
| 288 |
+
# Add a subtle border around the entire figure
|
| 289 |
+
fig.patch.set_edgecolor('lightgray')
|
| 290 |
+
fig.patch.set_linewidth(2)
|
| 291 |
|
| 292 |
# Prepare data
|
| 293 |
strategies = list(chunking_data.keys())
|
|
|
|
| 296 |
# Plot bars with consistent styling
|
| 297 |
bars = ax.bar(strategies, counts, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 298 |
|
| 299 |
+
# Add value labels
|
| 300 |
ax.bar_label(bars, fmt='%d', padding=3, fontsize=9)
|
| 301 |
|
| 302 |
+
# Customize plot
|
| 303 |
ax.set_title(
|
| 304 |
f"Chunking Strategy Distribution - {subset_name}",
|
| 305 |
fontsize=12,
|
|
|
|
| 308 |
)
|
| 309 |
ax.set_ylabel("Number of Chunks", fontsize=10)
|
| 310 |
|
| 311 |
+
# Rotate x-labels
|
| 312 |
ax.set_xticks(range(len(strategies)))
|
| 313 |
ax.set_xticklabels(
|
| 314 |
strategies,
|
| 315 |
+
rotation=25,
|
| 316 |
ha='right',
|
| 317 |
fontsize=9,
|
| 318 |
rotation_mode='anchor'
|
|
|
|
| 321 |
# Consistent grid and spines
|
| 322 |
ax.grid(axis='y', linestyle=':', alpha=0.6)
|
| 323 |
ax.spines[['top', 'right']].set_visible(False)
|
| 324 |
+
# Add border around plot area
|
| 325 |
+
ax.spines[['left', 'bottom']].set_color('lightgray')
|
| 326 |
+
ax.spines[['left', 'bottom']].set_linewidth(1.5)
|
| 327 |
|
| 328 |
# Auto-scale with same headroom
|
| 329 |
ax.set_ylim(0, max(counts) * 1.1)
|
| 330 |
|
| 331 |
return fig
|
|
|
|
| 332 |
except Exception as e:
|
| 333 |
print(f"Error plotting chunking strategies: {str(e)}")
|
| 334 |
|
| 335 |
def plot_subset_metrics(subset_name):
|
| 336 |
+
"""Generate a bar plot of key metrics with consistent formatting and border."""
|
| 337 |
try:
|
| 338 |
summary = ragbench_details[subset_name]["summary"]
|
| 339 |
|
|
|
|
| 346 |
'UniqueDocsPercent': '% Unique Docs'
|
| 347 |
}
|
| 348 |
|
| 349 |
+
# Create figure with white background and border
|
| 350 |
+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True, facecolor='white')
|
| 351 |
+
fig.patch.set_edgecolor('lightgray')
|
| 352 |
+
fig.patch.set_linewidth(2)
|
| 353 |
+
|
| 354 |
# Prepare data
|
| 355 |
display_names = list(metrics.values())
|
| 356 |
values = [summary.get(metric, 0) for metric in metrics.keys()]
|
| 357 |
|
|
|
|
|
|
|
|
|
|
| 358 |
# Plot bars with same style
|
| 359 |
bars = ax.bar(display_names, values, color='skyblue', edgecolor='white', linewidth=0.7)
|
| 360 |
|
|
|
|
| 368 |
|
| 369 |
ax.set_title(title, fontsize=12, pad=20, loc='left')
|
| 370 |
|
| 371 |
+
# Consistent axis styling with border
|
| 372 |
ax.set_ylabel("Count", fontsize=10)
|
| 373 |
ax.grid(axis='y', linestyle=':', alpha=0.6)
|
| 374 |
ax.spines[['top', 'right']].set_visible(False)
|
| 375 |
+
# Add border around plot area
|
| 376 |
+
ax.spines[['left', 'bottom']].set_color('lightgray')
|
| 377 |
+
ax.spines[['left', 'bottom']].set_linewidth(1.5)
|
| 378 |
|
| 379 |
# Same label rotation
|
| 380 |
ax.set_xticks(range(len(display_names)))
|
| 381 |
ax.set_xticklabels(display_names, rotation=25, ha='right', fontsize=9)
|
| 382 |
|
| 383 |
+
# Special percentage handling
|
| 384 |
if 'UniqueDocsPercent' in summary:
|
| 385 |
current_ylim = ax.get_ylim()
|
| 386 |
ax.set_ylim(current_ylim[0], max(current_ylim[1], summary['UniqueDocsPercent'] * 1.2))
|
|
|
|
| 395 |
)
|
| 396 |
|
| 397 |
return fig
|
|
|
|
| 398 |
except Exception as e:
|
| 399 |
print(f"Error plotting metrics: {str(e)}")
|
| 400 |
|