natolambert commited on
Commit
507a14d
1 Parent(s): d7244ec
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +129 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ evals/
app.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from pathlib import Path
4
+ from datasets import load_dataset
5
+ import json
6
+ import os
7
+ from huggingface_hub import HfApi, Repository
8
+ import numpy as np
9
+
10
+ api = HfApi()
11
+
12
+ COLLAB_TOKEN = os.environ.get("COLLAB_TOKEN")
13
+ evals_repo = "ai2-rlhf-collab/rm-benchmark-results"
14
+ BASE_DIR = "./evals/"
15
+ # def restart_space():
16
+ # api.restart_space(repo_id="ai2-rlhf-collab/rm-benchmark-viewer", token=COLLAB_TOKEN)
17
+
18
+
19
+ # From Open LLM Leaderboard
20
+ def model_hyperlink(link, model_name):
21
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
22
+
23
+ print("Pulling evaluation results")
24
+ repo = Repository(
25
+ local_dir=BASE_DIR,
26
+ clone_from=evals_repo,
27
+ use_auth_token=COLLAB_TOKEN,
28
+ repo_type="dataset",
29
+ )
30
+ repo.git_pull()
31
+
32
+ # Define a function to fetch and process data
33
+ def fetch_and_display_data(): # use HF api to pull the git repo
34
+ dir = Path(BASE_DIR)
35
+ data_dir = dir / "data"
36
+ orgs = [d for d in os.listdir(data_dir) if os.path.isdir(os.path.join(data_dir, d))]
37
+ # get all files within the sub folders orgs
38
+ models_results = []
39
+ for org in orgs:
40
+ org_dir = data_dir / org
41
+ files = [f for f in os.listdir(org_dir) if os.path.isfile(os.path.join(org_dir, f))]
42
+ for file in files:
43
+ if file.endswith(".json"):
44
+ models_results.append(org + "/" + file)
45
+
46
+ # create empty dataframe to add all data to
47
+ df = pd.DataFrame()
48
+
49
+ # load all json data in the list models_results one by one to avoid not having the same entries
50
+ for model in models_results:
51
+ model_data = load_dataset("json", data_files=BASE_DIR + "data/" + model, split="train")
52
+ df2 = pd.DataFrame(model_data)
53
+ # add to df
54
+ df = pd.concat([df2, df])
55
+
56
+
57
+ # remove chat_template comlumn
58
+ df = df.drop(columns=["chat_template"])
59
+
60
+ # move column "model" to the front
61
+ cols = list(df.columns)
62
+ cols.insert(0, cols.pop(cols.index('model')))
63
+ df = df.loc[:, cols]
64
+
65
+ # select all columns except "model"
66
+ cols = df.columns.tolist()
67
+ cols.remove("model")
68
+ # round
69
+ df[cols] = df[cols].round(2)
70
+ avg = np.mean(df[cols].values,axis=1).round(2)
71
+ # add average column
72
+ df["average"] = avg
73
+
74
+ # apply model_hyperlink function to column "model"
75
+ df["model"] = df["model"].apply(lambda x: model_hyperlink(f"https://huggingface.co/{x}", x))
76
+
77
+ # move average column to the second
78
+ cols = list(df.columns)
79
+ cols.insert(1, cols.pop(cols.index('average')))
80
+ df = df.loc[:, cols]
81
+ return df
82
+
83
+ benchmark_text = """
84
+ # HERM Results Viewer
85
+
86
+ We compute the win percentage for a reward model on hand curated chosen-rejected pairs for each prompt.
87
+ A win is when the score for the chosen response is higher than the score for the rejected response.
88
+
89
+ ### Subset summary
90
+
91
+ | Subset | Num. Samples (Pre-filtering, post-filtering) | Description |
92
+ | :--------------------- | :------------------------------------------: | :---------------------------------------------------------------- |
93
+ | alpacaeval-easy | 805 | Great model vs poor model |
94
+ | alpacaeval-length | 805 | Good model vs low model, equal length |
95
+ | alpacaeval-hard | 805 | Great model vs baseline model |
96
+ | mt-bench-easy | 28, 28 | MT Bench 10s vs 1s |
97
+ | mt-bench-medium | 45, 40 | MT Bench 9s vs 2-5s |
98
+ | mt-bench-hard | 45, 37 | MT Bench 7-8 vs 5-6 |
99
+ | refusals-dangerous | 505 | Dangerous response vs no response |
100
+ | refusals-offensive | 704 | Offensive response vs no response |
101
+ | llmbar-natural | 100 | (See [paper](https://arxiv.org/abs/2310.07641)) Manually curated instruction pairs |
102
+ | llmbar-adver-neighbor | 134 | (See [paper](https://arxiv.org/abs/2310.07641)) Instruction response vs. off-topic prompt response |
103
+ | llmbar-adver-GPTInst | 92 | (See [paper](https://arxiv.org/abs/2310.07641)) Instruction response vs. GPT4 generated off-topic prompt response |
104
+ | llmbar-adver-GPTOut | 47 | (See [paper](https://arxiv.org/abs/2310.07641)) Instruction response vs. unhelpful-prompted GPT4 responses |
105
+ | llmbar-adver-manual | 46 | (See [paper](https://arxiv.org/abs/2310.07641)) Challenge set chosen vs. rejected |
106
+ | XSTest | 450 | TODO curate |
107
+ | (?) repetitiveness | | |
108
+ | (?) grammar | | |
109
+
110
+
111
+ For more details, see the [dataset](https://huggingface.co/datasets/ai2-rlhf-collab/rm-benchmark-dev).
112
+ """
113
+ leaderboard_data = fetch_and_display_data()
114
+ with gr.Blocks() as app:
115
+ with gr.Row():
116
+ gr.Markdown(benchmark_text)
117
+
118
+ with gr.Row():
119
+ output_table = gr.Dataframe(
120
+ leaderboard_data.values,
121
+ headers=leaderboard_data.columns.tolist(),
122
+ )
123
+
124
+ # Load data when app starts
125
+ def load_data_on_start():
126
+ data = fetch_and_display_data()
127
+ output_table.update(data)
128
+
129
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pandas
2
+ datasets