File size: 15,465 Bytes
05398d1
 
 
ecb1e20
05398d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1138892
05398d1
 
 
 
 
 
 
 
 
 
 
 
 
 
ecb1e20
05398d1
1138892
05398d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1138892
05398d1
 
 
 
 
 
 
 
 
 
 
 
 
ecb1e20
05398d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f8e886
 
 
 
 
 
 
 
05398d1
0f8e886
05398d1
0f8e886
05398d1
0f8e886
05398d1
0f8e886
05398d1
0f8e886
05398d1
 
 
 
 
 
 
0f8e886
05398d1
0f8e886
05398d1
 
0f8e886
05398d1
0f8e886
 
05398d1
 
0f8e886
05398d1
0f8e886
05398d1
 
 
 
0f8e886
05398d1
 
 
 
0f8e886
05398d1
0f8e886
05398d1
 
0f8e886
05398d1
 
 
0f8e886
05398d1
0f8e886
05398d1
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
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 on Benchmark Agreement Testing (BAT) [work](#). "
    "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"{'KT' 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)
```
""")