Add FinCalc-NLI eval (financial arithmetic) + results for all checkpoints

#4
by anespo28 - opened
Files changed (2) hide show
  1. README.md +1 -0
  2. code/eval_fincalc.py +57 -0
README.md CHANGED
@@ -160,6 +160,7 @@ a small MLP head on the last-token latent (`mlp_heads_35b/`, one head per task,
160
  * `code/openjev_decide.py` β€” `OpenJev.decide(state, questions)`: typed decisions over a closed option set,
161
  and the JevBench adapter. `code/eval_jevbench.py`, `code/eval_extra.py`, `code/eval_security.py`,
162
  `code/order_test.py` reproduce every table above.
 
163
  * `code/` β€” everything used here: the trainer and data mixture builder, the evaluation harness, Flappy Bird, Doom
164
  (text and pixels), the Minecraft scaffold and bot, the radar, the SGLang package / launcher / client / benchmark.
165
  * `videos/` β€” Flappy Bird, Doom and Minecraft replays; `results/` β€” raw JSON for every run and the full report.
 
160
  * `code/openjev_decide.py` β€” `OpenJev.decide(state, questions)`: typed decisions over a closed option set,
161
  and the JevBench adapter. `code/eval_jevbench.py`, `code/eval_extra.py`, `code/eval_security.py`,
162
  `code/order_test.py` reproduce every table above.
163
+ * `code/eval_fincalc.py` β€” financial arithmetic: [FinCalc-NLI](https://huggingface.co/datasets/anespo28/fincalc-nli) (ratios, covenant tests, net figures; synthetic, labels computed in code). 4B v5 63.2%, 4B v2 58.2%, 0.8B v2s-long 50.5%, 4B original 31.9% (4,000-item test split).
164
  * `code/` β€” everything used here: the trainer and data mixture builder, the evaluation harness, Flappy Bird, Doom
165
  (text and pixels), the Minecraft scaffold and bot, the radar, the SGLang package / launcher / client / benchmark.
166
  * `videos/` β€” Flappy Bird, Doom and Minecraft replays; `results/` β€” raw JSON for every run and the full report.
code/eval_fincalc.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Financial arithmetic for jev cross-encoders: FinCalc-NLI test split. Nothing here is trained on.
3
+
4
+ python eval_fincalc.py --models ckpt/qwen3.5-4b-nli-v5 ckpt/qwen3.5-4b-nli --out results/fincalc_4b.json
5
+
6
+ FinCalc-NLI (anespo28/fincalc-nli, MIT, synthetic): premise = evidence with the inputs and distractor figures
7
+ (another company, the prior year, policy lines), hypothesis = a derived figure (LTV, DSCR, interest cover, net
8
+ leverage, EBITDA margin, CET1, NPL ratio, NPL coverage, annual interest, net debt), a covenant pass/breach, or a
9
+ plain lookup. Labels are computed in code. The test split uses names and templates disjoint from train, and one
10
+ formula (NPL coverage) that train never shows.
11
+
12
+ Reported: 3-way accuracy (argmax), per mistake kind (slip, inverted ratio, wrong entity, unit error, flipped
13
+ covenant, missing input, ...) and per metric.
14
+ """
15
+ import argparse
16
+ import json
17
+ from collections import defaultdict
18
+
19
+ import numpy as np
20
+
21
+ from eval import NLIScorer
22
+
23
+ REPO = "anespo28/fincalc-nli"
24
+
25
+
26
+ def load(n):
27
+ from datasets import load_dataset
28
+ ds = load_dataset(REPO, data_files={"test": "test.jsonl"}, split="test")
29
+ return ds.shuffle(seed=0).select(range(min(n, len(ds)))) if n else ds
30
+
31
+
32
+ def main():
33
+ ap = argparse.ArgumentParser()
34
+ ap.add_argument("--models", nargs="+", required=True)
35
+ ap.add_argument("--out", required=True)
36
+ ap.add_argument("--n", type=int, default=0, help="subsample the 4,000-item test split (0 = all)")
37
+ ap.add_argument("--bs", type=int, default=32)
38
+ a = ap.parse_args()
39
+ ds = load(a.n)
40
+ pairs = list(zip(ds["premise"], ds["hypothesis"]))
41
+ gold = np.array(ds["label"]) # already in jev order: 0 contradiction, 1 entailment, 2 neutral
42
+ res = {}
43
+ for path in a.models:
44
+ pred = NLIScorer(path, bs=a.bs).predict(pairs).argmax(1)
45
+ by = defaultdict(list)
46
+ for k, m, ok in zip(ds["kind"], ds["metric"], pred == gold):
47
+ by["kind:" + k].append(ok)
48
+ by["metric:" + m].append(ok)
49
+ res[path] = {"n": len(pairs), "accuracy": round(float((pred == gold).mean()), 4),
50
+ **{k: round(float(np.mean(v)), 4) for k, v in sorted(by.items())}}
51
+ print(path, json.dumps(res[path]), flush=True)
52
+ with open(a.out, "w") as f:
53
+ json.dump(res, f, indent=2)
54
+
55
+
56
+ if __name__ == "__main__":
57
+ main()