MCPcopy Create free account
hub / github.com/InternScience/SciReason / visualize

Function visualize

opencompass/summarizers/needlebench.py:256–365  ·  view source on GitHub ↗
(df_raw, save_path: str,model_name: str ,dataset_type:str)

Source from the content-addressed store, hash-verified

254 return model_scores
255
256def visualize(df_raw, save_path: str,model_name: str ,dataset_type:str):
257 df = df_raw.copy()
258 if df.empty:
259 return -1
260 df['Context Length'] = df['dataset'].apply(
261 lambda x: int(x.split('Length')[1].split('Depth')[0]))
262 df['Document Depth'] = df['dataset'].apply(
263 lambda x: float(x.split('Depth')[1].split('_')[0]))
264
265 model_columns = [
266 col for col in df.columns
267 if col not in ['Context Length', 'Document Depth']
268 ]
269
270 for model_name in model_columns[1:]:
271 model_df = df[['Document Depth', 'Context Length',
272 model_name]].copy()
273 model_df.rename(columns={model_name: 'Score'}, inplace=True)
274 pivot_table = pd.pivot_table(model_df,
275 values='Score',
276 index=['Document Depth'],
277 columns=['Context Length'],
278 aggfunc='mean')
279
280 mean_scores = pivot_table.mean().values
281 overall_score = mean_scores.mean()
282 plt.figure(figsize=(10, 6))
283 ax = plt.gca()
284 cmap = LinearSegmentedColormap.from_list(
285 'custom_cmap', ['#F0496E', '#EBB839', '#0CD79F'])
286
287 sns.heatmap(pivot_table,
288 cmap=cmap,
289 ax=ax,
290 vmin=0,
291 vmax=100)
292 cbar = ax.collections[0].colorbar
293 x_data = [i + 0.5 for i in range(len(mean_scores))]
294 y_data = mean_scores
295
296 ax2 = ax.twinx()
297 ax2.plot(x_data,
298 y_data,
299 color='white',
300 marker='o',
301 linestyle='-',
302 linewidth=2,
303 markersize=8,
304 label='Average Depth Score'
305 )
306 for x_value, y_value in zip(x_data, y_data):
307 ax2.text(x_value, y_value, f'{y_value:.2f}', ha='center', va='top')
308
309 ax2.set_ylim(0, 100)
310
311 ax2.set_yticklabels([])
312 ax2.set_yticks([])
313

Callers 1

save_results_to_plotsFunction · 0.85

Calls 3

convert_to_kFunction · 0.85
meanMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected