File size: 9,745 Bytes
554d184 23bce77 7d55365 554d184 0e52835 7d55365 0e52835 7d55365 0e52835 7d55365 0e52835 7d55365 0e52835 80c3833 0e52835 7d55365 0e52835 7d55365 80c3833 0e52835 80c3833 0e52835 7d55365 0e52835 80c3833 7d55365 23bce77 7d55365 23bce77 0d73c4d 23bce77 92944d2 80c3833 7d55365 80c3833 7d55365 0e52835 7d55365 80c3833 23bce77 7d55365 0e52835 23bce77 0e52835 80c3833 0e52835 7d55365 92944d2 0e52835 92944d2 7d55365 554d184 23bce77 80c3833 23bce77 80c3833 23bce77 5b272d7 b11e6cc b907c28 5b272d7 b907c28 23bce77 7d55365 23bce77 7d55365 23bce77 0d73c4d 7d55365 0d73c4d 7d55365 23bce77 80c3833 23bce77 7d55365 23bce77 7d55365 23bce77 80c3833 23bce77 7d55365 23bce77 80c3833 7d55365 0e52835 80c3833 7d55365 0e52835 |
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 |
import gradio as gr
import json
import os
import random
import datasets
from dipromats_evaluation_v2 import evaluate_results
# CONSTANTS
# Hugging Face datasets
DATASET_GOLD = "NLP-UNED/dipromats2024-t2_leaderboard-gold"
FILE_GOLD = 'gold_test.json'
DATASET_RESULTS = "NLP-UNED/dipromats2024-t2_leaderboard-results"
SPLIT_EN = 'results_en'
SPLIT_ES = 'results_es'
FEATURES_RESULTS = datasets.Features({
"team_name": datasets.Value("string"),
"run_id": datasets.Value("string"),
"description": datasets.Value("string"),
"lenient_f1": datasets.Value("float64"),
"strict_f1": datasets.Value("float64"),
"average_f1": datasets.Value("float64") })
EMPTY_RESULT={"team_name": [], "run_id": [], "description": [], "lenient_f1": [], "strict_f1": [], "average_f1": []}
# Before, you must create the Tokens in HF User Settings to give read and write access only to the datasets
try:
from google.colab import userdata
# Token must be copied and activated in Colab Secrets
HF_TOKEN_GOLD = userdata.get('HF_DIPROMATS2024_T2_GOLD_TOKEN')
HF_TOKEN_RESULTS = userdata.get('HF_DIPROMATS2024_T2_RESULTS_TOKEN')
except:
# Assume running in HF Space
# Tokens must be copied in Secrets under Space Settings
HF_TOKEN_GOLD = os.getenv('HF_DIPROMATS2024_T2_GOLD_TOKEN')
HF_TOKEN_RESULTS = os.getenv('HF_DIPROMATS2024_T2_RESULTS_TOKEN')
# LOAD DATASETS
# Load the Gold Standard data
# FILE_GOLD was uploaded directly through HF web, and the default split is train
dataset_gold = datasets.load_dataset(DATASET_GOLD, split='train', data_files=FILE_GOLD, token=HF_TOKEN_GOLD)
# Load the English dataset or create an empty one instead
try:
dataset_en = datasets.load_dataset(DATASET_RESULTS, split=SPLIT_EN)
except Exception as e:
print(f"Error loading English dataset: {e}. Creating it...")
dataset_en = datasets.Dataset.from_dict(EMPTY_RESULT, features=FEATURES_RESULTS, split=SPLIT_EN)
dataset_en.push_to_hub(DATASET_RESULTS, split=SPLIT_EN, token=HF_TOKEN_RESULTS)
# Load the Spanish dataset or create an empty one instead
try:
dataset_es = datasets.load_dataset(DATASET_RESULTS, split=SPLIT_ES)
except Exception as e:
print(f"Error loading Spanish dataset: {e}. Creating it...")
dataset_es = datasets.Dataset.from_dict(EMPTY_RESULT, features=FEATURES_RESULTS, split=SPLIT_ES)
dataset_es.push_to_hub(DATASET_RESULTS, split=SPLIT_ES, token=HF_TOKEN_RESULTS)
# AUX FUNCTIONS
# Funci贸n para convertir el dataset en tabla
def data_to_table(dataset):
table_data = []
for item in dataset:
table_data.append([item.get("team_name", ""), item.get("run_id", ""),
item.get("lenient_f1", ""), item.get("strict_f1", ""), item.get("average_f1", ""), item.get("description", "")])
return table_data
# Funci贸n para subir los resultados al leaderboard
def update_leaderboard(lang, file_path, email, team_input, run_id, description, lenient_f1, strict_f1, average_f1):
global dataset_en
global dataset_es
if lang == "en":
dataset = dataset_en
else:
dataset = dataset_es
warn = False
if not email:
gr.Warning("Email cannot be blank")
warn=True
if not team_input:
gr.Warning("Team name cannot be blank")
warn=True
if not run_id:
gr.Warning("Run ID cannot be blank")
warn=True
if not file_path:
gr.Warning("File cannot be blank")
warn=True
if not description:
gr.Warning("Description cannot be blank")
warn=True
if warn:
return data_to_table(dataset_en), data_to_table(dataset_es), gr.Tabs(selected=1), gr.Button(visible=False), gr.Column(visible=True), team_input, run_id, description, email, file_path, lenient_f1, strict_f1, average_f1
dataset = dataset.add_item({
"team_name": team_input,
"run_id": run_id,
"description": description,
"lenient_f1": lenient_f1,
"strict_f1": strict_f1,
"average_f1": average_f1
})
# Save change in database
dataset.push_to_hub(DATASET_RESULTS, token=HF_TOKEN_RESULTS)
# Update dataset in memory
if lang == "en":
dataset_en = dataset
else:
dataset_es = dataset
#output: leaderboard_table, tabs, evaluate_button, submission_col, team_input, run_id, description_input, email_input, file_input, lenient_f1, strict_f1, average_f1
return data_to_table(dataset_en), data_to_table(dataset_es), gr.Tabs(selected=0), gr.Button(visible=True), gr.Column(visible=False), "", "", "", "", None, None, None, None
# Funci贸n para procesar el archivo de resultados
def process_file(lang, file_path):
global dataset_gold
if not file_path:
gr.Warning("File cannot be blank")
return gr.Button(visible=True), gr.Row(visible=False), None, None, None
with open(file_path, 'r') as f:
test = json.load(f)
try:
results = evaluate_results(lang, dataset_gold, test)
#print(results)
except Exception as e:
gr.Warning("Invalid JSON file or Incorrect Language")
print(f"Error in function evaluate_results: {e}.")
print(dataset_gold)
return gr.Button(visible=True), gr.Row(visible=False), None, None, None
lenient_f1 = results['lenient']['micro']['scores']['f1-score']
strict_f1 = results['strict']['micro']['scores']['f1-score']
average_f1 = (lenient_f1 + strict_f1) / 2
return gr.Button(visible=False), gr.Row(visible=True), lenient_f1, strict_f1, average_f1
# Main
with gr.Blocks() as leaderboard:
gr.Markdown(
"""
# Dipromats 2024 Task 2 Leaderboard
# Automatic Detection of Narratives from Diplomats of Major Powers
These are the leaderboards for DIPROMATS 2024 Task 2 described in <a href=https://nlp.uned.es/dipromats2024>nlp.uned.es/dipromats2024</a>.
The Gold Standard is not publicly available so LLMs cannot be contamined with them. However, the datasets are available at https://nlp.uned.es/hamison-project/results.html
You can submit your results here and get your system automatically evaluated. Then you will have the choice to submit your results to the leaderboard.
The HuggingFace datasets of results displayed here are:
- https://huggingface.co/datasets/NLP-UNED/dipromats2024-t2_leaderboard-results/viewer/default/results_en
- https://huggingface.co/datasets/NLP-UNED/dipromats2024-t2_leaderboard-results/viewer/default/results_es
""")
with gr.Tabs() as tabs:
# Tab English Leaderboard
with gr.TabItem("English Leaderboard", id=0):
gr.Markdown(
"""
# English Leaderboard
""")
leaderboard_table_en = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1", "System Description"],
value=data_to_table(dataset_en),
interactive=False)
# Tab Spanish Leaderboard
with gr.TabItem("Spanish Leaderboard", id=2):
gr.Markdown(
"""
# Spanish Leaderboard
""")
leaderboard_table_es = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1", "System Description"],
value=data_to_table(dataset_es),
interactive=False)
# Tab Evaluate
with gr.TabItem("Evaluate your results", id=1):
gr.Markdown(
"""
# Upload your results and get evaluated
Then you can decide to submit your results to the leaderboard or not.
Make sure that you upload a file with the json format described in...
""")
with gr.Row():
file_input = gr.File(label="Upload a JSON file", file_types=[".json"], type="filepath", file_count="single")
with gr.Column():
lang = gr.Dropdown(label="Language", choices=["en", "es"], interactive=True)
evaluate_button = gr.Button("Evaluate")
# System results table
with gr.Row(visible=True):
lenient_f1 = gr.Number(label="Lenient F1", interactive=False)
strict_f1 = gr.Number(label="Strict F1", interactive=False)
average_f1 = gr.Number(label="Average F1", interactive=False)
# Submit to leaderboard
with gr.Column(visible=False) as submission_col:
with gr.Row():
with gr.Column():
with gr.Row():
team_input = gr.Textbox(label="Team Name")
run_id = gr.Textbox(label="Run ID")
email_input = gr.Textbox(label="Email (only for submission verification, it won't be shown)")
description_input = gr.Textbox(label="System description", lines=6)
submit_button = gr.Button("Submit to leaderboard")
evaluate_button.click(process_file,
inputs=[lang, file_input],
outputs=[evaluate_button, submission_col,lenient_f1, strict_f1, average_f1])
submit_button.click(update_leaderboard,
inputs=[lang, file_input, email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1],
outputs=[leaderboard_table_en, leaderboard_table_es, tabs, evaluate_button, submission_col, team_input, run_id, description_input, email_input, file_input, lenient_f1, strict_f1, average_f1])
leaderboard.launch()
|