jev-sort 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.
- jev_sort-0.1.0/.github/workflows/publish.yml +22 -0
- jev_sort-0.1.0/.github/workflows/test.yml +13 -0
- jev_sort-0.1.0/.gitignore +7 -0
- jev_sort-0.1.0/CHANGELOG.md +18 -0
- jev_sort-0.1.0/LICENSE +21 -0
- jev_sort-0.1.0/PKG-INFO +314 -0
- jev_sort-0.1.0/README.md +295 -0
- jev_sort-0.1.0/bench/fed.py +156 -0
- jev_sort-0.1.0/bench/probe.py +72 -0
- jev_sort-0.1.0/bench/readability.py +162 -0
- jev_sort-0.1.0/bench/simulate.py +85 -0
- jev_sort-0.1.0/pyproject.toml +40 -0
- jev_sort-0.1.0/src/jsort/__init__.py +7 -0
- jev_sort-0.1.0/src/jsort/__main__.py +3 -0
- jev_sort-0.1.0/src/jsort/cli.py +282 -0
- jev_sort-0.1.0/src/jsort/core.py +288 -0
- jev_sort-0.1.0/src/jsort/engine.py +170 -0
- jev_sort-0.1.0/src/jsort/inputs.py +111 -0
- jev_sort-0.1.0/src/jsort/model.py +277 -0
- jev_sort-0.1.0/src/jsort/schedule.py +80 -0
- jev_sort-0.1.0/tests/test_cli.py +267 -0
- jev_sort-0.1.0/tests/test_model.py +117 -0
- jev_sort-0.1.0/tests/test_schedule.py +64 -0
- jev_sort-0.1.0/uv.lock +488 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
# Push a tag like v0.1.0 to release. PyPI trusts this workflow directly (Trusted Publishing),
|
|
3
|
+
# so there is no API token to store, leak or rotate.
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
jobs:
|
|
8
|
+
pypi:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
contents: read
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v5
|
|
17
|
+
- name: The tag must match the version in pyproject.toml
|
|
18
|
+
run: test "v$(grep -m1 '^version' pyproject.toml | cut -d'"' -f2)" = "$GITHUB_REF_NAME"
|
|
19
|
+
- run: uv sync
|
|
20
|
+
- run: uv run pytest -q
|
|
21
|
+
- run: uv build
|
|
22
|
+
- run: uv publish
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
strategy:
|
|
7
|
+
matrix:
|
|
8
|
+
python: ["3.10", "3.13"]
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: astral-sh/setup-uv@v5
|
|
12
|
+
- run: uv sync --python ${{ matrix.python }}
|
|
13
|
+
- run: uv run pytest -q
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Sort lines, paragraphs (`--para`), whole files (`--whole`), CSV rows and JSONL records (`--field`) along a
|
|
6
|
+
plain-English dimension, from pairwise comparisons judged by Jev.
|
|
7
|
+
- Fit a Bradley-Terry scale to Jev's probabilities as a fractional logit, with a term for the lean toward
|
|
8
|
+
the first-shown text. Report a score and a robust standard error per text (`-o`), split-half reliability
|
|
9
|
+
and the first-position lean.
|
|
10
|
+
- Choose pairs adaptively: a random ring, then near neighbours on the current scale. `-k` sets the
|
|
11
|
+
comparisons per text; `--top N` retires texts that cannot reach the top and spends their questions on
|
|
12
|
+
the contenders.
|
|
13
|
+
- Add scores to a dataset without reordering it (`-o --keep-order --name NAME`), emit JSON (`--json`), and
|
|
14
|
+
rank from Python (`jsort.rank`).
|
|
15
|
+
- Seeded pair selection and the shared answer cache make a rerun free; `--budget` stops the questions and
|
|
16
|
+
sorts on what is known.
|
|
17
|
+
- Benchmarks: a simulated judge (`bench/simulate.py`), teachers' pairwise readability judgments
|
|
18
|
+
(`bench/readability.py`) and FOMC opening statements against the policy rate (`bench/fed.py`).
|
jev_sort-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Khaled Eltokhy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
jev_sort-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: jev-sort
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: sort by meaning: order lines along a plain-English dimension, from pairwise comparisons judged by TypeSafe's Jev model
|
|
5
|
+
Project-URL: Repository, https://github.com/keltokhy/jsort
|
|
6
|
+
Author: Khaled Eltokhy
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: bradley-terry,cli,jev,openrouter,pairwise comparison,rank,sort,typesafe
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Text Processing :: Filters
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: httpx>=0.27
|
|
17
|
+
Requires-Dist: numpy>=1.24
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# jsort
|
|
21
|
+
|
|
22
|
+
sort, but the key is a description.
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
$ jsort -o "more hawkish about inflation" presser.txt | head -6
|
|
26
|
+
2.18 0.12 The plain fact is that inflation is too high and has been for too long.
|
|
27
|
+
2.18 0.16 I defined the standard for action: We must be confident that underlying inflation is moving to our objective, clearly and at sufficient speed.
|
|
28
|
+
1.76 0.19 Yet for more than five years, inflation has been running above target.
|
|
29
|
+
1.68 0.36 Too many categories are still posting increases above 3 percent, on both a 6- and 12-month basis.
|
|
30
|
+
1.52 0.38 In the meeting just concluded, the FOMC decided to raise the target range for the federal funds rate by ¼ percentage point to 3¾ to 4 percent, in support of the Federal Reserve’s dual mandate.
|
|
31
|
+
1.39 0.22 The committee’s unanimous vote shows our resolve to achieve price stability on a timelier basis.
|
|
32
|
+
jsort: 51 texts, 255 comparisons in 10 rounds; reliability 0.96; first-position lean -0.07; 255 calls, 0 cached; 87,187 tokens; $0.0037; 7.2s
|
|
33
|
+
|
|
34
|
+
$ jsort -r "more hawkish about inflation" presser.txt | head -3 # the other end, from the cache
|
|
35
|
+
And with that, I’ll take a few of your questions.
|
|
36
|
+
New hiring, private-sector earnings, business capital investment—each of these markers has improved in recent months and is pointing in a good direction.
|
|
37
|
+
Those who are least well-off have the most to gain from a durable expansion, a solid labor market, and stable prices.
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`presser.txt` is the chair's opening statement at the FOMC press conference of September 16, 2026, one
|
|
41
|
+
sentence per line. The first column is the score and the second its standard error.
|
|
42
|
+
|
|
43
|
+
jsort shows [Jev](https://docs.typesafe.ai), TypeSafe's decision model, two texts at a time and asks
|
|
44
|
+
which ranks higher on the dimension you described. Jev answers with a probability in about 200 ms.
|
|
45
|
+
jsort asks about a few pairs per text, not all of them, fits a Bradley-Terry scale to the answers
|
|
46
|
+
and prints the texts from the top of the scale down. With `-o` each line carries its score and a
|
|
47
|
+
standard error, so the order can be used as a measurement and not only as a ranking.
|
|
48
|
+
|
|
49
|
+
The same command sorts whole documents. Every opening statement since press conferences began, 91
|
|
50
|
+
of them from January 2012 to this week, as files named by date:
|
|
51
|
+
|
|
52
|
+
```console
|
|
53
|
+
$ jsort --whole -o --max-chars 16000 "more hawkish about inflation" statements/*.txt | sed -n '1,4p;88,91p'
|
|
54
|
+
6.56 0.41 statements/2022-11-02.txt
|
|
55
|
+
6.08 0.66 statements/2022-09-21.txt
|
|
56
|
+
5.56 0.58 statements/2022-06-15.txt
|
|
57
|
+
5.49 0.30 statements/2022-12-14.txt
|
|
58
|
+
-3.33 0.25 statements/2020-11-05.txt
|
|
59
|
+
-3.44 0.29 statements/2020-07-29.txt
|
|
60
|
+
-3.46 0.24 statements/2021-01-27.txt
|
|
61
|
+
-3.56 0.20 statements/2020-06-10.txt
|
|
62
|
+
jsort: 91 texts, 455 comparisons in 10 rounds; reliability 0.98; first-position lean -0.03; 0 calls, 455 cached; 0.1s
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
That run came from the cache. The first time it was 26 seconds and six cents, for statements of
|
|
66
|
+
about 1,250 words each. The top four are 2022 hikes of 50 or 75 points. The bottom is the first year of the pandemic.
|
|
67
|
+
By chair, the average score is -2.35 for Bernanke (9 statements), -1.34 for Yellen (16), 0.55 for
|
|
68
|
+
Powell (63) and 2.67 for Warsh (3). `bench/fed.py` builds both files from federalreserve.gov and checks the
|
|
69
|
+
scale against what the Committee did; the results are [below](#how-well-does-it-work).
|
|
70
|
+
|
|
71
|
+
A thousand short lines take about 5,000 comparisons: roughly a minute and seven cents.
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uv tool install jev-sort # the command it installs is jsort
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
jsort finds a key the way [jgrep](https://github.com/keltokhy/jgrep) does: `TYPESAFE_API_KEY`,
|
|
80
|
+
`OPENROUTER_API_KEY`, or a System One gateway (`JEV_GATEWAY_URL` and `JEV_GATEWAY_API_KEY`), from the
|
|
81
|
+
environment or from `~/.config/jev/typesafe.key`, `openrouter.key` or `gateway.key`. Force a choice
|
|
82
|
+
with `--api` or `JEV_API`. The two tools share one answer cache.
|
|
83
|
+
|
|
84
|
+
## Use
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
jsort "more urgent" tickets.txt | head # the ten most urgent
|
|
88
|
+
jsort -r "more urgent" tickets.txt | head # the ten least
|
|
89
|
+
jsort -o "more hawkish about inflation" statements.txt # with scores and standard errors
|
|
90
|
+
jsort --top 5 "a more serious safety problem" complaints.txt
|
|
91
|
+
jsort --para "makes a stronger causal claim" paper.txt # paragraphs, not lines
|
|
92
|
+
jsort --whole "of more general interest" abstracts/*.txt # whole files; prints their names
|
|
93
|
+
jsort --jsonl --field event.message "angrier" events.jsonl # full records come back, sorted
|
|
94
|
+
jsort --csv --field narrative -o --keep-order --name breadth \
|
|
95
|
+
"drew broader participation" events.csv > scored.csv # add a variable, keep the row order
|
|
96
|
+
jsort --json "more urgent" tickets.txt # rank, score, se and source line
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
| Option | Meaning |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `-k N` | Comparisons each text takes part in. Default 10, minimum 2. The run asks about N/2 questions per text. |
|
|
102
|
+
| `--top N` | Print only the top N. Texts that are clearly out of the running stop being asked about, and their questions go to the contenders. With `-r` it is the bottom N that is hunted and printed. |
|
|
103
|
+
| `-r` | Lowest first. |
|
|
104
|
+
| `-o` | Put the score and its standard error in the first two tab-separated columns. With `--csv` or `--jsonl`, add `jsort_score`, `jsort_se` and `jsort_n` to each record. |
|
|
105
|
+
| `--name NAME` | Call those fields `NAME_score`, `NAME_se` and `NAME_n`, so that one file can carry several scales. |
|
|
106
|
+
| `--keep-order` | Print in input order. With `-o` this adds scores to a file without rearranging it. |
|
|
107
|
+
| `-n`, `-H` | Prefix each line with its line number or file name. |
|
|
108
|
+
| `--json` | One JSON object per text: `rank`, `score`, `se`, `comparisons`, `file`, `line`, `text`. |
|
|
109
|
+
| `--jsonl --field NAME`, `--csv --field NAME` | Compare one field and return the complete records. JSON fields can be dotted paths. |
|
|
110
|
+
| `--para`, `--whole` | Sort paragraphs or whole files in place of lines. |
|
|
111
|
+
| `--seed N` | Seed for the choice of pairs. Default 0. The same seed asks the same questions, so a rerun comes from the cache. |
|
|
112
|
+
| `--budget DOLLARS` | Stop asking once this much is spent and sort on what is known. Default 1.00, or `$JSORT_BUDGET`; 0 for no limit. |
|
|
113
|
+
| `--max-chars N` | Show Jev only the first N characters of a text. Default 8000. |
|
|
114
|
+
| `-j N`, `--timeout`, `--no-cache`, `--api`, `--model`, `--stats` | As in jgrep. |
|
|
115
|
+
|
|
116
|
+
Blank lines are dropped. Identical texts are compared once and share a score. Several files are
|
|
117
|
+
sorted together, as `sort` does. Exit status is 0 when the input was sorted and 2 on any error:
|
|
118
|
+
an unreadable file, a failed comparison, a stop at the budget, the API refusing further calls because
|
|
119
|
+
the credit ran out. In each of those cases whatever could be sorted from the answers already paid
|
|
120
|
+
for is still printed.
|
|
121
|
+
|
|
122
|
+
CSV needs a header with unique column names. A byte-order mark is ignored, a row with more values
|
|
123
|
+
than the header keeps them at its end, and a header with no rows comes back as a header. With `-o`,
|
|
124
|
+
jsort refuses to write over a column or JSON field that already exists; pick another prefix with
|
|
125
|
+
`--name`.
|
|
126
|
+
|
|
127
|
+
Write the description as a comparative: "more urgent", "easier to read", "drew broader military
|
|
128
|
+
participation". It goes into one question, `Text A ranks higher than text B on this criterion:
|
|
129
|
+
"..."`, so anything that completes that sentence sensibly will work.
|
|
130
|
+
|
|
131
|
+
## What the numbers mean
|
|
132
|
+
|
|
133
|
+
**Score.** The position on the scale, in logit units, centred on zero. A gap of 1.0 between two
|
|
134
|
+
texts means Jev gives the higher one about 73% in a head-to-head; a gap of 3 means about 95%.
|
|
135
|
+
Scores are relative to the other texts in the same run. They do not carry over to another file or
|
|
136
|
+
another description.
|
|
137
|
+
|
|
138
|
+
**Standard error.** How well the comparisons pin the score down. Jev's answer is a probability, not
|
|
139
|
+
a win or a loss, so the model is a fractional logit and the errors are the robust (sandwich) kind,
|
|
140
|
+
with a leverage correction because there is one parameter per text. Where Jev's answers line up on
|
|
141
|
+
one scale the errors are small. Where they contradict each other the errors grow. In simulation,
|
|
142
|
+
intervals of 1.96 standard errors cover the target 94 to 95% of the time from `-k 6` up
|
|
143
|
+
(`bench/simulate.py`). Above 4,000 distinct texts the same errors are estimated by random probing,
|
|
144
|
+
to within about 7% each, because the matrix the exact ones need no longer fits.
|
|
145
|
+
|
|
146
|
+
**Reliability.** The comparisons are dealt into two halves, a scale is fitted to each, and the
|
|
147
|
+
correlation between the two is stepped up to full length (Spearman-Brown). Near 1, the order does
|
|
148
|
+
not depend on which pairs happened to be asked. Below 0.8 jsort says so: raise `-k`, or the
|
|
149
|
+
description is not one these texts can be ranked on. It errs on the cautious side, and most at low
|
|
150
|
+
`-k`, where a half is only two comparisons per text: in simulation it reads 0.83 for a true 0.89 at
|
|
151
|
+
`-k 4`, and 0.955 for 0.964 at the default.
|
|
152
|
+
|
|
153
|
+
**First-position lean.** How far the first-shown text's chance sits from a half in an even matchup.
|
|
154
|
+
Positions are randomised and balanced and the lean is estimated with the scale, as home advantage
|
|
155
|
+
is in a sports model, so it does not tilt the scores. It has been a few points either way.
|
|
156
|
+
|
|
157
|
+
Reliability and the standard errors describe how consistent *Jev* is. They say nothing about
|
|
158
|
+
whether Jev is right. For that, check a sample against your own judgment.
|
|
159
|
+
|
|
160
|
+
## From Python
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import jsort
|
|
164
|
+
|
|
165
|
+
r = jsort.rank(statements, "more hawkish about inflation", per_item=10)
|
|
166
|
+
for i in r.order()[:5]:
|
|
167
|
+
print(f"{r.score[i]:6.2f} ±{r.se[i]:.2f} {statements[i]}")
|
|
168
|
+
r.reliability, r.lean, r.asked
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`r.score`, `r.se` and `r.comparisons` are arrays aligned with the input. The command's seat belt
|
|
172
|
+
applies here too: spending stops at `budget=` dollars, by default `$JSORT_BUDGET` or 1.00, and
|
|
173
|
+
`r.over_budget` says whether it was reached. It works inside a notebook. `jsort.arank` is the same
|
|
174
|
+
thing as a coroutine, for a client you already hold.
|
|
175
|
+
|
|
176
|
+
## How it chooses pairs
|
|
177
|
+
|
|
178
|
+
All n(n-1)/2 pairs are never needed. A lopsided pair says almost nothing, because the answer was
|
|
179
|
+
predictable. A pair of near neighbours says the most. The first round is a random ring: every text
|
|
180
|
+
meets two others, once in each position, which connects everything. After each round the scale is
|
|
181
|
+
refitted, and the next round pairs texts that currently sit next to each other, as a Swiss-system
|
|
182
|
+
tournament does. Each score is jittered in proportion to how uncertain it still is, so a text that
|
|
183
|
+
is not pinned down yet keeps meeting new neighbours. A pair is asked at most twice, once in each
|
|
184
|
+
order. With a handful of texts jsort simply runs out of pairs and stops early.
|
|
185
|
+
|
|
186
|
+
`--top N` adds one rule. Once a text has three comparisons, jsort asks how much worse the fit would
|
|
187
|
+
get if that text were moved up to the edge of the top N. If the answer is "much worse", the text
|
|
188
|
+
gets no more questions. A text that lost 0.03 to 0.97 against a middling opponent is out, and no
|
|
189
|
+
further comparison will change that. In simulation this is the same cost as a full sort or a little
|
|
190
|
+
less, and finds more of the true top ten (0.85 against 0.77 of them, among 2,000 texts).
|
|
191
|
+
|
|
192
|
+
## Cost
|
|
193
|
+
|
|
194
|
+
A comparison bills about 270 tokens of overhead plus both texts and the description. For short lines
|
|
195
|
+
that is about 320 tokens, or $0.0000135 at $0.042 per million, and the default `-k 10` asks five
|
|
196
|
+
questions per text: about 7 cents per thousand lines. For 170-word excerpts a comparison is about
|
|
197
|
+
735 tokens and a thousand texts cost about 15 cents. A run is about ten rounds, each as slow as its
|
|
198
|
+
slowest call, so a small sort takes five to ten seconds. A large one manages about 90 comparisons a
|
|
199
|
+
second through OpenRouter.
|
|
200
|
+
|
|
201
|
+
jsort stops asking at `--budget`, one dollar by default, and sorts on what it has. Nothing is lost:
|
|
202
|
+
every answer is cached in `~/.cache/jev/answers.sqlite`, and the choice of pairs is seeded, so a rerun
|
|
203
|
+
with a higher budget, or a higher `-k`, starts by replaying the same questions from the cache and
|
|
204
|
+
only pays for the new ones. The exception is a run in which a comparison failed. Later pairs depend
|
|
205
|
+
on earlier answers, so once the failed one succeeds the rounds after it can choose differently, and
|
|
206
|
+
those questions are new.
|
|
207
|
+
|
|
208
|
+
## How well does it work
|
|
209
|
+
|
|
210
|
+
Two checks, run on 2026-09-19 with Jev 1.13 through OpenRouter. Both run the installed `jsort`
|
|
211
|
+
command, uncached.
|
|
212
|
+
|
|
213
|
+
**Against people making the same comparisons.** `bench/readability.py`. The CommonLit Ease of
|
|
214
|
+
Readability corpus (Crossley et al. 2022) has 4,724 excerpts written for
|
|
215
|
+
grades 3 to 12. Each has an easiness score that is itself a Bradley-Terry fit, to teachers'
|
|
216
|
+
judgments of which of two excerpts is easier. So this is the same method with Jev in the teachers'
|
|
217
|
+
chair. On a random 300 excerpts, the teachers' scale has a reliability of about 0.78, which means no
|
|
218
|
+
measure can be expected to correlate with it above about 0.88.
|
|
219
|
+
|
|
220
|
+
| Measure | Pearson r | Spearman ρ | Calls | Cost |
|
|
221
|
+
|---|---:|---:|---:|---:|
|
|
222
|
+
| `jsort -k 16 "easier to read"` | 0.824 | 0.840 | 2,400 | $0.074 |
|
|
223
|
+
| **`jsort "easier to read"`** (`-k 10`) | **0.824** | **0.841** | 1,500 | $0.046 |
|
|
224
|
+
| `jsort -k 6` | 0.813 | 0.833 | 900 | $0.028 |
|
|
225
|
+
| `jsort -k 4` | 0.803 | 0.826 | 600 | $0.018 |
|
|
226
|
+
| One question per text: the probability it is "easy to read" (`jgrep -o`) | 0.754 | 0.804 | 300 | $0.004 |
|
|
227
|
+
| A five-level rubric, one call per text (Jev's `score` question) | 0.824 | 0.839 | 300 | $0.004 |
|
|
228
|
+
| Best readability formula shipped with the corpus (SMOG) | 0.661 | 0.647 | | |
|
|
229
|
+
| Flesch-Kincaid grade level | 0.598 | 0.595 | | |
|
|
230
|
+
|
|
231
|
+
Three things to take from it.
|
|
232
|
+
|
|
233
|
+
jsort gets most of the way to the ceiling from a two-word description, and it clearly beats the
|
|
234
|
+
other thing you can do with two words, which is to ask for a probability per text and sort on that.
|
|
235
|
+
That probability bunches up (73 distinct values among 300 texts) and it is weakest exactly where a
|
|
236
|
+
sort is needed, on texts that are close.
|
|
237
|
+
|
|
238
|
+
More comparisons stop helping early. `-k 10` and `-k 16` give the same answer, and `-k 6` is nearly
|
|
239
|
+
there. What is left between 0.82 and 0.88 is Jev disagreeing with teachers, not noise that more
|
|
240
|
+
questions would average away; the reliability of 0.98 says the same.
|
|
241
|
+
|
|
242
|
+
**A written rubric did just as well for a sixth of the price.** Five levels, from "suited to
|
|
243
|
+
children in the first years of school" to "suited to readers at the end of high school or beyond",
|
|
244
|
+
one call per text, and Jev's `score` answer interpolates between levels (2.9, not 3), so it does
|
|
245
|
+
not bunch up either. The two agree with each other at r = 0.92. Broken down by how far apart the
|
|
246
|
+
teachers put two excerpts, jsort is ahead only on the closest pairs, and not by much:
|
|
247
|
+
|
|
248
|
+
| Gap on the teachers' scale | Pairs | jsort | Rubric | p("easy") |
|
|
249
|
+
|---|---:|---:|---:|---:|
|
|
250
|
+
| 0.25 to 0.5 | 5,022 | 0.675 | 0.645 | 0.632 |
|
|
251
|
+
| 0.5 to 1 | 9,366 | 0.771 | 0.777 | 0.737 |
|
|
252
|
+
| 1 to 2 | 12,932 | 0.925 | 0.926 | 0.888 |
|
|
253
|
+
| over 2 | 7,233 | 0.990 | 0.992 | 0.981 |
|
|
254
|
+
|
|
255
|
+
Readability across ten school grades is friendly ground for a rubric: the levels are easy to name
|
|
256
|
+
and the texts spread across all of them. So:
|
|
257
|
+
|
|
258
|
+
- If you can write down what the levels are, write the rubric. It is what
|
|
259
|
+
[jcol](https://github.com/keltokhy/jcol)'s `tone: calm < upset < furious` columns do, and it costs one
|
|
260
|
+
call per text.
|
|
261
|
+
- Use jsort when you can say what "more" means but not what the levels are, when the texts would
|
|
262
|
+
all land on one or two rubric levels, or when the scale is going into a model and you need a
|
|
263
|
+
standard error on every score and a reliability figure for the whole.
|
|
264
|
+
|
|
265
|
+
**Against what the Fed then did.** `bench/fed.py`. The 91 opening statements above, sorted whole on
|
|
266
|
+
"more hawkish about inflation", against the top of the target range for the federal funds rate (FRED
|
|
267
|
+
series DFEDTARU). Both tests were written into the script before the sort was run. The rank
|
|
268
|
+
correlation between a statement's score and the move announced that day is +0.47 (91 statements).
|
|
269
|
+
With the change in the target over the following 180 days it is +0.38 (87 statements). Those are
|
|
270
|
+
moderate, and they should be: a chair can hold rates and talk tough. The holds of June, September and
|
|
271
|
+
November 2023 score near 4, among the ten most hawkish. What the scale gets right is the shape of
|
|
272
|
+
fourteen years. The six statements that announced hikes of 50 or 75 points in 2022 are the top six,
|
|
273
|
+
seven of 2023's eight statements fill ranks 7 to 13, and the bottom eight are all from March 2020 to January
|
|
274
|
+
2021.
|
|
275
|
+
|
|
276
|
+
## Things to know
|
|
277
|
+
|
|
278
|
+
- These are a model's judgments. Check a sample before you rely on an order.
|
|
279
|
+
- Jev reads the description literally and is weak at counting and at comparing numbers or dates.
|
|
280
|
+
"Mentions more people" or "happened earlier" are bad dimensions. Compute those in code.
|
|
281
|
+
- One dimension per run. If the description mixes two ("more urgent and more polite"), the scale
|
|
282
|
+
is whatever blend Jev makes of them, and reliability may not warn you.
|
|
283
|
+
- Both texts must fit in one call. `--max-chars` caps each at 8,000 characters; TypeSafe documents a
|
|
284
|
+
limit of 32k tokens for the state and question together. Long texts full of detail that is
|
|
285
|
+
irrelevant to the dimension are a documented weak spot, so cut them down first
|
|
286
|
+
(`jgrep --para` is one way).
|
|
287
|
+
- Jev is close to deterministic, not exactly so. The cache makes reruns exact. For results that
|
|
288
|
+
must reproduce, pin the model with `--model` (for example `typesafe/jev-1.13` on OpenRouter) and keep the
|
|
289
|
+
cache file with the project.
|
|
290
|
+
- Adding texts later means a new run and a new scale. The old answers are still cached, so the new
|
|
291
|
+
run is cheap, but scores from two runs are not on the same footing unless the texts are the same.
|
|
292
|
+
- Text in the input can try to steer the answer. Do not use an order from jsort as a security
|
|
293
|
+
boundary.
|
|
294
|
+
|
|
295
|
+
## Development
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
uv sync && uv run pytest # offline: a fake API, no key
|
|
299
|
+
uv run python bench/simulate.py # offline: a simulated judge with a known scale
|
|
300
|
+
uv run python bench/probe.py # live, under a cent: which question shape to use
|
|
301
|
+
uv run --group bench python bench/readability.py prepare && uv run --group bench python bench/readability.py run
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
`src/jsort/model.py` is the scale: the fit, the standard errors, reliability and the test `--top`
|
|
305
|
+
uses. `schedule.py` chooses pairs. `engine.py` runs the rounds and is the Python API. `inputs.py`
|
|
306
|
+
reads lines, paragraphs, files, CSV and JSONL. `core.py` is jgrep's client, unchanged: backends,
|
|
307
|
+
retries inside a time budget, the cache, in-flight deduplication and the cost meter.
|
|
308
|
+
|
|
309
|
+
Why a noul and not a choice: `bench/probe.py` asks every ordered pair of ten texts both ways. A
|
|
310
|
+
two-option `choice` and a `noul` ("A ranks higher than B") made the same decisions, 95.6% correct,
|
|
311
|
+
but the choice put 93% of its answers below 0.1 or above 0.9, where the noul left 28% of its answers
|
|
312
|
+
between the two. Those in-between answers are what a scale is fitted from.
|
|
313
|
+
|
|
314
|
+
MIT license.
|