SRK-CobuildX commited on
Commit
041950a
·
verified ·
1 Parent(s): ec76fb8

Release v0.1

Browse files
README.md CHANGED
@@ -1,3 +1,152 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ base_model: jhu-clsp/ettin-encoder-68m
4
+ pipeline_tag: text-classification
5
+ language:
6
+ - en
7
+ tags:
8
+ - rag
9
+ - rag-evaluation
10
+ - context-utilization
11
  ---
12
+
13
+ # cbx-rag-context-utilization-68M
14
+
15
+ Judges which **context sentences the answer actually used**. Give it the question, the passages and the answer. It
16
+ returns:
17
+ - a score and flag for every context sentence;
18
+ - the **utilization fraction**: the share of context sentences the answer used, with the RAGBench convention.
19
+
20
+ It is one of four CBX RAG evaluator models.
21
+
22
+ ## How to use
23
+
24
+ ```bash
25
+ pip install -U huggingface_hub
26
+ hf download CobuildX-AI/cbx-rag-context-utilization-68M --revision v0.1 --local-dir cbx-rag-context-utilization-68M
27
+ cd cbx-rag-context-utilization-68M
28
+ pip install -r requirements.txt
29
+ python example.py
30
+ ```
31
+
32
+ ```python
33
+ from cbx_rag_eval import ContextUtilization
34
+
35
+ judge = ContextUtilization(".")
36
+ out = judge(question, passages, answer)
37
+ out["utilization"]
38
+ [s for s in out["sentences"] if s["utilized"]]
39
+ ```
40
+
41
+ **How the fraction is computed:** each sentence probability is calibrated (isotonic, fitted on validation), and the
42
+ fraction is their average.
43
+
44
+ **Prefilter (`contract` profile):** only the 64 sentences closest to the question and answer (BM25), plus their
45
+ neighbours, are scored; the rest count as unused. On validation this kept 98.8% of used sentences while scoring
46
+ about 39% of all sentences, with the same RMSE. Pass `prefilter=False` to score everything. The test numbers
47
+ below are without the prefilter.
48
+
49
+ **Speed** (seconds per call, model loaded; GPU NVIDIA TITAN RTX fp16, CPU 8 threads fp32):
50
+
51
+ | Input | GPU | CPU |
52
+ |---|---|---|
53
+ | one contract (about 414 sentences) | 0.61 s | 23.43 s |
54
+ | several short passages (about 29 sentences) | 0.12 s | 3.04 s |
55
+
56
+ ## The four CBX RAG evaluator models
57
+
58
+ | Model | Judges | Output |
59
+ |---|---|---|
60
+ | [cbx-rag-faithfulness-68M](https://huggingface.co/CobuildX-AI/cbx-rag-faithfulness-68M) | each answer sentence against the passages | support score per sentence, answer score, hallucination flag |
61
+ | [cbx-rag-response-relevance-68M](https://huggingface.co/CobuildX-AI/cbx-rag-response-relevance-68M) | the answer against the question | direct / partial / irrelevant |
62
+ | [cbx-rag-context-relevance-68M](https://huggingface.co/CobuildX-AI/cbx-rag-context-relevance-68M) | each context sentence against the question | relevance per sentence, relevance fraction, context precision |
63
+ | [cbx-rag-context-utilization-68M](https://huggingface.co/CobuildX-AI/cbx-rag-context-utilization-68M) | each context sentence against the question and answer | use per sentence, utilization fraction |
64
+
65
+ All four share the wrapper `cbx_rag_eval.py`. Every model is fine-tuned from
66
+ [jhu-clsp/ettin-encoder-68m](https://huggingface.co/jhu-clsp/ettin-encoder-68m) (68M parameters). Current version:
67
+ **v0.1** (use `--revision v0.1` to pin it).
68
+
69
+ ## Sentences and profiles
70
+
71
+ - **Sentences:** the models judge sentences, and they were trained on RAGBench's sentence splits. The wrapper
72
+ splits raw text by profile (`split_sentences`; chosen on validation):
73
+ - `contract`: line breaks, then NLTK punkt;
74
+ - `financial`: blank lines, then pysbd.
75
+
76
+ On validation, the wrapper's splitting instead of RAGBench's own sentence splits changed sentence AUROC 0.990 → 0.981 (CUAD); sentence AUROC 0.996 → 0.995 (FinQA); answer RMSE 0.040 → 0.043 (CUAD); answer RMSE 0.036 → 0.040 (FinQA). For the best accuracy, pass your own sentences (a list of strings per passage, and `answer_sentences=`
77
+ for the answer); the splitter is then skipped.
78
+ - **Profiles:** the settings were fixed on two kinds of validation data, so every call takes a `profile`.
79
+ - `"contract"`: one document, such as a contract (CUAD-like).
80
+ - `"financial"`: several short passages with numbers and tables (FinQA-like). Faithfulness adds a numeric check
81
+ here.
82
+ - `"auto"` (default): `"contract"` for a single passage, `"financial"` for two or more.
83
+
84
+ For other kinds of text, choose the profile whose shape is closest and check the results on your own data.
85
+
86
+ ## Training data and labels
87
+
88
+ - **Source:** the CUAD (contracts) and FinQA (financial reports) subsets of
89
+ [RAGBench](https://huggingface.co/datasets/galileo-ai/ragbench) (CC BY 4.0). Its answers were written by
90
+ claude-3-haiku and gpt-3.5-turbo; its labels came from gpt-4-turbo.
91
+ - Train: 1,530 CUAD and 12,502 FinQA answers.
92
+ - Test: 510 CUAD (102 contracts) and 2,294 FinQA answers.
93
+ - **Labels were reviewed by LLMs, not humans:**
94
+ - **Faithfulness:** majority vote of RAGBench and two LLM reviewers: Claude Haiku and gpt-5.4-mini, or two Haiku
95
+ passes for CUAD train.
96
+ - **CUAD context relevance / utilization:** majority vote of RAGBench and two Claude Haiku passes.
97
+ - **FinQA context labels:** kept as RAGBench made them.
98
+ - **Audits:** samples were checked blind by Claude Opus and Claude Sonnet.
99
+ - **Response relevance:** uses its own set (rr-v0.1). Claude Haiku wrote varied answers to the RAGBench questions
100
+ and labelled them.
101
+ - **Test sets:** the RAGBench test splits, with the same label views.
102
+ - **Baselines:** RAGAS, GPT-3.5 and TruLens scores are the ones stored in RAGBench, not re-runs.
103
+ - **Rule:** every threshold and setting was fixed on validation.
104
+
105
+ ## Licence
106
+
107
+ Apache-2.0 for the model weights and code.
108
+
109
+ **Data attribution:**
110
+ - RAGBench (Friel et al., 2024), CC BY 4.0;
111
+ - CUAD (The Atticus Project), CC BY 4.0;
112
+ - FinQA (Chen et al., 2021), MIT.
113
+
114
+ Labels were produced with Claude (Anthropic) and gpt-5.4-mini (OpenAI) models.
115
+
116
+ **Disclaimer:** the scores are statistical estimates for evaluating RAG systems. They are not a guarantee that an
117
+ answer is correct, complete or safe. Do not use them as the sole basis for legal, financial or other consequential
118
+ decisions.
119
+
120
+ ## Results (test sets)
121
+
122
+ - **Labels:** CUAD uses reviewed labels (majority of RAGBench and two Claude Haiku passes); FinQA uses RAGBench
123
+ labels.
124
+ - **Constant:** predicts the validation average.
125
+
126
+ **Sentence level:**
127
+
128
+ | Test set | AUROC [95% CI] | PR-AUC [95% CI] | Precision / recall at the threshold |
129
+ |---|---|---|---|
130
+ | CUAD contracts | 0.981 [0.973, 0.987] | 0.737 [0.697, 0.774] | 0.78 / 0.60 |
131
+ | FinQA reports | 0.995 [0.994, 0.996] | 0.945 [0.933, 0.956] | 0.90 / 0.88 |
132
+
133
+ **Answer-level utilization fraction:** RMSE, lower is better. GPT-3.5 is RAGBench's stored score; RAGBench has no
134
+ other utilization baseline.
135
+
136
+ | Test set | This model | GPT-3.5 | Constant |
137
+ |---|---|---|---|
138
+ | CUAD contracts (415 answers with a baseline score) | **0.039** | 0.059 | 0.063 |
139
+ | FinQA reports (2,294) | **0.033** | 0.134 | 0.067 |
140
+
141
+ Both differences against GPT-3.5 and the constant are significant (context-clustered bootstrap). On RAGBench's own
142
+ CUAD labels the model ties GPT-3.5 (0.108 vs 0.105).
143
+
144
+ ## Limitations
145
+
146
+ - **CUAD recall:** at the default threshold it misses about 40% of used sentences (recall 0.60). When it flags a
147
+ sentence, it is usually right (precision 0.78).
148
+ - **Label noise:** in a blind Claude Sonnet audit, 6 of 10 sentences the review added and 4 of 10 model misses were
149
+ confirmed as used.
150
+ - **Not reported:** evidence completeness (relevant sentences the answer used). Combined with
151
+ cbx-rag-context-relevance it did not beat a constant.
152
+ - **Coverage:** two domains (contracts, financial reports), English, LLM-made labels.
cbx_rag_config.json ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "task": "context_utilization",
3
+ "version": "v0.1",
4
+ "run": "v0.4/util-68m-w2-e3-lr1e-4-s7",
5
+ "base_model": "jhu-clsp/ettin-encoder-68m",
6
+ "max_len": 768,
7
+ "q_max": 384,
8
+ "n_classes": 2,
9
+ "batch_tokens": 32768,
10
+ "window": 2,
11
+ "neighbour_chars": 300,
12
+ "auto_single_passage_is_contract": true,
13
+ "profiles": {
14
+ "contract": {
15
+ "sentence_threshold": 0.872782,
16
+ "answer_score": {
17
+ "agg": "mean_iso",
18
+ "iso_x": [
19
+ 1.0000000000287557e-06,
20
+ 0.0002809999999999757,
21
+ 0.00028200000000000447,
22
+ 0.0010299999999999754,
23
+ 0.0010310000000000041,
24
+ 0.0016129999999999756,
25
+ 0.001615000000000033,
26
+ 0.002933999999999992,
27
+ 0.002935000000000021,
28
+ 0.004785999999999957,
29
+ 0.0047880000000000145,
30
+ 0.013790999999999998,
31
+ 0.013792000000000026,
32
+ 0.015120000000000022,
33
+ 0.015122999999999998,
34
+ 0.024580999999999964,
35
+ 0.024585999999999997,
36
+ 0.037282999999999955,
37
+ 0.03729199999999999,
38
+ 0.05118900000000004,
39
+ 0.05120100000000005,
40
+ 0.06083499999999997,
41
+ 0.060863,
42
+ 0.06653900000000001,
43
+ 0.06656899999999999,
44
+ 0.123471,
45
+ 0.12357700000000005,
46
+ 0.12495900000000004,
47
+ 0.12506499999999998,
48
+ 0.13568999999999998,
49
+ 0.13580400000000004,
50
+ 0.22168699999999997,
51
+ 0.22185600000000005,
52
+ 0.317215,
53
+ 0.31784999999999997,
54
+ 0.329607,
55
+ 0.329823,
56
+ 0.34665199999999996,
57
+ 0.347094,
58
+ 0.40450699999999995,
59
+ 0.40474299999999996,
60
+ 0.5141560000000001,
61
+ 0.514644,
62
+ 0.637934,
63
+ 0.6395109999999999,
64
+ 0.6542319999999999,
65
+ 0.654674,
66
+ 0.657538,
67
+ 0.6577580000000001,
68
+ 0.677901,
69
+ 0.678327,
70
+ 0.795817,
71
+ 0.796134,
72
+ 0.818592,
73
+ 0.819605,
74
+ 0.8505929999999999,
75
+ 0.851089,
76
+ 0.872673,
77
+ 0.872782,
78
+ 0.921922,
79
+ 0.921992,
80
+ 0.9554860000000001,
81
+ 0.955651,
82
+ 0.958148,
83
+ 0.958905,
84
+ 0.959383,
85
+ 0.95944,
86
+ 0.981355,
87
+ 0.981622,
88
+ 0.984128,
89
+ 0.98425,
90
+ 0.98702,
91
+ 0.987097,
92
+ 0.994738,
93
+ 0.994809,
94
+ 0.99702,
95
+ 0.997025,
96
+ 0.998188,
97
+ 0.998283,
98
+ 0.999549,
99
+ 0.999551,
100
+ 0.999962
101
+ ],
102
+ "iso_y": [
103
+ 0.0,
104
+ 0.0,
105
+ 1.794108148839212e-05,
106
+ 1.794108148839212e-05,
107
+ 0.00020476417991945942,
108
+ 0.00020476417991945942,
109
+ 0.0002144542140253056,
110
+ 0.0002144542140253056,
111
+ 0.000513347022587269,
112
+ 0.000513347022587269,
113
+ 0.001895829175813211,
114
+ 0.001895829175813211,
115
+ 0.004885993485342019,
116
+ 0.004885993485342019,
117
+ 0.006019563581640331,
118
+ 0.006019563581640331,
119
+ 0.007865168539325843,
120
+ 0.007865168539325843,
121
+ 0.00922509225092251,
122
+ 0.00922509225092251,
123
+ 0.009671179883945842,
124
+ 0.009671179883945842,
125
+ 0.01694915254237288,
126
+ 0.01694915254237288,
127
+ 0.02216252518468771,
128
+ 0.02216252518468771,
129
+ 0.02857142857142857,
130
+ 0.02857142857142857,
131
+ 0.029585798816568046,
132
+ 0.029585798816568046,
133
+ 0.04081632653061224,
134
+ 0.04081632653061224,
135
+ 0.05460750853242321,
136
+ 0.05460750853242321,
137
+ 0.06451612903225806,
138
+ 0.06451612903225806,
139
+ 0.07407407407407407,
140
+ 0.07407407407407407,
141
+ 0.09268292682926829,
142
+ 0.09268292682926829,
143
+ 0.11326860841423948,
144
+ 0.11326860841423948,
145
+ 0.1588785046728972,
146
+ 0.1588785046728972,
147
+ 0.16129032258064516,
148
+ 0.16129032258064516,
149
+ 0.18181818181818182,
150
+ 0.18181818181818182,
151
+ 0.21951219512195122,
152
+ 0.21951219512195122,
153
+ 0.24180327868852458,
154
+ 0.24180327868852458,
155
+ 0.27906976744186046,
156
+ 0.27906976744186046,
157
+ 0.3246753246753247,
158
+ 0.3246753246753247,
159
+ 0.3488372093023256,
160
+ 0.3488372093023256,
161
+ 0.45081967213114754,
162
+ 0.45081967213114754,
163
+ 0.5333333333333333,
164
+ 0.5333333333333333,
165
+ 0.5882352941176471,
166
+ 0.5882352941176471,
167
+ 0.6666666666666666,
168
+ 0.6666666666666666,
169
+ 0.7777777777777778,
170
+ 0.7777777777777778,
171
+ 0.8125,
172
+ 0.8125,
173
+ 0.8181818181818182,
174
+ 0.8181818181818182,
175
+ 0.9022556390977443,
176
+ 0.9022556390977443,
177
+ 0.953125,
178
+ 0.953125,
179
+ 0.9565217391304348,
180
+ 0.9565217391304348,
181
+ 0.9880952380952381,
182
+ 0.9880952380952381,
183
+ 1.0,
184
+ 1.0
185
+ ]
186
+ },
187
+ "prefilter_top_n": 64
188
+ },
189
+ "financial": {
190
+ "sentence_threshold": 0.5874699999999999,
191
+ "answer_score": {
192
+ "agg": "mean_iso",
193
+ "iso_x": [
194
+ 1.0999999999983245e-05,
195
+ 0.00015100000000001224,
196
+ 0.000152000000000041,
197
+ 0.00034800000000001496,
198
+ 0.0003490000000000437,
199
+ 0.0006530000000000147,
200
+ 0.0006540000000000434,
201
+ 0.0010750000000000481,
202
+ 0.0010769999999999946,
203
+ 0.0012349999999999861,
204
+ 0.0012360000000000149,
205
+ 0.0024300000000000432,
206
+ 0.0024319999999999897,
207
+ 0.0032569999999999544,
208
+ 0.003259000000000012,
209
+ 0.0034530000000000394,
210
+ 0.003454999999999986,
211
+ 0.003928000000000043,
212
+ 0.003933999999999993,
213
+ 0.004479000000000011,
214
+ 0.0044840000000000435,
215
+ 0.01018399999999997,
216
+ 0.010189000000000004,
217
+ 0.011190000000000033,
218
+ 0.011193000000000008,
219
+ 0.014708000000000054,
220
+ 0.01475000000000004,
221
+ 0.015152999999999972,
222
+ 0.015193000000000012,
223
+ 0.030078999999999967,
224
+ 0.030115000000000003,
225
+ 0.048316000000000026,
226
+ 0.04845100000000002,
227
+ 0.05352699999999999,
228
+ 0.05369999999999997,
229
+ 0.07477,
230
+ 0.07504100000000002,
231
+ 0.09392699999999998,
232
+ 0.09401000000000004,
233
+ 0.11787599999999998,
234
+ 0.11807999999999996,
235
+ 0.12527900000000003,
236
+ 0.12549299999999997,
237
+ 0.14572200000000002,
238
+ 0.14608699999999997,
239
+ 0.15077799999999997,
240
+ 0.15102800000000005,
241
+ 0.167219,
242
+ 0.16735500000000003,
243
+ 0.2227,
244
+ 0.22354700000000005,
245
+ 0.287768,
246
+ 0.288369,
247
+ 0.321673,
248
+ 0.321886,
249
+ 0.39443399999999995,
250
+ 0.396068,
251
+ 0.586523,
252
+ 0.5874699999999999,
253
+ 0.626581,
254
+ 0.62681,
255
+ 0.775265,
256
+ 0.778481,
257
+ 0.8735390000000001,
258
+ 0.8742920000000001,
259
+ 0.946151,
260
+ 0.946275,
261
+ 0.955465,
262
+ 0.955569,
263
+ 0.957298,
264
+ 0.957517,
265
+ 0.973393,
266
+ 0.973437,
267
+ 0.979924,
268
+ 0.979996,
269
+ 0.986011,
270
+ 0.986074,
271
+ 0.988492,
272
+ 0.98851,
273
+ 0.994607,
274
+ 0.99462,
275
+ 0.998156,
276
+ 0.998165,
277
+ 0.999627,
278
+ 0.999628,
279
+ 0.999798
280
+ ],
281
+ "iso_y": [
282
+ 0.0,
283
+ 0.0,
284
+ 0.00012484394506866417,
285
+ 0.00012484394506866417,
286
+ 0.0002801905295601009,
287
+ 0.0002801905295601009,
288
+ 0.0005165289256198347,
289
+ 0.0005165289256198347,
290
+ 0.002232142857142857,
291
+ 0.002232142857142857,
292
+ 0.002233389168062535,
293
+ 0.002233389168062535,
294
+ 0.00333889816360601,
295
+ 0.00333889816360601,
296
+ 0.00847457627118644,
297
+ 0.00847457627118644,
298
+ 0.011673151750972763,
299
+ 0.011673151750972763,
300
+ 0.013157894736842105,
301
+ 0.013157894736842105,
302
+ 0.016028495102404273,
303
+ 0.016028495102404273,
304
+ 0.033707865168539325,
305
+ 0.033707865168539325,
306
+ 0.034334763948497854,
307
+ 0.034334763948497854,
308
+ 0.038461538461538464,
309
+ 0.038461538461538464,
310
+ 0.039735099337748346,
311
+ 0.039735099337748346,
312
+ 0.05194805194805195,
313
+ 0.05194805194805195,
314
+ 0.09523809523809523,
315
+ 0.09523809523809523,
316
+ 0.125,
317
+ 0.125,
318
+ 0.14285714285714285,
319
+ 0.14285714285714285,
320
+ 0.14473684210526316,
321
+ 0.14473684210526316,
322
+ 0.2,
323
+ 0.2,
324
+ 0.21818181818181817,
325
+ 0.21818181818181817,
326
+ 0.23076923076923078,
327
+ 0.23076923076923078,
328
+ 0.23809523809523808,
329
+ 0.23809523809523808,
330
+ 0.24107142857142855,
331
+ 0.24107142857142855,
332
+ 0.32926829268292684,
333
+ 0.32926829268292684,
334
+ 0.3333333333333333,
335
+ 0.3333333333333333,
336
+ 0.35,
337
+ 0.35,
338
+ 0.42105263157894735,
339
+ 0.42105263157894735,
340
+ 0.5,
341
+ 0.5,
342
+ 0.5073529411764703,
343
+ 0.5073529411764703,
344
+ 0.762962962962963,
345
+ 0.762962962962963,
346
+ 0.7821229050279329,
347
+ 0.7821229050279329,
348
+ 0.8571428571428571,
349
+ 0.8571428571428571,
350
+ 0.9,
351
+ 0.9,
352
+ 0.9202898550724637,
353
+ 0.9202898550724637,
354
+ 0.9423076923076923,
355
+ 0.9423076923076923,
356
+ 0.9463087248322147,
357
+ 0.9463087248322147,
358
+ 0.9583333333333334,
359
+ 0.9583333333333334,
360
+ 0.9601990049751243,
361
+ 0.9601990049751243,
362
+ 0.9856850715746421,
363
+ 0.9856850715746421,
364
+ 0.9959349593495935,
365
+ 0.9959349593495935,
366
+ 1.0,
367
+ 1.0
368
+ ]
369
+ },
370
+ "prefilter_top_n": null
371
+ }
372
+ }
373
+ }
cbx_rag_eval.py ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """CBX RAG evaluator v0.1: four Ettin-68M judges for retrieval-augmented answers.
2
+
3
+ from cbx_rag_eval import Faithfulness, ResponseRelevance, ContextRelevance, ContextUtilization
4
+ judge = ContextRelevance(".") # folder with model.safetensors + cbx_rag_config.json
5
+ out = judge(question, passages) # passages: str or list of str (or list of sentence lists)
6
+
7
+ Every judge works on sentences. Raw text is split per profile (`split_sentences`, chosen on validation): "contract"
8
+ splits on line breaks and then with NLTK punkt; "financial" splits on blank lines and then with pysbd. Pass pre-split
9
+ sentences (a list of strings per passage, `answer_sentences=`) to skip the splitter.
10
+
11
+ Profiles (settings fixed on validation, see the model card):
12
+ "contract" long single documents (CUAD-like)
13
+ "financial" several short passages, numbers and tables (FinQA-like); faithfulness adds a numeric check
14
+ "auto" (default) "contract" for a single passage, "financial" for two or more
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import re
20
+ from collections import Counter
21
+
22
+ import numpy as np
23
+ import torch
24
+ import torch.nn as nn
25
+ from safetensors.torch import load_file
26
+ from transformers import AutoConfig, AutoModel, AutoTokenizer
27
+
28
+ try:
29
+ from cbx_rag_numcheck import Checker
30
+ except ImportError: # development tree
31
+ from numcheck import Checker
32
+
33
+ VERSION = "v0.1"
34
+
35
+ # ---------------------------------------------------------------- sentences
36
+
37
+ _WS = re.compile(r"\s+")
38
+ _LINE = re.compile(r"\n+")
39
+
40
+
41
+ def _punkt():
42
+ import nltk
43
+ try:
44
+ nltk.data.find("tokenizers/punkt_tab")
45
+ except LookupError:
46
+ nltk.download("punkt_tab", quiet=True)
47
+ from nltk.tokenize import sent_tokenize
48
+ return sent_tokenize
49
+
50
+
51
+ _PARA = re.compile(r"\n\s*\n")
52
+ _SEG = None
53
+
54
+
55
+ def _pysbd():
56
+ global _SEG
57
+ if _SEG is None:
58
+ import warnings
59
+ with warnings.catch_warnings():
60
+ warnings.simplefilter("ignore")
61
+ import pysbd
62
+ _SEG = pysbd.Segmenter(language="en", clean=False)
63
+ return _SEG
64
+
65
+
66
+ def split_sentences(text, profile="contract"):
67
+ """Whitespace-collapsed sentences. "contract": line breaks, then NLTK punkt inside each line. "financial": blank
68
+ lines, then pysbd inside each paragraph. A JSON table ('[[' ...) stays one sentence."""
69
+ text = str(text)
70
+ if text.lstrip().startswith("[["):
71
+ return [text.strip()]
72
+ if profile == "financial":
73
+ parts = [x for p in _PARA.split(text) for x in _pysbd().segment(p)]
74
+ else:
75
+ tok = _punkt()
76
+ parts = [x for line in _LINE.split(text) for x in tok(line)]
77
+ out = [_WS.sub(" ", x).strip() for x in parts]
78
+ return [x for x in out if x]
79
+
80
+
81
+ def _letters(n):
82
+ s = ""
83
+ n += 1
84
+ while n:
85
+ n, r = divmod(n - 1, 26)
86
+ s = chr(97 + r) + s
87
+ return s
88
+
89
+
90
+ def _passages(passages):
91
+ return [passages] if isinstance(passages, str) else list(passages)
92
+
93
+
94
+ def _context(passages, profile):
95
+ """passages: str | list of str | list of list of str -> list of {key, doc, text}."""
96
+ ctx = []
97
+ for di, p in enumerate(_passages(passages)):
98
+ sents = list(p) if isinstance(p, (list, tuple)) else split_sentences(p, profile)
99
+ ctx += [{"key": f"{di}{_letters(j)}", "doc": di, "text": str(s)} for j, s in enumerate(sents)]
100
+ return ctx
101
+
102
+
103
+ def _answer(answer, answer_sentences, profile):
104
+ sents = list(answer_sentences) if answer_sentences is not None else split_sentences(answer, profile)
105
+ return [{"key": _letters(j), "text": str(s)} for j, s in enumerate(sents)]
106
+
107
+
108
+ def _profile(profile, passages):
109
+ """"auto": one passage -> "contract", two or more -> "financial" (fixed on validation)."""
110
+ if profile in ("contract", "financial"):
111
+ return profile
112
+ if profile not in (None, "auto"):
113
+ raise ValueError("profile must be 'auto', 'contract' or 'financial'")
114
+ return "contract" if len(_passages(passages)) <= 1 else "financial"
115
+
116
+
117
+ # ---------------------------------------------------------------- BM25 (as in training)
118
+
119
+ _TOKEN = re.compile(r"[a-z0-9]+")
120
+ _STOP = set("the a an of to and or in on for by with is are be this that any as at from it its such shall may "
121
+ "will which their there other than not no does do".split())
122
+
123
+
124
+ def _toks(text):
125
+ return [t for t in _TOKEN.findall(text.lower()) if t not in _STOP]
126
+
127
+
128
+ class BM25:
129
+ def __init__(self, docs, k1=1.2, b=0.75):
130
+ self.docs = [Counter(_toks(d)) for d in docs]
131
+ self.len = [sum(d.values()) for d in self.docs]
132
+ self.avg = (sum(self.len) / len(self.len)) if self.len else 1
133
+ df = Counter()
134
+ for d in self.docs:
135
+ df.update(d.keys())
136
+ n = len(docs)
137
+ self.idf = {t: math.log(1 + (n - c + 0.5) / (c + 0.5)) for t, c in df.items()}
138
+ self.k1, self.b = k1, b
139
+
140
+ def scores(self, query):
141
+ q = Counter(_toks(query))
142
+ out = []
143
+ for d, ln in zip(self.docs, self.len):
144
+ s = 0.0
145
+ for t in q:
146
+ if t in d:
147
+ tf = d[t]
148
+ s += self.idf[t] * tf * (self.k1 + 1) / (tf + self.k1 * (1 - self.b + self.b * ln / self.avg))
149
+ out.append(s)
150
+ return out
151
+
152
+
153
+ # ---------------------------------------------------------------- model
154
+
155
+ class _Classifier(nn.Module):
156
+ def __init__(self, config, n_classes):
157
+ super().__init__()
158
+ self.backbone = AutoModel.from_config(config, attn_implementation="sdpa")
159
+ self.head = nn.Linear(config.hidden_size, n_classes)
160
+
161
+ def forward(self, input_ids, attention_mask):
162
+ h = self.backbone(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
163
+ m = attention_mask.unsqueeze(-1).to(h.dtype)
164
+ return self.head((h * m).sum(1) / m.sum(1).clamp(min=1))
165
+
166
+
167
+ class _Judge:
168
+ TASK = None
169
+
170
+ def __init__(self, path=".", device=None, batch_tokens=None):
171
+ with open(os.path.join(path, "cbx_rag_config.json")) as f:
172
+ self.cfg = json.load(f)
173
+ if self.cfg["task"] != self.TASK:
174
+ raise ValueError(f"{path} holds the {self.cfg['task']} model, not {self.TASK}")
175
+ self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
176
+ self.tok = AutoTokenizer.from_pretrained(path)
177
+ self.model = _Classifier(AutoConfig.from_pretrained(path), self.cfg["n_classes"])
178
+ self.model.load_state_dict(load_file(os.path.join(path, "model.safetensors")))
179
+ self.model.to(self.device).eval()
180
+ self.batch_tokens = batch_tokens or self.cfg["batch_tokens"]
181
+ self._len = {}
182
+
183
+ def _ids(self, text):
184
+ return self.tok(text, add_special_tokens=False)["input_ids"]
185
+
186
+ def _encode(self, rows):
187
+ cls, sep = self.tok.cls_token_id, self.tok.sep_token_id
188
+ out = []
189
+ for q, ev, s in rows:
190
+ qi = self._ids(q)[:self.cfg["q_max"]]
191
+ si = self._ids(s)[:384]
192
+ ei = self._ids(ev)
193
+ room = self.cfg["max_len"] - len(qi) - len(si) - 4
194
+ out.append([cls] + qi + [sep] + ei[:max(0, room)] + [sep] + si + [sep])
195
+ return out
196
+
197
+ @torch.no_grad()
198
+ def _probs(self, rows):
199
+ """rows: (question, evidence, sentence) -> class probabilities [n, n_classes]."""
200
+ enc = self._encode(rows)
201
+ probs = np.zeros((len(enc), self.cfg["n_classes"]), dtype=np.float32)
202
+ if not enc:
203
+ return probs
204
+ lengths = [len(x) for x in enc]
205
+ order = sorted(range(len(enc)), key=lambda i: lengths[i])
206
+ pad = self.tok.pad_token_id
207
+ cur = []
208
+
209
+ def flush():
210
+ n = max(lengths[i] for i in cur)
211
+ ids = torch.full((len(cur), n), pad, dtype=torch.long)
212
+ mask = torch.zeros((len(cur), n), dtype=torch.long)
213
+ for k, i in enumerate(cur):
214
+ ids[k, :lengths[i]] = torch.tensor(enc[i])
215
+ mask[k, :lengths[i]] = 1
216
+ ids, mask = ids.to(self.device), mask.to(self.device)
217
+ if self.device.startswith("cuda"):
218
+ with torch.autocast("cuda", dtype=torch.float16):
219
+ logits = self.model(ids, mask).float()
220
+ else:
221
+ logits = self.model(ids, mask).float()
222
+ probs[cur] = torch.softmax(logits, -1).cpu().numpy()
223
+ for i in order:
224
+ if cur and lengths[i] * (len(cur) + 1) > self.batch_tokens * 2:
225
+ flush()
226
+ cur = []
227
+ cur.append(i)
228
+ flush()
229
+ return probs
230
+
231
+
232
+ # ---------------------------------------------------------------- faithfulness
233
+
234
+ class Faithfulness(_Judge):
235
+ """Is each answer sentence supported by the passages? Returns sentence scores, an answer score and the
236
+ hallucination flag (an answer is flagged when any sentence is)."""
237
+ TASK = "faithfulness"
238
+ VERDICTS = ("all_verified", "some_unverified")
239
+
240
+ def _ntok(self, text):
241
+ n = self._len.get(text)
242
+ if n is None:
243
+ n = len(self._ids(text))
244
+ if len(self._len) < 200_000:
245
+ self._len[text] = n
246
+ return n
247
+
248
+ def _line(self, c):
249
+ text = c["text"]
250
+ cap = self.cfg["sentence_cap_tokens"]
251
+ if self._ntok(text) > cap:
252
+ text = self.tok.decode(self._ids(text)[:cap]) + " ..."
253
+ return f"[{c['key']}] {text}"
254
+
255
+ def _evidence(self, question, ctx, sents, si, bm25):
256
+ budget = self.cfg["evidence_budget"]
257
+ overhead = self._ntok(question) + self._ntok(sents[si]["text"]) + 8
258
+ room = max(64, budget - overhead)
259
+ lines = [self._line(c) for c in ctx]
260
+ lens = [self._ntok(x) for x in lines]
261
+ if sum(lens) <= room:
262
+ return "\n".join(lines)
263
+ chosen, used = set(), 0
264
+
265
+ def take(i):
266
+ nonlocal used
267
+ if i in chosen or i < 0 or i >= len(ctx) or used + lens[i] > room:
268
+ return False
269
+ chosen.add(i)
270
+ used += lens[i]
271
+ return True
272
+ query = question + " " + sents[si]["text"]
273
+ if si > 0:
274
+ query += " " + sents[si - 1]["text"]
275
+ sc = bm25.scores(query)
276
+ for i in sorted(range(len(ctx)), key=lambda i: -sc[i]):
277
+ if used >= room - 16 or sc[i] <= 0:
278
+ break
279
+ for j in (i, i - 1, i + 1):
280
+ take(j)
281
+ if used < room:
282
+ for i in range(len(ctx)):
283
+ if not take(i) and used + min(lens) > room:
284
+ break
285
+ return "\n".join(lines[i] for i in sorted(chosen))
286
+
287
+ def __call__(self, question, passages, answer, answer_sentences=None, profile="auto", operating_point="default"):
288
+ """operating_point: "default" (flags about 4.5% of sentences on validation) or "high_recall"."""
289
+ prof = _profile(profile, passages)
290
+ ctx = _context(passages, prof)
291
+ sents = _answer(answer, answer_sentences, prof)
292
+ pc = self.cfg["profiles"][prof]
293
+ bm25 = BM25([c["text"] for c in ctx])
294
+ rows = [(question, self._evidence(question, ctx, sents, si, bm25), s["text"]) for si, s in enumerate(sents)]
295
+ p = 1 - self._probs(rows)[:, 0] # probability "unsupported"
296
+ score, checks = p.astype(float), [None] * len(sents)
297
+ thr = pc["thresholds"][operating_point]
298
+ if pc.get("numeric_check") and operating_point == "default":
299
+ ck = Checker(" ".join(c["text"] for c in ctx))
300
+ checks = ck.check_answer([s["text"] for s in sents])
301
+ c = pc["combiner"]
302
+ X = []
303
+ for pi, nc in zip(p, checks):
304
+ q = min(max(float(pi), 1e-6), 1 - 1e-6)
305
+ X.append([math.log(q / (1 - q))] + [float(nc["verdict"] == v) for v in self.VERDICTS]
306
+ + [min(nc["n_unverified"], 3), float(nc["eq_bad"] > 0), float(nc["eq_ok"] > 0)])
307
+ score = 1 / (1 + np.exp(-(np.array(X) @ np.array(c["coef"]) + c["intercept"])))
308
+ out = [{"key": s["key"], "text": s["text"], "unsupported_prob": round(float(pi), 6),
309
+ "score": round(float(si), 6), "flag": bool(si >= thr),
310
+ **({"numbers": checks[k]["verdict"]} if checks[k] else {})}
311
+ for k, (s, pi, si) in enumerate(zip(sents, p, score))]
312
+ return {"profile": prof, "operating_point": operating_point, "sentences": out,
313
+ "answer_score": round(float(max(score)) if len(out) else 0.0, 6),
314
+ "hallucination": any(x["flag"] for x in out)}
315
+
316
+
317
+ # ---------------------------------------------------------------- response relevance
318
+
319
+ class ResponseRelevance(_Judge):
320
+ """Does the answer address the question? direct / partial / irrelevant (question and answer only)."""
321
+ TASK = "response_relevance"
322
+
323
+ def __call__(self, question, answer):
324
+ return self.batch([(question, answer)])[0]
325
+
326
+ def batch(self, pairs):
327
+ pr = self._probs([(q, "", a) for q, a in pairs])
328
+ labels = self.cfg["labels"]
329
+ return [{"label": labels[int(x.argmax())], "probs": {l: round(float(v), 6) for l, v in zip(labels, x)}}
330
+ for x in pr]
331
+
332
+
333
+ # ---------------------------------------------------------------- context relevance / utilization
334
+
335
+ def _answer_score(p, spec):
336
+ if spec["agg"] == "count":
337
+ return float((p >= spec["thr"]).mean())
338
+ if spec["agg"] == "mean_iso":
339
+ return float(np.interp(p, spec["iso_x"], spec["iso_y"]).mean())
340
+ return float(p.mean())
341
+
342
+
343
+ def _ap_at_k(v):
344
+ v = np.asarray(v, float)
345
+ if v.sum() == 0:
346
+ return 0.0
347
+ return float(((np.cumsum(v) / np.arange(1, len(v) + 1)) * v).sum() / v.sum())
348
+
349
+
350
+ class _ContextJudge(_Judge):
351
+ def _rows(self, q, ctx, idx):
352
+ w, ch = self.cfg["window"], self.cfg["neighbour_chars"]
353
+ rows = []
354
+ for i in idx:
355
+ c = ctx[i]
356
+ js = [j for j in range(i - w, i + w + 1) if j != i and 0 <= j < len(ctx) and ctx[j]["doc"] == c["doc"]]
357
+ rows.append((q, " ".join(ctx[j]["text"][:ch] for j in js), c["text"]))
358
+ return rows
359
+
360
+ def _run(self, q, ctx, pc, prefilter_query=None):
361
+ idx = list(range(len(ctx)))
362
+ top = pc.get("prefilter_top_n")
363
+ if top and prefilter_query is not None and len(ctx) > top:
364
+ sc = np.asarray(BM25([c["text"] for c in ctx]).scores(prefilter_query))
365
+ m = np.zeros(len(ctx), bool)
366
+ for i in np.argsort(-sc)[:top]:
367
+ m[max(0, i - 1):i + 2] = True
368
+ idx = [i for i in idx if m[i]]
369
+ p = np.zeros(len(ctx))
370
+ if idx:
371
+ p[idx] = 1 - self._probs(self._rows(q, ctx, idx))[:, 0]
372
+ return p, len(idx)
373
+
374
+
375
+ class ContextRelevance(_ContextJudge):
376
+ """Is each context sentence relevant to the question? Returns sentence scores, the answer-level relevance
377
+ fraction and, with two or more passages, context precision (AP over passages in the given order)."""
378
+ TASK = "context_relevance"
379
+
380
+ def __call__(self, question, passages, profile="auto"):
381
+ prof = _profile(profile, passages)
382
+ ctx = _context(passages, prof)
383
+ pc = self.cfg["profiles"][prof]
384
+ p, _ = self._run(question, ctx, pc)
385
+ thr = pc["sentence_threshold"]
386
+ out = {"profile": prof,
387
+ "sentences": [{"key": c["key"], "passage": c["doc"], "text": c["text"], "score": round(float(x), 6),
388
+ "relevant": bool(x >= thr)} for c, x in zip(ctx, p)],
389
+ "relevance": round(_answer_score(p, pc["answer_score"]), 6)}
390
+ docs = sorted({c["doc"] for c in ctx})
391
+ if len(docs) > 1:
392
+ d = np.array([c["doc"] for c in ctx])
393
+ out["passage_relevant"] = [bool((p[d == k] >= thr).any()) for k in docs]
394
+ out["context_precision"] = round(_ap_at_k(out["passage_relevant"]), 6)
395
+ return out
396
+
397
+
398
+ class ContextUtilization(_ContextJudge):
399
+ """Did the answer use each context sentence? Returns sentence scores and the utilization fraction."""
400
+ TASK = "context_utilization"
401
+
402
+ def __call__(self, question, passages, answer, profile="auto", prefilter=True):
403
+ prof = _profile(profile, passages)
404
+ ctx = _context(passages, prof)
405
+ pc = dict(self.cfg["profiles"][prof])
406
+ if not prefilter:
407
+ pc["prefilter_top_n"] = None
408
+ q = question + " || " + str(answer)[:1200]
409
+ p, n_scored = self._run(q, ctx, pc, prefilter_query=question + " " + str(answer))
410
+ thr = pc["sentence_threshold"]
411
+ return {"profile": prof, "sentences_scored": n_scored,
412
+ "sentences": [{"key": c["key"], "passage": c["doc"], "text": c["text"], "score": round(float(x), 6),
413
+ "utilized": bool(x >= thr)} for c, x in zip(ctx, p)],
414
+ "utilization": round(_answer_score(p, pc["answer_score"]), 6)}
cbx_rag_numcheck.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """plan_v0.3 U3: deterministic FinQA numeric check (no learning).
2
+
3
+ .venv/bin/python src/eval/numcheck.py test # unit tests on hand-made cases
4
+ .venv/bin/python src/eval/numcheck.py run --split validation # en/cache/v0.3/numcheck/<split>.jsonl
5
+
6
+ For each answer sentence, every number (years and the constant 100 excluded) is classified:
7
+ direct it appears in the context (scale variants x1e3 / x1e6 / x1e-3 / x1e-6 allowed), within the rounding
8
+ of the sentence's printed precision;
9
+ derived it equals one operation on two context numbers: a+b, a-b, |a-b|, a*b, a/b, a/b*100,
10
+ (a-b)/b*100 (percent change), or the sum / mean of 2-5 consecutive context numbers;
11
+ chain same as derived, with one or both operands taken from numbers earlier in the same answer (incl. the
12
+ same sentence) that were themselves verified;
13
+ unverified otherwise.
14
+ Sentence verdict: all_verified / some_unverified / no_numbers. Tolerance: half a unit of the last printed digit
15
+ (+0.1% for the rounding of intermediate values), or 1e-4 relative.
16
+ """
17
+ import argparse
18
+ import bisect
19
+ import json
20
+ import math
21
+ import re
22
+ import sys
23
+ import warnings
24
+ from pathlib import Path
25
+
26
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
27
+
28
+ NUM = re.compile(r"(?<![\w.])(\()?\s*(-|−)?\s*\$?\s*(\d[\d,]*(?:\.\d+)?|\.\d+)\s*(\))?\s*(%|percent\b|pct\b)?"
29
+ r"(?:\s*(thousand|million|billion|mn|bn|k)\b)?", re.I)
30
+ SCALE = {"thousand": 1e3, "k": 1e3, "million": 1e6, "mn": 1e6, "billion": 1e9, "bn": 1e9}
31
+
32
+
33
+ def numbers(text):
34
+ """-> list of dicts {v, tol, pct, year}. v includes sign and the scale word; tol = half a unit of the last digit."""
35
+ out = []
36
+ for m in NUM.finditer(text):
37
+ lp, neg, raw, rp, pct, scale = m.groups()
38
+ raw = raw.rstrip(",")
39
+ s = raw.replace(",", "")
40
+ if s.count(".") > 1:
41
+ continue
42
+ try:
43
+ v = float(s)
44
+ except ValueError:
45
+ continue
46
+ dec = len(s.split(".")[1]) if "." in s else 0
47
+ tol = 0.5 * 10 ** (-dec)
48
+ is_year = (dec == 0 and "," not in raw and 1900 <= v <= 2100 and not pct and not scale)
49
+ if neg or (lp and rp):
50
+ v = -v
51
+ mult = SCALE.get((scale or "").lower(), 1.0)
52
+ out.append({"v": v * mult, "tol": tol * mult, "pct": bool(pct), "year": is_year, "raw": m.group(0).strip(),
53
+ "mult": mult})
54
+ return out
55
+
56
+
57
+ EQ_EXPR = re.compile(r"([\d$.,()%\s+\-−*/×÷x]+?)\s*(=|≈)\s*(\(?-?\$?\s*\d[\d,]*(?:\.\d+)?\)?\s*%?)")
58
+
59
+
60
+ def _eval(expr):
61
+ e = expr.replace("$", "").replace("%", "").replace("−", "-").replace("×", "*").replace("÷", "/")
62
+ e = re.sub(r"(?<=\d)\s*x\s*(?=[\d(])", "*", e)
63
+ e = re.sub(r"(?<=\d),(?=\d{3})", "", e).strip()
64
+ if not re.fullmatch(r"[\d.\s+\-*/()]+", e) or not re.search(r"\d\s*[-+*/]\s*[\d(]|\)\s*[-+*/]", e):
65
+ return None
66
+ if e.count("(") != e.count(")"):
67
+ e = e.strip("()") if e.count("(") + e.count(")") == 1 else e
68
+ try:
69
+ with warnings.catch_warnings():
70
+ warnings.simplefilter("ignore")
71
+ return float(eval(e, {"__builtins__": {}}, {})) # digits, operators and brackets only
72
+ except Exception: # noqa: BLE001
73
+ return None
74
+
75
+
76
+ def equations(text):
77
+ """Explicit 'expression = number' statements in a sentence (chains 'a - b = c / d = e' included) -> list of
78
+ 1 (holds) / 0 (does not). Scale words are dropped on both sides (they cancel in these FinQA answers); a percent
79
+ result may be a ratio x100. Tolerance: half a unit of the result's last digit + 0.2% (0.4% after an
80
+ approximate sign) for the rounding of intermediate values."""
81
+ t = re.sub(r"\b(thousand|million|billion|mn|bn)\b", "", text, flags=re.I)
82
+ parts = re.split(r"(=|≈|approximately equals)", t)
83
+ out = []
84
+ for i in range(0, len(parts) - 2, 2):
85
+ m = re.search(r"[\d$.,()%\s+\-−*/×÷x]+$", parts[i])
86
+ r = re.match(r"\s*(\(?\s*-?\s*\$?\s*\d[\d,]*(?:\.\d+)?\s*\)?\s*%?)", parts[i + 2])
87
+ if not m or not r:
88
+ continue
89
+ val = _eval(m.group(0))
90
+ if val is None:
91
+ continue
92
+ rr = r.group(1).strip()
93
+ neg = (rr.startswith("(") and rr.endswith(")")) or "-" in rr
94
+ rs = re.sub(r"[^\d.]", "", rr.replace(",", ""))
95
+ try:
96
+ rv = float(rs) * (-1 if neg else 1)
97
+ except ValueError:
98
+ continue
99
+ dec = len(rs.split(".")[1]) if "." in rs else 0
100
+ tol = 0.5 * 10 ** (-dec) + 0.002 * abs(rv) * (2 if parts[i + 1] != "=" else 1)
101
+ out.append(int(any(abs(abs(c) - abs(rv)) <= tol for c in (val, val * 100, val / 100))))
102
+ return out
103
+
104
+
105
+ def _close(x, tol, sorted_vals):
106
+ """Is any value in sorted_vals within tol of x?"""
107
+ i = bisect.bisect_left(sorted_vals, x - tol)
108
+ return i < len(sorted_vals) and sorted_vals[i] <= x + tol
109
+
110
+
111
+ def candidates(ops):
112
+ """All one-step results from operand list (context order kept for the consecutive sums / means)."""
113
+ vals = [o for o in ops if o != 0 or True]
114
+ out = []
115
+ n = len(vals)
116
+ for i in range(n):
117
+ a = vals[i]
118
+ for j in range(n):
119
+ if i == j:
120
+ continue
121
+ b = vals[j]
122
+ out += [a + b, a - b, a * b]
123
+ if b != 0:
124
+ out += [a / b, a / b * 100, (a - b) / b * 100, (a - b) / b]
125
+ for k in range(2, 6):
126
+ for i in range(0, n - k + 1):
127
+ s = sum(vals[i:i + k])
128
+ out += [s, s / k]
129
+ return out
130
+
131
+
132
+ class Checker:
133
+ def __init__(self, context_text):
134
+ cn = [x for x in numbers(context_text) if not x["year"]]
135
+ self.ctx = [x["v"] for x in cn]
136
+ base = set()
137
+ for v in self.ctx:
138
+ for m in (1, 1e3, 1e6, 1e-3, 1e-6):
139
+ base.add(v * m)
140
+ base |= {abs(v) for v in list(base)}
141
+ self.direct = sorted(base)
142
+ cand = candidates(self.ctx[:220])
143
+ self.derived = sorted({c for c in cand if math.isfinite(c)} | {abs(c) for c in cand if math.isfinite(c)})
144
+
145
+ @staticmethod
146
+ def tol(x):
147
+ return max(x["tol"] * 1.0 + 0.001 * abs(x["v"]) * 0 + 1e-9, 1e-4 * abs(x["v"]))
148
+
149
+ def check_answer(self, sentences):
150
+ """sentences: list of texts in answer order. Returns per sentence {verdict, n, n_unverified, kinds}."""
151
+ verified_answer = []
152
+ res = []
153
+ for text in sentences:
154
+ nums = [x for x in numbers(text) if not x["year"] and abs(x["v"]) != 100]
155
+ kinds = []
156
+ for x in nums:
157
+ t = self.tol(x)
158
+ v = x["v"]
159
+ k = None
160
+ forms = [(v, t)] + ([(v / x["mult"], t / x["mult"])] if x["mult"] != 1 else [])
161
+ if any(_close(abs(fv), ft, self.direct) for fv, ft in forms):
162
+ k = "direct"
163
+ elif any(_close(abs(fv), ft, self.derived) for fv, ft in forms):
164
+ k = "derived"
165
+ else:
166
+ pool = verified_answer + [y["v"] for y in nums if y is not x]
167
+ if pool:
168
+ mixed = []
169
+ for a in pool:
170
+ for b in self.ctx + pool:
171
+ if a is b:
172
+ continue
173
+ mixed += [a + b, a - b, b - a, a * b]
174
+ if b:
175
+ mixed += [a / b, a / b * 100, (a - b) / b * 100]
176
+ if a:
177
+ mixed += [b / a, b / a * 100, (b - a) / a * 100]
178
+ if any(abs(abs(fv) - abs(c)) <= ft for c in mixed if math.isfinite(c) for fv, ft in forms):
179
+ k = "chain"
180
+ kinds.append(k or "unverified")
181
+ if k:
182
+ verified_answer.append(v)
183
+ nu = kinds.count("unverified")
184
+ verdict = "no_numbers" if not nums else ("all_verified" if nu == 0 else "some_unverified")
185
+ eq = equations(text)
186
+ res.append({"verdict": verdict, "n": len(nums), "n_unverified": nu, "kinds": kinds,
187
+ "nums": [x["raw"] for x in nums], "eq_ok": sum(e for e in eq), "eq_bad": sum(1 - e for e in eq)})
188
+ return res
189
+
190
+
191
+ def run(a):
192
+ from paths import P
193
+ _, files = P.dataset("v0.2")
194
+ d = P.cache / "v0.3" / "numcheck"
195
+ d.mkdir(parents=True, exist_ok=True)
196
+ from collections import Counter
197
+ st = Counter()
198
+ with open(d / f"{a.split}.jsonl", "w") as f:
199
+ for line in open(files[a.split]):
200
+ r = json.loads(line)
201
+ if r["subset"] != "finqa":
202
+ continue
203
+ ck = Checker(" ".join(c["text"] for c in r["context_sentences"]))
204
+ out = ck.check_answer([s["text"] for s in r["response_sentences"]])
205
+ for s, o in zip(r["response_sentences"], out):
206
+ y = int(not s["reviewed_supported"])
207
+ f.write(json.dumps({"id": f"{r['example_id']}:{s['key']}", "label_reviewed": y, **o}) + "\n")
208
+ st[f"{o['verdict']}:n"] += 1
209
+ st[f"{o['verdict']}:unsup"] += y
210
+ for v in ("all_verified", "some_unverified", "no_numbers"):
211
+ n = st[f"{v}:n"]
212
+ print(f"{a.split} {v:16s} n {n:6d} reviewed-unsupported rate {st[f'{v}:unsup'] / max(n, 1):.3f}")
213
+
214
+
215
+ def test(_):
216
+ ctx = ("rental expense was approximately $ 66.9 million , $ 57.2 million and $ 49.0 million during 2010 , 2009 and "
217
+ "2008 . [[\"2011\", \"$ 62465\"], [\"2012\", \"54236\"]] net loss ( 1,234 ) . total 22176 vs 27885 .")
218
+ ck = Checker(ctx)
219
+ cases = [
220
+ ("Rental expense in 2010: $66.9 million", "all_verified"),
221
+ ("Absolute change = $66.9 million - $57.2 million = $9.7 million", "all_verified"),
222
+ ("Percentage change = ($9.7 million / $57.2 million) * 100 ≈ 16.96%", "all_verified"),
223
+ ("The change was (22176 - 27885) / 27885 = -20.47%", "all_verified"),
224
+ ("The net loss was $1,234.", "all_verified"),
225
+ ("Rental expense in 2010 was $71.3 million", "some_unverified"),
226
+ ("The change was 25.3%", "some_unverified"),
227
+ ("The leases are described below.", "no_numbers"),
228
+ ("Payments in 2011 and 2012 total 116701", "all_verified"),
229
+ ("In 2012, the net trading assets were $66.9 million.", "all_verified"),
230
+ ]
231
+ out = ck.check_answer([c for c, _ in cases])
232
+ bad = 0
233
+ for (c, want), o in zip(cases, out):
234
+ ok = o["verdict"] == want
235
+ bad += not ok
236
+ print("ok " if ok else "BAD", want, o["verdict"], o["kinds"], "|", c)
237
+ for txt, want in (("(226 + 209 + 221) / 3 = 220", 0), ("(22176 - 27885) / 27885 = -20.47%", 1),
238
+ ("$66.9 million - $57.2 million = $9.7 million", 1), ("908.4 / 3 = 302.8 million", 1),
239
+ ("$19686 * 1.05 = $20670.30", 1), ("x = 5 + 5 = 11", 0), ("Margin = 473 / 7170 ≈ 6.6%", 1)):
240
+ e = equations(txt)
241
+ ok = bool(e) and e[-1] == want
242
+ bad += not ok
243
+ print("ok " if ok else "BAD", "eq", want, e, "|", txt)
244
+ print("failures", bad)
245
+ return bad
246
+
247
+
248
+ def main():
249
+ ap = argparse.ArgumentParser()
250
+ ap.add_argument("cmd", choices=["test", "run"])
251
+ ap.add_argument("--split", default="validation")
252
+ a = ap.parse_args()
253
+ sys.exit(test(a) if a.cmd == "test" else run(a))
254
+
255
+
256
+ if __name__ == "__main__":
257
+ main()
checksums.sha256 ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 7688a0a074494af58c5d63dac14c47c73f3783b32adce0f64df441db0ee0c0af README.md
2
+ f8f801f5695cda0df2b0b9e2201bf7493db861968a58029d900ce3403685438d cbx_rag_config.json
3
+ 466c603bc801909655cf192874faf8efb3b164947bdcbaf22ad3de645d634079 cbx_rag_eval.py
4
+ d18b5d365189ddaca9b123ea73d49bdf0b9825aa0409921f413f117587d717fe cbx_rag_numcheck.py
5
+ 0b8f2e4c6bff549b5c3fcfcb5da4265d1d24acd7e5159ae6956c7e85ac2de14e config.json
6
+ 9b7a60d12007821374c2ba140d8d0cf1730ee4b7e89223313d3539e9a14d4dc9 example.py
7
+ 0add06df9460fe8db202300f300aa5be2ccdf9c5081174d4c107c69adfb553c7 model.safetensors
8
+ f688a784a5bbba4e3c659d37b99dc74461fa787f253d37219ac66628d8d65238 requirements.txt
9
+ ea97ecdbcc73713039d8d64dbb05e3689495c96657fbd9a18f5bed381be81049 special_tokens_map.json
10
+ 9fd55248d51d33976b324fc11592e28071da7d41e0e9401dfb7082e30574b7b1 tokenizer.json
11
+ 3cd2017ff46d0a527e5d39cae39272eccfa1f19bb9f89b05d166aab2e38354e2 tokenizer_config.json
config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "ettin-encoder-68m",
3
+ "architectures": [
4
+ "ModernBertForMaskedLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 50281,
9
+ "classifier_activation": "gelu",
10
+ "classifier_bias": false,
11
+ "classifier_dropout": 0.0,
12
+ "classifier_pooling": "mean",
13
+ "cls_token_id": 50281,
14
+ "decoder_bias": true,
15
+ "deterministic_flash_attn": false,
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 50282,
18
+ "global_attn_every_n_layers": 3,
19
+ "global_rope_theta": 160000.0,
20
+ "gradient_checkpointing": false,
21
+ "hidden_activation": "gelu",
22
+ "hidden_size": 512,
23
+ "initializer_cutoff_factor": 2.0,
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 768,
26
+ "layer_norm_eps": 1e-05,
27
+ "local_attention": 128,
28
+ "local_rope_theta": 160000.0,
29
+ "max_position_embeddings": 7999,
30
+ "mlp_bias": false,
31
+ "mlp_dropout": 0.0,
32
+ "model_type": "modernbert",
33
+ "norm_bias": false,
34
+ "norm_eps": 1e-05,
35
+ "num_attention_heads": 8,
36
+ "num_hidden_layers": 19,
37
+ "pad_token_id": 50283,
38
+ "position_embedding_type": "sans_pos",
39
+ "sep_token_id": 50282,
40
+ "tie_word_embeddings": true,
41
+ "torch_dtype": "float32",
42
+ "transformers_version": "4.47.0.dev0",
43
+ "vocab_size": 50368,
44
+ "is_causal": false,
45
+ "causal_mask": false
46
+ }
example.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Which context sentences did the answer use? Run from this folder: python example.py"""
2
+ from cbx_rag_eval import ContextUtilization
3
+
4
+ judge = ContextUtilization(".")
5
+ question = "What was the company's operating income in 2023?"
6
+ passages = [
7
+ "The company was founded in 1998 and is headquartered in Ohio. It operates three plants.",
8
+ "Operating income was $412 million in 2023, compared with $380 million in 2022. "
9
+ "The increase reflects higher volumes.",
10
+ "The board declared a quarterly dividend of $0.25 per share.",
11
+ ]
12
+ answer = "Operating income was $412 million in 2023."
13
+ out = judge(question, passages, answer)
14
+ print("utilization:", out["utilization"], "| sentences scored:", out["sentences_scored"])
15
+ for s in out["sentences"]:
16
+ print(f" passage {s['passage']} utilized={s['utilized']!s:5} score={s['score']:.3f} {s['text']}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0add06df9460fe8db202300f300aa5be2ccdf9c5081174d4c107c69adfb553c7
3
+ size 272595112
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch>=2.1
2
+ transformers>=5.0
3
+ safetensors>=0.4
4
+ numpy>=1.24
5
+ nltk>=3.9
6
+ pysbd>=0.3.4
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": true,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,944 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "|||IP_ADDRESS|||",
5
+ "lstrip": false,
6
+ "normalized": true,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": false
10
+ },
11
+ "1": {
12
+ "content": "<|padding|>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "50254": {
20
+ "content": " ",
21
+ "lstrip": false,
22
+ "normalized": true,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": false
26
+ },
27
+ "50255": {
28
+ "content": " ",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": false
34
+ },
35
+ "50256": {
36
+ "content": " ",
37
+ "lstrip": false,
38
+ "normalized": true,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": false
42
+ },
43
+ "50257": {
44
+ "content": " ",
45
+ "lstrip": false,
46
+ "normalized": true,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": false
50
+ },
51
+ "50258": {
52
+ "content": " ",
53
+ "lstrip": false,
54
+ "normalized": true,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": false
58
+ },
59
+ "50259": {
60
+ "content": " ",
61
+ "lstrip": false,
62
+ "normalized": true,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": false
66
+ },
67
+ "50260": {
68
+ "content": " ",
69
+ "lstrip": false,
70
+ "normalized": true,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": false
74
+ },
75
+ "50261": {
76
+ "content": " ",
77
+ "lstrip": false,
78
+ "normalized": true,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": false
82
+ },
83
+ "50262": {
84
+ "content": " ",
85
+ "lstrip": false,
86
+ "normalized": true,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": false
90
+ },
91
+ "50263": {
92
+ "content": " ",
93
+ "lstrip": false,
94
+ "normalized": true,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": false
98
+ },
99
+ "50264": {
100
+ "content": " ",
101
+ "lstrip": false,
102
+ "normalized": true,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": false
106
+ },
107
+ "50265": {
108
+ "content": " ",
109
+ "lstrip": false,
110
+ "normalized": true,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": false
114
+ },
115
+ "50266": {
116
+ "content": " ",
117
+ "lstrip": false,
118
+ "normalized": true,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": false
122
+ },
123
+ "50267": {
124
+ "content": " ",
125
+ "lstrip": false,
126
+ "normalized": true,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": false
130
+ },
131
+ "50268": {
132
+ "content": " ",
133
+ "lstrip": false,
134
+ "normalized": true,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": false
138
+ },
139
+ "50269": {
140
+ "content": " ",
141
+ "lstrip": false,
142
+ "normalized": true,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": false
146
+ },
147
+ "50270": {
148
+ "content": " ",
149
+ "lstrip": false,
150
+ "normalized": true,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": false
154
+ },
155
+ "50271": {
156
+ "content": " ",
157
+ "lstrip": false,
158
+ "normalized": true,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": false
162
+ },
163
+ "50272": {
164
+ "content": " ",
165
+ "lstrip": false,
166
+ "normalized": true,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": false
170
+ },
171
+ "50273": {
172
+ "content": " ",
173
+ "lstrip": false,
174
+ "normalized": true,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": false
178
+ },
179
+ "50274": {
180
+ "content": " ",
181
+ "lstrip": false,
182
+ "normalized": true,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": false
186
+ },
187
+ "50275": {
188
+ "content": " ",
189
+ "lstrip": false,
190
+ "normalized": true,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": false
194
+ },
195
+ "50276": {
196
+ "content": " ",
197
+ "lstrip": false,
198
+ "normalized": true,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": false
202
+ },
203
+ "50277": {
204
+ "content": "|||EMAIL_ADDRESS|||",
205
+ "lstrip": false,
206
+ "normalized": true,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": false
210
+ },
211
+ "50278": {
212
+ "content": "|||PHONE_NUMBER|||",
213
+ "lstrip": false,
214
+ "normalized": true,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": false
218
+ },
219
+ "50279": {
220
+ "content": "<|endoftext|>",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "50280": {
228
+ "content": "[UNK]",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "50281": {
236
+ "content": "[CLS]",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "50282": {
244
+ "content": "[SEP]",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "50283": {
252
+ "content": "[PAD]",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "50284": {
260
+ "content": "[MASK]",
261
+ "lstrip": true,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "50285": {
268
+ "content": "[unused0]",
269
+ "lstrip": false,
270
+ "normalized": true,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": false
274
+ },
275
+ "50286": {
276
+ "content": "[unused1]",
277
+ "lstrip": false,
278
+ "normalized": true,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": false
282
+ },
283
+ "50287": {
284
+ "content": "[unused2]",
285
+ "lstrip": false,
286
+ "normalized": true,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": false
290
+ },
291
+ "50288": {
292
+ "content": "[unused3]",
293
+ "lstrip": false,
294
+ "normalized": true,
295
+ "rstrip": false,
296
+ "single_word": false,
297
+ "special": false
298
+ },
299
+ "50289": {
300
+ "content": "[unused4]",
301
+ "lstrip": false,
302
+ "normalized": true,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": false
306
+ },
307
+ "50290": {
308
+ "content": "[unused5]",
309
+ "lstrip": false,
310
+ "normalized": true,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": false
314
+ },
315
+ "50291": {
316
+ "content": "[unused6]",
317
+ "lstrip": false,
318
+ "normalized": true,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": false
322
+ },
323
+ "50292": {
324
+ "content": "[unused7]",
325
+ "lstrip": false,
326
+ "normalized": true,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": false
330
+ },
331
+ "50293": {
332
+ "content": "[unused8]",
333
+ "lstrip": false,
334
+ "normalized": true,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": false
338
+ },
339
+ "50294": {
340
+ "content": "[unused9]",
341
+ "lstrip": false,
342
+ "normalized": true,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": false
346
+ },
347
+ "50295": {
348
+ "content": "[unused10]",
349
+ "lstrip": false,
350
+ "normalized": true,
351
+ "rstrip": false,
352
+ "single_word": false,
353
+ "special": false
354
+ },
355
+ "50296": {
356
+ "content": "[unused11]",
357
+ "lstrip": false,
358
+ "normalized": true,
359
+ "rstrip": false,
360
+ "single_word": false,
361
+ "special": false
362
+ },
363
+ "50297": {
364
+ "content": "[unused12]",
365
+ "lstrip": false,
366
+ "normalized": true,
367
+ "rstrip": false,
368
+ "single_word": false,
369
+ "special": false
370
+ },
371
+ "50298": {
372
+ "content": "[unused13]",
373
+ "lstrip": false,
374
+ "normalized": true,
375
+ "rstrip": false,
376
+ "single_word": false,
377
+ "special": false
378
+ },
379
+ "50299": {
380
+ "content": "[unused14]",
381
+ "lstrip": false,
382
+ "normalized": true,
383
+ "rstrip": false,
384
+ "single_word": false,
385
+ "special": false
386
+ },
387
+ "50300": {
388
+ "content": "[unused15]",
389
+ "lstrip": false,
390
+ "normalized": true,
391
+ "rstrip": false,
392
+ "single_word": false,
393
+ "special": false
394
+ },
395
+ "50301": {
396
+ "content": "[unused16]",
397
+ "lstrip": false,
398
+ "normalized": true,
399
+ "rstrip": false,
400
+ "single_word": false,
401
+ "special": false
402
+ },
403
+ "50302": {
404
+ "content": "[unused17]",
405
+ "lstrip": false,
406
+ "normalized": true,
407
+ "rstrip": false,
408
+ "single_word": false,
409
+ "special": false
410
+ },
411
+ "50303": {
412
+ "content": "[unused18]",
413
+ "lstrip": false,
414
+ "normalized": true,
415
+ "rstrip": false,
416
+ "single_word": false,
417
+ "special": false
418
+ },
419
+ "50304": {
420
+ "content": "[unused19]",
421
+ "lstrip": false,
422
+ "normalized": true,
423
+ "rstrip": false,
424
+ "single_word": false,
425
+ "special": false
426
+ },
427
+ "50305": {
428
+ "content": "[unused20]",
429
+ "lstrip": false,
430
+ "normalized": true,
431
+ "rstrip": false,
432
+ "single_word": false,
433
+ "special": false
434
+ },
435
+ "50306": {
436
+ "content": "[unused21]",
437
+ "lstrip": false,
438
+ "normalized": true,
439
+ "rstrip": false,
440
+ "single_word": false,
441
+ "special": false
442
+ },
443
+ "50307": {
444
+ "content": "[unused22]",
445
+ "lstrip": false,
446
+ "normalized": true,
447
+ "rstrip": false,
448
+ "single_word": false,
449
+ "special": false
450
+ },
451
+ "50308": {
452
+ "content": "[unused23]",
453
+ "lstrip": false,
454
+ "normalized": true,
455
+ "rstrip": false,
456
+ "single_word": false,
457
+ "special": false
458
+ },
459
+ "50309": {
460
+ "content": "[unused24]",
461
+ "lstrip": false,
462
+ "normalized": true,
463
+ "rstrip": false,
464
+ "single_word": false,
465
+ "special": false
466
+ },
467
+ "50310": {
468
+ "content": "[unused25]",
469
+ "lstrip": false,
470
+ "normalized": true,
471
+ "rstrip": false,
472
+ "single_word": false,
473
+ "special": false
474
+ },
475
+ "50311": {
476
+ "content": "[unused26]",
477
+ "lstrip": false,
478
+ "normalized": true,
479
+ "rstrip": false,
480
+ "single_word": false,
481
+ "special": false
482
+ },
483
+ "50312": {
484
+ "content": "[unused27]",
485
+ "lstrip": false,
486
+ "normalized": true,
487
+ "rstrip": false,
488
+ "single_word": false,
489
+ "special": false
490
+ },
491
+ "50313": {
492
+ "content": "[unused28]",
493
+ "lstrip": false,
494
+ "normalized": true,
495
+ "rstrip": false,
496
+ "single_word": false,
497
+ "special": false
498
+ },
499
+ "50314": {
500
+ "content": "[unused29]",
501
+ "lstrip": false,
502
+ "normalized": true,
503
+ "rstrip": false,
504
+ "single_word": false,
505
+ "special": false
506
+ },
507
+ "50315": {
508
+ "content": "[unused30]",
509
+ "lstrip": false,
510
+ "normalized": true,
511
+ "rstrip": false,
512
+ "single_word": false,
513
+ "special": false
514
+ },
515
+ "50316": {
516
+ "content": "[unused31]",
517
+ "lstrip": false,
518
+ "normalized": true,
519
+ "rstrip": false,
520
+ "single_word": false,
521
+ "special": false
522
+ },
523
+ "50317": {
524
+ "content": "[unused32]",
525
+ "lstrip": false,
526
+ "normalized": true,
527
+ "rstrip": false,
528
+ "single_word": false,
529
+ "special": false
530
+ },
531
+ "50318": {
532
+ "content": "[unused33]",
533
+ "lstrip": false,
534
+ "normalized": true,
535
+ "rstrip": false,
536
+ "single_word": false,
537
+ "special": false
538
+ },
539
+ "50319": {
540
+ "content": "[unused34]",
541
+ "lstrip": false,
542
+ "normalized": true,
543
+ "rstrip": false,
544
+ "single_word": false,
545
+ "special": false
546
+ },
547
+ "50320": {
548
+ "content": "[unused35]",
549
+ "lstrip": false,
550
+ "normalized": true,
551
+ "rstrip": false,
552
+ "single_word": false,
553
+ "special": false
554
+ },
555
+ "50321": {
556
+ "content": "[unused36]",
557
+ "lstrip": false,
558
+ "normalized": true,
559
+ "rstrip": false,
560
+ "single_word": false,
561
+ "special": false
562
+ },
563
+ "50322": {
564
+ "content": "[unused37]",
565
+ "lstrip": false,
566
+ "normalized": true,
567
+ "rstrip": false,
568
+ "single_word": false,
569
+ "special": false
570
+ },
571
+ "50323": {
572
+ "content": "[unused38]",
573
+ "lstrip": false,
574
+ "normalized": true,
575
+ "rstrip": false,
576
+ "single_word": false,
577
+ "special": false
578
+ },
579
+ "50324": {
580
+ "content": "[unused39]",
581
+ "lstrip": false,
582
+ "normalized": true,
583
+ "rstrip": false,
584
+ "single_word": false,
585
+ "special": false
586
+ },
587
+ "50325": {
588
+ "content": "[unused40]",
589
+ "lstrip": false,
590
+ "normalized": true,
591
+ "rstrip": false,
592
+ "single_word": false,
593
+ "special": false
594
+ },
595
+ "50326": {
596
+ "content": "[unused41]",
597
+ "lstrip": false,
598
+ "normalized": true,
599
+ "rstrip": false,
600
+ "single_word": false,
601
+ "special": false
602
+ },
603
+ "50327": {
604
+ "content": "[unused42]",
605
+ "lstrip": false,
606
+ "normalized": true,
607
+ "rstrip": false,
608
+ "single_word": false,
609
+ "special": false
610
+ },
611
+ "50328": {
612
+ "content": "[unused43]",
613
+ "lstrip": false,
614
+ "normalized": true,
615
+ "rstrip": false,
616
+ "single_word": false,
617
+ "special": false
618
+ },
619
+ "50329": {
620
+ "content": "[unused44]",
621
+ "lstrip": false,
622
+ "normalized": true,
623
+ "rstrip": false,
624
+ "single_word": false,
625
+ "special": false
626
+ },
627
+ "50330": {
628
+ "content": "[unused45]",
629
+ "lstrip": false,
630
+ "normalized": true,
631
+ "rstrip": false,
632
+ "single_word": false,
633
+ "special": false
634
+ },
635
+ "50331": {
636
+ "content": "[unused46]",
637
+ "lstrip": false,
638
+ "normalized": true,
639
+ "rstrip": false,
640
+ "single_word": false,
641
+ "special": false
642
+ },
643
+ "50332": {
644
+ "content": "[unused47]",
645
+ "lstrip": false,
646
+ "normalized": true,
647
+ "rstrip": false,
648
+ "single_word": false,
649
+ "special": false
650
+ },
651
+ "50333": {
652
+ "content": "[unused48]",
653
+ "lstrip": false,
654
+ "normalized": true,
655
+ "rstrip": false,
656
+ "single_word": false,
657
+ "special": false
658
+ },
659
+ "50334": {
660
+ "content": "[unused49]",
661
+ "lstrip": false,
662
+ "normalized": true,
663
+ "rstrip": false,
664
+ "single_word": false,
665
+ "special": false
666
+ },
667
+ "50335": {
668
+ "content": "[unused50]",
669
+ "lstrip": false,
670
+ "normalized": true,
671
+ "rstrip": false,
672
+ "single_word": false,
673
+ "special": false
674
+ },
675
+ "50336": {
676
+ "content": "[unused51]",
677
+ "lstrip": false,
678
+ "normalized": true,
679
+ "rstrip": false,
680
+ "single_word": false,
681
+ "special": false
682
+ },
683
+ "50337": {
684
+ "content": "[unused52]",
685
+ "lstrip": false,
686
+ "normalized": true,
687
+ "rstrip": false,
688
+ "single_word": false,
689
+ "special": false
690
+ },
691
+ "50338": {
692
+ "content": "[unused53]",
693
+ "lstrip": false,
694
+ "normalized": true,
695
+ "rstrip": false,
696
+ "single_word": false,
697
+ "special": false
698
+ },
699
+ "50339": {
700
+ "content": "[unused54]",
701
+ "lstrip": false,
702
+ "normalized": true,
703
+ "rstrip": false,
704
+ "single_word": false,
705
+ "special": false
706
+ },
707
+ "50340": {
708
+ "content": "[unused55]",
709
+ "lstrip": false,
710
+ "normalized": true,
711
+ "rstrip": false,
712
+ "single_word": false,
713
+ "special": false
714
+ },
715
+ "50341": {
716
+ "content": "[unused56]",
717
+ "lstrip": false,
718
+ "normalized": true,
719
+ "rstrip": false,
720
+ "single_word": false,
721
+ "special": false
722
+ },
723
+ "50342": {
724
+ "content": "[unused57]",
725
+ "lstrip": false,
726
+ "normalized": true,
727
+ "rstrip": false,
728
+ "single_word": false,
729
+ "special": false
730
+ },
731
+ "50343": {
732
+ "content": "[unused58]",
733
+ "lstrip": false,
734
+ "normalized": true,
735
+ "rstrip": false,
736
+ "single_word": false,
737
+ "special": false
738
+ },
739
+ "50344": {
740
+ "content": "[unused59]",
741
+ "lstrip": false,
742
+ "normalized": true,
743
+ "rstrip": false,
744
+ "single_word": false,
745
+ "special": false
746
+ },
747
+ "50345": {
748
+ "content": "[unused60]",
749
+ "lstrip": false,
750
+ "normalized": true,
751
+ "rstrip": false,
752
+ "single_word": false,
753
+ "special": false
754
+ },
755
+ "50346": {
756
+ "content": "[unused61]",
757
+ "lstrip": false,
758
+ "normalized": true,
759
+ "rstrip": false,
760
+ "single_word": false,
761
+ "special": false
762
+ },
763
+ "50347": {
764
+ "content": "[unused62]",
765
+ "lstrip": false,
766
+ "normalized": true,
767
+ "rstrip": false,
768
+ "single_word": false,
769
+ "special": false
770
+ },
771
+ "50348": {
772
+ "content": "[unused63]",
773
+ "lstrip": false,
774
+ "normalized": true,
775
+ "rstrip": false,
776
+ "single_word": false,
777
+ "special": false
778
+ },
779
+ "50349": {
780
+ "content": "[unused64]",
781
+ "lstrip": false,
782
+ "normalized": true,
783
+ "rstrip": false,
784
+ "single_word": false,
785
+ "special": false
786
+ },
787
+ "50350": {
788
+ "content": "[unused65]",
789
+ "lstrip": false,
790
+ "normalized": true,
791
+ "rstrip": false,
792
+ "single_word": false,
793
+ "special": false
794
+ },
795
+ "50351": {
796
+ "content": "[unused66]",
797
+ "lstrip": false,
798
+ "normalized": true,
799
+ "rstrip": false,
800
+ "single_word": false,
801
+ "special": false
802
+ },
803
+ "50352": {
804
+ "content": "[unused67]",
805
+ "lstrip": false,
806
+ "normalized": true,
807
+ "rstrip": false,
808
+ "single_word": false,
809
+ "special": false
810
+ },
811
+ "50353": {
812
+ "content": "[unused68]",
813
+ "lstrip": false,
814
+ "normalized": true,
815
+ "rstrip": false,
816
+ "single_word": false,
817
+ "special": false
818
+ },
819
+ "50354": {
820
+ "content": "[unused69]",
821
+ "lstrip": false,
822
+ "normalized": true,
823
+ "rstrip": false,
824
+ "single_word": false,
825
+ "special": false
826
+ },
827
+ "50355": {
828
+ "content": "[unused70]",
829
+ "lstrip": false,
830
+ "normalized": true,
831
+ "rstrip": false,
832
+ "single_word": false,
833
+ "special": false
834
+ },
835
+ "50356": {
836
+ "content": "[unused71]",
837
+ "lstrip": false,
838
+ "normalized": true,
839
+ "rstrip": false,
840
+ "single_word": false,
841
+ "special": false
842
+ },
843
+ "50357": {
844
+ "content": "[unused72]",
845
+ "lstrip": false,
846
+ "normalized": true,
847
+ "rstrip": false,
848
+ "single_word": false,
849
+ "special": false
850
+ },
851
+ "50358": {
852
+ "content": "[unused73]",
853
+ "lstrip": false,
854
+ "normalized": true,
855
+ "rstrip": false,
856
+ "single_word": false,
857
+ "special": false
858
+ },
859
+ "50359": {
860
+ "content": "[unused74]",
861
+ "lstrip": false,
862
+ "normalized": true,
863
+ "rstrip": false,
864
+ "single_word": false,
865
+ "special": false
866
+ },
867
+ "50360": {
868
+ "content": "[unused75]",
869
+ "lstrip": false,
870
+ "normalized": true,
871
+ "rstrip": false,
872
+ "single_word": false,
873
+ "special": false
874
+ },
875
+ "50361": {
876
+ "content": "[unused76]",
877
+ "lstrip": false,
878
+ "normalized": true,
879
+ "rstrip": false,
880
+ "single_word": false,
881
+ "special": false
882
+ },
883
+ "50362": {
884
+ "content": "[unused77]",
885
+ "lstrip": false,
886
+ "normalized": true,
887
+ "rstrip": false,
888
+ "single_word": false,
889
+ "special": false
890
+ },
891
+ "50363": {
892
+ "content": "[unused78]",
893
+ "lstrip": false,
894
+ "normalized": true,
895
+ "rstrip": false,
896
+ "single_word": false,
897
+ "special": false
898
+ },
899
+ "50364": {
900
+ "content": "[unused79]",
901
+ "lstrip": false,
902
+ "normalized": true,
903
+ "rstrip": false,
904
+ "single_word": false,
905
+ "special": false
906
+ },
907
+ "50365": {
908
+ "content": "[unused80]",
909
+ "lstrip": false,
910
+ "normalized": true,
911
+ "rstrip": false,
912
+ "single_word": false,
913
+ "special": false
914
+ },
915
+ "50366": {
916
+ "content": "[unused81]",
917
+ "lstrip": false,
918
+ "normalized": true,
919
+ "rstrip": false,
920
+ "single_word": false,
921
+ "special": false
922
+ },
923
+ "50367": {
924
+ "content": "[unused82]",
925
+ "lstrip": false,
926
+ "normalized": true,
927
+ "rstrip": false,
928
+ "single_word": false,
929
+ "special": false
930
+ }
931
+ },
932
+ "clean_up_tokenization_spaces": true,
933
+ "cls_token": "[CLS]",
934
+ "mask_token": "[MASK]",
935
+ "model_max_length": 8192,
936
+ "pad_token": "[PAD]",
937
+ "sep_token": "[SEP]",
938
+ "tokenizer_class": "PreTrainedTokenizerFast",
939
+ "model_input_names": [
940
+ "input_ids",
941
+ "attention_mask"
942
+ ],
943
+ "unk_token": "[UNK]"
944
+ }