idealens 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.
- idealens-0.1.0/LICENSE +201 -0
- idealens-0.1.0/PKG-INFO +243 -0
- idealens-0.1.0/README.md +199 -0
- idealens-0.1.0/pyproject.toml +51 -0
- idealens-0.1.0/setup.cfg +4 -0
- idealens-0.1.0/src/idealens/__init__.py +25 -0
- idealens-0.1.0/src/idealens/assets/__init__.py +17 -0
- idealens-0.1.0/src/idealens/assets/classifier.json +51 -0
- idealens-0.1.0/src/idealens/assets/extraction.json +1221 -0
- idealens-0.1.0/src/idealens/assets/usage_stats.json +202 -0
- idealens-0.1.0/src/idealens/backends/__init__.py +30 -0
- idealens-0.1.0/src/idealens/backends/classifier.py +99 -0
- idealens-0.1.0/src/idealens/backends/hf.py +92 -0
- idealens-0.1.0/src/idealens/backends/logistic.py +49 -0
- idealens-0.1.0/src/idealens/backends/tinker.py +54 -0
- idealens-0.1.0/src/idealens/backends/tinker_merge.py +48 -0
- idealens-0.1.0/src/idealens/backends/vllm.py +121 -0
- idealens-0.1.0/src/idealens/calibrate.py +154 -0
- idealens-0.1.0/src/idealens/classify.py +147 -0
- idealens-0.1.0/src/idealens/cli.py +386 -0
- idealens-0.1.0/src/idealens/cost.py +244 -0
- idealens-0.1.0/src/idealens/detector.py +182 -0
- idealens-0.1.0/src/idealens/extract.py +84 -0
- idealens-0.1.0/src/idealens/formats.py +131 -0
- idealens-0.1.0/src/idealens/outline.py +90 -0
- idealens-0.1.0/src/idealens/parse.py +91 -0
- idealens-0.1.0/src/idealens/pipeline.py +78 -0
- idealens-0.1.0/src/idealens/prompts.py +86 -0
- idealens-0.1.0/src/idealens/providers/__init__.py +60 -0
- idealens-0.1.0/src/idealens/providers/anthropic.py +138 -0
- idealens-0.1.0/src/idealens/providers/gemini.py +218 -0
- idealens-0.1.0/src/idealens/providers/openai_compat.py +232 -0
- idealens-0.1.0/src/idealens/registry.py +91 -0
- idealens-0.1.0/src/idealens/runner.py +26 -0
- idealens-0.1.0/src/idealens/thresholds.py +170 -0
- idealens-0.1.0/src/idealens.egg-info/PKG-INFO +243 -0
- idealens-0.1.0/src/idealens.egg-info/SOURCES.txt +43 -0
- idealens-0.1.0/src/idealens.egg-info/dependency_links.txt +1 -0
- idealens-0.1.0/src/idealens.egg-info/entry_points.txt +2 -0
- idealens-0.1.0/src/idealens.egg-info/requires.txt +33 -0
- idealens-0.1.0/src/idealens.egg-info/top_level.txt +1 -0
- idealens-0.1.0/tests/test_calibrate.py +87 -0
- idealens-0.1.0/tests/test_core.py +241 -0
- idealens-0.1.0/tests/test_llm_steps.py +139 -0
- idealens-0.1.0/tests/test_providers.py +188 -0
idealens-0.1.0/LICENSE
ADDED
|
@@ -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.
|
idealens-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: idealens
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Detect whether a document's ideas came from a person or an AI model (IdeaLens), and related detectors.
|
|
5
|
+
Author: Rishanth Rajendhran
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/RishanthRajendhran/IdeaLens
|
|
8
|
+
Project-URL: Source, https://github.com/RishanthRajendhran/IdeaLens
|
|
9
|
+
Project-URL: Model, https://huggingface.co/rishanthrajendhran/IdeaLens
|
|
10
|
+
Project-URL: Corpus, https://huggingface.co/datasets/rishanthrajendhran/WildOutlines
|
|
11
|
+
Keywords: ai-text-detection,idea-provenance,machine-generated-text
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: numpy>=1.24
|
|
19
|
+
Requires-Dist: huggingface_hub>=0.30
|
|
20
|
+
Provides-Extra: hf
|
|
21
|
+
Requires-Dist: torch>=2.4; extra == "hf"
|
|
22
|
+
Requires-Dist: transformers>=5.15; extra == "hf"
|
|
23
|
+
Requires-Dist: safetensors>=0.4; extra == "hf"
|
|
24
|
+
Requires-Dist: accelerate>=1.0; extra == "hf"
|
|
25
|
+
Provides-Extra: vllm
|
|
26
|
+
Requires-Dist: vllm==0.21.*; extra == "vllm"
|
|
27
|
+
Requires-Dist: transformers>=5.15; extra == "vllm"
|
|
28
|
+
Requires-Dist: xgrammar==0.2.1; extra == "vllm"
|
|
29
|
+
Provides-Extra: vertex
|
|
30
|
+
Requires-Dist: google-auth>=2.20; extra == "vertex"
|
|
31
|
+
Requires-Dist: google-cloud-storage>=2.10; extra == "vertex"
|
|
32
|
+
Provides-Extra: openai
|
|
33
|
+
Requires-Dist: openai>=1.40; extra == "openai"
|
|
34
|
+
Provides-Extra: anthropic
|
|
35
|
+
Requires-Dist: anthropic>=1.0; extra == "anthropic"
|
|
36
|
+
Provides-Extra: weborganizer
|
|
37
|
+
Requires-Dist: torch>=2.4; extra == "weborganizer"
|
|
38
|
+
Requires-Dist: transformers>=5.15; extra == "weborganizer"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Requires-Dist: idealens[anthropic,hf,openai,vertex,vllm,weborganizer]; extra == "all"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# idealens
|
|
46
|
+
|
|
47
|
+
`idealens` detects whether a document's **ideas** came from a person or an AI model, whoever wrote the words. It runs
|
|
48
|
+
the IdeaLens pipeline end to end:
|
|
49
|
+
|
|
50
|
+
1. **Classify** the document into one of eight long-form formats (an LLM with WebOrganizer's annotation prompt, or
|
|
51
|
+
WebOrganizer's encoder).
|
|
52
|
+
2. **Extract** an outline: an LLM writes a role-labelled list of the document's ideas, using the same prompt and six
|
|
53
|
+
worked examples the detector was trained with.
|
|
54
|
+
3. **Score** the outline with a detector, which returns P(human) and a verdict at a calibrated false-positive rate.
|
|
55
|
+
|
|
56
|
+
The same package also scores the prose-level detector ProseLens and the baselines released with the paper.
|
|
57
|
+
|
|
58
|
+
Models: [IdeaLens](https://huggingface.co/rishanthrajendhran/IdeaLens) and the other detectors listed under
|
|
59
|
+
[Models](#models). Data: [WildOutlines](https://huggingface.co/datasets/rishanthrajendhran/WildOutlines) (training
|
|
60
|
+
corpus), [IdeaShift](https://huggingface.co/datasets/rishanthrajendhran/IdeaShift),
|
|
61
|
+
[IdeaShift-X](https://huggingface.co/datasets/rishanthrajendhran/IdeaShift-X) and
|
|
62
|
+
[TwiceTold](https://huggingface.co/datasets/rishanthrajendhran/TwiceTold) (evaluation sets).
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install "idealens[vllm]" # the default scoring backend (Nemotron models, one 80 GB GPU)
|
|
68
|
+
pip install "idealens[hf]" # transformers backend; needed for the ModernBERT and Qwen models
|
|
69
|
+
pip install "idealens[openai]" # OpenAI, OpenRouter or any OpenAI-compatible endpoint (also the logistic models)
|
|
70
|
+
pip install "idealens[anthropic]" # Claude
|
|
71
|
+
pip install "idealens[vertex]" # Gemini on Vertex AI (batch mode also needs a GCS bucket)
|
|
72
|
+
pip install "idealens[weborganizer]" # WebOrganizer's encoder for format classification
|
|
73
|
+
pip install "idealens[all]"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Python 3.10 or later. The vLLM extra pins `vllm==0.21.*`, `transformers>=5.15` and `xgrammar==0.2.1`.
|
|
77
|
+
|
|
78
|
+
The model repos are gated: request access on the model's Hugging Face page, then `huggingface-cli login`.
|
|
79
|
+
|
|
80
|
+
## Credentials
|
|
81
|
+
|
|
82
|
+
| Provider (`--provider`) | Variable |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `gemini` (default) | `GEMINI_API_KEY` or `GOOGLE_API_KEY` |
|
|
85
|
+
| `vertex` | `GOOGLE_CLOUD_PROJECT` and application-default credentials; `IDEALENS_GCS_BUCKET` for batch mode |
|
|
86
|
+
| `openai` | `OPENAI_API_KEY` |
|
|
87
|
+
| `anthropic` | `ANTHROPIC_API_KEY` |
|
|
88
|
+
| `openrouter` | `OPENROUTER_API_KEY` |
|
|
89
|
+
| `compatible` | `--base-url` and, if the endpoint needs one, `--api-key` |
|
|
90
|
+
|
|
91
|
+
The logistic models embed outlines with OpenAI's `text-embedding-3-large`, so they also need `OPENAI_API_KEY`.
|
|
92
|
+
|
|
93
|
+
## Quick start
|
|
94
|
+
|
|
95
|
+
Input is JSONL with a `text` field and, optionally, `id`, `url`, `format` and `topic`.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
idealens run docs.jsonl -o scores.jsonl --dry-run # estimate tokens and cost; sends nothing
|
|
99
|
+
idealens run docs.jsonl -o scores.jsonl # classify, extract and score with IdeaLens
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or one step at a time, which lets you extract once and score with several models:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
idealens classify docs.jsonl -o formats.jsonl
|
|
106
|
+
idealens extract formats.jsonl -o outlines.jsonl
|
|
107
|
+
idealens score outlines.jsonl -o scores.jsonl --model IdeaLens
|
|
108
|
+
idealens score outlines.jsonl -o scores_np.jsonl --model IdeaLens-NoParaphrase
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Every command keeps the input record's fields and appends to its output. Re-running a command resumes it: records
|
|
112
|
+
already in the output are skipped, and records whose provider call failed are retried (the failed attempts are
|
|
113
|
+
moved to `<output>.failed.jsonl`).
|
|
114
|
+
|
|
115
|
+
In Python:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import idealens as il
|
|
119
|
+
|
|
120
|
+
texts = ["...", "..."]
|
|
121
|
+
formats = il.classify(texts) # gemini-3.7-flash by default
|
|
122
|
+
outlines = il.extract(texts, formats)
|
|
123
|
+
with il.Detector("IdeaLens") as det: # vLLM; the repo's published thresholds
|
|
124
|
+
records = det.score_outlines(outlines, format=formats)
|
|
125
|
+
|
|
126
|
+
for r in records:
|
|
127
|
+
print(r["p_human"], r["verdict"]["ai"])
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`il.run(texts, det)` does all three steps. Any provider can be passed as an object:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from idealens.providers import make
|
|
134
|
+
prov = make("openai", "gpt-6-sol")
|
|
135
|
+
outlines = il.extract(texts, formats, provider=prov, mode="batch")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Models
|
|
139
|
+
|
|
140
|
+
`idealens models` lists them. All read the output of the same extraction step, except the two ProseLens models,
|
|
141
|
+
which read the document itself.
|
|
142
|
+
|
|
143
|
+
| Model | Reads | Backends |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| **IdeaLens** (default) | outline | vllm, hf |
|
|
146
|
+
| ProseLens | document | vllm, hf |
|
|
147
|
+
| IdeaLens-NoParaphrase | outline | vllm, hf |
|
|
148
|
+
| IdeaLens-Qwen3.5-9B | outline | hf |
|
|
149
|
+
| IdeaLens-Qwen3.5-9B-PerItem | each outline item | hf |
|
|
150
|
+
| IdeaLens-ModernBERT-L | outline | hf |
|
|
151
|
+
| IdeaLens-ModernBERT-L-NoParaphrase | outline | hf |
|
|
152
|
+
| IdeaLens-ModernBERT-L-RolesOnly | the outline's role sequence | hf |
|
|
153
|
+
| IdeaLens-ModernBERT-L-PerItem | each outline item | hf |
|
|
154
|
+
| ProseLens-ModernBERT-L | document | hf |
|
|
155
|
+
| IdeaLens-LogisticClassifier | outline | logistic |
|
|
156
|
+
| IdeaLens-LogisticClassifier-PerItem | each outline item | logistic |
|
|
157
|
+
|
|
158
|
+
Per-item models score each item and pool the item scores by their mean log-odds. Each model uses its own backend
|
|
159
|
+
unless you pass `--backend`.
|
|
160
|
+
|
|
161
|
+
The package does not paraphrase outlines. IdeaLens was trained and calibrated on paraphrased outlines;
|
|
162
|
+
IdeaLens-NoParaphrase was trained on outlines as extracted, and is the closer match to what this package produces.
|
|
163
|
+
|
|
164
|
+
## Verdicts and thresholds
|
|
165
|
+
|
|
166
|
+
A document is flagged as AI when its P(human) is **strictly below** the cut. The default verdict uses the 1% global
|
|
167
|
+
cut: the score below which 1% of the human calibration documents fall. Each record carries:
|
|
168
|
+
|
|
169
|
+
| Field | Contents |
|
|
170
|
+
|---|---|
|
|
171
|
+
| `p_human` | the detector's P(human) |
|
|
172
|
+
| `verdict` | the default verdict: `fpr`, `scheme`, `cut`, `ai` |
|
|
173
|
+
| `verdicts` | every calibrated false-positive rate (0.1%, 0.5%, 1%, 2%, 5%) under each scheme: `global`, `per_format`, `per_topic`, and `group:<field>` for cuts you fitted yourself |
|
|
174
|
+
| `warnings` | departures from how the cuts were fitted, such as a different extractor model |
|
|
175
|
+
| `item_p_human` | per-item scores (per-item models) |
|
|
176
|
+
|
|
177
|
+
Choose another operating point with `--fpr 0.005 --scheme per_format`. When a document has no cut under a scheme
|
|
178
|
+
(its format or topic was not calibrated, or its format was force-fitted), that verdict is `None` with a reason. It
|
|
179
|
+
never falls back to the global cut.
|
|
180
|
+
|
|
181
|
+
The published cuts were fitted on 80,000 human documents with outlines extracted by `gemini-3.7-flash` with the six
|
|
182
|
+
worked examples. Other extractor models work, but their outlines can shift the score distribution, so the
|
|
183
|
+
calibrated false-positive rate is no longer guaranteed. Every record says so in `warnings`.
|
|
184
|
+
|
|
185
|
+
### Calibrating on your own data
|
|
186
|
+
|
|
187
|
+
If your documents differ from web text, fit cuts on human documents from your own domain:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
idealens calibrate my_humans.jsonl --save-as my_domain --model IdeaLens
|
|
191
|
+
idealens score outlines.jsonl -o scores.jsonl --thresholds my_domain
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The input can be scored records, outlines or documents; the missing steps are run first. `--group-by FIELD` fits a
|
|
195
|
+
cut per value of a field, and `--label-field` / `--human-value` let you pass a mixed file and calibrate on its human
|
|
196
|
+
rows. A cut is fitted only where there are enough documents to estimate it (at least 25 expected below the cut and
|
|
197
|
+
200 in the group). Profiles are saved under `~/.config/idealens/thresholds` (or `$IDEALENS_HOME/thresholds`).
|
|
198
|
+
|
|
199
|
+
## Formats
|
|
200
|
+
|
|
201
|
+
The detectors were trained on eight formats: Academic Writing, Creative Writing, Knowledge Article, News Article,
|
|
202
|
+
Nonfiction Writing, Personal About Page, Personal Blog and User Reviews. A document in another format is assigned
|
|
203
|
+
the closest of the eight by a second LLM pass (or by the encoder's probabilities). Such a document has
|
|
204
|
+
`forced_format: true`, keeps its original label in `original_format`, and gets no per-format verdict.
|
|
205
|
+
|
|
206
|
+
If you know a document's format, give it in the record's `format` field or with `--format`; classification is then
|
|
207
|
+
skipped. `idealens run --check-format` classifies anyway and reports disagreements.
|
|
208
|
+
|
|
209
|
+
## Cost
|
|
210
|
+
|
|
211
|
+
`--dry-run` estimates the tokens and cost of a run before anything is sent, and `idealens cost output.jsonl` totals
|
|
212
|
+
a finished one. Extraction dominates: the prompt carries six worked examples, and reasoning tokens make up most of
|
|
213
|
+
the output. Batch mode (`--mode batch`) costs half as much where the provider has a batch API (Gemini on Vertex,
|
|
214
|
+
OpenAI, Anthropic); not every model is served by it.
|
|
215
|
+
|
|
216
|
+
## Hardware
|
|
217
|
+
|
|
218
|
+
| Model | Needs |
|
|
219
|
+
|---|---|
|
|
220
|
+
| IdeaLens, ProseLens, IdeaLens-NoParaphrase | one 80 GB GPU (A100 80GB or H100 80GB); the weights take 59 GiB; about 60 GiB of CPU RAM while loading |
|
|
221
|
+
| IdeaLens-Qwen3.5-9B models | one GPU; the weights take about 19 GB in bf16 (tested on 80 GB GPUs) |
|
|
222
|
+
| ModernBERT models | any GPU; a CPU works for small jobs |
|
|
223
|
+
| Logistic models | CPU only |
|
|
224
|
+
|
|
225
|
+
The vLLM backend checks that the weights fit before it starts, and stops with a message otherwise. Use
|
|
226
|
+
`tensor_parallel_size` (`Detector(..., tensor_parallel_size=2)`) to spread a model over two smaller GPUs.
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
pip install -e ".[dev]"
|
|
232
|
+
pytest tests
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The tests need no GPU, network or API key.
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
The code is released under the Apache License 2.0. Each model has its own license, given on its model page.
|
|
240
|
+
|
|
241
|
+
## Citation
|
|
242
|
+
|
|
243
|
+
A citation will be added here once the paper is on arXiv.
|
idealens-0.1.0/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# idealens
|
|
2
|
+
|
|
3
|
+
`idealens` detects whether a document's **ideas** came from a person or an AI model, whoever wrote the words. It runs
|
|
4
|
+
the IdeaLens pipeline end to end:
|
|
5
|
+
|
|
6
|
+
1. **Classify** the document into one of eight long-form formats (an LLM with WebOrganizer's annotation prompt, or
|
|
7
|
+
WebOrganizer's encoder).
|
|
8
|
+
2. **Extract** an outline: an LLM writes a role-labelled list of the document's ideas, using the same prompt and six
|
|
9
|
+
worked examples the detector was trained with.
|
|
10
|
+
3. **Score** the outline with a detector, which returns P(human) and a verdict at a calibrated false-positive rate.
|
|
11
|
+
|
|
12
|
+
The same package also scores the prose-level detector ProseLens and the baselines released with the paper.
|
|
13
|
+
|
|
14
|
+
Models: [IdeaLens](https://huggingface.co/rishanthrajendhran/IdeaLens) and the other detectors listed under
|
|
15
|
+
[Models](#models). Data: [WildOutlines](https://huggingface.co/datasets/rishanthrajendhran/WildOutlines) (training
|
|
16
|
+
corpus), [IdeaShift](https://huggingface.co/datasets/rishanthrajendhran/IdeaShift),
|
|
17
|
+
[IdeaShift-X](https://huggingface.co/datasets/rishanthrajendhran/IdeaShift-X) and
|
|
18
|
+
[TwiceTold](https://huggingface.co/datasets/rishanthrajendhran/TwiceTold) (evaluation sets).
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install "idealens[vllm]" # the default scoring backend (Nemotron models, one 80 GB GPU)
|
|
24
|
+
pip install "idealens[hf]" # transformers backend; needed for the ModernBERT and Qwen models
|
|
25
|
+
pip install "idealens[openai]" # OpenAI, OpenRouter or any OpenAI-compatible endpoint (also the logistic models)
|
|
26
|
+
pip install "idealens[anthropic]" # Claude
|
|
27
|
+
pip install "idealens[vertex]" # Gemini on Vertex AI (batch mode also needs a GCS bucket)
|
|
28
|
+
pip install "idealens[weborganizer]" # WebOrganizer's encoder for format classification
|
|
29
|
+
pip install "idealens[all]"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Python 3.10 or later. The vLLM extra pins `vllm==0.21.*`, `transformers>=5.15` and `xgrammar==0.2.1`.
|
|
33
|
+
|
|
34
|
+
The model repos are gated: request access on the model's Hugging Face page, then `huggingface-cli login`.
|
|
35
|
+
|
|
36
|
+
## Credentials
|
|
37
|
+
|
|
38
|
+
| Provider (`--provider`) | Variable |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `gemini` (default) | `GEMINI_API_KEY` or `GOOGLE_API_KEY` |
|
|
41
|
+
| `vertex` | `GOOGLE_CLOUD_PROJECT` and application-default credentials; `IDEALENS_GCS_BUCKET` for batch mode |
|
|
42
|
+
| `openai` | `OPENAI_API_KEY` |
|
|
43
|
+
| `anthropic` | `ANTHROPIC_API_KEY` |
|
|
44
|
+
| `openrouter` | `OPENROUTER_API_KEY` |
|
|
45
|
+
| `compatible` | `--base-url` and, if the endpoint needs one, `--api-key` |
|
|
46
|
+
|
|
47
|
+
The logistic models embed outlines with OpenAI's `text-embedding-3-large`, so they also need `OPENAI_API_KEY`.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
Input is JSONL with a `text` field and, optionally, `id`, `url`, `format` and `topic`.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
idealens run docs.jsonl -o scores.jsonl --dry-run # estimate tokens and cost; sends nothing
|
|
55
|
+
idealens run docs.jsonl -o scores.jsonl # classify, extract and score with IdeaLens
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or one step at a time, which lets you extract once and score with several models:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
idealens classify docs.jsonl -o formats.jsonl
|
|
62
|
+
idealens extract formats.jsonl -o outlines.jsonl
|
|
63
|
+
idealens score outlines.jsonl -o scores.jsonl --model IdeaLens
|
|
64
|
+
idealens score outlines.jsonl -o scores_np.jsonl --model IdeaLens-NoParaphrase
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Every command keeps the input record's fields and appends to its output. Re-running a command resumes it: records
|
|
68
|
+
already in the output are skipped, and records whose provider call failed are retried (the failed attempts are
|
|
69
|
+
moved to `<output>.failed.jsonl`).
|
|
70
|
+
|
|
71
|
+
In Python:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import idealens as il
|
|
75
|
+
|
|
76
|
+
texts = ["...", "..."]
|
|
77
|
+
formats = il.classify(texts) # gemini-3.7-flash by default
|
|
78
|
+
outlines = il.extract(texts, formats)
|
|
79
|
+
with il.Detector("IdeaLens") as det: # vLLM; the repo's published thresholds
|
|
80
|
+
records = det.score_outlines(outlines, format=formats)
|
|
81
|
+
|
|
82
|
+
for r in records:
|
|
83
|
+
print(r["p_human"], r["verdict"]["ai"])
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`il.run(texts, det)` does all three steps. Any provider can be passed as an object:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from idealens.providers import make
|
|
90
|
+
prov = make("openai", "gpt-6-sol")
|
|
91
|
+
outlines = il.extract(texts, formats, provider=prov, mode="batch")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Models
|
|
95
|
+
|
|
96
|
+
`idealens models` lists them. All read the output of the same extraction step, except the two ProseLens models,
|
|
97
|
+
which read the document itself.
|
|
98
|
+
|
|
99
|
+
| Model | Reads | Backends |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| **IdeaLens** (default) | outline | vllm, hf |
|
|
102
|
+
| ProseLens | document | vllm, hf |
|
|
103
|
+
| IdeaLens-NoParaphrase | outline | vllm, hf |
|
|
104
|
+
| IdeaLens-Qwen3.5-9B | outline | hf |
|
|
105
|
+
| IdeaLens-Qwen3.5-9B-PerItem | each outline item | hf |
|
|
106
|
+
| IdeaLens-ModernBERT-L | outline | hf |
|
|
107
|
+
| IdeaLens-ModernBERT-L-NoParaphrase | outline | hf |
|
|
108
|
+
| IdeaLens-ModernBERT-L-RolesOnly | the outline's role sequence | hf |
|
|
109
|
+
| IdeaLens-ModernBERT-L-PerItem | each outline item | hf |
|
|
110
|
+
| ProseLens-ModernBERT-L | document | hf |
|
|
111
|
+
| IdeaLens-LogisticClassifier | outline | logistic |
|
|
112
|
+
| IdeaLens-LogisticClassifier-PerItem | each outline item | logistic |
|
|
113
|
+
|
|
114
|
+
Per-item models score each item and pool the item scores by their mean log-odds. Each model uses its own backend
|
|
115
|
+
unless you pass `--backend`.
|
|
116
|
+
|
|
117
|
+
The package does not paraphrase outlines. IdeaLens was trained and calibrated on paraphrased outlines;
|
|
118
|
+
IdeaLens-NoParaphrase was trained on outlines as extracted, and is the closer match to what this package produces.
|
|
119
|
+
|
|
120
|
+
## Verdicts and thresholds
|
|
121
|
+
|
|
122
|
+
A document is flagged as AI when its P(human) is **strictly below** the cut. The default verdict uses the 1% global
|
|
123
|
+
cut: the score below which 1% of the human calibration documents fall. Each record carries:
|
|
124
|
+
|
|
125
|
+
| Field | Contents |
|
|
126
|
+
|---|---|
|
|
127
|
+
| `p_human` | the detector's P(human) |
|
|
128
|
+
| `verdict` | the default verdict: `fpr`, `scheme`, `cut`, `ai` |
|
|
129
|
+
| `verdicts` | every calibrated false-positive rate (0.1%, 0.5%, 1%, 2%, 5%) under each scheme: `global`, `per_format`, `per_topic`, and `group:<field>` for cuts you fitted yourself |
|
|
130
|
+
| `warnings` | departures from how the cuts were fitted, such as a different extractor model |
|
|
131
|
+
| `item_p_human` | per-item scores (per-item models) |
|
|
132
|
+
|
|
133
|
+
Choose another operating point with `--fpr 0.005 --scheme per_format`. When a document has no cut under a scheme
|
|
134
|
+
(its format or topic was not calibrated, or its format was force-fitted), that verdict is `None` with a reason. It
|
|
135
|
+
never falls back to the global cut.
|
|
136
|
+
|
|
137
|
+
The published cuts were fitted on 80,000 human documents with outlines extracted by `gemini-3.7-flash` with the six
|
|
138
|
+
worked examples. Other extractor models work, but their outlines can shift the score distribution, so the
|
|
139
|
+
calibrated false-positive rate is no longer guaranteed. Every record says so in `warnings`.
|
|
140
|
+
|
|
141
|
+
### Calibrating on your own data
|
|
142
|
+
|
|
143
|
+
If your documents differ from web text, fit cuts on human documents from your own domain:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
idealens calibrate my_humans.jsonl --save-as my_domain --model IdeaLens
|
|
147
|
+
idealens score outlines.jsonl -o scores.jsonl --thresholds my_domain
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The input can be scored records, outlines or documents; the missing steps are run first. `--group-by FIELD` fits a
|
|
151
|
+
cut per value of a field, and `--label-field` / `--human-value` let you pass a mixed file and calibrate on its human
|
|
152
|
+
rows. A cut is fitted only where there are enough documents to estimate it (at least 25 expected below the cut and
|
|
153
|
+
200 in the group). Profiles are saved under `~/.config/idealens/thresholds` (or `$IDEALENS_HOME/thresholds`).
|
|
154
|
+
|
|
155
|
+
## Formats
|
|
156
|
+
|
|
157
|
+
The detectors were trained on eight formats: Academic Writing, Creative Writing, Knowledge Article, News Article,
|
|
158
|
+
Nonfiction Writing, Personal About Page, Personal Blog and User Reviews. A document in another format is assigned
|
|
159
|
+
the closest of the eight by a second LLM pass (or by the encoder's probabilities). Such a document has
|
|
160
|
+
`forced_format: true`, keeps its original label in `original_format`, and gets no per-format verdict.
|
|
161
|
+
|
|
162
|
+
If you know a document's format, give it in the record's `format` field or with `--format`; classification is then
|
|
163
|
+
skipped. `idealens run --check-format` classifies anyway and reports disagreements.
|
|
164
|
+
|
|
165
|
+
## Cost
|
|
166
|
+
|
|
167
|
+
`--dry-run` estimates the tokens and cost of a run before anything is sent, and `idealens cost output.jsonl` totals
|
|
168
|
+
a finished one. Extraction dominates: the prompt carries six worked examples, and reasoning tokens make up most of
|
|
169
|
+
the output. Batch mode (`--mode batch`) costs half as much where the provider has a batch API (Gemini on Vertex,
|
|
170
|
+
OpenAI, Anthropic); not every model is served by it.
|
|
171
|
+
|
|
172
|
+
## Hardware
|
|
173
|
+
|
|
174
|
+
| Model | Needs |
|
|
175
|
+
|---|---|
|
|
176
|
+
| IdeaLens, ProseLens, IdeaLens-NoParaphrase | one 80 GB GPU (A100 80GB or H100 80GB); the weights take 59 GiB; about 60 GiB of CPU RAM while loading |
|
|
177
|
+
| IdeaLens-Qwen3.5-9B models | one GPU; the weights take about 19 GB in bf16 (tested on 80 GB GPUs) |
|
|
178
|
+
| ModernBERT models | any GPU; a CPU works for small jobs |
|
|
179
|
+
| Logistic models | CPU only |
|
|
180
|
+
|
|
181
|
+
The vLLM backend checks that the weights fit before it starts, and stops with a message otherwise. Use
|
|
182
|
+
`tensor_parallel_size` (`Detector(..., tensor_parallel_size=2)`) to spread a model over two smaller GPUs.
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pip install -e ".[dev]"
|
|
188
|
+
pytest tests
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The tests need no GPU, network or API key.
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
The code is released under the Apache License 2.0. Each model has its own license, given on its model page.
|
|
196
|
+
|
|
197
|
+
## Citation
|
|
198
|
+
|
|
199
|
+
A citation will be added here once the paper is on arXiv.
|