File size: 8,412 Bytes
c923467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""A gradio app that renders a static leaderboard. This is used for Hugging Face Space."""

import ast
import argparse
import glob
import pickle

import gradio as gr
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import pandas as pd


def make_default_md():

    leaderboard_md = f"""
# ๐Ÿ† CZ-EVAL Leaderboard
[Developer](https://me.hynky.name/) | [Twitter](https://twitter.com/HKydlicek)

CZ-EVAL is a evaluation leadboard of Tasks in Czech for LLMs.

It's evaluated on following datasets:

- Math Problems Understanding [Klokan-QA](https://huggingface.co/datasets/hynky/klokan-qa)
- Reasoning and General Knowledge [TSP-QA](https://huggingface.co/datasets/hynky/tsp-qa)

๐Ÿ’ป Code: The evaluation code can be found at [hynky1999/LLM-Eval](https://github.com/hynky1999/LLM-Eval). Model inference is done using [Open-Router](https://openrouter.ai/) or on cloud using [Modal Labs](https://modal.com/).
"""
    return leaderboard_md


def make_arena_leaderboard_md(arena_df):
    total_models = len(arena_df)

    leaderboard_md = f"""
Total #models: **{total_models}**. Last updated: Feb 15, 2024.
"""
    return leaderboard_md


def make_full_leaderboard_md(elo_results):
    leaderboard_md = f"""
Three benchmarks are displayed: **Arena Elo**, **MT-Bench** and **MMLU**.
- [Klokan-QA](https://huggingface.co/datasets/hynky/klokan-qa) - Mathematical competitions dataset
- [TSP](https://huggingface.co/datasets/hynky/TSP) - Comprehensive dataset of 

"""
    return leaderboard_md


# Combine all category accuracies into a single DataFrame


def plot_spider(df, title):
    categories = df.columns.tolist()[1:]
    categories = [
        *categories,
        categories[0],
    ]  # Ensure the graph is circular by appending the start to the end
    colors = [
        "#1f77b4",  # muted blue
        "#ff7f0e",  # safety orange
        "#2ca02c",  # cooked asparagus green
        "#d62728",  # brick red
        "#9467bd",  # muted purple
        "#8c564b",  # chestnut brown
        "#e377c2",  # raspberry yogurt pink
        "#7f7f7f",  # middle gray
        "#bcbd22",  # curry yellow-green
        "#17becf",  # blue-teal
    ]

    # Setting for 1000x1000
    fig_1000 = go.Figure()

    for i, (idx, row) in enumerate(df.iterrows()):
        name = row[0]
        row = row.tolist()[1:]
        row = row + [
            row[0]
        ]  # Ensure the graph is circular by appending the start to the end
        color = colors[i]
        fig_1000.add_trace(
            go.Scatterpolar(
                r=row,
                theta=categories,
                opacity=0.4,
                name=name,
                line=dict(
                    color=color, width=4
                ),  # Adjust line width for better visibility
            )
        )

    fig_1000.update_layout(
        width=600,
        height=628,
        polar=dict(
            angularaxis=dict(
                gridwidth=2,  # Increase line width for better visibility
                rotation=90,
                direction="clockwise",
            ),
            radialaxis=dict(
                visible=True,
                range=[0, 100],
                angle=45,
                tickangle=45,
                tickvals=[0, 25, 50, 75, 100],
                ticktext=["0%", "25%", "50%", "75%", "100%"],
            ),
        ),
        title_text=title,
        title_x=0.5,
        title_y=0.97,
        title_xanchor="center",
        title_yanchor="top",
        title_font_size=24,
        title_font_color="#333333",
        font=dict(family="Arial", size=16, color="#333333"),
        legend=dict(
            orientation="h", yanchor="bottom", y=-0.45, xanchor="center", x=0.5
        ),
    )
    return fig_1000


def openrouter_hyperlink(model_name):
    return f'<a target="_blank" href="https://openrouter.ai/models/{model_name}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'


def get_full_table(model_table_df):
    num_cols = ["klokan", "culture", "analytical", "critical", "verbal"]
    # Multiply by 100 and round to 2 decimals
    # Add average
    model_table_df["average"] = model_table_df[num_cols].mean(axis=1)
    model_table_df[num_cols + ["average"]] = model_table_df[
        num_cols + ["average"]
    ].apply(lambda x: round(x * 100, 2))

    # Sort and add rank
    model_table_df.sort_values(by="average", ascending=False, inplace=True)
    model_table_df.insert(0, "rank", np.arange(1, len(model_table_df) + 1))

    # Add link
    model_table_df["model_name"] = model_table_df["model_name"].apply(
        lambda x: openrouter_hyperlink(x)
    )

    model_table_df.rename(
        columns={
            "model_name": "๐Ÿค– Model",
            "klokan": "๐Ÿงฎ Klokan-QA",
            "culture": "๐ŸŒ TSP-Culture",
            "analytical": "๐Ÿ” TSP-Analytical",
            "critical": "๐Ÿ’ก TSP-Critical",
            "verbal": "๐Ÿ“– TSP-Verbal",
            "average": "๐Ÿ“Š Average",
        },
        inplace=True,
    )

    return model_table_df


def build_leaderboard_tab(leaderboard_table_file, klokan_table_file, tsp_table_file):

    results = pd.read_csv(leaderboard_table_file)
    results = get_full_table(results)
    # p1, p2 = get_grafs(pd.read_json(klokan_table_file), pd.read_json(tsp_table_file))
    default_md = make_default_md()

    md_1 = gr.Markdown(default_md, elem_id="leaderboard_markdown")
    with gr.Tabs() as tabs:
        # arena table
        with gr.Tab("CZ-EVAL Leaderboard", id=0):
            md = make_arena_leaderboard_md(results)
            gr.Markdown(md, elem_id="leaderboard_markdown")
            gr.Dataframe(
                datatype=[
                    "str",
                    "markdown",
                    "number",
                    "number",
                    "number",
                    "number",
                    "number",
                    "number",
                    "str",
                    "str",
                    "str",
                ],
                value=results,
                elem_id="arena_leaderboard_dataframe",
                height=700,
                column_widths=[
                    50,
                    200,
                    120,
                    100,
                    100,
                    150,
                    150,
                    100,
                    150,
                    150,
                    150,
                ],
                wrap=True,
            )

    p1 = plot_spider(pd.read_csv(klokan_table_file), "Klokan-QA - Acurracy")
    p2 = plot_spider(pd.read_csv(tsp_table_file), "TSP - Accuracy")

    gr.Markdown(
        f"""## More Statistics for CZ-EVAL\n
Below are figures for more statistics.
""",
        elem_id="leaderboard_markdown",
    )
    with gr.Row():
        with gr.Column():
            gr.Markdown(
                "#### Figure 1: Performance of models on Klokan-QA per difficulty"
            )
            plot_1 = gr.Plot(p1, show_label=False)
        with gr.Column():
            gr.Markdown("#### Figure 2: Performance of models on TSP dataset")
            plot_2 = gr.Plot(p2, show_label=False)

    return [md_1, plot_1, plot_2]


block_css = """
#notice_markdown {
    font-size: 104%
}
#notice_markdown th {
    display: none;
}
#notice_markdown td {
    padding-top: 6px;
    padding-bottom: 6px;
}
#leaderboard_markdown {
    font-size: 104%
}
#leaderboard_markdown td {
    padding-top: 6px;
    padding-bottom: 6px;
}
#leaderboard_dataframe td {
    line-height: 0.1em;
}
footer {
    display:none !important
}
.image-container {
    display: flex;
    align-items: center;
    padding: 1px;
}
.image-container img {
    margin: 0 30px;
    height: 20px;
    max-height: 100%;
    width: auto;
    max-width: 20%;
}
"""


def build_demo(leadboard_table, klokan_table, tsp_table):
    text_size = gr.themes.sizes.text_lg

    with gr.Blocks(
        title="CZ-EVAL Leaderboard",
        theme=gr.themes.Base(text_size=text_size),
        css=block_css,
    ) as demo:
        leader_components = build_leaderboard_tab(
            leadboard_table, klokan_table, tsp_table
        )
    return demo


demo = build_demo(
    leadboard_table="./leaderboard/table.csv",
    klokan_table="./leaderboard/klokan.csv",
    tsp_table="./leaderboard/tsp.csv",
)

if __name__ == "__main__":
    demo.launch()