policywinds-labeler 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.
- policywinds_labeler-0.1.0/LICENSE +201 -0
- policywinds_labeler-0.1.0/PKG-INFO +114 -0
- policywinds_labeler-0.1.0/README.md +93 -0
- policywinds_labeler-0.1.0/pyproject.toml +67 -0
- policywinds_labeler-0.1.0/pyproject.toml.orig +51 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/__init__.py +19 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/label.py +224 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/llm/__init__.py +14 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/llm/prices.py +63 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/llm/providers.py +229 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/llm/schema.py +57 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/llm/types.py +82 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/prefilter.py +93 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/text.py +138 -0
- policywinds_labeler-0.1.0/src/policywinds_labeler/topics.py +316 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: policywinds-labeler
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Labels US bills by policy topic and by which way they move each topic's fixed measure, with checked quotes
|
|
5
|
+
Author: Kernelcraft LLC
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Requires-Dist: anthropic>=2.12.0
|
|
12
|
+
Requires-Dist: httpx>=0.28
|
|
13
|
+
Requires-Dist: openai>=1.60
|
|
14
|
+
Requires-Dist: pydantic>=2.10
|
|
15
|
+
Requires-Dist: pypdf>=7.0.1
|
|
16
|
+
Requires-Python: >=3.13
|
|
17
|
+
Project-URL: Homepage, https://policywinds.com
|
|
18
|
+
Project-URL: Source, https://github.com/policywinds/labeler
|
|
19
|
+
Project-URL: Issues, https://github.com/policywinds/labeler/issues
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# PolicyWinds labeler
|
|
23
|
+
|
|
24
|
+
The labeling engine behind [PolicyWinds](https://policywinds.com), which tracks U.S. state and federal bills on
|
|
25
|
+
firearms, transgender issues, abortion, immigration enforcement, and child custody and support.
|
|
26
|
+
|
|
27
|
+
For each bill a language model reads, the labeler returns which topics the bill really touches and, for each one,
|
|
28
|
+
**which way the bill moves that topic's fixed measure**: `expands`, `restricts`, `mixed` or `neutral`. Every
|
|
29
|
+
answer comes with a short quote from the bill, and the quote is checked against the bill's text.
|
|
30
|
+
|
|
31
|
+
Labels are produced by AI. The site's owner reviews labels, and a review always overrides the model; labels
|
|
32
|
+
that have not been reviewed are marked as AI labels on the site.
|
|
33
|
+
|
|
34
|
+
## The measures
|
|
35
|
+
|
|
36
|
+
Each topic has one fixed measure, worded so that "expands" and "restricts" do not take a side:
|
|
37
|
+
|
|
38
|
+
| Topic | "Expands" and "restricts" refer to |
|
|
39
|
+
|---|---|
|
|
40
|
+
| firearms | the ability to buy, own, carry or make firearms and accessories |
|
|
41
|
+
| transgender | legal recognition of, and access to services and facilities for, transgender people |
|
|
42
|
+
| abortion | legal access to abortion |
|
|
43
|
+
| immigration-enforcement | the scope of immigration enforcement |
|
|
44
|
+
| custody-support | the rights of the parent who pays support or has less custody, against the obligations placed on that parent |
|
|
45
|
+
|
|
46
|
+
A bill that requires more background checks therefore *restricts* firearms; a bill that bans sanctuary policies
|
|
47
|
+
*expands* immigration enforcement. The full definitions, subtags and scope rules are in
|
|
48
|
+
`src/policywinds_labeler/topics.py`; the prompt is in `src/policywinds_labeler/label.py`.
|
|
49
|
+
|
|
50
|
+
## What the code does
|
|
51
|
+
|
|
52
|
+
| Module | Job |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `topics` | Topics, subtags, definitions, keywords, scope exclusions and the measure of each topic |
|
|
55
|
+
| `prefilter` | Keyword filter on the title (which bills a model reads) and the text windows it is shown |
|
|
56
|
+
| `text` | Plain text from official HTML, XML or PDF; struck-out law is kept and marked `[deleted: ...]` |
|
|
57
|
+
| `label` | The prompt, the request message and the checks on every answer: quotes must appear in the text, custody labels need the topic's keywords in the title, duplicate tags are merged, stray foreign-script text is retried |
|
|
58
|
+
| `llm` | Answer schema, provider adapters (Anthropic, OpenAI, xAI), prices |
|
|
59
|
+
|
|
60
|
+
The model never decides alone what counts: an answer whose quote is not in the bill is marked unverified, and for
|
|
61
|
+
topics that need it (`REQUIRES_KEYWORD`: custody and support), a label is dropped when the topic's keywords are not
|
|
62
|
+
in the bill's title or description.
|
|
63
|
+
|
|
64
|
+
## Use it
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
uv sync
|
|
68
|
+
uv run pytest # unit tests, no keys needed
|
|
69
|
+
cd eval && uv run python fetch_texts.py && ANTHROPIC_API_KEY=... uv run python run_eval.py
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from policywinds_labeler.label import system_prompt, user_message, verify_quotes
|
|
74
|
+
from policywinds_labeler.llm.providers import get_provider
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Keys are read from `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` or `XAI_API_KEY`, or from any function passed as
|
|
78
|
+
`get_provider(name, secret=...)`.
|
|
79
|
+
|
|
80
|
+
## The eval
|
|
81
|
+
|
|
82
|
+
`eval/` holds checks with known answers on real bills, the official texts, and the harness. See
|
|
83
|
+
`eval/README.md`. Any change to the prompt, keywords or model must run it first.
|
|
84
|
+
|
|
85
|
+
## How the model was chosen
|
|
86
|
+
|
|
87
|
+
PolicyWinds labels with Claude Sonnet 5.5 (`claude-sonnet-5-5`), chosen from a test of 13 models on the eval set
|
|
88
|
+
(2026-11-21): it had 2 real errors on 44 checks, at 3.3 seconds a bill. Any model the provider adapters support
|
|
89
|
+
can be compared with `eval/run_eval.py --provider P --model M`.
|
|
90
|
+
|
|
91
|
+
## Versions
|
|
92
|
+
|
|
93
|
+
The package version follows semantic versioning, read for labels:
|
|
94
|
+
|
|
95
|
+
- **Minor** (0.1.0 -> 0.2.0, while the version is 0.x): anything that can change labels. That is the prompt, topics,
|
|
96
|
+
definitions, keywords, scope exclusions, the answer schema, or the checks on answers.
|
|
97
|
+
- **Patch** (0.1.0 -> 0.1.1): changes that cannot change labels, such as provider adapters, prices, docs or tests.
|
|
98
|
+
|
|
99
|
+
The prompt has its own number, `policywinds_labeler.label.PROMPT_VERSION`. Every release note names it, and
|
|
100
|
+
`eval/results/` keeps that release's eval output.
|
|
101
|
+
|
|
102
|
+
| Release | Prompt | Eval (claude-sonnet-5-5) |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| 0.1.0 | v9 | `eval/results/0.1.0.txt` |
|
|
105
|
+
|
|
106
|
+
## Wrong label?
|
|
107
|
+
|
|
108
|
+
Open an issue with the bill, the tag, the label and what you think it should be, quoting the bill's text.
|
|
109
|
+
Confirmed cases become new eval checks.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
Code: Apache-2.0 (`LICENSE`). Eval checks: CC BY 4.0 (`eval/LICENSE`).
|
|
114
|
+
Copyright 2026 Kernelcraft LLC, which publishes PolicyWinds.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# PolicyWinds labeler
|
|
2
|
+
|
|
3
|
+
The labeling engine behind [PolicyWinds](https://policywinds.com), which tracks U.S. state and federal bills on
|
|
4
|
+
firearms, transgender issues, abortion, immigration enforcement, and child custody and support.
|
|
5
|
+
|
|
6
|
+
For each bill a language model reads, the labeler returns which topics the bill really touches and, for each one,
|
|
7
|
+
**which way the bill moves that topic's fixed measure**: `expands`, `restricts`, `mixed` or `neutral`. Every
|
|
8
|
+
answer comes with a short quote from the bill, and the quote is checked against the bill's text.
|
|
9
|
+
|
|
10
|
+
Labels are produced by AI. The site's owner reviews labels, and a review always overrides the model; labels
|
|
11
|
+
that have not been reviewed are marked as AI labels on the site.
|
|
12
|
+
|
|
13
|
+
## The measures
|
|
14
|
+
|
|
15
|
+
Each topic has one fixed measure, worded so that "expands" and "restricts" do not take a side:
|
|
16
|
+
|
|
17
|
+
| Topic | "Expands" and "restricts" refer to |
|
|
18
|
+
|---|---|
|
|
19
|
+
| firearms | the ability to buy, own, carry or make firearms and accessories |
|
|
20
|
+
| transgender | legal recognition of, and access to services and facilities for, transgender people |
|
|
21
|
+
| abortion | legal access to abortion |
|
|
22
|
+
| immigration-enforcement | the scope of immigration enforcement |
|
|
23
|
+
| custody-support | the rights of the parent who pays support or has less custody, against the obligations placed on that parent |
|
|
24
|
+
|
|
25
|
+
A bill that requires more background checks therefore *restricts* firearms; a bill that bans sanctuary policies
|
|
26
|
+
*expands* immigration enforcement. The full definitions, subtags and scope rules are in
|
|
27
|
+
`src/policywinds_labeler/topics.py`; the prompt is in `src/policywinds_labeler/label.py`.
|
|
28
|
+
|
|
29
|
+
## What the code does
|
|
30
|
+
|
|
31
|
+
| Module | Job |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `topics` | Topics, subtags, definitions, keywords, scope exclusions and the measure of each topic |
|
|
34
|
+
| `prefilter` | Keyword filter on the title (which bills a model reads) and the text windows it is shown |
|
|
35
|
+
| `text` | Plain text from official HTML, XML or PDF; struck-out law is kept and marked `[deleted: ...]` |
|
|
36
|
+
| `label` | The prompt, the request message and the checks on every answer: quotes must appear in the text, custody labels need the topic's keywords in the title, duplicate tags are merged, stray foreign-script text is retried |
|
|
37
|
+
| `llm` | Answer schema, provider adapters (Anthropic, OpenAI, xAI), prices |
|
|
38
|
+
|
|
39
|
+
The model never decides alone what counts: an answer whose quote is not in the bill is marked unverified, and for
|
|
40
|
+
topics that need it (`REQUIRES_KEYWORD`: custody and support), a label is dropped when the topic's keywords are not
|
|
41
|
+
in the bill's title or description.
|
|
42
|
+
|
|
43
|
+
## Use it
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
uv sync
|
|
47
|
+
uv run pytest # unit tests, no keys needed
|
|
48
|
+
cd eval && uv run python fetch_texts.py && ANTHROPIC_API_KEY=... uv run python run_eval.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from policywinds_labeler.label import system_prompt, user_message, verify_quotes
|
|
53
|
+
from policywinds_labeler.llm.providers import get_provider
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Keys are read from `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` or `XAI_API_KEY`, or from any function passed as
|
|
57
|
+
`get_provider(name, secret=...)`.
|
|
58
|
+
|
|
59
|
+
## The eval
|
|
60
|
+
|
|
61
|
+
`eval/` holds checks with known answers on real bills, the official texts, and the harness. See
|
|
62
|
+
`eval/README.md`. Any change to the prompt, keywords or model must run it first.
|
|
63
|
+
|
|
64
|
+
## How the model was chosen
|
|
65
|
+
|
|
66
|
+
PolicyWinds labels with Claude Sonnet 5.5 (`claude-sonnet-5-5`), chosen from a test of 13 models on the eval set
|
|
67
|
+
(2026-11-21): it had 2 real errors on 44 checks, at 3.3 seconds a bill. Any model the provider adapters support
|
|
68
|
+
can be compared with `eval/run_eval.py --provider P --model M`.
|
|
69
|
+
|
|
70
|
+
## Versions
|
|
71
|
+
|
|
72
|
+
The package version follows semantic versioning, read for labels:
|
|
73
|
+
|
|
74
|
+
- **Minor** (0.1.0 -> 0.2.0, while the version is 0.x): anything that can change labels. That is the prompt, topics,
|
|
75
|
+
definitions, keywords, scope exclusions, the answer schema, or the checks on answers.
|
|
76
|
+
- **Patch** (0.1.0 -> 0.1.1): changes that cannot change labels, such as provider adapters, prices, docs or tests.
|
|
77
|
+
|
|
78
|
+
The prompt has its own number, `policywinds_labeler.label.PROMPT_VERSION`. Every release note names it, and
|
|
79
|
+
`eval/results/` keeps that release's eval output.
|
|
80
|
+
|
|
81
|
+
| Release | Prompt | Eval (claude-sonnet-5-5) |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| 0.1.0 | v9 | `eval/results/0.1.0.txt` |
|
|
84
|
+
|
|
85
|
+
## Wrong label?
|
|
86
|
+
|
|
87
|
+
Open an issue with the bill, the tag, the label and what you think it should be, quoting the bill's text.
|
|
88
|
+
Confirmed cases become new eval checks.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
Code: Apache-2.0 (`LICENSE`). Eval checks: CC BY 4.0 (`eval/LICENSE`).
|
|
93
|
+
Copyright 2026 Kernelcraft LLC, which publishes PolicyWinds.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "policywinds-labeler"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Labels US bills by policy topic and by which way they move each topic's fixed measure, with checked quotes"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.13"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"anthropic>=2.12.0",
|
|
11
|
+
"httpx>=0.28",
|
|
12
|
+
"openai>=1.60",
|
|
13
|
+
"pydantic>=2.10",
|
|
14
|
+
"pypdf>=7.0.1",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Text Processing :: Linguistic",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[[project.authors]]
|
|
23
|
+
name = "Kernelcraft LLC"
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://policywinds.com"
|
|
27
|
+
Source = "https://github.com/policywinds/labeler"
|
|
28
|
+
Issues = "https://github.com/policywinds/labeler/issues"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=9.2.0",
|
|
33
|
+
"ruff>=0.17.4",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.uv.build-backend]
|
|
37
|
+
module-name = "policywinds_labeler"
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 120
|
|
41
|
+
target-version = "py313"
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint]
|
|
44
|
+
select = [
|
|
45
|
+
"E",
|
|
46
|
+
"F",
|
|
47
|
+
"I",
|
|
48
|
+
"B",
|
|
49
|
+
"UP",
|
|
50
|
+
"S",
|
|
51
|
+
"BLE",
|
|
52
|
+
]
|
|
53
|
+
ignore = [
|
|
54
|
+
"S101",
|
|
55
|
+
"E501",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[tool.ruff.lint.per-file-ignores]
|
|
59
|
+
"tests/**" = ["S"]
|
|
60
|
+
"eval/**" = ["S"]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
|
|
65
|
+
[build-system]
|
|
66
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
67
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "policywinds-labeler"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Labels US bills by policy topic and by which way they move each topic's fixed measure, with checked quotes"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Kernelcraft LLC" }]
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"anthropic>=2.12.0",
|
|
12
|
+
"httpx>=0.28",
|
|
13
|
+
"openai>=1.60",
|
|
14
|
+
"pydantic>=2.10",
|
|
15
|
+
"pypdf>=7.0.1",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Text Processing :: Linguistic",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://policywinds.com"
|
|
25
|
+
Source = "https://github.com/policywinds/labeler"
|
|
26
|
+
Issues = "https://github.com/policywinds/labeler/issues"
|
|
27
|
+
|
|
28
|
+
[dependency-groups]
|
|
29
|
+
dev = ["pytest>=9.2.0", "ruff>=0.17.4"]
|
|
30
|
+
|
|
31
|
+
[tool.uv.build-backend]
|
|
32
|
+
module-name = "policywinds_labeler"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
36
|
+
build-backend = "uv_build"
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 120
|
|
40
|
+
target-version = "py313"
|
|
41
|
+
|
|
42
|
+
[tool.ruff.lint]
|
|
43
|
+
select = ["E", "F", "I", "B", "UP", "S", "BLE"]
|
|
44
|
+
ignore = ["S101", "E501"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint.per-file-ignores]
|
|
47
|
+
"tests/**" = ["S"]
|
|
48
|
+
"eval/**" = ["S"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright 2026 Kernelcraft LLC (PolicyWinds)
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
"""PolicyWinds labeling engine: topics with fixed direction measures, a keyword filter, the labeling prompt, the
|
|
17
|
+
checks on every answer, and adapters for the model providers (docs: README)."""
|
|
18
|
+
|
|
19
|
+
__version__ = "0.1.0"
|