File size: 13,637 Bytes
4c59875
0b20d0d
4c59875
 
 
 
5542fa4
6964a16
5542fa4
 
 
 
 
 
 
 
 
6964a16
 
5542fa4
49b4a14
6964a16
 
 
 
5542fa4
 
6964a16
 
 
4c59875
5542fa4
 
 
 
 
6964a16
aa9beda
5542fa4
aa9beda
5542fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5ae15c
5542fa4
 
8599bf2
 
5542fa4
 
 
 
 
 
 
 
 
 
 
 
 
8599bf2
 
 
 
5542fa4
8599bf2
 
5542fa4
 
 
4c59875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa9beda
5542fa4
aa9beda
 
 
 
 
 
 
 
 
697b3ec
5542fa4
697b3ec
7918cff
 
 
 
 
 
5542fa4
7918cff
5542fa4
697b3ec
 
5542fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
c5ae15c
 
 
 
 
 
 
 
 
 
 
 
5542fa4
 
4c59875
a888db4
 
5542fa4
 
a888db4
6964a16
 
 
 
b83aee7
6964a16
 
 
 
 
 
 
 
 
7918cff
 
5542fa4
7918cff
 
 
5542fa4
7918cff
 
aa9beda
 
 
 
7918cff
6964a16
 
4c59875
5542fa4
aa9beda
4c59875
 
 
aa9beda
4c59875
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5542fa4
 
4c59875
 
 
5542fa4
 
4c59875
 
 
 
5542fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c59875
 
 
 
 
 
 
 
 
 
 
 
 
6ccb59a
8599bf2
6ccb59a
aa9beda
 
5542fa4
aa9beda
 
5542fa4
8599bf2
 
5542fa4
aa9beda
5542fa4
 
 
7918cff
 
4c59875
 
 
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
import pandas as pd
import numpy as np
import gradio as gr
import plotly.express as px
import plotly.graph_objects as go

# Creating data for explanation df in about section
explanation_data = {
    "Accuracy Scores": [
        "DrugMatchQA",
        "MedMCQA: G2B",
        "MedMCQA: Original",
        "MedMCQA: Difference",
        "MedQA: G2B",
        "MedQA: Original",
        "MedQA: Difference",
        "Adjusted Robustness Score"
    ],
    "Description": [
        "A custom MC task where the model is asked to match a brand name to its generic counterpart and vice versa. This task is designed to test the model's ability to understand drug name synonyms.",
        "G2B Refers to the 'Generic' to 'Brand' name swap. This is model accuracy on MedMCQA task where generic drug names are substituted with brand names.",
        "Model accuracy on MedMCQA task with original data. (Only includes questions that overlap with the g2b dataset)",
        "Difference in MedMCQA accuracy for swapped and non-swapped datasets, highlighting the impact of G2B drug name substitution on performance.",
        "Model accuracy on MedQA (4 options) task where generic drug names are substituted with brand names.",
        "Model accuracy on MedQA (4 options) task with original data. (Only includes questions that overlap with the g2b dataset)",
        "Difference in MedMCQA accuracy for swapped and non-swapped datasets, highlighting the impact of G2B drug name substitution on performance.",
        "A score given by Avg Difference / Avg G2B Accuracy. A higher score indicates a model that is more robust to drug name synonym substitution."
    ]
}
explanation_df = pd.DataFrame(explanation_data)




#Loading and cleaning eval data processed by json2df.py

df = pd.read_csv("data/csv/models_data.csv")
df['average_g2b'] = df[['medmcqa_g2b', 'medqa_4options_g2b']].mean(axis=1).round(2)
df['average_original_acc'] = df[['medmcqa_orig_filtered', 'medqa_4options_orig_filtered']].mean(axis=1).round(2)
df['average_diff'] = df[['medmcqa_diff', 'medqa_diff']].mean(axis=1).round(2)
df.drop(columns=['b4b'], inplace=True)
#Rename columns for clarity

df.rename(columns={
    'medmcqa_g2b': 'MedMCQA: G2B',
    'medmcqa_orig_filtered': 'MedMCQA: Original',
    'medmcqa_diff': 'MedMCQA: Difference',
    'medqa_4options_g2b': 'MedQA: G2B',
    'medqa_4options_orig_filtered': 'MedQA: Original',
    'medqa_diff': 'MedQA: Difference',
    'b4bqa': 'DrugMatchQA',
    'average_g2b': 'Average G2B Accuracy',
    'average_original_acc': 'Average Original Accuracy',
    'average_diff': 'Average Difference'
}, inplace=True)

#Create adjusted robustness score that accounts for g2b accuracy and difference in accuracy

df['Average Accuracy (Original and G2B)'] = (df['Average G2B Accuracy'] + df['Average Original Accuracy']) / 2

#df['Adjusted Robustness Score'] = df['Average Accuracy (Original and G2B)'] - 0.25 - df['Average Difference'].abs()
#df['Adjusted Robustness Score'] = df['Adjusted Robustness Score'].round(2)








#if acc is 0 in DrugMatchQA column, set it to none
df['DrugMatchQA'] = df['DrugMatchQA'].apply(lambda x: None if x == 0 else x)



def remove_rows_with_strings(df, column, strings):
    for string in strings:
        df = df[~df[column].str.contains(string)]
    return df

models_to_remove = ['microsoft-phi-1', 'microsoft-phi-1_5', 'meta-llama-Llama-2-7b-hf']
non_random_df = remove_rows_with_strings(df, 'Model', models_to_remove)


#Defining functions for filtering and plotting

filter_mapping = {
    "all": "all",
    "🟒 Pre-trained": "🟒",
    "🟩 Continuously pre-trained": "🟩",
    "πŸ”Ά Fine-tuned on domain-specific data": "πŸ”Ά",
    "πŸ’¬ Chat-models (RLHF, DPO, IFT, ...)": "πŸ’¬"
}

def filter_items(df, query):
    if query == "all":
        return df
    filter_value = filter_mapping[query]
    return df[df["T"].str.contains(filter_value, na=False)]

def create_scatter_plot(df, x_col, y_col, title, x_title, y_title):
    fig = px.scatter(df, x=x_col, y=y_col, color='Model', title=title)
    fig.add_trace(
        go.Scatter(
            x=[0, 100],
            y=[0, 100],
            mode="lines",
            name="y=x line",
            line=dict(color='black', dash='dash')
        )
    )
    
    fig.update_layout(
        xaxis_title=x_title,
        yaxis_title=y_title,
        xaxis=dict(range=[0, 100]),
        yaxis=dict(range=[0, 100]),
        legend_title_text='Model'
    )
    fig.update_traces(marker=dict(size=10), selector=dict(mode='markers'))
    return fig

def create_lm_plot(df, x_col, y_col, title, x_title, y_title):
    fig = px.scatter(df, x=x_col, y=y_col, color='Model', title=title, trendline='ols')
    
    fig.update_layout(
        xaxis_title=x_title,
        yaxis_title=y_title,
        legend_title_text='Model'
    )
    fig.update_traces(marker=dict(size=10), selector=dict(mode='markers'))
    return fig

def create_bar_plot(df, col, title):

    sorted_df = df.sort_values(by=col, ascending=True)
    fig = px.bar(sorted_df, 
                 x=col, 
                 y='Model', 
                 orientation='h', 
                 title=title, 
                 color=col, 
                 color_continuous_scale='Aggrnyl')
    fig.update_layout(xaxis_title=col, yaxis_title='Model', height=600, coloraxis_showscale=False)
    fig.update_xaxes(range=[-20, 20])
    return fig


def create_bar_plot_drugmatchqa(df, col, title):
    clean_df = df.dropna(subset=['DrugMatchQA'])
    sorted_df = clean_df.sort_values(by=col, ascending=True)
    fig = px.bar(sorted_df, 
                 x=col, 
                 y='Model', 
                 orientation='h', 
                 title=title, 
                 color=col, 
                 color_continuous_scale='Aggrnyl')
    fig.update_layout(xaxis_title=col, yaxis_title='Model', height=600, coloraxis_showscale=False)
    return fig

def create_bar_plot_adjusted(df, col, title):
    sorted_df = df.sort_values(by=col, ascending=True)
    fig = px.bar(sorted_df, 
                 x=col, 
                 y='Model', 
                 orientation='h', 
                 title=title, 
                 color=col, 
                 color_continuous_scale='Aggrnyl')
    fig.update_layout(xaxis_title=col, yaxis_title='Model', height=600, coloraxis_showscale=False)
    return fig

#Create UI/Layout

with gr.Blocks(css="custom.css") as demo:
    with gr.Column():
        gr.Markdown(
            """<div style="text-align: center;"><h1> <span style='color: #00BF63;'>🐰 RABBITS</span>: <span style='color: #00BF63;'>R</span>obust <span style='color: #00BF63;'>A</span>ssessment of <span style='color: #00BF63;'>B</span>iomedical <span style='color: #00BF63;'>B</span>enchmarks <span style='color: #00BF63;'>I</span>nvolving drug
<span style='color: #00BF63;'>T</span>erm <span style='color: #00BF63;'>S</span>ubstitutions<span style='color: #00BF63;'></span></h1></div>"""
        )
    with gr.Row():
        gr.Markdown("""  """)    
    with gr.Row():       
        gr.Markdown(
            """<div style="text-align: justify;">
            <p class='markdown-text'>Robust language models are crucial in the medical domain and the RABBITS project tests the robustness of LLMs by evaluating their handling of synonyms, specifically brand and generic drug names. We assessed 16 open-source language models from Hugging Face using systematic synonym substitution on MedQA and MedMCQA tasks. Our results show a consistent decline in performance across all model sizes, highlighting challenges in synonym comprehension. Additionally, we discovered significant dataset contamination by identifying overlaps between MedQA, MedMCQA test sets, and the Dolma 1.6 dataset using an 8-gram analysis. This highlights the need to improve model robustness and address contamination in open-source datasets.</p>
            </div>"""
        )
    with gr.Row():
        gr.Markdown("""  """)

    with gr.Row():
        gr.Markdown("""  """)

    with gr.Row():
        bar1 = gr.Plot(
            value=create_bar_plot(df, "MedMCQA: Difference", "Impact of Generic2Brand swap on MedMCQA Accuracy"),
            elem_id="bar1"
        )
        bar2 = gr.Plot(
            value=create_bar_plot(df, "MedQA: Difference", "Impact of Generic2Brand swap on MedQA Accuracy"),
            elem_id="bar2"
        )
    
    

    

    with gr.Row():
        gr.Markdown("""  """)

    #default_visible_columns = []    

    with gr.Tabs(elem_classes="tab-buttons"):
        with gr.TabItem("πŸ” Evaluation table"):
            with gr.Column():
                with gr.Accordion("➑️ See All Columns", open=False):
                    shown_columns = gr.CheckboxGroup(
                        choices=df.columns.tolist(),
                        value=df.columns.tolist(),
                        label="Select Columns",
                        interactive=True,
                    )
                with gr.Row():
                    search_bar = gr.Textbox(
                        placeholder="πŸ” Search for your model and press ENTER...",
                        show_label=False,
                        elem_id="search-bar"
                    )
                    filter_columns = gr.Radio(
                        label="⏚ Filter model types",
                        choices=[
                            "all", 
                            "🟒 Pre-trained", 
                            "🟩 Continuously pre-trained", 
                            "πŸ”Ά Fine-tuned on domain-specific data", 
                            "πŸ’¬ Chat-models (RLHF, DPO, IFT, ...)"
                        ],
                        value="all",
                        elem_id="filter-columns",
                    )
                leaderboard_df = gr.Dataframe(
                    value=df,
                    headers="keys",
                    datatype=["html" if col == "Model" else "str" for col in df.columns],
                    interactive=False,
                    elem_id="leaderboard-table"
                )

                def update_leaderboard(search_query):
                    filtered_df = df[df["Model"].str.contains(search_query, case=False)]
                    return filtered_df

                search_bar.submit(
                    update_leaderboard,
                    inputs=search_bar,
                    outputs=leaderboard_df
                )

                def filter_update(query):
                    filtered_df = filter_items(df, query)
                    return filtered_df

                filter_columns.change(
                    filter_update,
                    inputs=filter_columns,
                    outputs=leaderboard_df
                )

                shown_columns.change(
                    lambda cols: df[cols], 
                    inputs=shown_columns, 
                    outputs=leaderboard_df
                )

        with gr.TabItem("πŸ“Š Evaluation Plots"):
            with gr.Column():
                with gr.Row():
                    scatter1 = gr.Plot(
                        value=create_scatter_plot(df, "MedMCQA: Original", "MedMCQA: G2B",
                                                "MedMCQA: Orig vs G2B", "MedMCQA: Original", "MedMCQA: G2B"),
                        elem_id="scatter1"
                    )
                    scatter2 = gr.Plot(
                        value=create_scatter_plot(df, "MedQA: Original", "MedQA: G2B",
                                                "MedQA: Orig vs G2B", "MedQA: Original", "MedQA: G2B"),
                        elem_id="scatter2"
                    )

        with gr.TabItem("πŸ“ About"):
            with gr.Column():
                gr.Markdown(
                    """<div style="text-align: center;">
                    <h2>About the RABBITS LLM Leaderboard</h2>
                    <p>The following is an overview of the framework, along with an explanation of scores in the evaluation table.</p>
                    </div>""",
                    elem_classes="markdown-text"
                )
            with gr.Row():
                    gr.Image(value="workflow-1-2.svg",  width=200, height=450)
                    gr.Image(value="workflow-3-4.svg",  width=200, height=450)
            with gr.Row():
                gr.Dataframe(
                    value=explanation_df,
                    headers="keys",
                    datatype=["str", "str"],
                    interactive=False,
                    label="Explanation of Scores"
                    )


        with gr.TabItem("πŸš€ Submit Here!"):
            gr.Markdown(
                """<div style="text-align: center;">
                <h2>Submit Your Model Results</h2>
                <p>If you have new model results that you would like to add to the leaderboard, please follow the submission guidelines below:</p>
                <ul>
                    <li>COMING SOON</li>
                </ul>
                <p>COMING SOON</p>
                </div>""",
                elem_classes="markdown-text"
            )



    with gr.Row():
        bar3 = gr.Plot(
            value=create_bar_plot_drugmatchqa(df, "DrugMatchQA", "Which LLMs are best at matching brand names to generic drug names?"),
            elem_id="bar3"
        )
        bar4 = gr.Plot(
            #remove model in model column
            value=create_bar_plot_adjusted(non_random_df, "Average Difference", "Which LLMs are most robust to drug name synonym substitution?"),
            elem_id="bar4"
        )
    
        
    



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