File size: 2,356 Bytes
6f4a3dd
 
 
 
 
 
 
 
 
d14a54c
6f4a3dd
 
 
 
 
 
 
 
d14a54c
6f4a3dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import requests
from tqdm.auto import tqdm
from huggingface_hub import HfApi, hf_hub_download
from huggingface_hub.repocard import metadata_load
import matplotlib.pyplot as plt


def plot_bar(value,name,x_name,y_name,title):
    fig, ax = plt.subplots(figsize=(10,4),tight_layout=True)

    ax.set(xlabel=x_name, ylabel=y_name,title=title)

    ax.bar(name, value)
   
  
    return ax.figure 
def plot_barh(value,name,x_name,y_name,title):
    fig, ax = plt.subplots(figsize=(10,4),tight_layout=True)

    ax.set(xlabel=x_name, ylabel=y_name,title=title)

    ax.barh(name, value)
   
  
    return ax.figure 
# Based on Omar Sanseviero work
# Make model clickable link
def make_clickable_model(model_name):
    # remove user from model name
    model_name_show = ' '.join(model_name.split('/')[1:])

    link = "https://huggingface.co/" + model_name
    return f'<a target="_blank" href="{link}">{model_name_show}</a>'

# Make user clickable link
def make_clickable_user(user_id):
    link = "https://huggingface.co/" + user_id
    return f'<a  target="_blank" href="{link}">{user_id}</a>'
    


def get_model_ids(rl_env):
    api = HfApi()
    models = api.list_models(filter=rl_env)
    model_ids = [x.modelId for x in models]
    return model_ids
    
def get_metadata(model_id):
    try:
        readme_path = hf_hub_download(model_id, filename="README.md")
        metadata = metadata_load(readme_path)
        metadata['model_id'] = model_id 
        return metadata
    except requests.exceptions.HTTPError:
        # 404 README.md not found
        return None
        
def parse_metrics_accuracy(meta):
    if "model-index" not in meta:
        return None
    result = meta["model-index"][0]["results"]
    metrics = result[0]["metrics"]
    accuracy = metrics[0]["value"]
    return accuracy

# We keep the worst case episode
def parse_rewards(accuracy):
    default_std = -1000
    default_reward=-1000
    if accuracy !=  None:
        parsed =  accuracy.split(' +/- ')
        if len(parsed)>1:
            mean_reward = float(parsed[0])
            std_reward =  float(parsed[1])
        else: 
            mean_reward = float(default_std)
            std_reward = float(default_reward)

    else:
        mean_reward = float(default_std)
        std_reward = float(default_reward)
    return mean_reward, std_reward