diff --git a/opencompass/summarizers/subjective/subjective.py b/opencompass/summarizers/subjective/subjective.py index 55c14933e..9693c6ed4 100644 --- a/opencompass/summarizers/subjective/subjective.py +++ b/opencompass/summarizers/subjective/subjective.py @@ -4,7 +4,7 @@ import pandas as pd from mmengine import ConfigDict - +from collections import OrderedDict from .utils import get_outdir @@ -73,24 +73,24 @@ def summarize( None """ output_dir, results_folder = get_outdir(self.cfg, time_str) - flat_data, models_order = flatten_data(subjective_scores) - # Create a DataFrame for each judgemodel with models as rows and datasets as columns judgemodel_dfs_final_corrected = {} for judgemodel_name, datasets_scores in flat_data.items(): dfs = {} # Dictionary to hold DataFrames for each dataset for dataset_name, scores in datasets_scores.items(): # Create a DataFrame with models as index and datasets as columns - df = pd.DataFrame.from_dict(scores, - orient='index', - columns=models_order) + + order_of_rows = list(scores.keys()) + df = pd.DataFrame.from_dict({k: scores[k] for k in order_of_rows}, orient='index') + df = df.reindex(order_of_rows) # Insert a new row at the top for the dataset names df.insert(0, 'Detailed Scores', df.index.values) df.insert(0, 'Dataset', [dataset_name for _ in range(len(df.index))]) dfs[dataset_name] = df + # Concatenate all DataFrames for the current judgemodel judgemodel_df = pd.concat(dfs.values(), ignore_index=True) judgemodel_dfs_final_corrected[judgemodel_name] = judgemodel_df @@ -103,3 +103,6 @@ def summarize( print('Your subjective evaluation results have been saved at ' + str(fout)) df.to_csv(fout, index=False) + + +