File size: 10,897 Bytes
1205683
1bc77fb
 
1205683
6c3704b
 
 
 
 
 
 
 
3d1714b
6c3704b
 
3d1714b
254bcd7
3d1714b
 
254bcd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d1714b
 
254bcd7
 
1bc77fb
 
3d1714b
1bc77fb
 
3d1714b
 
 
1bc77fb
3d1714b
1bc77fb
 
3d1714b
 
254bcd7
 
 
3d1714b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b145c4b
3d1714b
 
1bc77fb
3d1714b
b145c4b
6c3704b
3d1714b
1bc77fb
 
3d1714b
1bc77fb
6c3704b
 
3d1714b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c3704b
3d1714b
 
 
 
 
 
 
 
1bc77fb
3d1714b
 
 
6c3704b
3d1714b
 
 
6c3704b
3d1714b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bc77fb
3d1714b
1bc77fb
254bcd7
 
b145c4b
254bcd7
3d1714b
1bc77fb
 
 
254bcd7
3d1714b
1bc77fb
3d1714b
1bc77fb
 
254bcd7
3d1714b
1bc77fb
3d1714b
254bcd7
1bc77fb
254bcd7
3d1714b
1bc77fb
3d1714b
1bc77fb
 
 
 
b145c4b
 
 
1bc77fb
3d1714b
254bcd7
3d1714b
 
 
 
 
 
 
 
254bcd7
b145c4b
254bcd7
3d1714b
 
b145c4b
 
 
 
3d1714b
 
254bcd7
 
3d1714b
b145c4b
 
 
 
 
 
3d1714b
254bcd7
1bc77fb
 
b145c4b
1bc77fb
3d1714b
254bcd7
b145c4b
254bcd7
3d1714b
254bcd7
 
 
 
3d1714b
254bcd7
 
 
3d1714b
254bcd7
b145c4b
254bcd7
3d1714b
254bcd7
 
1bc77fb
3d1714b
b145c4b
 
 
 
 
1bc77fb
3d1714b
 
 
 
 
254bcd7
1bc77fb
 
3d1714b
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
import gradio as gr
import pandas as pd
import numpy as np

# Load data from TSV file
df = pd.read_csv('FACTS.tsv', sep='\t')

# Clean up the data
df = df.dropna()  # Remove any rows with missing values
df.columns = df.columns.str.strip()  # Remove any whitespace from column names

# Rename columns to match our expected format
df = df.rename(columns={
    'model': 'Model Name',
    'size': 'Size'
})

# Create size display format
df["Size_Display"] = df["Size"].apply(lambda x: f"{int(x)}B" if x == int(x) else f"{x}B")

# Add size category for filtering
def get_size_category(size):
    if size <= 5:
        return "0-5B"
    elif size <= 10:
        return "5-10B"
    elif size <= 20:
        return "10-20B"
    elif size <= 40:
        return "20-40B"
    elif size <= 80:
        return "40-80B"
    else:
        return ">80B"

df["Size_Category"] = df["Size"].apply(get_size_category)


def filter_and_search_models(search_query, size_ranges, sort_by):
    """Filter and search models based on user inputs"""
    filtered_df = df.copy()

    # Apply search filter
    if search_query:
        mask = filtered_df["Model Name"].str.contains(
            search_query, case=False, na=False
        )
        filtered_df = filtered_df[mask]

    # Apply size range filter
    if size_ranges and len(size_ranges) > 0:
        filtered_df = filtered_df[filtered_df["Size_Category"].isin(size_ranges)]

    # Sort by selected metric
    if sort_by in filtered_df.columns:
        filtered_df = filtered_df.sort_values(sort_by, ascending=False)

    # Add ranking based on the sorted metric
    filtered_df = filtered_df.reset_index(drop=True)
    filtered_df["Rank"] = range(1, len(filtered_df) + 1)

    # Select columns to display (including Rank and Size)
    display_df = filtered_df[
        [
            "Rank",
            "Model Name",
            "Size_Display",
            "Separate Grounding Score",
            "Separate Quality Score",
            "Combined Score",
        ]
    ]

    # Rename Size_Display to Size for cleaner display
    display_df = display_df.rename(columns={"Size_Display": "Size"})

    # Round numerical values for better display
    for col in ["Separate Grounding Score", "Separate Quality Score", "Combined Score"]:
        display_df = display_df.copy()  # Create a copy to avoid SettingWithCopyWarning
        display_df[col] = display_df[col].round(6)

    return display_df


# Create the Gradio interface
with gr.Blocks(title="FACTS Grounding Leaderboard", theme=gr.themes.Base()) as app:
    gr.Markdown("# 🏆 FACTS Grounding Leaderboard")
    gr.Markdown(
        "### FACTS Medical Grounding is a benchmark designed to evaluate Open Models over medical domain."
    )

    with gr.Tabs():
        with gr.TabItem("Leaderboard"):
            # Filters at the top
            with gr.Row():
                with gr.Column(scale=2):
                    search_box = gr.Textbox(
                        label="Model Search",
                        placeholder="Search for a model name...",
                        value="",
                    )

                with gr.Column(scale=1):
                    sort_dropdown = gr.Dropdown(
                        choices=[
                            "Combined Score",
                            "Separate Grounding Score",
                            "Separate Quality Score",
                        ],
                        value="Combined Score",
                        label="Sort by",
                        elem_classes="sort-dropdown",
                    )

            # Size filters in a row
            with gr.Row():
                gr.Markdown("**Filter by Model Size:**")
                size_checkboxes = gr.CheckboxGroup(
                    choices=["0-5B", "5-10B", "10-20B", "20-40B", "40-80B", ">80B"],
                    value=["0-5B", "5-10B", "10-20B", "20-40B", "40-80B", ">80B"],
                    label="",
                    elem_classes="size-filter",
                    container=False,
                )

            # Model count
            total_models = gr.Markdown(f"**Showing {len(df)} models**")

            # Results table below filters
            results_table = gr.Dataframe(
                value=filter_and_search_models(
                    "",
                    ["0-5B", "5-10B", "10-20B", "20-40B", "40-80B", ">80B"],
                    "Combined Score",
                ),
                headers=[
                    "Rank",
                    "Model Name",
                    "Size",
                    "Separate Grounding Score",
                    "Separate Quality Score",
                    "Combined Score",
                ],
                datatype=["number", "str", "str", "number", "number", "number"],
                elem_id="leaderboard-table",
                interactive=False,
                wrap=True,
            )

            # Metric explanations at the bottom
            with gr.Accordion("Metric Explanations", open=False):
                gr.Markdown("""
                - **Grounding Score**: Measures the model's ability to provide factually accurate responses based on given context
                - **Quality Score**: Evaluates the overall quality of the model's responses including coherence and relevance
                - **Combined Score**: A weighted combination of grounding and quality scores representing overall performance
                """)

        with gr.TabItem("About"):
            gr.Markdown(
                """
            # About This Evaluation

            ## FACTS Grounding Leaderboard

            The FACTS Grounding Leaderboard is a benchmark developed by Google DeepMind to evaluate how well Large Language Models (LLMs) can generate factually accurate responses that are fully grounded in provided context documents.

            ### How It Works:
            1. **Input**: Each example contains a system instruction, a context document (up to 32k tokens), and a user request
            2. **Task**: Models must generate responses that answer the user's request using ONLY information from the provided context
            3. **Evaluation**: Responses are evaluated in two phases:
               - **Quality Check**: Does the response adequately address the user's request?
               - **Grounding Check**: Is every claim in the response supported by the context document?

            ## Medical Domain Variation

            This implementation focuses specifically on medical domain examples from the FACTS benchmark to evaluate smaller, open-source models in healthcare contexts.

            ### Key Modifications:
            - **Domain-Specific**: Uses only the 236 medical examples from the original 860-example dataset
            - **Single Judge Model**: Employs Gemini 1.5 Flash as the sole evaluator (vs. the original's ensemble of 3 models)
            - **Focus on Open Models**: Evaluates open-source models often missing from mainstream leaderboards for medical domain

            ### Why Medical Domain?
            Medical information requires exceptional accuracy and grounding. By focusing on this domain, we can assess how well smaller models handle critical healthcare information while strictly adhering to provided sources—a crucial capability for safe medical AI applications.

            ### Evaluation Metrics:
            - **Grounding Score**: Percentage of responses where all claims are supported by the context
            - **Quality Score**: Percentage of responses that adequately address the user's request
            - **Combined Score**: Percentage of responses that pass both quality and grounding checks

            This focused approach enables rapid iteration and testing of smaller models on domain-specific factual grounding tasks.

            ---

            ## References

            - **Original Leaderboard by Google**: [FACTS Grounding Benchmark Leaderboard](https://www.kaggle.com/benchmarks/google/facts-grounding/leaderboard)
            - **Public Dataset**: [FACTS Grounding Examples Dataset](https://www.kaggle.com/datasets/deepmind/facts-grounding-examples/data)
            - **Technical Documentation**: [FACTS Grounding Benchmark Starter Code](https://www.kaggle.com/code/andrewmingwang/facts-grounding-benchmark-starter-code/notebook)

            ---
            """
            )

    # Update table when filters change
    def update_table(search, sizes, sort_by):
        filtered_df = filter_and_search_models(search, sizes, sort_by)
        model_count = f"**Showing {len(filtered_df)} models**"
        return filtered_df, model_count

    # Connect all inputs to the update function
    search_box.change(
        fn=update_table,
        inputs=[search_box, size_checkboxes, sort_dropdown],
        outputs=[results_table, total_models],
    )

    size_checkboxes.change(
        fn=update_table,
        inputs=[search_box, size_checkboxes, sort_dropdown],
        outputs=[results_table, total_models],
    )

    sort_dropdown.change(
        fn=update_table,
        inputs=[search_box, size_checkboxes, sort_dropdown],
        outputs=[results_table, total_models],
    )

    # Add custom CSS for better styling
    app.css = """
    #leaderboard-table {
        font-size: 14px;
        margin-top: 20px;
        max-height: 600px;
        overflow-y: auto;
    }

    #leaderboard-table td:first-child {
        text-align: center;
        font-weight: 600;
        color: #444;
        background-color: #f8f9fa;
        width: 60px;
    }

    #leaderboard-table td:nth-child(2) {
        font-weight: 500;
        max-width: 400px;
    }

    #leaderboard-table td:nth-child(3) {
        text-align: center;
        font-weight: 500;
        color: #666;
    }

    #leaderboard-table td:nth-child(n+4) {
        text-align: center;
    }

    .size-filter {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
        margin-top: 10px;
    }

    .size-filter label {
        display: flex;
        align-items: center;
        margin: 0;
    }

    .size-filter input[type="checkbox"] {
        margin-right: 5px;
    }

    /* Highlight rows based on model family */
    #leaderboard-table tr:has(td:contains("meta-llama")) {
        background-color: #fffbf0;
    }

    #leaderboard-table tr:has(td:contains("deepseek")) {
        background-color: #f0f8ff;
    }

    #leaderboard-table tr:has(td:contains("Qwen")) {
        background-color: #f5fff5;
    }

    #leaderboard-table tr:has(td:contains("google")) {
        background-color: #fff0f5;
    }

    /* Header styling */
    #leaderboard-table th {
        background-color: #f8f9fa;
        font-weight: 600;
    }

    #leaderboard-table th:first-child {
        width: 60px;
        text-align: center;
    }
    """

# Launch the app
if __name__ == "__main__":
    app.launch()