Update app.py
Browse files
app.py
CHANGED
|
@@ -7,27 +7,36 @@ def run_eval(hf_token, subset, task, n_samples):
|
|
| 7 |
model="ibm-granite/granite-3.3-8b-instruct",
|
| 8 |
token=hf_token
|
| 9 |
)
|
| 10 |
-
ds = load_dataset("RMT-team/babilong", subset)[task]
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
correct = 0
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
prompt = f"{s['input']}\n\nQuestion: {s['question']}\nAnswer:"
|
| 16 |
pred = client.text_generation(prompt, max_new_tokens=10).strip().lower()
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
correct += 1
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
demo = gr.Interface(
|
| 23 |
fn=run_eval,
|
| 24 |
inputs=[
|
| 25 |
gr.Textbox(label="HF Token", type="password"),
|
| 26 |
-
gr.Dropdown(["0k","1k","2k","4k","8k"], label="
|
| 27 |
-
gr.Dropdown(["qa1","qa2","qa3"], label="Task", value="qa1"),
|
| 28 |
-
gr.Slider(5,
|
| 29 |
],
|
| 30 |
-
outputs=gr.Textbox(label="
|
| 31 |
)
|
| 32 |
|
| 33 |
demo.launch()
|
|
|
|
| 7 |
model="ibm-granite/granite-3.3-8b-instruct",
|
| 8 |
token=hf_token
|
| 9 |
)
|
|
|
|
| 10 |
|
| 11 |
+
ds = load_dataset("RMT-team/babilong", subset)
|
| 12 |
+
samples = ds[task]
|
| 13 |
+
|
| 14 |
+
results = []
|
| 15 |
correct = 0
|
| 16 |
+
n = int(n_samples)
|
| 17 |
+
|
| 18 |
+
for i in range(n):
|
| 19 |
+
s = samples[i]
|
| 20 |
prompt = f"{s['input']}\n\nQuestion: {s['question']}\nAnswer:"
|
| 21 |
pred = client.text_generation(prompt, max_new_tokens=10).strip().lower()
|
| 22 |
+
gold = s['target'].lower()
|
| 23 |
+
match = gold in pred
|
| 24 |
+
if match:
|
| 25 |
correct += 1
|
| 26 |
+
results.append(f"[{i+1}] Q: {s['question']} | Gold: {gold} | Pred: {pred} | {'OK' if match else 'WRONG'}")
|
| 27 |
|
| 28 |
+
summary = f"Accuracy: {correct}/{n} = {correct/n:.2%}\n\n" + "\n".join(results)
|
| 29 |
+
return summary
|
| 30 |
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=run_eval,
|
| 33 |
inputs=[
|
| 34 |
gr.Textbox(label="HF Token", type="password"),
|
| 35 |
+
gr.Dropdown(["0k","1k","2k","4k","8k"], label="Context Length", value="0k"),
|
| 36 |
+
gr.Dropdown(["qa1","qa2","qa3","qa4","qa5"], label="Task", value="qa1"),
|
| 37 |
+
gr.Slider(5, 50, value=10, step=5, label="Number of Samples"),
|
| 38 |
],
|
| 39 |
+
outputs=gr.Textbox(label="Results", lines=30)
|
| 40 |
)
|
| 41 |
|
| 42 |
demo.launch()
|