from typing import List import gradio as gr import numpy as np import pandas as pd _ORIGINAL_DF = pd.read_csv("./data/benchmark.csv") _METRICS = ["MCC", "F1", "ACC"] _AGGREGATION_METHODS = ["mean", "max", "min", "median"] _DATASETS = list(set(_ORIGINAL_DF["Dataset"])) _BIBTEX = """@article{DallaTorre2023TheNT, title={The Nucleotide Transformer: Building and Evaluating Robust Foundation Models for Human Genomics}, author={Hugo Dalla-Torre and Liam Gonzalez and Javier Mendoza Revilla and Nicolas Lopez Carranza and Adam Henryk Grzywaczewski and Francesco Oteri and Christian Dallago and Evan Trop and Hassan Sirelkhatim and Guillaume Richard and Marcin J. Skwark and Karim Beguir and Marie Lopez and Thomas Pierrot}, journal={bioRxiv}, year={2023}, url={https://api.semanticscholar.org/CorpusID:255943445} } """ # noqa _LAST_UPDATED = "Aug 28, 2023" banner_url = "./assets/logo.png" _BANNER = f'
Banner
' # noqa _INTRODUCTION_TEXT = "The 🤗 Nucleotide Transformer Leaderboard aims to track, rank and evaluate DNA foundational models on a set of curated downstream tasks with a standardized evaluation protocole." # noqa def retrieve_array_from_text(text): return np.fromstring(text.replace("[", "").replace("]", ""), dtype=float, sep=",") def format_number(x): return float(f"{x:.3}") def get_dataset( tasks: List[str], target_metric: str = "MCC", aggregation_method: str = "mean" ): aggr_fn = getattr(np, aggregation_method) scores = _ORIGINAL_DF[target_metric].apply(retrieve_array_from_text).apply(aggr_fn) scores = scores.apply(format_number) df = _ORIGINAL_DF.drop(columns=_METRICS) df["Score"] = scores df = df.pivot(index="Model", columns="Dataset", values="Score") df = df[tasks] df["All Tasks"] = df.agg("mean", axis="columns").apply(format_number) columns = list(df.columns.values) columns.sort() df = df[columns] df.reset_index(inplace=True) df = df.rename(columns={"index": "Model"}) df = df.sort_values(by=["All Tasks"], ascending=False) leaderboard_table = gr.components.Dataframe.update( value=df, # datatype=TYPES, max_rows=None, interactive=False, visible=True, ) return leaderboard_table with gr.Blocks() as demo: with gr.Row(): gr.Image(banner_url, height=160, scale=1) gr.Textbox(_INTRODUCTION_TEXT, scale=5) with gr.Row(): metric_choice = gr.Dropdown( choices=_METRICS, value="MCC", label="Metric displayed.", ) aggr_choice = gr.Dropdown( choices=_AGGREGATION_METHODS, value="mean", label="Aggregation used over 10-folds.", ) with gr.Row(): selected_tasks = gr.CheckboxGroup( choices=_DATASETS, value=_DATASETS, label="Tasks", info="Downstream tasks." ) with gr.Tabs(elem_classes="tab-buttons") as tabs: with gr.TabItem("🏅 Leaderboard", elem_id="od-benchmark-tab-table", id=0): dataframe = gr.components.Dataframe( elem_id="leaderboard-table", ) with gr.TabItem("📈 Metrics", elem_id="od-benchmark-tab-table", id=1): gr.Markdown("Hey hey hey", elem_classes="markdown-text") # with gr.TabItem("✉️✨ Request a model here!", elem_id="od-benchmark-tab-table", # id=2): # with gr.Column(): # gr.Markdown("# ✉️✨ Request results for a new model here!", # elem_classes="markdown-text") # with gr.Column(): # gr.Markdown("Select a dataset:", elem_classes="markdown-text") # with gr.Column(): # model_name_textbox = gr.Textbox( # label="Model name (user_name/model_name)") # chb_coco2017 = gr.Checkbox(label="COCO validation 2017 dataset", # visible=False, value=True, # interactive=False) # with gr.Column(): # mdw_submission_result = gr.Markdown() # btn_submitt = gr.Button(value="🚀 Request") gr.Markdown(f"Last updated on **{_LAST_UPDATED}**", elem_classes="markdown-text") with gr.Row(): with gr.Accordion("📙 Citation", open=False): gr.Textbox( value=_BIBTEX, lines=7, label="Copy the BibTeX snippet to cite this source", elem_id="citation-button", ).style(show_copy_button=True) selected_tasks.change( get_dataset, inputs=[selected_tasks, metric_choice, aggr_choice], outputs=dataframe, ) metric_choice.change( get_dataset, inputs=[selected_tasks, metric_choice, aggr_choice], outputs=dataframe, ) aggr_choice.change( get_dataset, inputs=[selected_tasks, metric_choice, aggr_choice], outputs=dataframe, ) demo.load( fn=get_dataset, inputs=[selected_tasks, metric_choice, aggr_choice], outputs=dataframe, ) demo.launch()