Spaces:
Sleeping
Sleeping
Ajaykanth Maddi commited on
Commit ·
b8d801d
1
Parent(s): 99ce3fc
Code Changes - Reranking Implementation
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import json
|
|
| 4 |
import logging
|
| 5 |
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
# ==== Metrics Calculation
|
|
@@ -197,7 +198,7 @@ def plot_subset_metrics_old(subset_name):
|
|
| 197 |
ax.set_xticklabels(keys, rotation=21, ha='right')
|
| 198 |
return fig
|
| 199 |
|
| 200 |
-
def
|
| 201 |
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 202 |
|
| 203 |
plt.figure(figsize=(8, 4))
|
|
@@ -222,6 +223,69 @@ def plot_chunking_strategies(subset_name):
|
|
| 222 |
# Return plot as figure (Gradio accepts it)
|
| 223 |
return plt.gcf()
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
# Initialize with first subset's summary
|
| 226 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 227 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|
|
|
|
| 4 |
import logging
|
| 5 |
|
| 6 |
from datetime import datetime
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
|
| 10 |
# ==== Metrics Calculation
|
|
|
|
| 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))
|
|
|
|
| 223 |
# Return plot as figure (Gradio accepts it)
|
| 224 |
return plt.gcf()
|
| 225 |
|
| 226 |
+
def plot_chunking_strategies(subset_name):
|
| 227 |
+
"""Visualize chunking strategy distribution with enhanced formatting."""
|
| 228 |
+
try:
|
| 229 |
+
chunking_data = ragbench_details[subset_name]["chunking"]
|
| 230 |
+
|
| 231 |
+
# Create figure with constrained layout to prevent clipping
|
| 232 |
+
fig, ax = plt.subplots(figsize=(10, 5), constrained_layout=True)
|
| 233 |
+
|
| 234 |
+
# Prepare data
|
| 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=colors, edgecolor='white', linewidth=0.7)
|
| 243 |
+
|
| 244 |
+
# Add value labels with better positioning
|
| 245 |
+
for bar in bars:
|
| 246 |
+
height = bar.get_height()
|
| 247 |
+
ax.text(
|
| 248 |
+
bar.get_x() + bar.get_width()/2,
|
| 249 |
+
height + max(counts)*0.02, # Dynamic padding
|
| 250 |
+
f'{int(height):,}', # Format with thousands separator
|
| 251 |
+
ha='center',
|
| 252 |
+
va='bottom',
|
| 253 |
+
fontsize=10,
|
| 254 |
+
fontweight='bold'
|
| 255 |
+
)
|
| 256 |
+
|
| 257 |
+
# Customize plot
|
| 258 |
+
ax.set_title(
|
| 259 |
+
f"Chunking Strategy Distribution\n{subset_name}",
|
| 260 |
+
fontsize=12,
|
| 261 |
+
pad=20,
|
| 262 |
+
fontweight='bold'
|
| 263 |
+
)
|
| 264 |
+
ax.set_ylabel("Number of Chunks", fontsize=10)
|
| 265 |
+
ax.set_xlabel("Chunking Method", fontsize=10, labelpad=10)
|
| 266 |
+
|
| 267 |
+
# Rotate x-labels and adjust appearance
|
| 268 |
+
ax.set_xticks(range(len(strategies)))
|
| 269 |
+
ax.set_xticklabels(
|
| 270 |
+
strategies,
|
| 271 |
+
rotation=30,
|
| 272 |
+
ha='right',
|
| 273 |
+
fontsize=9,
|
| 274 |
+
rotation_mode='anchor'
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
# Improve grid and spines
|
| 278 |
+
ax.grid(axis='y', linestyle=':', alpha=0.6)
|
| 279 |
+
ax.spines[['top', 'right']].set_visible(False)
|
| 280 |
+
|
| 281 |
+
# Auto-scale y-axis with 10% headroom
|
| 282 |
+
ax.set_ylim(0, max(counts) * 1.1)
|
| 283 |
+
|
| 284 |
+
return fig
|
| 285 |
+
|
| 286 |
+
except Exception as e:
|
| 287 |
+
print(f"Error plotting chunking strategies: {str(e)}")
|
| 288 |
+
|
| 289 |
# Initialize with first subset's summary
|
| 290 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 291 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|