Spaces:
Running
Running
import hashlib | |
import os | |
import pandas as pd | |
import plotly.express as px | |
import streamlit as st | |
from bat import Benchmark, Config, Reporter, Tester | |
from bat.utils import get_holistic_benchmark | |
benchmarks_dict = { | |
"arena_elo": "LMSys Arena", | |
"mt_bench": "MT Bench", | |
"mixeval": "Mix Eval", | |
"alpacav2": "AlpacaEval V2", | |
"arena_hard": "Arena Hard", | |
"arc_c": "ARC-C", | |
"eq_benchv2": "EQ Bench V2", | |
"agieval": "AGIEval", | |
"llmonitor": "LLMonitor", | |
"bbh": "BBH", | |
"mmlu": "MMLU", | |
"alpacav1": "AlpacaEval V1", | |
"magi": "MAGI", | |
"alpacaeval2_lc": "AlpacaEval V2 Length Adjusted", | |
"gpt4all": "GPT-4-All", | |
"humaneval": "HumanEval", | |
"mbpp": "MBPP", | |
"hellaswag": "HellaSwag", | |
"hugging_6": "HF OpenLLM V1", | |
"winogrande": "Winogrande", | |
} | |
st.markdown( | |
"""<h1 style='text-align: center; color: black;'>๐๏ธโโ๏ธ BenchBench Leaderboard ๐๏ธโโ๏ธ</h1>""", | |
unsafe_allow_html=True, | |
) | |
st.markdown( | |
"We are excited to share the BenchBench-Leaderboard, a crucial component of our comprehensive research work -- [Benchmark Agreement Testing Done Right: A Guide for LLM Benchmark Evaluation](https://arxiv.org/abs/2407.13696)." | |
"This leaderboard is a meta-benchmark that ranks benchmarks based on their agreement with the crowd harnessing many different references. " | |
) | |
all_scenarios_for_aggragate = get_holistic_benchmark().get_scenarios() | |
st.subheader("The Leaderboard", divider=True) | |
# st.subheader("๐๏ธโโ๏ธ BenchBench Leaderboard ๐", divider=True) | |
leftcol, rightcol = st.columns([2, 1]) | |
with leftcol: | |
with st.expander("Leaderboard configurations (defaults are great BTW)", icon="โ๏ธ"): | |
with st.form("my_form"): | |
all_scenarios_for_aggragate_with_all = all_scenarios_for_aggragate.tolist() | |
all_scenarios_for_aggragate_with_all.append("All Holistic") | |
aggragate_scenarios = st.multiselect( | |
"Scenarios in Aggregate", | |
all_scenarios_for_aggragate_with_all, | |
["All Holistic"], | |
# all_scenarios_for_aggragate, | |
) | |
corr_type = st.selectbox( | |
label="Select Correlation type", options=["kendall", "pearson"], index=0 | |
) | |
aggragate_scenario_blacklist = ( | |
[ | |
scen | |
for scen in all_scenarios_for_aggragate | |
if scen not in aggragate_scenarios | |
] | |
if "All Holistic" not in aggragate_scenarios | |
else [] | |
) | |
model_select_strategy = st.selectbox( | |
label="Select strategy", | |
options=["random", "top_aggregate", "somewhere_aggregate"], | |
index=0, | |
) | |
n_models_taken_list = [5] | |
n_exps = 10 | |
submitted = st.form_submit_button(label="Run BAT") | |
with rightcol: | |
st.button("โ Add your benchmark here!") | |
def run_load( | |
aggragate_scenario_blacklist=[], | |
n_models_taken_list=[5], | |
model_select_strategy_list=["random"], | |
corr_types=["kendall"], | |
n_exps=10, | |
): | |
# Create a hash of the inputs to generate a unique cache file for each set of inputs | |
input_str = ( | |
str(aggragate_scenario_blacklist) | |
+ str(n_models_taken_list) | |
+ str(model_select_strategy_list) | |
+ str(corr_types) | |
+ str(n_exps) | |
) | |
input_hash = hashlib.md5(input_str.encode()).hexdigest() | |
cache_file = f"agreements_cache_{input_hash}.csv" | |
# Define the cache directory | |
cache_dir = "cache" | |
cache_path = os.path.join(cache_dir, cache_file) | |
# Check if the cache file exists | |
if os.path.exists(cache_path): | |
print("Loading cached results...") | |
agreements = pd.read_csv(cache_path) | |
return agreements | |
else: | |
print("Cached results not found, calculating") | |
cfg = Config( | |
exp_to_run="example", | |
n_models_taken_list=n_models_taken_list, | |
model_select_strategy_list=model_select_strategy_list, | |
corr_types=corr_types, | |
n_exps=n_exps if n_models_taken_list != [0] else 1, | |
# reference_data_path="data/combined_holistic.csv", | |
) | |
holistic = get_holistic_benchmark() | |
holistic_scenarios = holistic.get_scenarios() | |
holistic.clear_repeated_scenarios() | |
holistic.add_aggragete( | |
new_col_name="aggregate", | |
agg_source_name="holistic", | |
scenario_blacklist=aggragate_scenario_blacklist, | |
min_scenario_for_models_to_appear_in_agg=5, | |
) | |
allbench = Benchmark( | |
pd.read_csv("assets/combined_20240704.csv"), | |
# data_source=newbench_name, | |
) | |
allbench.df = allbench.df.drop(columns=["tag"]) | |
allbench.clear_repeated_scenarios() | |
allbench.df = allbench.df.query("scenario not in @holistic_scenarios") | |
allbench.df = allbench.df[~allbench.df["scenario"].str.contains("_mixed")] | |
allbench.df = allbench.df[~allbench.df["scenario"].str.contains("agentbench")] | |
# st.dataframe(holistic.df.query('scenario=="aggregate"')) | |
allbench = allbench.extend(holistic) | |
tester = Tester(cfg=cfg) | |
# len(allbench.get_scenario_appearences_count().keys()) | |
agreements = tester.all_vs_all_agreement_testing( | |
allbench, single_source_scenario="aggregate" | |
) | |
agreements.to_csv(cache_path, index=False) | |
return agreements | |
agreements = run_load( | |
aggragate_scenario_blacklist=aggragate_scenario_blacklist, | |
n_models_taken_list=n_models_taken_list, | |
model_select_strategy_list=[model_select_strategy], | |
corr_types=[corr_type], | |
n_exps=n_exps, | |
) | |
reporter = Reporter() | |
z_scores = reporter.get_all_z_scores(agreements=agreements, aggragate_name="aggregate") | |
corr_name = f"{'Kendall Tau' if corr_type=='kendall' else 'Per.'} Corr." | |
z_scores["z_score"] = z_scores["z_score"].round(2) | |
z_scores["corr_with_agg"] = z_scores["corr_with_agg"].round(2) | |
z_scores["p_value_of_corr_with_agg"] = z_scores["p_value_of_corr_with_agg"].round(2) | |
data = ( | |
z_scores.rename( | |
columns={ | |
"scenario": "Benchmark", | |
"z_score": "Z Score", | |
"corr_with_agg": corr_name, | |
"p_value_of_corr_with_agg": "p value of Corr.", | |
"source": "Source", | |
} | |
) | |
.sort_values("Z Score", ascending=False) | |
.reset_index(drop=True) | |
) | |
data = data[~data["Source"].str.contains("livebench")] | |
data = data[~data["Source"].str.contains("biggen")] | |
data.drop(columns=["Source"], inplace=True) | |
data["Benchmark"] = data["Benchmark"].apply(lambda x: benchmarks_dict[x]) | |
# Apply coloring based on 'Z' valuesz | |
styled_data = data.style.background_gradient( | |
subset=["Z Score"], | |
cmap="RdYlGn", | |
vmin=-data["Z Score"].abs().max(), | |
vmax=data["Z Score"].abs().max(), | |
).format(subset=["Z Score", corr_name, "p value of Corr."], formatter="{:.2}") | |
st.dataframe( | |
data=styled_data, | |
hide_index=True, | |
use_container_width=True, | |
height=300, | |
) | |
st.markdown( | |
"BenchBench-Leaderboard complements our study, where we analyzed over 40 prominent benchmarks and introduced standardized practices to enhance the robustness and validity of benchmark evaluations through the [BenchBench Python package](#). " | |
"The BenchBench-Leaderboard serves as a dynamic platform for benchmark comparison and is an essential tool for researchers and practitioners in the language model field aiming to select and utilize benchmarks effectively. " | |
) | |
st.subheader("How did we get the Z Scores?", divider=True) | |
st.write(r""" | |
Section 3.1 in our work shows how using a single reference benchmark drastically hurts the roubustness and validity of BAT. | |
To remedy this, we propose to test benchmark agreement with an aggragate benchmark and compare the agreement to other benchmarks. | |
We recommend to perform this comparison using the [Z score](https://en.wikipedia.org/wiki/Standard_score) and demonstrate obtaining it to a benchmark of your selection. | |
In the follwing way: $z_i=(x_i-\mu_{i...N}) / \sigma_{i...N}$ where $x_i$ is the agreement of the $i$th benchmark to the aggragate and $\mu_{i...N}$,$\sigma_{i...N}$ are the | |
mean and standard deviation of the agreements of the other benchmarks to the aggragate. | |
""") | |
benchmarks = data["Benchmark"].unique().tolist() | |
plotted_scenario = st.selectbox( | |
"Choose Benchmark to plot", benchmarks, index=benchmarks.index("LMSys Arena") | |
) | |
fig = px.histogram( | |
data.query("Benchmark!=@plotted_scenario"), x=corr_name, nbins=len(data) - 1 | |
) | |
# Add a vertical line at a specific x-coordinate | |
# Replace 'x_value' with the actual value where you want the line | |
x_value = 0.5 # Example value, adjust as necessary | |
fig.add_vline( | |
x=data.query("Benchmark==@plotted_scenario")[corr_name].iloc[0], | |
line_dash="dash", | |
line_color="red", | |
) | |
# Update layout to add a title | |
fig.update_layout( | |
title="Histogram of Correlation Values", # Change the title text as needed | |
title_x=0.3, # Centers the title | |
title_font=dict(size=20, family="CMU"), # Customize font if needed | |
) | |
# # Plot! | |
st.plotly_chart(fig, use_container_width=True) | |
st.subheader("Why should you use the BenchBench Leaderboard?") | |
st.markdown( | |
""" | |
Current practices in Benchmark Agreement Testing (BAT) often suffer from a lack of standardization and transparency, which can lead to inconsistent results and diminished trust in benchmark evaluations. Several key issues are prevalent in the field: | |
""" | |
) | |
st.markdown( | |
""" | |
- **Lack of Standard Methodologies:** Unlike other scientific procedures that follow rigorous methodologies, BAT lacks uniform procedures across different studies. Researchers often employ varied criteria for selecting benchmarks and models for comparison, which leads to results that cannot be easily compared or replicated. This variation undermines the reliability of conclusions drawn from BAT and makes it difficult for other researchers to build on existing work. | |
""" | |
) | |
st.image( | |
"images/motivation.png", | |
caption="Conclusions depend on the models considered. Kendall-tau correlations between the LMSys Arena benchmark and three other benchmarks: BBH, MMLU, and Alpaca v2. Each group of bars represents the correlation for different sets of top models, specifically the top 5, top 10, and top 15 (overlapping) models (according to the Arena). The results indicate that the degree of agreement between benchmarks varies with the number of top models considered, highlighting that different selections of models can lead to varying conclusions about benchmark agreement.", | |
use_column_width=True, | |
) | |
st.markdown( | |
""" | |
- **Arbitrary Selection of Reference Benchmarks:** One of the most critical decisions in BAT is the choice of reference benchmarks. Currently, this choice is often arbitrary and lacks a clear rationale, influenced by availability or personal preference rather than strategic alignment with the benchmarkโs purpose. This can skew the results significantly, as different benchmarks may not be equally representative or relevant to the models being tested. | |
""" | |
) | |
st.markdown( | |
""" | |
- **Inadequate Model Representation:** BAT frequently relies on a limited subset of models, which may not comprehensively represent the diversity of architectures and training paradigms in modern language models. This selective representation can lead to biased agreement scores that favor certain types of models over others, failing to provide a holistic view of model performance across different benchmarks. | |
""" | |
) | |
st.image( | |
"images/pointplot_granularity_matters.png", | |
caption="Correlations increase with number of models. Mean correlation (y) between each benchmark (lines) and the rest, given different numbers of models. The Blue and Orange lines are the average of all benchmark pair correlations with models sampled randomly (orange) or in contiguous sets (blue). The shaded lines represents adjacent sampling for the different benchmarks.", | |
use_column_width=True, | |
) | |
st.markdown( | |
""" | |
- **Overemphasis on Correlation Metrics:** Current BAT practices tend to over-rely on correlation metrics without adequately considering their limitations and the context of their application. While these metrics can provide useful insights, they are often treated as definitive evidence of agreement without acknowledging that high correlation does not necessarily imply conceptual alignment between benchmarks. | |
""" | |
) | |
st.markdown( | |
""" | |
To address these issues, there is a critical need for a more structured approach to BAT that includes clear guidelines for benchmark and model selection, a broader consideration of agreement metrics, and an acknowledgment of the evolving nature of technology in this space. By reforming BAT practices, the research community can improve the reliability and utility of benchmarks as tools for evaluating and advancing language models. | |
""" | |
) | |
st.image( | |
"images/ablations.png", | |
caption="Our recommendations substantially reduce the variance of BAT. Ablation analysis for each BAT recommendation separately and their combinations.", | |
use_column_width=True, | |
) | |
st.header("The BenchBench package") | |
st.markdown(""" | |
### Overview | |
The BAT package is designed to facilitate benchmark agreement testing for NLP models. It allows users to easily compare multiple models against various benchmarks and generate comprehensive reports on their agreement. | |
### Installation | |
To install the BAT package, you can use pip: | |
``` | |
pip install bat-package | |
``` | |
### Usage Example | |
Below is a step-by-step example of how to use the BAT package to perform agreement testing. | |
#### Step 1: Configuration | |
First, set up the configuration for the tests: | |
```python | |
import pandas as pd | |
from bat import Tester, Config, Benchmark, Reporter | |
from bat.utils import get_holistic_benchmark | |
cfg = Config( | |
exp_to_run="example", | |
n_models_taken_list=[0], | |
model_select_strategy_list=["random"], | |
n_exps=10 | |
) | |
``` | |
#### Step 2: Fetch Model Names | |
Fetch the names of the reference models to be used for scoring: | |
```python | |
tester = Tester(cfg=cfg) | |
models_for_benchmark_scoring = tester.fetch_reference_models_names( | |
reference_benchmark=get_holistic_benchmark(), n_models=20 | |
) | |
print(models_for_benchmark_scoring) | |
``` | |
#### Step 3: Load and Prepare Benchmark | |
Load a new benchmark and add an aggregate column: | |
```python | |
newbench_name = "fakebench" | |
newbench = Benchmark( | |
pd.read_csv(f"src/bat/assets/{newbench_name}.csv"), | |
data_source=newbench_name, | |
) | |
newbench.add_aggregate(new_col_name=f"{newbench_name}_mwr") | |
``` | |
#### Step 4: Agreement Testing | |
Perform all-vs-all agreement testing on the new benchmark: | |
```python | |
newbench_agreements = tester.all_vs_all_agreement_testing(newbench) | |
reporter = Reporter() | |
reporter.draw_agreements(newbench_agreements) | |
``` | |
#### Step 5: Extend and Clean Benchmark | |
Extend the new benchmark with holistic data and clear repeated scenarios: | |
```python | |
allbench = newbench.extend(get_holistic_benchmark()) | |
allbench.clear_repeated_scenarios(source_to_keep=newbench_name) | |
``` | |
#### Step 6: Comprehensive Agreement Testing | |
Perform comprehensive agreement testing and visualize: | |
```python | |
all_agreements = tester.all_vs_all_agreement_testing(allbench) | |
reporter.draw_agreements(all_agreements) | |
``` | |
""") | |