gtfeng 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gtfeng might be problematic. Click here for more details.

gtfeng-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
gtfeng-0.1.0/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ GT-FENG (General Theory of Factual Evaluation and Normative Grounding)
2
+ Copyright 2026 Jiayu Feng
3
+
4
+ This product includes software developed by Jiayu Feng as part of GT-FENG.
5
+
6
+ If you use GT-FENG in research, please cite:
7
+ Feng, J. (2026). GT-FENG: General Theory of Factual Evaluation and Normative Grounding in Language Models. arXiv:2611.18279. https://arxiv.org/abs/2611.18279
gtfeng-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: gtfeng
3
+ Version: 0.1.0
4
+ Summary: GT-FENG (General Theory of Factual Evaluation and Normative Grounding): evaluate language-model answers about rule-governed facts
5
+ Author: Jiayu Feng
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/VonFlair/gtfeng
8
+ Project-URL: Paper, https://arxiv.org/abs/2611.18279
9
+ Project-URL: Medicaid study, https://arxiv.org/abs/2610.09458
10
+ Keywords: language models,evaluation,factuality,law,policy,temporal,jurisdiction
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ License-File: NOTICE
18
+ Requires-Dist: pandas>=1.5
19
+ Requires-Dist: numpy
20
+ Dynamic: license-file
21
+
22
+ # gtfeng
23
+
24
+ **GT-FENG (General Theory of Factual Evaluation and Normative Grounding)** evaluates language-model answers about facts whose correct value is set by a rule: an income limit, a filing deadline, a legal duty. The same answer can be right under one jurisdiction, date, or definition and wrong under another. `gtfeng` scores each answer against the rule that applies and lists every documented rule that matches a wrong answer. Paper: [arXiv:2611.18279](https://arxiv.org/abs/2611.18279).
25
+
26
+ Use it when you evaluate model answers about numbers, dates, or yes/no facts set by law or policy, and you want to know whether a wrong answer is the correct value for another state, another year, or another definition.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ pip install gtfeng # from PyPI
32
+ pip install . # from a clone of this repository
33
+ ```
34
+
35
+ Requires Python 3.9+ and pandas.
36
+
37
+ ## Quick start
38
+
39
+ ```python
40
+ import pandas as pd
41
+ import gtfeng
42
+
43
+ references = pd.DataFrame(
44
+ [("limit", "A", 2025, "x", 50), ("limit", "A", 2018, "x", 40), ("limit", "B", 2025, "x", 40)],
45
+ columns=["quantity", "jurisdiction", "time", "definition", "value"])
46
+ answers = pd.DataFrame(
47
+ [{"model": "m", "quantity": "limit", "jurisdiction": "A", "time": 2025, "definition": "x", "answer": 40}])
48
+
49
+ result = gtfeng.evaluate(answers, references, groups=["model"])
50
+ result.items[["jurisdiction", "answer", "label", "n_sources"]]
51
+ # jurisdiction answer label n_sources
52
+ # A 40 ambiguous {J, T} 2
53
+ result.report(families={"cross_jurisdiction": ["J", "JD"]})
54
+ ```
55
+
56
+ The answer 40 is wrong for A in 2025. It matches B's current rule (shift **J**, another jurisdiction) and A's 2018 rule (shift **T**, another time), so GT-FENG labels it ambiguous and reports both sources.
57
+
58
+ ## Key terms
59
+
60
+ | Term | Meaning | Example (quick start) |
61
+ |---|---|---|
62
+ | match | a documented rule, other than the one asked about, that gives the same value as a wrong answer | 40 matches B's 2025 rule and A's 2018 rule |
63
+ | U | a wrong answer with no match | an answer of 45 |
64
+ | shift | the coordinates in which a match differs from the question, written as their initials | B 2025 has shift J (another jurisdiction); A 2018 has shift T (another time) |
65
+ | source | where a match comes from; matches that differ only in year count as one source | A's 2018 and A's 2021 rules would be one source |
66
+ | reference level | how many documented rules a wrong answer is checked against; R1 is the smallest set, and each later level adds rules. Set with the `level` column or `level_by_shift` (default: everything at R1) | in the Medicaid example, R1 holds other states' current limits and R2 adds the asked state's earlier ones |
67
+ | ambiguous | the matches have two or more different shifts (shift ambiguity); matches from two or more sources are source ambiguity | 40 is `ambiguous {J, T}` |
68
+ | family | a set of shifts treated as one kind of error | {J, JD}: the value belongs to another jurisdiction |
69
+ | grounded in a family | every match of the wrong answer has a shift in the family | 40 is not grounded in {J, JD}, because its match A 2018 has shift T |
70
+
71
+ ## Inputs
72
+
73
+ | Table | Required columns | Optional columns |
74
+ |---|---|---|
75
+ | `references` | the coordinates (default `quantity`, `jurisdiction`, `time`, `definition`) and `value` | `level` (reference level, default 1); scope columns |
76
+ | `answers` | the coordinates and `answer` | group columns such as `model`; repeated rows for repeated responses |
77
+
78
+ Coordinates are configurable (`coordinates=[...]`); each must have a distinct initial, which names its shift. Values can be numbers, Booleans, strings, or lists compared as sets.
79
+
80
+ ## What it computes
81
+
82
+ Rule numbers follow the [GT-FENG paper](https://arxiv.org/abs/2611.18279).
83
+
84
+ | Paper | `gtfeng` |
85
+ |---|---|
86
+ | Stability | an item enters only when all repeats give the same answer (`result.unstable` lists the rest) |
87
+ | Rule 1, correct | `label == "correct"` |
88
+ | Rules 2–3, matches and U | `matches`; `label == "U"` when nothing matches |
89
+ | Rule 4, shift | `shifts`, e.g. `J`, `T`, `JD`, `JT` |
90
+ | Rule 5, label and ambiguity | single shift, or `ambiguous {...}` (shift ambiguity); `n_sources` counts distinct sources, so source ambiguity is `n_sources >= 2` (documented rules that differ only in time are one source) |
91
+ | Rule 6, reference levels | `level` column (level k means R_k); extension `level_by_shift`, e.g. `{"T": 2}` holds matches with shift T back until level 2 |
92
+ | Rule 7, local perturbation baseline | `result.feng_value(family)`: O, N, E, the FENG value, and p |
93
+ | Standard report | `result.report(families=...)`: correct, U, single-shift labels, shift-ambiguous, source-ambiguous, mean sources per matched item, and O for each family |
94
+
95
+ Extension `scope={"ref_column": "answer_coordinate"}` restricts a documented rule to items whose coordinate equals the rule's value in that column.
96
+
97
+ ## Rule 7 and the FENG value
98
+
99
+ For a family of shifts F, `result.feng_value(F)` compares how often wrong answers are grounded in F with how often nearby values are:
100
+
101
+ ```python
102
+ result.feng_value(["J", "JD"]) # one row per group and reference level
103
+ # W O N E feng_value p
104
+ ```
105
+
106
+ | Column | Meaning |
107
+ |---|---|
108
+ | `W` | wrong items |
109
+ | `O` | wrong items grounded in F (they have matches, and every match has a shift in F) |
110
+ | `N` | local perturbation baseline: each wrong answer A is replaced by A + i for every increment i (default ±1 to ±4; increments that reach the correct value are dropped), and N sums each item's share of nearby values grounded in F |
111
+ | `E` | O − N |
112
+ | `feng_value` | (O − N) / (W − N); NaN when N ≥ W |
113
+ | `p` | share of random perturbations (one increment per item) whose grounded count reaches O |
114
+
115
+ The FENG value is 0 when wrong answers are grounded in F as often as nearby values, 1 when every wrong answer is grounded in F, and negative when nearby values are grounded more often. It has the chance-corrected form of Cohen's kappa; the match event and the local baseline come from GT-FENG. Rule 7 needs numeric answers, and the increments must leave out any known definition shift (the Medicaid example leaves out 5).
116
+
117
+ Report the FENG value next to accuracy: it describes the structure of wrong answers and does not rank models.
118
+
119
+ ## Example: Medicaid income limits
120
+
121
+ [`examples/medicaid/`](https://github.com/VonFlair/gtfeng/tree/main/examples/medicaid) (in the GitHub repository) reproduces the paper's Medicaid instance (two models, 51 jurisdictions, three quantities). Its four reference levels follow the paper's Table 2:
122
+
123
+ | Level | A wrong answer is also checked against |
124
+ |---|---|
125
+ | R1 | other states' July 2025 limits, with and without the 5-point income disregard |
126
+ | R2 | the asked state's own limit under the other definition, three earlier editions, and the federal anchors 100, 133 and 138 (percent of the federal poverty level) |
127
+ | R3 | every edition of the asked state's limits, 2018–2024 |
128
+ | R4 | every other number in the asked state's rows of the MACStats data book, 2018–2025 |
129
+
130
+ ```bash
131
+ cd examples/medicaid
132
+ python run_example.py
133
+ ```
134
+
135
+ The input tables are included (`build_tables.py` rebuilds them from the original paper's supplementary materials), and `run_example.py` shows how to set reference levels with `level_by_shift` and limit rules with `scope`. The test suite checks that the output equals the paper's Table 3 and that Rule 7 reproduces the local perturbation baseline of the Medicaid instance.
136
+
137
+ ## Citation
138
+
139
+ `gtfeng.cite()` returns the BibTeX entry (`gtfeng.cite("text")` a plain reference), and `result.report_markdown()` signs every report with "Evaluated with GT-FENG v0.1.0 (Feng, 2026)." If you use GT-FENG, please cite:
140
+
141
+ ```bibtex
142
+ @article{feng2026gtfeng,
143
+ title = {GT-FENG: General Theory of Factual Evaluation and Normative Grounding in Language Models},
144
+ author = {Feng, Jiayu},
145
+ journal = {arXiv preprint arXiv:2611.18279},
146
+ year = {2026},
147
+ url = {https://arxiv.org/abs/2611.18279}
148
+ }
149
+ ```
150
+
151
+ ## License
152
+
153
+ The code is licensed under the [Apache License 2.0](https://github.com/VonFlair/gtfeng/blob/main/LICENSE). Anyone who redistributes it, modified or not, must keep the `LICENSE` and `NOTICE` files, which carry the GT-FENG name and its author. The license grants no right to use the name GT-FENG for other products.
154
+
155
+ The example data in `examples/medicaid/` are licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The gold values are derived from MACPAC MACStats Exhibits 35–36.
gtfeng-0.1.0/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # gtfeng
2
+
3
+ **GT-FENG (General Theory of Factual Evaluation and Normative Grounding)** evaluates language-model answers about facts whose correct value is set by a rule: an income limit, a filing deadline, a legal duty. The same answer can be right under one jurisdiction, date, or definition and wrong under another. `gtfeng` scores each answer against the rule that applies and lists every documented rule that matches a wrong answer. Paper: [arXiv:2611.18279](https://arxiv.org/abs/2611.18279).
4
+
5
+ Use it when you evaluate model answers about numbers, dates, or yes/no facts set by law or policy, and you want to know whether a wrong answer is the correct value for another state, another year, or another definition.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install gtfeng # from PyPI
11
+ pip install . # from a clone of this repository
12
+ ```
13
+
14
+ Requires Python 3.9+ and pandas.
15
+
16
+ ## Quick start
17
+
18
+ ```python
19
+ import pandas as pd
20
+ import gtfeng
21
+
22
+ references = pd.DataFrame(
23
+ [("limit", "A", 2025, "x", 50), ("limit", "A", 2018, "x", 40), ("limit", "B", 2025, "x", 40)],
24
+ columns=["quantity", "jurisdiction", "time", "definition", "value"])
25
+ answers = pd.DataFrame(
26
+ [{"model": "m", "quantity": "limit", "jurisdiction": "A", "time": 2025, "definition": "x", "answer": 40}])
27
+
28
+ result = gtfeng.evaluate(answers, references, groups=["model"])
29
+ result.items[["jurisdiction", "answer", "label", "n_sources"]]
30
+ # jurisdiction answer label n_sources
31
+ # A 40 ambiguous {J, T} 2
32
+ result.report(families={"cross_jurisdiction": ["J", "JD"]})
33
+ ```
34
+
35
+ The answer 40 is wrong for A in 2025. It matches B's current rule (shift **J**, another jurisdiction) and A's 2018 rule (shift **T**, another time), so GT-FENG labels it ambiguous and reports both sources.
36
+
37
+ ## Key terms
38
+
39
+ | Term | Meaning | Example (quick start) |
40
+ |---|---|---|
41
+ | match | a documented rule, other than the one asked about, that gives the same value as a wrong answer | 40 matches B's 2025 rule and A's 2018 rule |
42
+ | U | a wrong answer with no match | an answer of 45 |
43
+ | shift | the coordinates in which a match differs from the question, written as their initials | B 2025 has shift J (another jurisdiction); A 2018 has shift T (another time) |
44
+ | source | where a match comes from; matches that differ only in year count as one source | A's 2018 and A's 2021 rules would be one source |
45
+ | reference level | how many documented rules a wrong answer is checked against; R1 is the smallest set, and each later level adds rules. Set with the `level` column or `level_by_shift` (default: everything at R1) | in the Medicaid example, R1 holds other states' current limits and R2 adds the asked state's earlier ones |
46
+ | ambiguous | the matches have two or more different shifts (shift ambiguity); matches from two or more sources are source ambiguity | 40 is `ambiguous {J, T}` |
47
+ | family | a set of shifts treated as one kind of error | {J, JD}: the value belongs to another jurisdiction |
48
+ | grounded in a family | every match of the wrong answer has a shift in the family | 40 is not grounded in {J, JD}, because its match A 2018 has shift T |
49
+
50
+ ## Inputs
51
+
52
+ | Table | Required columns | Optional columns |
53
+ |---|---|---|
54
+ | `references` | the coordinates (default `quantity`, `jurisdiction`, `time`, `definition`) and `value` | `level` (reference level, default 1); scope columns |
55
+ | `answers` | the coordinates and `answer` | group columns such as `model`; repeated rows for repeated responses |
56
+
57
+ Coordinates are configurable (`coordinates=[...]`); each must have a distinct initial, which names its shift. Values can be numbers, Booleans, strings, or lists compared as sets.
58
+
59
+ ## What it computes
60
+
61
+ Rule numbers follow the [GT-FENG paper](https://arxiv.org/abs/2611.18279).
62
+
63
+ | Paper | `gtfeng` |
64
+ |---|---|
65
+ | Stability | an item enters only when all repeats give the same answer (`result.unstable` lists the rest) |
66
+ | Rule 1, correct | `label == "correct"` |
67
+ | Rules 2–3, matches and U | `matches`; `label == "U"` when nothing matches |
68
+ | Rule 4, shift | `shifts`, e.g. `J`, `T`, `JD`, `JT` |
69
+ | Rule 5, label and ambiguity | single shift, or `ambiguous {...}` (shift ambiguity); `n_sources` counts distinct sources, so source ambiguity is `n_sources >= 2` (documented rules that differ only in time are one source) |
70
+ | Rule 6, reference levels | `level` column (level k means R_k); extension `level_by_shift`, e.g. `{"T": 2}` holds matches with shift T back until level 2 |
71
+ | Rule 7, local perturbation baseline | `result.feng_value(family)`: O, N, E, the FENG value, and p |
72
+ | Standard report | `result.report(families=...)`: correct, U, single-shift labels, shift-ambiguous, source-ambiguous, mean sources per matched item, and O for each family |
73
+
74
+ Extension `scope={"ref_column": "answer_coordinate"}` restricts a documented rule to items whose coordinate equals the rule's value in that column.
75
+
76
+ ## Rule 7 and the FENG value
77
+
78
+ For a family of shifts F, `result.feng_value(F)` compares how often wrong answers are grounded in F with how often nearby values are:
79
+
80
+ ```python
81
+ result.feng_value(["J", "JD"]) # one row per group and reference level
82
+ # W O N E feng_value p
83
+ ```
84
+
85
+ | Column | Meaning |
86
+ |---|---|
87
+ | `W` | wrong items |
88
+ | `O` | wrong items grounded in F (they have matches, and every match has a shift in F) |
89
+ | `N` | local perturbation baseline: each wrong answer A is replaced by A + i for every increment i (default ±1 to ±4; increments that reach the correct value are dropped), and N sums each item's share of nearby values grounded in F |
90
+ | `E` | O − N |
91
+ | `feng_value` | (O − N) / (W − N); NaN when N ≥ W |
92
+ | `p` | share of random perturbations (one increment per item) whose grounded count reaches O |
93
+
94
+ The FENG value is 0 when wrong answers are grounded in F as often as nearby values, 1 when every wrong answer is grounded in F, and negative when nearby values are grounded more often. It has the chance-corrected form of Cohen's kappa; the match event and the local baseline come from GT-FENG. Rule 7 needs numeric answers, and the increments must leave out any known definition shift (the Medicaid example leaves out 5).
95
+
96
+ Report the FENG value next to accuracy: it describes the structure of wrong answers and does not rank models.
97
+
98
+ ## Example: Medicaid income limits
99
+
100
+ [`examples/medicaid/`](https://github.com/VonFlair/gtfeng/tree/main/examples/medicaid) (in the GitHub repository) reproduces the paper's Medicaid instance (two models, 51 jurisdictions, three quantities). Its four reference levels follow the paper's Table 2:
101
+
102
+ | Level | A wrong answer is also checked against |
103
+ |---|---|
104
+ | R1 | other states' July 2025 limits, with and without the 5-point income disregard |
105
+ | R2 | the asked state's own limit under the other definition, three earlier editions, and the federal anchors 100, 133 and 138 (percent of the federal poverty level) |
106
+ | R3 | every edition of the asked state's limits, 2018–2024 |
107
+ | R4 | every other number in the asked state's rows of the MACStats data book, 2018–2025 |
108
+
109
+ ```bash
110
+ cd examples/medicaid
111
+ python run_example.py
112
+ ```
113
+
114
+ The input tables are included (`build_tables.py` rebuilds them from the original paper's supplementary materials), and `run_example.py` shows how to set reference levels with `level_by_shift` and limit rules with `scope`. The test suite checks that the output equals the paper's Table 3 and that Rule 7 reproduces the local perturbation baseline of the Medicaid instance.
115
+
116
+ ## Citation
117
+
118
+ `gtfeng.cite()` returns the BibTeX entry (`gtfeng.cite("text")` a plain reference), and `result.report_markdown()` signs every report with "Evaluated with GT-FENG v0.1.0 (Feng, 2026)." If you use GT-FENG, please cite:
119
+
120
+ ```bibtex
121
+ @article{feng2026gtfeng,
122
+ title = {GT-FENG: General Theory of Factual Evaluation and Normative Grounding in Language Models},
123
+ author = {Feng, Jiayu},
124
+ journal = {arXiv preprint arXiv:2611.18279},
125
+ year = {2026},
126
+ url = {https://arxiv.org/abs/2611.18279}
127
+ }
128
+ ```
129
+
130
+ ## License
131
+
132
+ The code is licensed under the [Apache License 2.0](https://github.com/VonFlair/gtfeng/blob/main/LICENSE). Anyone who redistributes it, modified or not, must keep the `LICENSE` and `NOTICE` files, which carry the GT-FENG name and its author. The license grants no right to use the name GT-FENG for other products.
133
+
134
+ The example data in `examples/medicaid/` are licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The gold values are derived from MACPAC MACStats Exhibits 35–36.
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gtfeng"
7
+ version = "0.1.0"
8
+ description = "GT-FENG (General Theory of Factual Evaluation and Normative Grounding): evaluate language-model answers about rule-governed facts"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ authors = [{ name = "Jiayu Feng" }]
14
+ dependencies = ["pandas>=1.5", "numpy"]
15
+ keywords = ["language models", "evaluation", "factuality", "law", "policy", "temporal", "jurisdiction"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Intended Audience :: Science/Research",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/VonFlair/gtfeng"
24
+ Paper = "https://arxiv.org/abs/2611.18279"
25
+ "Medicaid study" = "https://arxiv.org/abs/2610.09458"
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
gtfeng-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,27 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jiayu Feng
3
+ """GT-FENG: General Theory of Factual Evaluation and Normative Grounding.
4
+
5
+ import gtfeng
6
+ result = gtfeng.evaluate(answers, references, groups=["model"])
7
+ result.report(families={"cross_jurisdiction": ["J", "JD"]})
8
+ result.feng_value(["J", "JD"]) # Rule 7 and the FENG value
9
+ print(gtfeng.cite()) # BibTeX for the GT-FENG paper
10
+
11
+ Modules, in the order of the paper:
12
+ values how an answer and a gold value are compared
13
+ references the reference set R of documented rules
14
+ rules Rules 1-6, one function each
15
+ core evaluate(): runs the rules on every stable item
16
+ baseline Rule 7 (local perturbation baseline) and the FENG value
17
+ report the standard report and citation helpers
18
+ """
19
+ from .baseline import DEFAULT_INCREMENTS
20
+ from .core import DEFAULT_COORDINATES, Result, evaluate
21
+ from .report import VERSION, cite
22
+ from .rules import AMBIGUOUS, CORRECT, UNMATCHED
23
+ from .values import normalize
24
+
25
+ __version__ = VERSION
26
+ __all__ = ["evaluate", "cite", "Result", "normalize", "DEFAULT_COORDINATES", "CORRECT", "UNMATCHED", "AMBIGUOUS",
27
+ "DEFAULT_INCREMENTS", "__version__"]
@@ -0,0 +1,95 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jiayu Feng
3
+ """Rule 7 (local perturbation baseline) and the FENG value.
4
+
5
+ For a family F (a set of shifts, e.g. {"J", "JD"} for another jurisdiction):
6
+
7
+ W wrong items at a reference level
8
+ O wrong items grounded in F: they have matches, and every shift in M belongs to F
9
+ N the number of grounded items that nearby values produce. Each wrong answer A is replaced by A + i for every
10
+ increment i in I; increments that reach the correct value are dropped for that item. N is the sum over wrong
11
+ items of the share of nearby values that are grounded in F.
12
+ E = O - N, the excess over the baseline
13
+ p the share of random perturbations (one increment per item, drawn independently) whose grounded count
14
+ reaches O
15
+
16
+ FENG value = (O - N) / (W - N)
17
+
18
+ The FENG value is 0 when wrong answers are grounded in F as often as nearby values are, 1 when every wrong answer
19
+ is grounded in F, and negative when they are grounded less often than nearby values. It has the chance-corrected
20
+ form of Cohen's kappa; the match event and the local baseline come from GT-FENG.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ from typing import Iterable, Sequence
25
+
26
+ import numpy as np
27
+ import pandas as pd
28
+
29
+ from .rules import CORRECT, find_matches
30
+
31
+ # Increments must leave out any known definition shift. The Medicaid instance leaves out 5 (the 5% disregard).
32
+ DEFAULT_INCREMENTS = (-4, -3, -2, -1, 1, 2, 3, 4)
33
+
34
+
35
+ def _grounded(shifts: Iterable[str], family: frozenset) -> bool:
36
+ shifts = set(shifts)
37
+ return bool(shifts) and shifts <= family
38
+
39
+
40
+ def feng_values(result, family: Iterable[str], *, increments: Sequence[float] = DEFAULT_INCREMENTS,
41
+ permutations: int = 10000, seed: int = 0) -> pd.DataFrame:
42
+ """Rule 7 and the FENG value, one row per group and reference level. Numeric answers only."""
43
+ context = result._context
44
+ if context is None:
45
+ raise ValueError("this Result was not produced by gtfeng.evaluate")
46
+ family = frozenset(family)
47
+ increments = [i for i in increments if i != 0]
48
+ if not increments:
49
+ raise ValueError("increments must contain at least one nonzero value")
50
+ references = context["references"]
51
+ coordinates = context["coordinates"]
52
+ item_columns = list(result.groups) + coordinates
53
+ rng = np.random.default_rng(seed)
54
+
55
+ # Nearby values of each wrong item, with their matches (computed once, then filtered by level).
56
+ nearby = {}
57
+ wrong_rows = result.items[result.items.label != CORRECT]
58
+ for row in wrong_rows.drop_duplicates(item_columns).to_dict("records"):
59
+ answer = row["answer"]
60
+ if isinstance(answer, bool) or not isinstance(answer, (int, float, np.integer, np.floating)):
61
+ raise ValueError(f"Rule 7 needs numeric answers; got {answer!r} for {row}")
62
+ item = {c: row[c] for c in item_columns}
63
+ asked_index = tuple(row[c] for c in coordinates)
64
+ gold = references.gold(asked_index)
65
+ values = []
66
+ for i in increments:
67
+ key = context["compare"](float(answer) + i)
68
+ if key == gold: # an increment that reaches the correct value is dropped for this item
69
+ continue
70
+ values.append(find_matches(key, item, asked_index, references, coordinates,
71
+ context["initials"], context["level_by_shift"]))
72
+ nearby[tuple(item.values())] = values
73
+
74
+ rows = []
75
+ keys = list(result.groups) + ["level"]
76
+ for key_values, group in result.items.groupby(keys, sort=True):
77
+ key_values = key_values if isinstance(key_values, tuple) else (key_values,)
78
+ level = key_values[-1]
79
+ wrong = group[group.label != CORRECT]
80
+ observed = int(sum(_grounded(s, family) for s in wrong.shifts))
81
+ hits = []
82
+ for row in wrong[item_columns].itertuples(index=False, name=None):
83
+ hits.append(np.array([_grounded({m.shift for m in ms if m.level <= level}, family)
84
+ for ms in nearby[tuple(row)]], dtype=float))
85
+ null = float(sum(h.mean() for h in hits if len(h)))
86
+ draws = np.zeros(permutations)
87
+ for h in hits:
88
+ if len(h):
89
+ draws += h[rng.integers(len(h), size=permutations)]
90
+ n_wrong = len(wrong)
91
+ rows.append({**dict(zip(keys, key_values)),
92
+ "W": n_wrong, "O": observed, "N": round(null, 2), "E": round(observed - null, 2),
93
+ "feng_value": round((observed - null) / (n_wrong - null), 3) if n_wrong > null else float("nan"),
94
+ "p": float((draws >= observed).mean())})
95
+ return pd.DataFrame(rows)