Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -64,16 +64,7 @@ scores = torch.sigmoid(logits.squeeze(-1).squeeze(0))[-len(response_ids):]
|
|
| 64 |
|
| 65 |
## Evaluation
|
| 66 |
|
| 67 |
-
TokenHD
|
| 68 |
-
|
| 69 |
-
- **S_incor**: Token-level F1 on hallucinated (incorrect) responses — measures how precisely the detector localizes errors.
|
| 70 |
-
- **S_cor**: Recall on hallucination-free (correct) responses — measures how rarely the detector raises false alarms.
|
| 71 |
-
|
| 72 |
-
---
|
| 73 |
-
|
| 74 |
-
## Evaluation
|
| 75 |
-
|
| 76 |
-
Evaluate using the [TokenHD eval dataset](https://huggingface.co/datasets/mr233/TokenHD-eval-data):
|
| 77 |
|
| 78 |
```python
|
| 79 |
from datasets import load_dataset
|
|
@@ -99,32 +90,43 @@ model = AutoModelForTokenClassification.from_pretrained(
|
|
| 99 |
)
|
| 100 |
model.eval()
|
| 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 |
```
|
|
|
|
| 64 |
|
| 65 |
## Evaluation
|
| 66 |
|
| 67 |
+
Use the [TokenHD eval dataset](https://huggingface.co/datasets/mr233/TokenHD-eval-data) to compute **S_incor** (token F1 on hallucinated samples) and **S_cor** (recall on hallucination-free samples):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
```python
|
| 70 |
from datasets import load_dataset
|
|
|
|
| 90 |
)
|
| 91 |
model.eval()
|
| 92 |
|
| 93 |
+
benchmarks = [
|
| 94 |
+
"tokenhd_eval_math_500",
|
| 95 |
+
"tokenhd_eval_math_aime",
|
| 96 |
+
"tokenhd_eval_math_gpqa",
|
| 97 |
+
"tokenhd_eval_math_fin_qa",
|
| 98 |
+
"tokenhd_eval_math_olym",
|
| 99 |
+
"tokenhd_eval_math_olym_phy",
|
| 100 |
+
"tokenhd_eval_code_codeelo",
|
| 101 |
+
"tokenhd_eval_code_live_code_lite",
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
for bench in benchmarks:
|
| 105 |
+
dataset = load_dataset("mr233/TokenHD-eval-data",
|
| 106 |
+
data_files=f"{bench}.jsonl", split="train")
|
| 107 |
+
f1_incor, f1_cor = [], []
|
| 108 |
+
for item in dataset:
|
| 109 |
+
token_weights_gt = np.array(item["token_weights"], dtype=np.float32)
|
| 110 |
+
gt_hard = (token_weights_gt > 0.5).astype(np.float32)
|
| 111 |
+
|
| 112 |
+
messages = [{"role": "user", "content": item["problem"]},
|
| 113 |
+
{"role": "assistant", "content": item["raw_answer"]}]
|
| 114 |
+
input_ids = tokenizer.apply_chat_template(
|
| 115 |
+
messages, tokenize=True, add_generation_prompt=False)[:-2]
|
| 116 |
+
input_tensor = torch.tensor(input_ids, device=model.device).unsqueeze(0)
|
| 117 |
+
|
| 118 |
+
with torch.no_grad():
|
| 119 |
+
logits = model(input_ids=input_tensor).logits
|
| 120 |
+
scores = torch.sigmoid(logits.squeeze(-1).squeeze(0))[-len(gt_hard):]
|
| 121 |
+
pred_hard = (scores.float().cpu().numpy() > 0.5).astype(np.float32)
|
| 122 |
+
|
| 123 |
+
_, _, f1 = hard_f1(gt_hard, pred_hard)
|
| 124 |
+
if item["correctness"] == -1:
|
| 125 |
+
f1_incor.append(f1)
|
| 126 |
+
else:
|
| 127 |
+
f1_cor.append(f1)
|
| 128 |
+
|
| 129 |
+
s_incor = np.mean(f1_incor) * 100 if f1_incor else float("nan")
|
| 130 |
+
s_cor = np.mean(f1_cor) * 100 if f1_cor else float("nan")
|
| 131 |
+
print(f"{bench:<44s} S_incor={s_incor:.2f} S_cor={s_cor:.2f}")
|
| 132 |
```
|