kesimeg commited on
Commit
aebc1ea
·
verified ·
1 Parent(s): 1f6b408

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +204 -0
app.py ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from gradio_leaderboard import Leaderboard, SelectColumns, ColumnFilter
5
+
6
+
7
+ TITLE = '''<h1>
8
+ <span style="font-variant: small-caps;">TR-RewardBench</span>: Evaluating Reward Models in Turkish
9
+ </h1>'''
10
+ INTRODUCTION_TEXT = '''
11
+ Evaluating the chat, safety, reasoning, and translation capabilities of Reward Models in Turkish. This space is a more detailed version of [M-RewardBench](https://huggingface.co/spaces/C4AI-Community/m-rewardbench) for Turkish
12
+ You can find more details (paper,code,etc.) on their space. This space uses the Turkish subset of [C4AI-Community/multilingual-reward-bench](https://hf.co/datasets/C4AI-Community/multilingual-reward-bench)
13
+ I want to thank them for relasing this dataset 🤗.
14
+
15
+ Most of the current models were evaluated with max token lenght of 2048. This effects the performance since it can cut some of the text. So if you try replicating the results with higher token size
16
+ you may get slightly better results (which also depends on the model).
17
+
18
+ For the description of subsets you can check out the about section of the original [space](https://huggingface.co/spaces/allenai/reward-bench).
19
+
20
+ ### Important warning: ⚠️,
21
+ In the original [English version of the dataset](https://huggingface.co/spaces/allenai/reward-bench) it is noted that some of the models are
22
+ unintentionally contaminated. You can find more on [here](https://gist.github.com/natolambert/1aed306000c13e0e8c5bc17c1a5dd300). I am doubt that models can generalize enough to have a performance boost even if they are trained with the English translation of a dataset but I just wanted to
23
+ warn anyways.
24
+
25
+ '''
26
+
27
+ class AutoEvalColumn:
28
+ model = {
29
+ "name": "Model",
30
+ "type": "markdown",
31
+ "displayed_by_default": True,
32
+ "never_hidden": True,
33
+ }
34
+
35
+ @classmethod
36
+ def add_columns_from_df(cls, df, columns):
37
+ for col in columns:
38
+ if col.lower() != 'model': # Skip if it's the model column since it's predefined
39
+ setattr(cls, col, {
40
+ "name": col,
41
+ "type": "markdown",
42
+ "displayed_by_default": True,
43
+ "never_hidden": False,
44
+ })
45
+
46
+
47
+ class AutoEvalColumnCategorical:
48
+ model = {
49
+ "name": "Model",
50
+ "type": "markdown",
51
+ "displayed_by_default": True,
52
+ "never_hidden": True,
53
+ }
54
+
55
+ @classmethod
56
+ def add_columns_from_df(cls, df, columns):
57
+ for col in columns:
58
+ if col.lower() != 'model': # Skip if it's the model column since it's predefined
59
+ setattr(cls, col, {
60
+ "name": col,
61
+ "type": "markdown",
62
+ "displayed_by_default": True,
63
+ "never_hidden": False,
64
+ })
65
+
66
+ def get_result_data():
67
+ return pd.read_csv("Model performance/model_performance.csv")
68
+
69
+
70
+ def get_categorical_data():
71
+ return pd.read_csv("Model performance/model_performance_categorical.csv")
72
+
73
+
74
+ def init_leaderboard(dataframe, df_class):
75
+ if dataframe is None or dataframe.empty:
76
+ raise ValueError("Leaderboard DataFrame is empty or None.")
77
+
78
+ return Leaderboard(
79
+ value=dataframe,
80
+ datatype=[
81
+ col["type"]
82
+ for col in df_class.__dict__.values()
83
+ if isinstance(col, dict)
84
+ ],
85
+ select_columns=SelectColumns(
86
+ default_selection=[
87
+ col["name"]
88
+ for col in df_class.__dict__.values()
89
+ if isinstance(col, dict) and col["displayed_by_default"]
90
+ ],
91
+ cant_deselect=[
92
+ col["name"]
93
+ for col in df_class.__dict__.values()
94
+ if isinstance(col, dict) and col.get("never_hidden", False)
95
+ ],
96
+ label="Select Columns to Display:",
97
+ ),
98
+ search_columns=["Model"],
99
+ interactive=False,
100
+ )
101
+
102
+
103
+ def format_model_link(row):
104
+ """Format model name as HTML link if URL is available"""
105
+ model_name = row["Model"]
106
+
107
+ return model_name
108
+
109
+ from functools import partial
110
+ def format_with_color(val, min_val=50, max_val=100):
111
+ """
112
+ Formats a value with inline green color gradient CSS.
113
+ Returns an HTML string with bold, black text and muted green background.
114
+ """
115
+ try:
116
+ val = float(val)
117
+ if pd.isna(val):
118
+ return str(val)
119
+
120
+ # Normalize value between 50 and 100 to 0-1 range
121
+ normalized = (val - min_val) / (max_val - min_val)
122
+
123
+ # Clamp value between 0 and 1
124
+ normalized = max(0, min(1, normalized))
125
+
126
+ # Create color gradient with reduced brightness (max 200 instead of 255)
127
+ # and increased minimum intensity (50 instead of 0)
128
+ intensity = int(50 + (150 * (1 - normalized)))
129
+
130
+ # Return HTML with inline CSS - bold black text
131
+ show_val = val*100
132
+
133
+ return f'<div val={val} style="background-color: rgb({intensity}, 200, {intensity}); color: black; font-weight: bold; text-align: center; vertical-align: middle;">{show_val:.1f}</div>'
134
+
135
+ except (ValueError, TypeError):
136
+ return str(val)
137
+
138
+ demo = gr.Blocks(theme=gr.themes.Soft())
139
+
140
+ with demo:
141
+ gr.HTML(TITLE)
142
+ gr.Markdown(INTRODUCTION_TEXT)
143
+
144
+ with gr.Tabs() as tabs:
145
+ with gr.TabItem("🏅 Subset performance"):
146
+ df = get_result_data()
147
+
148
+
149
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
150
+ global_min = df.select_dtypes(include='number').min().min()#.astype(float)
151
+ global_max = df.select_dtypes(include='number').max().max()#.astype(float)
152
+
153
+
154
+ for col in numeric_cols:
155
+ lang_format_with_color = partial(format_with_color,
156
+ min_val=global_min,
157
+ max_val=global_max,
158
+ )
159
+
160
+ df[col] = df[col].apply(lang_format_with_color)
161
+
162
+
163
+ AutoEvalColumn.add_columns_from_df(df, numeric_cols)
164
+ leaderboard = init_leaderboard(df, AutoEvalColumn)
165
+
166
+ with gr.TabItem("🏅 Categorical"):
167
+ df = get_categorical_data()
168
+
169
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
170
+
171
+ global_min = df.select_dtypes(include='number').min().min()#.astype(float)
172
+ global_max = df.select_dtypes(include='number').max().max()#.astype(float)
173
+
174
+ for col in numeric_cols:
175
+
176
+ lang_format_with_color = partial(format_with_color,
177
+ min_val=global_min,
178
+ max_val=global_max,
179
+ )
180
+ df[col] = df[col].apply(lang_format_with_color)
181
+
182
+
183
+ AutoEvalColumnCategorical.add_columns_from_df(df, numeric_cols)
184
+ leaderboard = init_leaderboard(df, AutoEvalColumnCategorical)
185
+
186
+ with gr.Row():
187
+ with gr.Accordion("📚 Citation", open=False):
188
+ citation_button = gr.Textbox(
189
+ value=r"""@misc{gureja2024mrewardbench,
190
+ title={M-RewardBench: Evaluating Reward Models in Multilingual Settings},
191
+ author={Srishti Gureja and Lester James V. Miranda and Shayekh Bin Islam and Rishabh Maheshwary and Drishti Sharma and Gusti Winata and Nathan Lambert and Sebastian Ruder and Sara Hooker and Marzieh Fadaee},
192
+ year={2024},
193
+ eprint={2410.15522},
194
+ archivePrefix={arXiv},
195
+ primaryClass={cs.CL},
196
+ url={https://arxiv.org/abs/2410.15522},
197
+ }""",
198
+ lines=7,
199
+ label="BibTeX",
200
+ elem_id="citation-button",
201
+ show_copy_button=True,
202
+ )
203
+
204
+ demo.launch(ssr_mode=False)