Urdatorn Claude Opus 5 commited on
Commit
6fc8784
·
1 Parent(s): 83dae89

Remove annotation-scheme leakage from model-facing columns

Browse files

Sphragis merges seven annotation projects whose author inventories do not
overlap, so every convention that separates the projects also separates the
authors. A classifier seeing annotation markup and no Greek at all reached
63.4% accuracy and 45.3 macro-F1 on the 17-way sentence_1 task against a
14.6% baseline, and single rules were near-deterministic: no PUNCT token
identified Herodotus at 99.6% precision over 83% of his sentences, and an
empty MISC column separated the Iliad from the Odyssey at 83.5%.

Every published column is now reduced to one shared representation:

- MISC is cleared; NativeRel, NativeHead and HeadRepair move to a new
native_syntax audit column, keyed by published and source token index.
- Editorial punctuation tokens are removed and trees re-indexed, because UD
PROIEL does not tokenize punctuation at all.
- Elision is written as a combining comma by AGDT and UD Perseus, as three
different apostrophes within Gorman, and as U+2019 by Pedalion and PROIEL;
all spellings now reduce to the same truncated form.
- Word forms, lemmas, text and metre syllables are lowercased with
grc_utils.lower_grc.
- UPOS is derived from the normalized XPOS, and UPOS, XPOS, FEATS and DEPREL
are collapsed onto the inventories every project shares.
- The # text comment is dropped; the text column already carried it.

This removes the deterministic tells but not the confound: the projects
disagree about tree shape, not only about labels. Markup-only attribution
falls to 52.7% / 34.0 and treebank recoverability to 82.2%.

The source_held_out_* configurations are the actual remedy. Each author's
second-largest source project is held out entirely as its validation and
test data, so a model that recognizes annotators is penalized rather than
rewarded. Eleven authors qualify. There markup-only attribution falls to
22.0% / 11.2 against an 11.9% baseline, and treebank recoverability to 35.3%.

scripts/audit_leakage.py measures all of this into metadata/leakage_report.json
and runs in the rebuild, so the floor a real model must clear is published
rather than assumed.

Two upstream defects surfaced while validating, both previously silent:
some AGDT and Pedalion trees have their tag column offset against their
forms, so punctuation is now decided from the form rather than the tag; and
2,092 Sphragis Metre units hold more than one sentence block, which are now
finalized separately instead of being merged into one malformed tree.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Files changed (43) hide show
  1. README.md +156 -25
  2. SOURCES.md +12 -6
  3. data/sentence_1/test-00000-of-00001.parquet +2 -2
  4. data/sentence_1/train-00000-of-00001.parquet +2 -2
  5. data/sentence_1/validation-00000-of-00001.parquet +2 -2
  6. data/sentence_10/test-00000-of-00001.parquet +2 -2
  7. data/sentence_10/train-00000-of-00001.parquet +2 -2
  8. data/sentence_10/validation-00000-of-00001.parquet +2 -2
  9. data/sentence_100/test-00000-of-00001.parquet +2 -2
  10. data/sentence_100/train-00000-of-00001.parquet +2 -2
  11. data/sentence_100/validation-00000-of-00001.parquet +2 -2
  12. data/sentence_50/test-00000-of-00001.parquet +2 -2
  13. data/sentence_50/train-00000-of-00001.parquet +2 -2
  14. data/sentence_50/validation-00000-of-00001.parquet +2 -2
  15. data/source_held_out_1/test-00000-of-00001.parquet +3 -0
  16. data/source_held_out_1/train-00000-of-00001.parquet +3 -0
  17. data/source_held_out_1/validation-00000-of-00001.parquet +3 -0
  18. data/source_held_out_10/test-00000-of-00001.parquet +3 -0
  19. data/source_held_out_10/train-00000-of-00001.parquet +3 -0
  20. data/source_held_out_10/validation-00000-of-00001.parquet +3 -0
  21. data/source_held_out_100/test-00000-of-00001.parquet +3 -0
  22. data/source_held_out_100/train-00000-of-00001.parquet +3 -0
  23. data/source_held_out_100/validation-00000-of-00001.parquet +3 -0
  24. data/source_held_out_50/test-00000-of-00001.parquet +3 -0
  25. data/source_held_out_50/train-00000-of-00001.parquet +3 -0
  26. data/source_held_out_50/validation-00000-of-00001.parquet +3 -0
  27. inspection/sphragis.sqlite +2 -2
  28. metadata/build_report.json +831 -0
  29. metadata/dataset_variants.json +0 -0
  30. metadata/leakage_report.json +201 -0
  31. requirements-build.txt +2 -0
  32. scripts/audit_leakage.py +197 -0
  33. scripts/build_dataset.py +317 -50
  34. scripts/build_sqlite_mirror.py +9 -6
  35. scripts/dataset_variants.py +14 -3
  36. scripts/model_facing.py +373 -0
  37. scripts/syntax_normalization.py +93 -0
  38. scripts/validate_publication.py +90 -37
  39. slurm/rebuild_dataset.slurm +7 -0
  40. tests/test_conllu_well_formed.py +4 -37
  41. tests/test_model_facing.py +342 -0
  42. tests/test_split_stratification.py +13 -1
  43. tests/test_verse_character_coverage.py +1 -0
README.md CHANGED
@@ -43,6 +43,38 @@ configs:
43
  path: data/sentence_100/validation-*
44
  - split: test
45
  path: data/sentence_100/test-*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ---
47
 
48
  # Sphragis
@@ -66,8 +98,17 @@ provenance preserved.
66
 
67
  ## Tasks
68
 
69
- There are four task sizes. Prose and verse sentences share one closed-set
70
- authorship problem; the `genre` column preserves their source representation.
 
 
 
 
 
 
 
 
 
71
 
72
  ## Configurations
73
 
@@ -77,6 +118,15 @@ authorship problem; the `genre` column preserves their source representation.
77
  | `sentence_10` | 17 | 10-sentence chunk | 4,330 | 480 | 480 |
78
  | `sentence_50` | 17 | 50-sentence chunk | 866 | 96 | 96 |
79
  | `sentence_100` | 17 | 100-sentence chunk | 433 | 48 | 48 |
 
 
 
 
 
 
 
 
 
80
 
81
  The suffix gives the chunk size in every split. `_100` defines one shared
82
  source corpus for all four tasks: an author is retained
@@ -141,16 +191,49 @@ multiples of 100 per author. This makes the
141
  published source-row ratio slightly different from the initial 80/10/10 split.
142
  A stricter work-held-out evaluation can be added as a later track.
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  ## Principal columns
145
 
146
  All configurations contain:
147
 
148
  - `id`, `author`, `work`, `work_id`, `genre`, `text`;
149
  - `conllu`, `cts_urn`, `passage`, `treebank_source`;
 
 
150
  - `source_records`: JSON containing every contributing upstream record,
151
  revision, URL, license, annotation provenance and syntax scheme;
152
  - `licenses`, `dedup_key`, and `split`.
153
 
 
 
154
  `text` is always a JSON list of strings. Atomic `_1` rows contain one string;
155
  every split of `_10`, `_50`, and `_100` contains exactly 10, 50, or 100 separate sentence
156
  strings. No whitespace separator is used to encode unit boundaries.
@@ -170,34 +253,81 @@ All sentence rows share one schema. There are no metrical, scanned-line, or
170
  external-alignment columns. `genre` has exactly two values: `prose` and
171
  `verse`.
172
 
173
- ## Dependency representation
174
-
175
- Existing UD data is retained verbatim. Native AGDT/Arethusa trees are
176
- serialized as CoNLL-U while preserving heads. Their dependency relations are
177
- conservatively mapped to the Universal Dependencies v2 inventory; opaque
178
- source-specific categories fall back to `dep`. The lossless original
179
- `NativeRel` and `NativeHead` values remain in MISC for audit and future mapping
180
- improvements. Repairs required after removing artificial ellipsis nodes—or to
181
- break an upstream beta self-loop/cycle—are explicitly marked `HeadRepair=Yes`.
182
-
183
- XPOS is normalized across every source to the nine-position Ancient Greek
184
- AGDT/Perseus tag convention. Existing valid positional tags are retained;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  incompatible source-specific tags are reconstructed from UPOS and FEATS, with
186
- unavailable distinctions represented by `-`. UPOS and FEATS remain the
187
- canonical UD fields.
 
 
 
 
 
 
188
 
189
  Every distinct published `conllu` document is loaded during testing with the
190
- [official CoNLL 2018 shared-task `load_conllu` parser](https://github.com/CoNLL-UD-2018/UDPipe-Future/blob/master/conll18_ud_eval.py).
191
- This checks sentence
192
  termination, ten-column structure, token IDs, heads, roots and dependency
193
- cycles across all configurations.
 
 
 
 
 
 
 
 
 
194
 
195
- To prevent authorship-label leakage, model-facing `conllu` values retain only
196
- the non-identifying `# text = ...` comment. Comments carrying `sent_id`,
197
- `source`, `cts`, `passage`, or `newdoc id` are removed. The same information
198
- remains available for audit in the dataset's dedicated provenance columns.
199
- Token-level MISC identifiers (`Cite`, `Ref`, and `LId`) are also removed; only
200
- `NativeRel`, `NativeHead`, `HeadRepair`, and `SpaceAfter` are retained there.
 
201
 
202
  ## Deduplication
203
 
@@ -261,6 +391,7 @@ python scripts/build_dataset.py --sources /path/to/frozen/checkouts \
261
  --metre-output ../sphragis-metre/data \
262
  --metre-metadata ../sphragis-metre/metadata \
263
  --stoicheia-conllu .stoicheia-cache/hypotactic_conllu_punctuationless_udv2.jsonl
 
264
  python scripts/validate_publication.py --publication sentence --data data
265
  python scripts/validate_publication.py \
266
  --publication metre --data ../sphragis-metre/data
 
43
  path: data/sentence_100/validation-*
44
  - split: test
45
  path: data/sentence_100/test-*
46
+ - config_name: source_held_out_1
47
+ data_files:
48
+ - split: train
49
+ path: data/source_held_out_1/train-*
50
+ - split: validation
51
+ path: data/source_held_out_1/validation-*
52
+ - split: test
53
+ path: data/source_held_out_1/test-*
54
+ - config_name: source_held_out_10
55
+ data_files:
56
+ - split: train
57
+ path: data/source_held_out_10/train-*
58
+ - split: validation
59
+ path: data/source_held_out_10/validation-*
60
+ - split: test
61
+ path: data/source_held_out_10/test-*
62
+ - config_name: source_held_out_50
63
+ data_files:
64
+ - split: train
65
+ path: data/source_held_out_50/train-*
66
+ - split: validation
67
+ path: data/source_held_out_50/validation-*
68
+ - split: test
69
+ path: data/source_held_out_50/test-*
70
+ - config_name: source_held_out_100
71
+ data_files:
72
+ - split: train
73
+ path: data/source_held_out_100/train-*
74
+ - split: validation
75
+ path: data/source_held_out_100/validation-*
76
+ - split: test
77
+ path: data/source_held_out_100/test-*
78
  ---
79
 
80
  # Sphragis
 
98
 
99
  ## Tasks
100
 
101
+ There are four task sizes on each of two tracks. Prose and verse sentences
102
+ share one closed-set authorship problem; the `genre` column preserves their
103
+ source representation.
104
+
105
+ The **main track** (`sentence_*`) splits rows randomly within author and work.
106
+ The **source-held-out track** (`source_held_out_*`) splits them by annotation
107
+ project: each author's validation and test sentences come from a treebank that
108
+ supplies none of that author's training sentences. See
109
+ [Source-held-out track](#source-held-out-track) for why this exists and
110
+ [Model-facing representation](#model-facing-representation) for what was done
111
+ to the main track in consequence.
112
 
113
  ## Configurations
114
 
 
118
  | `sentence_10` | 17 | 10-sentence chunk | 4,330 | 480 | 480 |
119
  | `sentence_50` | 17 | 50-sentence chunk | 866 | 96 | 96 |
120
  | `sentence_100` | 17 | 100-sentence chunk | 433 | 48 | 48 |
121
+ | `source_held_out_1` | 11 | sentence | 25,100 | 4,200 | 4,200 |
122
+ | `source_held_out_10` | 11 | 10-sentence chunk | 2,510 | 420 | 420 |
123
+ | `source_held_out_50` | 11 | 50-sentence chunk | 502 | 84 | 84 |
124
+ | `source_held_out_100` | 11 | 100-sentence chunk | 251 | 42 | 42 |
125
+
126
+ The `source_held_out_*` configurations use the same rows, the same chunk sizes
127
+ and the same 100-row bottleneck, over the eleven authors that more than one
128
+ project annotates. Two of them, Hesiod and Lucian, do not reach the main
129
+ track's threshold under random splitting but do under this arrangement.
130
 
131
  The suffix gives the chunk size in every split. `_100` defines one shared
132
  source corpus for all four tasks: an author is retained
 
191
  published source-row ratio slightly different from the initial 80/10/10 split.
192
  A stricter work-held-out evaluation can be added as a later track.
193
 
194
+ ### Source-held-out track
195
+
196
+ Sphragis merges seven annotation projects, and those projects do not overlap in
197
+ authors. UD PROIEL contributes Herodotus and nobody else; Pedalion contributes
198
+ Aristophanes and Procopius; the *Odyssey* is entirely AGDT while most of the
199
+ *Iliad* is UD Perseus. Any convention that distinguishes the projects therefore
200
+ also distinguishes the authors, and a model can score well on the main track by
201
+ recognizing the annotator instead of the writer.
202
+
203
+ The `source_held_out_*` configurations remove that possibility by construction.
204
+ For each author, the **second-largest** source project is held out entirely:
205
+ its sentences become that author's validation and test data, split evenly, and
206
+ every other project supplies training. An author is retained only when the
207
+ held-out project yields at least 100 validation and 100 test rows and at least
208
+ 100 training rows remain. A model that has learned to recognize annotators is
209
+ actively penalized here, because every author arrives at evaluation in a scheme
210
+ it was never trained in.
211
+
212
+ Which project is held out per author, and the row counts that follow, are
213
+ recorded under `source_held_out_track` in
214
+ [`metadata/build_report.json`](metadata/build_report.json). The
215
+ `held_out_source` column repeats it on every row.
216
+
217
+ This track is the benchmark's answer to the confound. The normalization
218
+ described below removes the parts of the leak that are indefensible on their
219
+ own terms, but it cannot remove all of it: projects genuinely disagree about
220
+ tree shape, and no relabelling can normalize that away. Scores on the two
221
+ tracks are not comparable, and the gap between them is the interesting number.
222
+
223
  ## Principal columns
224
 
225
  All configurations contain:
226
 
227
  - `id`, `author`, `work`, `work_id`, `genre`, `text`;
228
  - `conllu`, `cts_urn`, `passage`, `treebank_source`;
229
+ - `native_syntax`: JSON audit record of the original relation, head and any
230
+ head repair for every token whose source project used a non-UD scheme;
231
  - `source_records`: JSON containing every contributing upstream record,
232
  revision, URL, license, annotation provenance and syntax scheme;
233
  - `licenses`, `dedup_key`, and `split`.
234
 
235
+ The `source_held_out_*` configurations add `held_out_source`.
236
+
237
  `text` is always a JSON list of strings. Atomic `_1` rows contain one string;
238
  every split of `_10`, `_50`, and `_100` contains exactly 10, 50, or 100 separate sentence
239
  strings. No whitespace separator is used to encode unit boundaries.
 
253
  external-alignment columns. `genre` has exactly two values: `prose` and
254
  `verse`.
255
 
256
+ ## Model-facing representation
257
+
258
+ Every published `conllu` document and every `text` unit is reduced to one
259
+ scheme-neutral representation, so that no category boundary the source projects
260
+ disagree about can be used as an authorship feature.
261
+
262
+ **No comments.** CoNLL-U documents contain token rows only. The `# text`
263
+ comment was removed in favour of the dedicated `text` column, which already
264
+ carried the same string; comments carrying `sent_id`, `source`, `cts`,
265
+ `passage` or `newdoc id` had already been stripped.
266
+
267
+ **No punctuation.** Editorial punctuation tokens are removed from the trees and
268
+ re-indexed, and any dependent hanging from one is re-attached to its nearest
269
+ surviving ancestor. Punctuation is likewise removed from `text`. UD PROIEL does
270
+ not tokenize punctuation at all, so its absence alone identified its single
271
+ author.
272
+
273
+ **Lowercase throughout.** Word forms, lemmas and `text` are lowercased with
274
+ [`grc_utils.lower_grc`](https://pypi.org/project/grc-utils/), which handles the
275
+ precomposed polytonic letters correctly. Capitalization marked sentence
276
+ openings and proper nouns inconsistently between projects and editions.
277
+
278
+ **Empty MISC.** The MISC column is `_` on every token. `NativeRel`,
279
+ `NativeHead` and `HeadRepair` sat on every token of the natively converted
280
+ projects and on none of the UD ones, and `SpaceAfter` occurred in UD Perseus
281
+ alone. They now live in the `native_syntax` column, which records the source
282
+ relation, source head and any head repair per token, keyed by both the
283
+ published token index (`i`) and the source document's own numbering (`src`).
284
+
285
+ **Shared inventories.** UPOS is derived from the normalized XPOS so both
286
+ columns express one scheme, and the categories the projects disagree about are
287
+ merged:
288
+
289
+ | Column | Published inventory | Merged because |
290
+ |---|---|---|
291
+ | UPOS | `NOUN VERB ADJ PRON ADV ADP NUM INTJ X` | `PROPN` is PROIEL-only; `AUX` is UD-only; δέ is `PART` in AGDT, `ADV` in Gorman and `CCONJ` in UD Perseus; the article is `DET` in UD and a pronoun in the AGDT lineage |
292
+ | DEPREL | `root nsubj obj ccomp obl nmod advmod case conj appos vocative discourse dep` | `cc`, `cop` and `aux` are never produced by the native conversions; `iobj` is UD Perseus only; subtypes such as `nsubj:pass` and `obl:arg` are PROIEL only; the two conversions of the same AGDT trees split attribution between `amod`, `nmod` and `det` |
293
+ | FEATS | `Case Degree Gender Mood Number Person Tense Voice` | `VerbForm` is absent from every native conversion and already carried by XPOS position 5; `PronType`, `Definite`, `Polarity`, `Poss` and `Reflex` occur in one project only |
294
+ | XPOS | nine positions, part of speech in `n v a p d r m i x` | same merges as UPOS, applied to position 1 |
295
+
296
+ XPOS positions 2–9 are unchanged: the nine-position AGDT/Perseus normalization
297
+ already levelled them across sources, and they are the least source-dependent
298
+ signal in the dataset. Existing valid positional tags are retained;
299
  incompatible source-specific tags are reconstructed from UPOS and FEATS, with
300
+ unavailable distinctions represented by `-`.
301
+
302
+ Native AGDT/Arethusa trees are serialized as CoNLL-U while preserving heads.
303
+ Their dependency relations are conservatively mapped to Universal Dependencies
304
+ v2 before the shared inventory is applied; opaque source-specific categories
305
+ fall back to `dep`. Repairs required after removing artificial ellipsis
306
+ nodes—or to break an upstream beta self-loop/cycle—are recorded as
307
+ `repair` in `native_syntax`.
308
 
309
  Every distinct published `conllu` document is loaded during testing with the
310
+ [official CoNLL 2018 shared-task `load_conllu` parser](https://github.com/CoNLL-UD-2018/UDPipe-Future/blob/master/conll18_ud_eval.py),
311
+ and separately checked against every invariant above. This checks sentence
312
  termination, ten-column structure, token IDs, heads, roots and dependency
313
+ cycles across all configurations, and that the CoNLL-U forms reconstruct the
314
+ `text` column exactly.
315
+
316
+ ### Residual leakage
317
+
318
+ The normalization above removes the deterministic tells. It does not remove the
319
+ confound, and it was never going to: the projects disagree about tree shape
320
+ itself, not only about labels. AGDT-lineage trees mark `conj` on roughly 14% of
321
+ tokens where UD Perseus marks 4% *of the same Iliad*, and no relabelling
322
+ normalizes a genuine analytic disagreement.
323
 
324
+ [`scripts/audit_leakage.py`](scripts/audit_leakage.py) measures what remains by
325
+ fitting classifiers that see annotation markup and no Greek at all, and writes
326
+ [`metadata/leakage_report.json`](metadata/leakage_report.json). Those numbers
327
+ are the floor a real model must clear: a system that does not beat them has
328
+ demonstrated source identification rather than authorship attribution. They are
329
+ published on the leaderboard for that reason, and the `source_held_out_*` track
330
+ exists because they cannot be driven to chance.
331
 
332
  ## Deduplication
333
 
 
391
  --metre-output ../sphragis-metre/data \
392
  --metre-metadata ../sphragis-metre/metadata \
393
  --stoicheia-conllu .stoicheia-cache/hypotactic_conllu_punctuationless_udv2.jsonl
394
+ python scripts/audit_leakage.py --data data --metadata metadata
395
  python scripts/validate_publication.py --publication sentence --data data
396
  python scripts/validate_publication.py \
397
  --publication metre --data ../sphragis-metre/data
SOURCES.md CHANGED
@@ -19,12 +19,18 @@ The beta integrates:
19
 
20
  Non-UD dependency trees are serialized as valid CoNLL-U without claiming that
21
  their relations have been manually reannotated as Universal Dependencies.
22
- Heads are preserved, a best-effort UPOS/features conversion is supplied,
23
- native relations are represented as `dep:<native-relation>`, and the original
24
- relation and head are retained as `NativeRel` and `NativeHead` in MISC. Empty
25
- and artificial ellipsis nodes are omitted. If this would leave no surface root,
26
- or if an upstream beta tree contains a self-loop/cycle, the smallest necessary
27
- repair is marked `HeadRepair=Yes`.
 
 
 
 
 
 
28
 
29
  Exact sentence duplicates across prose and verse are identified by lowercasing, converting final sigma,
30
  removing diacritics, and retaining letters only. One syntactic representation
 
19
 
20
  Non-UD dependency trees are serialized as valid CoNLL-U without claiming that
21
  their relations have been manually reannotated as Universal Dependencies.
22
+ Heads are preserved and a best-effort UPOS/features conversion is supplied.
23
+ Empty and artificial ellipsis nodes are omitted. If this would leave no surface
24
+ root, or if an upstream beta tree contains a self-loop/cycle, the smallest
25
+ necessary repair is applied.
26
+
27
+ Because the seven projects do not overlap in authors, their annotation
28
+ conventions identify authors. Every published tree is therefore reduced to one
29
+ shared inventory of parts of speech, features and dependency relations,
30
+ stripped of punctuation, comments and MISC, and lowercased; the original
31
+ relation, head and any repair are preserved per token in the `native_syntax`
32
+ column. See "Model-facing representation" in the README, and
33
+ `metadata/leakage_report.json` for the measured residual.
34
 
35
  Exact sentence duplicates across prose and verse are identified by lowercasing, converting final sigma,
36
  removing diacritics, and retaining letters only. One syntactic representation
data/sentence_1/test-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad55c6f23b4ba1dc42abe1bc150a091dc87957a4e399934f894af5e91edef891
3
- size 1968403
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6b955124e767a679f22f5831beeea2521d6eb8449ef9aa7fe12067478877d51
3
+ size 1801614
data/sentence_1/train-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:067cff2d494fd4634e5dc96490df9e4e6e1e96097c579c6ac1588a8432b6ad44
3
- size 17324579
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68a53a6675832c3b3a4f0d1d353a46a3f25ba847b62bff2d3d79ea355d3d3d5f
3
+ size 15710369
data/sentence_1/validation-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2ac869c4d9a54177e52be472027539134b20adb6e4249392b45e0fad7c94c699
3
- size 1953585
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48afb349a9743ccce2906f36e720ddfbd07a819292da4f14899355990c9ea91a
3
+ size 1782350
data/sentence_10/test-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5ecdd99f802b600356dfe4a440dc98276bfffa8b4420d5e26b74cfe8d824ad0b
3
- size 1653944
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1886acd279e524a4a2c030ad7d50d07fb518436ec048189b0dac80b80e17f297
3
+ size 1516058
data/sentence_10/train-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:af764f6eaffbf8d9bfc63e822273a63023f5a3cd984c8b081fe6ba51ae86286e
3
- size 13245244
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdcdc569edd363708d4d3c36df811d8bf2f459d1a0dd6d799739d6cd8fa42a5e
3
+ size 12197728
data/sentence_10/validation-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:65eb9527a57ce29a9551a42c329ce285c0501f01b2c0d27cc8023b419f2bc20e
3
- size 1634568
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6df7e15fc7d3c83cf7093613bfde26922699af463ac3257954d6c021807d8b62
3
+ size 1497141
data/sentence_100/test-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f1504f10076c7de58e34fa57e67502c18cbeee04403c1d9ff56c0bb86075ccae
3
- size 1588918
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9cb775a24a9df9b4a86fd856c4d40cb43675457360cf8564e9460f5947bbbcc
3
+ size 1448714
data/sentence_100/train-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:91b6f94d0b4cb560542fac18ad1de3986e74ebc88c83c644f33e4b67655bcf1b
3
- size 12827249
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aadad114cb26e6bf6866d8936007f721e1fcc15a8ce386fcdedbd45ed458e5bd
3
+ size 11739798
data/sentence_100/validation-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c68535eaf5f3037d86c5a9d253e5bd903e78ffdeef5417bb7287f0765827bfe8
3
- size 1577597
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb738b386bb359e532197c0d0354e3df98cb538d44fb6a635a77ca844fd774e4
3
+ size 1437967
data/sentence_50/test-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:63a0be018cd297899b0db08dcd1da8a6fc194c7230143a6b0012b3db6b1e04d1
3
- size 1594282
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e1fbee9bb71b752f83abcc64c4faf538266fec2900460c484435ae14811b321
3
+ size 1454270
data/sentence_50/train-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dbc570ab5bd97d2c441373b14bd232b1b592b0291c13360431921896b3e05bb3
3
- size 12868346
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbf0be2e803934c1c14bdbfadd57dd60767cbd7852a6c49c559ffda79609f7d6
3
+ size 11784864
data/sentence_50/validation-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:69b2a39bd530f1f149556f198e62f0792a8af38c5caf70a77391eb8bca7d5874
3
- size 1582843
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4092d9ba16f513811445f7ca3182bbe5e5c33cdac1291216108484cb020d011a
3
+ size 1443442
data/source_held_out_1/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e294aef1a0a056edaa489d61320205fde0e57669eaa23f7bb35444c4c8dba744
3
+ size 1654025
data/source_held_out_1/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3cbada9a11a829a3ef5f774ae3421ade82224569cfb51b8a9b0ebb1430bc7b35
3
+ size 8043847
data/source_held_out_1/validation-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58fa135a2206a37cdfb30eca36f2ad1284f37d40df7c3f058f7fbc0d50b85708
3
+ size 1648704
data/source_held_out_10/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16eff6560ee8c0bb0cc0a211f61ffa01034870b34c17d12348857e723ea46b15
3
+ size 1394817
data/source_held_out_10/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e96d00d745ecba81971c3afcdc0a3b2bf4a83a84d1e09a45bc357c3fd16245b1
3
+ size 6191144
data/source_held_out_10/validation-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fbc3f2053bccef43989ab3a471914a98026b7ec794a10af90327714f16f87caf
3
+ size 1385080
data/source_held_out_100/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f576ef312ec20202a0b69ea13c571ae9a77d7e9d1768a318220395ff73cffadf
3
+ size 1335959
data/source_held_out_100/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6319ee0a2224767594c4ea503fcd2e92c4ec423f0680b7360b63a29fdb500ee8
3
+ size 5919927
data/source_held_out_100/validation-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:602f48433963085b53853dab8359a6c6b3a140ef10f66cdd3fb0b3af3ba7c15b
3
+ size 1331779
data/source_held_out_50/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f0ce0f89ea1136c637f7e7c57ae3fb1b3e8ef8e075cb23e40891de1e16614ca
3
+ size 1340261
data/source_held_out_50/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b31da7353f4685e21ae743f81e23098e261ac5c241efa5143cc6fc6f4412d118
3
+ size 5944559
data/source_held_out_50/validation-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4712ed5fd6a7aed31acee1f20cc253835ed219da9fffa2b0bea0e4900c5ab16
3
+ size 1336054
inspection/sphragis.sqlite CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ef1b7d6fbe11364a00c4028b8c77589b0840753e790b295fc8f394e4780e9f47
3
- size 795017216
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72eefbb52ba62741072d6478aaf3b67b51ac98a88d3f357992272f5f43d2de72
3
+ size 1237647360
metadata/build_report.json CHANGED
@@ -373,6 +373,26 @@
373
  "test": 96,
374
  "train": 866,
375
  "validation": 96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  }
377
  },
378
  "deduplication": {
@@ -730,7 +750,466 @@
730
  "papyri.xml"
731
  ]
732
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
  "publication": "sentence",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
  "splitting": {
735
  "chunking": {
736
  "ordering": "natural passage or line order within canonical work ID",
@@ -807,6 +1286,358 @@
807
  "train": 866,
808
  "validation": 96
809
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
  }
811
  }
812
  }
 
373
  "test": 96,
374
  "train": 866,
375
  "validation": 96
376
+ },
377
+ "source_held_out_1": {
378
+ "test": 4200,
379
+ "train": 25100,
380
+ "validation": 4200
381
+ },
382
+ "source_held_out_10": {
383
+ "test": 420,
384
+ "train": 2510,
385
+ "validation": 420
386
+ },
387
+ "source_held_out_100": {
388
+ "test": 42,
389
+ "train": 251,
390
+ "validation": 42
391
+ },
392
+ "source_held_out_50": {
393
+ "test": 84,
394
+ "train": 502,
395
+ "validation": 84
396
  }
397
  },
398
  "deduplication": {
 
750
  "papyri.xml"
751
  ]
752
  },
753
+ "model_facing_normalization": {
754
+ "case": "word forms, lemmas and text are lowercased with grc_utils.lower_grc",
755
+ "conllu_comments": "removed; the text column carries the text",
756
+ "deprel_inventory": [
757
+ "advmod",
758
+ "appos",
759
+ "case",
760
+ "ccomp",
761
+ "conj",
762
+ "dep",
763
+ "discourse",
764
+ "nmod",
765
+ "nsubj",
766
+ "obj",
767
+ "obl",
768
+ "root",
769
+ "vocative"
770
+ ],
771
+ "feats_inventory": [
772
+ "Case",
773
+ "Degree",
774
+ "Gender",
775
+ "Mood",
776
+ "Number",
777
+ "Person",
778
+ "Tense",
779
+ "Voice"
780
+ ],
781
+ "misc": "cleared; NativeRel, NativeHead and HeadRepair move to native_syntax",
782
+ "punctuation": "editorial punctuation tokens are removed from CoNLL-U and from text, because UD PROIEL does not tokenize punctuation at all",
783
+ "rationale": "Sphragis merges seven annotation projects whose author inventories do not overlap, so any convention that distinguishes those projects also identifies the author. Every published column is reduced to one shared representation; the project-specific annotation is retained for audit in the native_syntax column.",
784
+ "statistics": {
785
+ "rows": 67568,
786
+ "units": 67568,
787
+ "units_with_native_syntax": 47556
788
+ },
789
+ "upos_inventory": [
790
+ "ADJ",
791
+ "ADP",
792
+ "ADV",
793
+ "INTJ",
794
+ "NOUN",
795
+ "NUM",
796
+ "PRON",
797
+ "VERB",
798
+ "X"
799
+ ],
800
+ "xpos_part_of_speech_inventory": [
801
+ "a",
802
+ "d",
803
+ "i",
804
+ "m",
805
+ "n",
806
+ "p",
807
+ "r",
808
+ "v",
809
+ "x"
810
+ ]
811
+ },
812
  "publication": "sentence",
813
+ "source_held_out_track": {
814
+ "author_decisions": {
815
+ "Athenaeus": {
816
+ "held_out_source": "gorman",
817
+ "rows": {
818
+ "test": 424,
819
+ "train": 1628,
820
+ "validation": 424
821
+ },
822
+ "source_rows": {
823
+ "agdt": 11,
824
+ "gorman": 848,
825
+ "ud_perseus": 1617
826
+ },
827
+ "training_sources": [
828
+ "ud_perseus",
829
+ "agdt"
830
+ ]
831
+ },
832
+ "Diodorus Siculus": {
833
+ "held_out_source": "gorman",
834
+ "rows": {
835
+ "test": 227,
836
+ "train": 828,
837
+ "validation": 227
838
+ },
839
+ "source_rows": {
840
+ "agdt": 104,
841
+ "gorman": 455,
842
+ "ud_perseus": 724
843
+ },
844
+ "training_sources": [
845
+ "ud_perseus",
846
+ "agdt"
847
+ ]
848
+ },
849
+ "Herodotus": {
850
+ "held_out_source": "ud_perseus",
851
+ "rows": {
852
+ "test": 546,
853
+ "train": 6285,
854
+ "validation": 546
855
+ },
856
+ "source_rows": {
857
+ "agdt": 5,
858
+ "gorman": 179,
859
+ "ud_perseus": 1092,
860
+ "ud_proiel": 6101
861
+ },
862
+ "training_sources": [
863
+ "ud_proiel",
864
+ "gorman",
865
+ "agdt"
866
+ ]
867
+ },
868
+ "Hesiod": {
869
+ "held_out_source": "agdt",
870
+ "rows": {
871
+ "test": 183,
872
+ "train": 547,
873
+ "validation": 183
874
+ },
875
+ "source_rows": {
876
+ "agdt": 366,
877
+ "ud_perseus": 547
878
+ },
879
+ "training_sources": [
880
+ "ud_perseus"
881
+ ]
882
+ },
883
+ "Homeric-Iliad": {
884
+ "held_out_source": "agdt",
885
+ "rows": {
886
+ "test": 1158,
887
+ "train": 5527,
888
+ "validation": 1158
889
+ },
890
+ "source_rows": {
891
+ "agdt": 2316,
892
+ "ud_perseus": 5527
893
+ },
894
+ "training_sources": [
895
+ "ud_perseus"
896
+ ]
897
+ },
898
+ "Lucian": {
899
+ "held_out_source": "harrington",
900
+ "rows": {
901
+ "test": 161,
902
+ "train": 397,
903
+ "validation": 161
904
+ },
905
+ "source_rows": {
906
+ "harrington": 322,
907
+ "pedalion": 397
908
+ },
909
+ "training_sources": [
910
+ "pedalion"
911
+ ]
912
+ },
913
+ "Plato": {
914
+ "held_out_source": "agdt",
915
+ "rows": {
916
+ "test": 183,
917
+ "train": 779,
918
+ "validation": 183
919
+ },
920
+ "source_rows": {
921
+ "agdt": 366,
922
+ "gorman": 724,
923
+ "pedalion": 55
924
+ },
925
+ "training_sources": [
926
+ "gorman",
927
+ "pedalion"
928
+ ]
929
+ },
930
+ "Plutarch": {
931
+ "held_out_source": "ud_perseus",
932
+ "rows": {
933
+ "test": 248,
934
+ "train": 1157,
935
+ "validation": 248
936
+ },
937
+ "source_rows": {
938
+ "agdt": 100,
939
+ "gorman": 1057,
940
+ "ud_perseus": 496
941
+ },
942
+ "training_sources": [
943
+ "gorman",
944
+ "agdt"
945
+ ]
946
+ },
947
+ "Sophocles": {
948
+ "held_out_source": "agdt",
949
+ "rows": {
950
+ "test": 781,
951
+ "train": 2314,
952
+ "validation": 781
953
+ },
954
+ "source_rows": {
955
+ "agdt": 1563,
956
+ "ud_perseus": 2314
957
+ },
958
+ "training_sources": [
959
+ "ud_perseus"
960
+ ]
961
+ },
962
+ "Thucydides": {
963
+ "held_out_source": "ud_perseus",
964
+ "rows": {
965
+ "test": 265,
966
+ "train": 674,
967
+ "validation": 265
968
+ },
969
+ "source_rows": {
970
+ "agdt": 2,
971
+ "gorman": 672,
972
+ "ud_perseus": 531
973
+ },
974
+ "training_sources": [
975
+ "gorman",
976
+ "agdt"
977
+ ]
978
+ },
979
+ "Xenophon": {
980
+ "held_out_source": "pedalion",
981
+ "rows": {
982
+ "test": 637,
983
+ "train": 5578,
984
+ "validation": 637
985
+ },
986
+ "source_rows": {
987
+ "gorman": 5578,
988
+ "pedalion": 1275
989
+ },
990
+ "training_sources": [
991
+ "gorman"
992
+ ]
993
+ }
994
+ },
995
+ "excluded_authors": {
996
+ "Aeneas Tacticus": {
997
+ "reason": "only one source project",
998
+ "sources": {
999
+ "pedalion": 300
1000
+ }
1001
+ },
1002
+ "Aeschines": {
1003
+ "reason": "only one source project",
1004
+ "sources": {
1005
+ "gorman": 666
1006
+ }
1007
+ },
1008
+ "Aeschylus": {
1009
+ "held_out_source": "ud_perseus",
1010
+ "reason": "held-out source too small for a 100-row validation and test split",
1011
+ "sources": {
1012
+ "agdt": 3115,
1013
+ "ud_perseus": 163
1014
+ }
1015
+ },
1016
+ "Andocides": {
1017
+ "reason": "only one source project",
1018
+ "sources": {
1019
+ "gorman": 269
1020
+ }
1021
+ },
1022
+ "Antiphon": {
1023
+ "reason": "only one source project",
1024
+ "sources": {
1025
+ "gorman": 513
1026
+ }
1027
+ },
1028
+ "Appian": {
1029
+ "reason": "only one source project",
1030
+ "sources": {
1031
+ "gorman": 966
1032
+ }
1033
+ },
1034
+ "Aristophanes": {
1035
+ "reason": "only one source project",
1036
+ "sources": {
1037
+ "pedalion": 1853
1038
+ }
1039
+ },
1040
+ "Aristotle": {
1041
+ "reason": "only one source project",
1042
+ "sources": {
1043
+ "gorman": 871
1044
+ }
1045
+ },
1046
+ "Chariton": {
1047
+ "reason": "only one source project",
1048
+ "sources": {
1049
+ "pedalion": 402
1050
+ }
1051
+ },
1052
+ "Demosthenes": {
1053
+ "reason": "only one source project",
1054
+ "sources": {
1055
+ "gorman": 3035
1056
+ }
1057
+ },
1058
+ "Dionysius of Halicarnassus": {
1059
+ "reason": "only one source project",
1060
+ "sources": {
1061
+ "gorman": 1063
1062
+ }
1063
+ },
1064
+ "Epicurus": {
1065
+ "reason": "only one source project",
1066
+ "sources": {
1067
+ "pedalion": 67
1068
+ }
1069
+ },
1070
+ "Euripides": {
1071
+ "reason": "only one source project",
1072
+ "sources": {
1073
+ "pedalion": 793
1074
+ }
1075
+ },
1076
+ "Ezechiel": {
1077
+ "reason": "only one source project",
1078
+ "sources": {
1079
+ "pedalion": 146
1080
+ }
1081
+ },
1082
+ "Heron": {
1083
+ "reason": "only one source project",
1084
+ "sources": {
1085
+ "pedalion": 484
1086
+ }
1087
+ },
1088
+ "Homeric-Odyssey": {
1089
+ "reason": "only one source project",
1090
+ "sources": {
1091
+ "agdt": 6100
1092
+ }
1093
+ },
1094
+ "Isaeus": {
1095
+ "reason": "only one source project",
1096
+ "sources": {
1097
+ "gorman": 194
1098
+ }
1099
+ },
1100
+ "Isocrates": {
1101
+ "reason": "only one source project",
1102
+ "sources": {
1103
+ "gorman": 153
1104
+ }
1105
+ },
1106
+ "Josephus": {
1107
+ "reason": "only one source project",
1108
+ "sources": {
1109
+ "gorman": 1039
1110
+ }
1111
+ },
1112
+ "Julian": {
1113
+ "reason": "only one source project",
1114
+ "sources": {
1115
+ "pedalion": 50
1116
+ }
1117
+ },
1118
+ "Longus": {
1119
+ "reason": "only one source project",
1120
+ "sources": {
1121
+ "pedalion": 34
1122
+ }
1123
+ },
1124
+ "Lysias": {
1125
+ "held_out_source": "pedalion",
1126
+ "reason": "held-out source too small for a 100-row validation and test split",
1127
+ "sources": {
1128
+ "agdt": 54,
1129
+ "gorman": 833,
1130
+ "pedalion": 80
1131
+ }
1132
+ },
1133
+ "Menander": {
1134
+ "reason": "only one source project",
1135
+ "sources": {
1136
+ "pedalion": 895
1137
+ }
1138
+ },
1139
+ "Paeanius": {
1140
+ "reason": "only one source project",
1141
+ "sources": {
1142
+ "pedalion": 360
1143
+ }
1144
+ },
1145
+ "Paul": {
1146
+ "reason": "only one source project",
1147
+ "sources": {
1148
+ "ud_proiel": 900
1149
+ }
1150
+ },
1151
+ "Phlegon": {
1152
+ "reason": "only one source project",
1153
+ "sources": {
1154
+ "pedalion": 237
1155
+ }
1156
+ },
1157
+ "Polybius": {
1158
+ "held_out_source": "agdt",
1159
+ "reason": "held-out source too small for a 100-row validation and test split",
1160
+ "sources": {
1161
+ "agdt": 1,
1162
+ "gorman": 3804
1163
+ }
1164
+ },
1165
+ "Procopius": {
1166
+ "reason": "only one source project",
1167
+ "sources": {
1168
+ "pedalion": 1188
1169
+ }
1170
+ },
1171
+ "Sappho": {
1172
+ "reason": "only one source project",
1173
+ "sources": {
1174
+ "pedalion": 402
1175
+ }
1176
+ },
1177
+ "Semonides": {
1178
+ "reason": "only one source project",
1179
+ "sources": {
1180
+ "pedalion": 58
1181
+ }
1182
+ },
1183
+ "Sextus Empiricus": {
1184
+ "reason": "only one source project",
1185
+ "sources": {
1186
+ "pedalion": 677
1187
+ }
1188
+ },
1189
+ "Theophrastus": {
1190
+ "reason": "only one source project",
1191
+ "sources": {
1192
+ "pedalion": 459
1193
+ }
1194
+ }
1195
+ },
1196
+ "minimum_rows_per_split": 100,
1197
+ "policy": "hold out each author's second-largest source project entirely; its sentences form that author's validation and test data and every other project supplies training",
1198
+ "retained_authors": [
1199
+ "Athenaeus",
1200
+ "Diodorus Siculus",
1201
+ "Herodotus",
1202
+ "Hesiod",
1203
+ "Homeric-Iliad",
1204
+ "Lucian",
1205
+ "Plato",
1206
+ "Plutarch",
1207
+ "Sophocles",
1208
+ "Thucydides",
1209
+ "Xenophon"
1210
+ ],
1211
+ "seed": 776
1212
+ },
1213
  "splitting": {
1214
  "chunking": {
1215
  "ordering": "natural passage or line order within canonical work ID",
 
1286
  "train": 866,
1287
  "validation": 96
1288
  }
1289
+ },
1290
+ "source_held_out_1": {
1291
+ "authors": 11,
1292
+ "genres": [
1293
+ "prose",
1294
+ "verse"
1295
+ ],
1296
+ "held_out_sources": {
1297
+ "Athenaeus": {
1298
+ "held_out_source": "gorman",
1299
+ "training_sources": [
1300
+ "agdt",
1301
+ "ud_perseus"
1302
+ ]
1303
+ },
1304
+ "Diodorus Siculus": {
1305
+ "held_out_source": "gorman",
1306
+ "training_sources": [
1307
+ "agdt",
1308
+ "ud_perseus"
1309
+ ]
1310
+ },
1311
+ "Herodotus": {
1312
+ "held_out_source": "ud_perseus",
1313
+ "training_sources": [
1314
+ "agdt",
1315
+ "gorman",
1316
+ "ud_proiel"
1317
+ ]
1318
+ },
1319
+ "Hesiod": {
1320
+ "held_out_source": "agdt",
1321
+ "training_sources": [
1322
+ "ud_perseus"
1323
+ ]
1324
+ },
1325
+ "Homeric-Iliad": {
1326
+ "held_out_source": "agdt",
1327
+ "training_sources": [
1328
+ "ud_perseus"
1329
+ ]
1330
+ },
1331
+ "Lucian": {
1332
+ "held_out_source": "harrington",
1333
+ "training_sources": [
1334
+ "pedalion"
1335
+ ]
1336
+ },
1337
+ "Plato": {
1338
+ "held_out_source": "agdt",
1339
+ "training_sources": [
1340
+ "gorman",
1341
+ "pedalion"
1342
+ ]
1343
+ },
1344
+ "Plutarch": {
1345
+ "held_out_source": "ud_perseus",
1346
+ "training_sources": [
1347
+ "agdt",
1348
+ "gorman"
1349
+ ]
1350
+ },
1351
+ "Sophocles": {
1352
+ "held_out_source": "agdt",
1353
+ "training_sources": [
1354
+ "ud_perseus"
1355
+ ]
1356
+ },
1357
+ "Thucydides": {
1358
+ "held_out_source": "ud_perseus",
1359
+ "training_sources": [
1360
+ "agdt",
1361
+ "gorman"
1362
+ ]
1363
+ },
1364
+ "Xenophon": {
1365
+ "held_out_source": "pedalion",
1366
+ "training_sources": [
1367
+ "gorman"
1368
+ ]
1369
+ }
1370
+ },
1371
+ "rows": 33500,
1372
+ "splits": {
1373
+ "test": 4200,
1374
+ "train": 25100,
1375
+ "validation": 4200
1376
+ }
1377
+ },
1378
+ "source_held_out_10": {
1379
+ "authors": 11,
1380
+ "genres": [
1381
+ "prose",
1382
+ "verse"
1383
+ ],
1384
+ "held_out_sources": {
1385
+ "Athenaeus": {
1386
+ "held_out_source": "gorman",
1387
+ "training_sources": [
1388
+ "agdt",
1389
+ "ud_perseus"
1390
+ ]
1391
+ },
1392
+ "Diodorus Siculus": {
1393
+ "held_out_source": "gorman",
1394
+ "training_sources": [
1395
+ "agdt",
1396
+ "ud_perseus"
1397
+ ]
1398
+ },
1399
+ "Herodotus": {
1400
+ "held_out_source": "ud_perseus",
1401
+ "training_sources": [
1402
+ "agdt",
1403
+ "gorman",
1404
+ "ud_proiel"
1405
+ ]
1406
+ },
1407
+ "Hesiod": {
1408
+ "held_out_source": "agdt",
1409
+ "training_sources": [
1410
+ "ud_perseus"
1411
+ ]
1412
+ },
1413
+ "Homeric-Iliad": {
1414
+ "held_out_source": "agdt",
1415
+ "training_sources": [
1416
+ "ud_perseus"
1417
+ ]
1418
+ },
1419
+ "Lucian": {
1420
+ "held_out_source": "harrington",
1421
+ "training_sources": [
1422
+ "pedalion"
1423
+ ]
1424
+ },
1425
+ "Plato": {
1426
+ "held_out_source": "agdt",
1427
+ "training_sources": [
1428
+ "gorman",
1429
+ "pedalion"
1430
+ ]
1431
+ },
1432
+ "Plutarch": {
1433
+ "held_out_source": "ud_perseus",
1434
+ "training_sources": [
1435
+ "agdt",
1436
+ "gorman"
1437
+ ]
1438
+ },
1439
+ "Sophocles": {
1440
+ "held_out_source": "agdt",
1441
+ "training_sources": [
1442
+ "ud_perseus"
1443
+ ]
1444
+ },
1445
+ "Thucydides": {
1446
+ "held_out_source": "ud_perseus",
1447
+ "training_sources": [
1448
+ "agdt",
1449
+ "gorman"
1450
+ ]
1451
+ },
1452
+ "Xenophon": {
1453
+ "held_out_source": "pedalion",
1454
+ "training_sources": [
1455
+ "gorman"
1456
+ ]
1457
+ }
1458
+ },
1459
+ "rows": 3350,
1460
+ "splits": {
1461
+ "test": 420,
1462
+ "train": 2510,
1463
+ "validation": 420
1464
+ }
1465
+ },
1466
+ "source_held_out_100": {
1467
+ "authors": 11,
1468
+ "genres": [
1469
+ "prose",
1470
+ "verse"
1471
+ ],
1472
+ "held_out_sources": {
1473
+ "Athenaeus": {
1474
+ "held_out_source": "gorman",
1475
+ "training_sources": [
1476
+ "agdt",
1477
+ "ud_perseus"
1478
+ ]
1479
+ },
1480
+ "Diodorus Siculus": {
1481
+ "held_out_source": "gorman",
1482
+ "training_sources": [
1483
+ "agdt",
1484
+ "ud_perseus"
1485
+ ]
1486
+ },
1487
+ "Herodotus": {
1488
+ "held_out_source": "ud_perseus",
1489
+ "training_sources": [
1490
+ "agdt",
1491
+ "gorman",
1492
+ "ud_proiel"
1493
+ ]
1494
+ },
1495
+ "Hesiod": {
1496
+ "held_out_source": "agdt",
1497
+ "training_sources": [
1498
+ "ud_perseus"
1499
+ ]
1500
+ },
1501
+ "Homeric-Iliad": {
1502
+ "held_out_source": "agdt",
1503
+ "training_sources": [
1504
+ "ud_perseus"
1505
+ ]
1506
+ },
1507
+ "Lucian": {
1508
+ "held_out_source": "harrington",
1509
+ "training_sources": [
1510
+ "pedalion"
1511
+ ]
1512
+ },
1513
+ "Plato": {
1514
+ "held_out_source": "agdt",
1515
+ "training_sources": [
1516
+ "gorman",
1517
+ "pedalion"
1518
+ ]
1519
+ },
1520
+ "Plutarch": {
1521
+ "held_out_source": "ud_perseus",
1522
+ "training_sources": [
1523
+ "agdt",
1524
+ "gorman"
1525
+ ]
1526
+ },
1527
+ "Sophocles": {
1528
+ "held_out_source": "agdt",
1529
+ "training_sources": [
1530
+ "ud_perseus"
1531
+ ]
1532
+ },
1533
+ "Thucydides": {
1534
+ "held_out_source": "ud_perseus",
1535
+ "training_sources": [
1536
+ "agdt",
1537
+ "gorman"
1538
+ ]
1539
+ },
1540
+ "Xenophon": {
1541
+ "held_out_source": "pedalion",
1542
+ "training_sources": [
1543
+ "gorman"
1544
+ ]
1545
+ }
1546
+ },
1547
+ "rows": 335,
1548
+ "splits": {
1549
+ "test": 42,
1550
+ "train": 251,
1551
+ "validation": 42
1552
+ }
1553
+ },
1554
+ "source_held_out_50": {
1555
+ "authors": 11,
1556
+ "genres": [
1557
+ "prose",
1558
+ "verse"
1559
+ ],
1560
+ "held_out_sources": {
1561
+ "Athenaeus": {
1562
+ "held_out_source": "gorman",
1563
+ "training_sources": [
1564
+ "agdt",
1565
+ "ud_perseus"
1566
+ ]
1567
+ },
1568
+ "Diodorus Siculus": {
1569
+ "held_out_source": "gorman",
1570
+ "training_sources": [
1571
+ "agdt",
1572
+ "ud_perseus"
1573
+ ]
1574
+ },
1575
+ "Herodotus": {
1576
+ "held_out_source": "ud_perseus",
1577
+ "training_sources": [
1578
+ "agdt",
1579
+ "gorman",
1580
+ "ud_proiel"
1581
+ ]
1582
+ },
1583
+ "Hesiod": {
1584
+ "held_out_source": "agdt",
1585
+ "training_sources": [
1586
+ "ud_perseus"
1587
+ ]
1588
+ },
1589
+ "Homeric-Iliad": {
1590
+ "held_out_source": "agdt",
1591
+ "training_sources": [
1592
+ "ud_perseus"
1593
+ ]
1594
+ },
1595
+ "Lucian": {
1596
+ "held_out_source": "harrington",
1597
+ "training_sources": [
1598
+ "pedalion"
1599
+ ]
1600
+ },
1601
+ "Plato": {
1602
+ "held_out_source": "agdt",
1603
+ "training_sources": [
1604
+ "gorman",
1605
+ "pedalion"
1606
+ ]
1607
+ },
1608
+ "Plutarch": {
1609
+ "held_out_source": "ud_perseus",
1610
+ "training_sources": [
1611
+ "agdt",
1612
+ "gorman"
1613
+ ]
1614
+ },
1615
+ "Sophocles": {
1616
+ "held_out_source": "agdt",
1617
+ "training_sources": [
1618
+ "ud_perseus"
1619
+ ]
1620
+ },
1621
+ "Thucydides": {
1622
+ "held_out_source": "ud_perseus",
1623
+ "training_sources": [
1624
+ "agdt",
1625
+ "gorman"
1626
+ ]
1627
+ },
1628
+ "Xenophon": {
1629
+ "held_out_source": "pedalion",
1630
+ "training_sources": [
1631
+ "gorman"
1632
+ ]
1633
+ }
1634
+ },
1635
+ "rows": 670,
1636
+ "splits": {
1637
+ "test": 84,
1638
+ "train": 502,
1639
+ "validation": 84
1640
+ }
1641
  }
1642
  }
1643
  }
metadata/dataset_variants.json CHANGED
The diff for this file is too large to render. See raw diff
 
metadata/leakage_report.json ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "configurations": {
3
+ "sentence_1": {
4
+ "authors": 17,
5
+ "inventory_to_author": {
6
+ "accuracy": 36.5208,
7
+ "features": 55,
8
+ "macro_f1": 17.9549
9
+ },
10
+ "majority_baseline": {
11
+ "accuracy": 14.5833,
12
+ "features": 0,
13
+ "macro_f1": 1.4973
14
+ },
15
+ "markup_to_author": {
16
+ "accuracy": 52.7083,
17
+ "features": 116,
18
+ "macro_f1": 34.0167
19
+ },
20
+ "markup_to_treebank_source": {
21
+ "accuracy": 82.3125,
22
+ "features": 116,
23
+ "macro_f1": 76.3751
24
+ },
25
+ "test_rows": 4800
26
+ },
27
+ "sentence_10": {
28
+ "authors": 17,
29
+ "inventory_to_author": {
30
+ "accuracy": 39.7917,
31
+ "features": 55,
32
+ "macro_f1": 16.6515
33
+ },
34
+ "majority_baseline": {
35
+ "accuracy": 14.5833,
36
+ "features": 0,
37
+ "macro_f1": 1.4973
38
+ },
39
+ "markup_to_author": {
40
+ "accuracy": 79.5833,
41
+ "features": 116,
42
+ "macro_f1": 65.9773
43
+ },
44
+ "markup_to_treebank_source": {
45
+ "accuracy": 88.125,
46
+ "features": 116,
47
+ "macro_f1": 70.5903
48
+ },
49
+ "test_rows": 480
50
+ },
51
+ "sentence_100": {
52
+ "authors": 17,
53
+ "inventory_to_author": {
54
+ "accuracy": 50.0,
55
+ "features": 55,
56
+ "macro_f1": 27.274
57
+ },
58
+ "majority_baseline": {
59
+ "accuracy": 14.5833,
60
+ "features": 0,
61
+ "macro_f1": 1.4973
62
+ },
63
+ "markup_to_author": {
64
+ "accuracy": 72.9167,
65
+ "features": 116,
66
+ "macro_f1": 41.6694
67
+ },
68
+ "markup_to_treebank_source": {
69
+ "accuracy": 64.5833,
70
+ "features": 116,
71
+ "macro_f1": 53.377
72
+ },
73
+ "test_rows": 48
74
+ },
75
+ "sentence_50": {
76
+ "authors": 17,
77
+ "inventory_to_author": {
78
+ "accuracy": 47.9167,
79
+ "features": 55,
80
+ "macro_f1": 28.9223
81
+ },
82
+ "majority_baseline": {
83
+ "accuracy": 14.5833,
84
+ "features": 0,
85
+ "macro_f1": 1.4973
86
+ },
87
+ "markup_to_author": {
88
+ "accuracy": 78.125,
89
+ "features": 116,
90
+ "macro_f1": 48.9063
91
+ },
92
+ "markup_to_treebank_source": {
93
+ "accuracy": 75.0,
94
+ "features": 116,
95
+ "macro_f1": 62.6627
96
+ },
97
+ "test_rows": 96
98
+ },
99
+ "source_held_out_1": {
100
+ "authors": 11,
101
+ "inventory_to_author": {
102
+ "accuracy": 16.881,
103
+ "features": 55,
104
+ "macro_f1": 7.6827
105
+ },
106
+ "majority_baseline": {
107
+ "accuracy": 11.9048,
108
+ "features": 0,
109
+ "macro_f1": 1.9342
110
+ },
111
+ "markup_to_author": {
112
+ "accuracy": 22.0238,
113
+ "features": 116,
114
+ "macro_f1": 11.1817
115
+ },
116
+ "markup_to_treebank_source": {
117
+ "accuracy": 35.3095,
118
+ "features": 116,
119
+ "macro_f1": 20.9741
120
+ },
121
+ "test_rows": 4200
122
+ },
123
+ "source_held_out_10": {
124
+ "authors": 11,
125
+ "inventory_to_author": {
126
+ "accuracy": 12.8571,
127
+ "features": 55,
128
+ "macro_f1": 4.5931
129
+ },
130
+ "majority_baseline": {
131
+ "accuracy": 11.9048,
132
+ "features": 0,
133
+ "macro_f1": 1.9342
134
+ },
135
+ "markup_to_author": {
136
+ "accuracy": 42.619,
137
+ "features": 116,
138
+ "macro_f1": 28.8832
139
+ },
140
+ "markup_to_treebank_source": {
141
+ "accuracy": 33.8095,
142
+ "features": 116,
143
+ "macro_f1": 17.7488
144
+ },
145
+ "test_rows": 420
146
+ },
147
+ "source_held_out_100": {
148
+ "authors": 11,
149
+ "inventory_to_author": {
150
+ "accuracy": 23.8095,
151
+ "features": 55,
152
+ "macro_f1": 8.2867
153
+ },
154
+ "majority_baseline": {
155
+ "accuracy": 11.9048,
156
+ "features": 0,
157
+ "macro_f1": 1.9342
158
+ },
159
+ "markup_to_author": {
160
+ "accuracy": 28.5714,
161
+ "features": 116,
162
+ "macro_f1": 12.6748
163
+ },
164
+ "markup_to_treebank_source": {
165
+ "accuracy": 21.4286,
166
+ "features": 116,
167
+ "macro_f1": 11.413
168
+ },
169
+ "test_rows": 42
170
+ },
171
+ "source_held_out_50": {
172
+ "authors": 11,
173
+ "inventory_to_author": {
174
+ "accuracy": 7.1429,
175
+ "features": 55,
176
+ "macro_f1": 2.7308
177
+ },
178
+ "majority_baseline": {
179
+ "accuracy": 11.9048,
180
+ "features": 0,
181
+ "macro_f1": 1.9342
182
+ },
183
+ "markup_to_author": {
184
+ "accuracy": 30.9524,
185
+ "features": 116,
186
+ "macro_f1": 19.9491
187
+ },
188
+ "markup_to_treebank_source": {
189
+ "accuracy": 25.0,
190
+ "features": 116,
191
+ "macro_f1": 12.4508
192
+ },
193
+ "test_rows": 84
194
+ }
195
+ },
196
+ "probes": {
197
+ "inventory": "binary presence of each tag, feature, relation and MISC key",
198
+ "markup": "non-lexical rates over UPOS, DEPREL, FEATS, MISC and XPOS"
199
+ },
200
+ "purpose": "Scheme-only baselines. These classifiers see annotation markup and no Greek at all; a model that does not clearly beat them has demonstrated source identification, not authorship attribution."
201
+ }
requirements-build.txt CHANGED
@@ -1,3 +1,5 @@
1
  edlib>=1.3.9,<2
2
  grc-utils==0.2.2
3
  pyarrow>=21,<22
 
 
 
1
  edlib>=1.3.9,<2
2
  grc-utils==0.2.2
3
  pyarrow>=21,<22
4
+ # scripts/audit_leakage.py fits the scheme-only baselines.
5
+ scikit-learn>=1.4
scripts/audit_leakage.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Measure how much of Sphragis is solvable without reading any Greek.
3
+
4
+ Sphragis merges seven annotation projects whose author inventories do not
5
+ overlap, so the annotation scheme is itself a partial answer key. This script
6
+ fits deliberately crippled classifiers that see only annotation *markup* — no
7
+ word forms, no lemmas — and reports what they score. Any model that does not
8
+ clearly beat these numbers has demonstrated source identification rather than
9
+ authorship attribution, and the leaderboard publishes them for that reason.
10
+
11
+ Two probes:
12
+
13
+ ``inventory``
14
+ 43 binary flags recording only which tags, features, relations and MISC
15
+ keys a document happens to use. It cannot represent frequency, word order
16
+ or any word.
17
+ ``markup``
18
+ Rates over UPOS, DEPREL, FEATS keys, MISC keys and XPOS positions, plus
19
+ token count. Still entirely non-lexical.
20
+
21
+ It also reports how recoverable ``treebank_source`` itself is, which is the
22
+ quantity the normalization is trying to reduce.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ import argparse
28
+ from collections import Counter
29
+ import json
30
+ from pathlib import Path
31
+
32
+ import pyarrow.parquet as pq
33
+ from sklearn.feature_extraction import DictVectorizer
34
+ from sklearn.linear_model import LogisticRegression
35
+ from sklearn.metrics import accuracy_score, f1_score
36
+
37
+ try:
38
+ from scripts.conllu_units import load_conllu_units
39
+ except ModuleNotFoundError: # Direct execution from the scripts directory.
40
+ from conllu_units import load_conllu_units
41
+
42
+
43
+ SPLITS = ("train", "validation", "test")
44
+
45
+ FLAG_UPOS = ("NOUN", "VERB", "ADJ", "PRON", "ADV", "ADP", "NUM", "INTJ", "X",
46
+ "PUNCT", "PROPN", "AUX", "CCONJ", "SCONJ", "PART", "DET")
47
+ FLAG_FEATS = ("Case", "Gender", "Number", "Person", "Tense", "Mood", "Voice",
48
+ "Degree", "VerbForm", "PronType", "Definite", "Aspect")
49
+ FLAG_MISC = ("NativeRel", "NativeHead", "HeadRepair", "SpaceAfter")
50
+ FLAG_DEPREL = ("root", "nsubj", "obj", "ccomp", "obl", "nmod", "advmod", "case",
51
+ "conj", "appos", "vocative", "discourse", "dep", "cc", "cop",
52
+ "iobj", "punct", "det", "amod", "dislocated", "nsubj:pass")
53
+
54
+
55
+ def tokens(conllu: str) -> list[list[str]]:
56
+ return [
57
+ line.split("\t") for line in conllu.splitlines()
58
+ if line and not line.startswith("#") and len(line.split("\t")) == 10
59
+ ]
60
+
61
+
62
+ def inventory_features(units: list[str]) -> dict[str, float]:
63
+ upos, feats, misc, deprel = set(), set(), set(), set()
64
+ empty_misc = True
65
+ has_punct = False
66
+ for unit in units:
67
+ for token in tokens(unit):
68
+ upos.add(token[3])
69
+ deprel.add(token[7])
70
+ has_punct = has_punct or token[3] == "PUNCT"
71
+ if token[5] != "_":
72
+ feats.update(item.split("=", 1)[0] for item in token[5].split("|"))
73
+ if token[9] != "_":
74
+ empty_misc = False
75
+ misc.update(item.split("=", 1)[0] for item in token[9].split("|"))
76
+ features = {f"U:{key}": float(key in upos) for key in FLAG_UPOS}
77
+ features.update({f"F:{key}": float(key in feats) for key in FLAG_FEATS})
78
+ features.update({f"M:{key}": float(key in misc) for key in FLAG_MISC})
79
+ features.update({f"R:{key}": float(key in deprel) for key in FLAG_DEPREL})
80
+ features["empty-misc"] = float(empty_misc)
81
+ features["no-punct"] = float(not has_punct)
82
+ return features
83
+
84
+
85
+ def markup_features(units: list[str]) -> dict[str, float]:
86
+ counts: Counter[str] = Counter()
87
+ total = 0
88
+ for unit in units:
89
+ for token in tokens(unit):
90
+ total += 1
91
+ counts[f"u:{token[3]}"] += 1
92
+ counts[f"r:{token[7]}"] += 1
93
+ if token[5] == "_":
94
+ counts["f:none"] += 1
95
+ else:
96
+ for item in token[5].split("|"):
97
+ counts[f"f:{item}"] += 1
98
+ if token[9] == "_":
99
+ counts["m:none"] += 1
100
+ else:
101
+ for item in token[9].split("|"):
102
+ counts[f"m:{item.split('=', 1)[0]}"] += 1
103
+ if token[4] != "_":
104
+ for position, value in enumerate(token[4]):
105
+ counts[f"x{position}:{value}"] += 1
106
+ total = max(total, 1)
107
+ features = {key: value / total for key, value in counts.items()}
108
+ features["tokens"] = total / 50.0
109
+ return features
110
+
111
+
112
+ def read_config(data: Path, config: str) -> dict[str, list[dict]]:
113
+ rows = {}
114
+ for split in SPLITS:
115
+ path = data / config / f"{split}-00000-of-00001.parquet"
116
+ rows[split] = pq.read_table(
117
+ path, columns=["author", "treebank_source", "conllu"],
118
+ ).to_pylist()
119
+ return rows
120
+
121
+
122
+ def score(rows: dict[str, list[dict]], featurizer, label: str) -> dict:
123
+ vectorizer = DictVectorizer(sparse=True)
124
+ train = [featurizer(load_conllu_units(row["conllu"])) for row in rows["train"]]
125
+ test = [featurizer(load_conllu_units(row["conllu"])) for row in rows["test"]]
126
+ x_train = vectorizer.fit_transform(train)
127
+ x_test = vectorizer.transform(test)
128
+ y_train = [row[label] for row in rows["train"]]
129
+ y_test = [row[label] for row in rows["test"]]
130
+ model = LogisticRegression(max_iter=3000).fit(x_train, y_train)
131
+ predicted = model.predict(x_test)
132
+ return {
133
+ "features": int(x_train.shape[1]),
134
+ "accuracy": round(100 * accuracy_score(y_test, predicted), 4),
135
+ "macro_f1": round(100 * f1_score(y_test, predicted, average="macro"), 4),
136
+ }
137
+
138
+
139
+ def majority_baseline(rows: dict[str, list[dict]], label: str) -> dict:
140
+ commonest = Counter(row[label] for row in rows["train"]).most_common(1)[0][0]
141
+ y_test = [row[label] for row in rows["test"]]
142
+ predicted = [commonest] * len(y_test)
143
+ return {
144
+ "features": 0,
145
+ "accuracy": round(100 * accuracy_score(y_test, predicted), 4),
146
+ "macro_f1": round(100 * f1_score(y_test, predicted, average="macro"), 4),
147
+ }
148
+
149
+
150
+ def main() -> None:
151
+ parser = argparse.ArgumentParser()
152
+ parser.add_argument("--data", type=Path, default=Path("data"))
153
+ parser.add_argument("--metadata", type=Path, default=Path("metadata"))
154
+ parser.add_argument(
155
+ "--configs", nargs="*",
156
+ default=[
157
+ *(f"sentence_{suffix}" for suffix in (1, 10, 50, 100)),
158
+ *(f"source_held_out_{suffix}" for suffix in (1, 10, 50, 100)),
159
+ ],
160
+ )
161
+ args = parser.parse_args()
162
+
163
+ report = {
164
+ "purpose": (
165
+ "Scheme-only baselines. These classifiers see annotation markup and "
166
+ "no Greek at all; a model that does not clearly beat them has "
167
+ "demonstrated source identification, not authorship attribution."
168
+ ),
169
+ "probes": {
170
+ "inventory": "binary presence of each tag, feature, relation and MISC key",
171
+ "markup": "non-lexical rates over UPOS, DEPREL, FEATS, MISC and XPOS",
172
+ },
173
+ "configurations": {},
174
+ }
175
+ for config in args.configs:
176
+ rows = read_config(args.data, config)
177
+ entry = {
178
+ "test_rows": len(rows["test"]),
179
+ "authors": len({row["author"] for row in rows["train"]}),
180
+ "majority_baseline": majority_baseline(rows, "author"),
181
+ "inventory_to_author": score(rows, inventory_features, "author"),
182
+ "markup_to_author": score(rows, markup_features, "author"),
183
+ "markup_to_treebank_source": score(
184
+ rows, markup_features, "treebank_source",
185
+ ),
186
+ }
187
+ report["configurations"][config] = entry
188
+ print(config, json.dumps(entry, indent=2), flush=True)
189
+
190
+ args.metadata.mkdir(parents=True, exist_ok=True)
191
+ output = args.metadata / "leakage_report.json"
192
+ output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n")
193
+ print(f"wrote {output}")
194
+
195
+
196
+ if __name__ == "__main__":
197
+ main()
scripts/build_dataset.py CHANGED
@@ -30,7 +30,11 @@ import pyarrow.parquet as pq
30
  from grc_utils import vowel
31
 
32
  try:
33
- from scripts.conllu_units import load_conllu_units
 
 
 
 
34
  from scripts.dataset_variants import (
35
  fields_first,
36
  make_dataset_variants,
@@ -38,20 +42,63 @@ try:
38
  )
39
  from scripts.metre_units import load_metre_units, load_syllable_units
40
  from scripts.metrical_lines import cropped_public_metrical_line, load_public_metrical_lines
41
- from scripts.text_units import load_text_units
42
- from scripts.syntax_normalization import is_universal_deprel, syntax_text_normalize
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  from scripts.vendor.conll18_ud_eval import UDError, load_conllu
44
  except ModuleNotFoundError: # Direct execution from the scripts directory.
45
- from conllu_units import load_conllu_units
 
 
 
 
46
  from dataset_variants import fields_first, make_dataset_variants, variant_schema
47
  from metre_units import load_metre_units, load_syllable_units
48
  from metrical_lines import cropped_public_metrical_line, load_public_metrical_lines
49
- from text_units import load_text_units
50
- from syntax_normalization import is_universal_deprel, syntax_text_normalize
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  from vendor.conll18_ud_eval import UDError, load_conllu
52
 
53
 
54
  RANDOM_SEED = 776
 
 
 
55
  SAFE_CONLLU_MISC_KEYS = {"NativeRel", "NativeHead", "HeadRepair", "SpaceAfter"}
56
 
57
 
@@ -1955,6 +2002,143 @@ def assign_splits(rows: list[dict]) -> None:
1955
  row["split"] = split
1956
 
1957
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1958
  def write_parquet(
1959
  rows: list[dict], output_root: Path, config: str, schema: pa.Schema | None = None,
1960
  ) -> dict:
@@ -1970,15 +2154,63 @@ def write_parquet(
1970
  return stats
1971
 
1972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1973
  def validate_publication(
1974
  rows_by_config: dict[str, list[dict]], publication: str,
1975
  ) -> dict:
1976
  """Validate final repository-level rows after the publication split."""
1977
- expected_configs = (
1978
- tuple(f"sentence_{suffix}" for suffix in ("1", "10", "50", "100"))
1979
- if publication == "sentence"
1980
- else tuple(f"verse_{suffix}" for suffix in ("1", "10", "50", "100"))
1981
- )
 
 
 
1982
  assert set(rows_by_config) == set(expected_configs)
1983
  report = {}
1984
  for config in expected_configs:
@@ -2024,6 +2256,8 @@ def validate_publication(
2024
  }
2025
  if publication == "sentence":
2026
  report[config]["genres"] = sorted({row["genre"] for row in rows})
 
 
2027
 
2028
  atomic = rows_by_config[expected_configs[0]]
2029
  if publication == "metre":
@@ -2036,17 +2270,25 @@ def validate_publication(
2036
  feature_authors[feature].add(row["author"])
2037
  assert feature_authors["caesura"] == authors
2038
  assert feature_authors["hiatus"] == authors
2039
- for config in expected_configs[1:]:
2040
- for split in ("train", "validation", "test"):
2041
- expected_ids = {row["id"] for row in atomic if row["split"] == split}
2042
- represented_ids = [
2043
- row_id
2044
- for row in rows_by_config[config]
2045
- if row["split"] == split
2046
- for row_id in row["constituent_ids"]
2047
- ]
2048
- assert len(represented_ids) == len(set(represented_ids))
2049
- assert set(represented_ids) == expected_ids
 
 
 
 
 
 
 
 
2050
  report["checks"] = {
2051
  "expected_configurations": True,
2052
  "identical_source_rows_across_task_sizes": True,
@@ -2126,31 +2368,13 @@ def validate(rows_by_config: dict[str, list[dict]]) -> dict:
2126
  for row in rows:
2127
  row_text_units = load_text_units(row["text"])
2128
  for conllu_index, conllu in enumerate(load_conllu_units(row["conllu"])):
2129
- comments = [
2130
- line for line in conllu.splitlines()
2131
- if line.startswith("#")
2132
- ]
2133
- assert all(line.startswith("# text = ") for line in comments), (
2134
- f"Identifying CoNLL-U comment in {config}, row {row['id']}: {comments}"
2135
  )
2136
- for line in conllu.splitlines():
2137
- if not line or line.startswith("#"):
2138
- continue
2139
- columns = line.split("\t")
2140
- assert len(columns) == 10
2141
- if base_config == "verse_metre":
2142
- assert is_universal_deprel(columns[7]), columns[7]
2143
- misc_keys = {
2144
- item.split("=", 1)[0]
2145
- for item in columns[9].split("|")
2146
- if item != "_"
2147
- }
2148
- assert misc_keys <= SAFE_CONLLU_MISC_KEYS, (
2149
- f"Identifying CoNLL-U MISC field in {config}, "
2150
- f"row {row['id']}: {misc_keys}"
2151
- )
2152
- if base_config == "verse_metre":
2153
- assert misc_keys <= {"HeadRepair"}
2154
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
2155
  if digest in checked_conllu:
2156
  continue
@@ -2316,6 +2540,8 @@ def main() -> None:
2316
  sentence_input, sentence_curation = curate_sentences(sentence_input)
2317
  sentences, dedup_stats = deduplicate_sentences(sentence_input)
2318
  assign_splits(sentences)
 
 
2319
 
2320
  hyp = load_hypotactic(args.sources / "hypotactic", all_files=True)
2321
  verse_input, verse_curation = curate_sentences(agdt_verse + pedalion_verse)
@@ -2351,11 +2577,12 @@ def main() -> None:
2351
  # only while consuming the established RNG sequence, then publish machine
2352
  # rows alone. This preserves every existing benchmark split and chunk.
2353
  assign_splits([*verse_metre, *split_rng_padding])
 
2354
  stoicheia_stats["split_rng_padding_gold_rows_not_published"] = len(
2355
  split_rng_padding
2356
  )
2357
  sentence_rows, sentence_variant_report = make_dataset_variants(
2358
- {"sentence": sentences}
2359
  )
2360
  metre_rows, metre_variant_report = make_dataset_variants(
2361
  {"verse_metre": verse_metre}
@@ -2365,11 +2592,19 @@ def main() -> None:
2365
 
2366
  sentence_stats = {}
2367
  sentence_schema = pa.Table.from_pylist(sentences).schema
 
 
 
 
 
2368
  for config, rows in sentence_rows.items():
 
 
 
 
 
2369
  schema = (
2370
- sentence_schema
2371
- if config.endswith("_1")
2372
- else variant_schema(sentence_schema)
2373
  )
2374
  sentence_stats[config] = write_parquet(rows, args.output, config, schema)
2375
  metre_stats = {}
@@ -2415,6 +2650,34 @@ def main() -> None:
2415
  "treebank_sentence_input": sentence_curation,
2416
  },
2417
  "deduplication": dedup_stats,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2418
  "splitting": {
2419
  "seed": RANDOM_SEED,
2420
  "strategy": "independent row-level 80/10/10 stratification by author and work",
@@ -2462,6 +2725,10 @@ def main() -> None:
2462
  "disputed_verse_passages": passage_curation,
2463
  },
2464
  "splitting": sentence_report["splitting"],
 
 
 
 
2465
  "alignment": alignment_stats,
2466
  "automatic_syntax": stoicheia_stats,
2467
  "metrical_representation": {
 
30
  from grc_utils import vowel
31
 
32
  try:
33
+ from scripts.conllu_units import (
34
+ encode_conllu_units,
35
+ load_conllu_units,
36
+ source_conllu_units,
37
+ )
38
  from scripts.dataset_variants import (
39
  fields_first,
40
  make_dataset_variants,
 
42
  )
43
  from scripts.metre_units import load_metre_units, load_syllable_units
44
  from scripts.metrical_lines import cropped_public_metrical_line, load_public_metrical_lines
45
+ from scripts.text_units import (
46
+ encode_text_units,
47
+ load_text_units,
48
+ source_text_units,
49
+ )
50
+ from scripts.syntax_normalization import (
51
+ CORE_DEPRELS,
52
+ CORE_FEATS,
53
+ CORE_XPOS_POS,
54
+ is_universal_deprel,
55
+ syntax_text_normalize,
56
+ )
57
+ from scripts.model_facing import (
58
+ CORE_UPOS,
59
+ check_model_facing_conllu,
60
+ encode_native_syntax,
61
+ finalize_conllu_unit,
62
+ lower_greek,
63
+ punctuationless_text,
64
+ )
65
  from scripts.vendor.conll18_ud_eval import UDError, load_conllu
66
  except ModuleNotFoundError: # Direct execution from the scripts directory.
67
+ from conllu_units import (
68
+ encode_conllu_units,
69
+ load_conllu_units,
70
+ source_conllu_units,
71
+ )
72
  from dataset_variants import fields_first, make_dataset_variants, variant_schema
73
  from metre_units import load_metre_units, load_syllable_units
74
  from metrical_lines import cropped_public_metrical_line, load_public_metrical_lines
75
+ from text_units import (
76
+ encode_text_units,
77
+ load_text_units,
78
+ source_text_units,
79
+ )
80
+ from syntax_normalization import (
81
+ CORE_DEPRELS,
82
+ CORE_FEATS,
83
+ CORE_XPOS_POS,
84
+ is_universal_deprel,
85
+ syntax_text_normalize,
86
+ )
87
+ from model_facing import (
88
+ CORE_UPOS,
89
+ check_model_facing_conllu,
90
+ encode_native_syntax,
91
+ finalize_conllu_unit,
92
+ lower_greek,
93
+ punctuationless_text,
94
+ )
95
  from vendor.conll18_ud_eval import UDError, load_conllu
96
 
97
 
98
  RANDOM_SEED = 776
99
+ # MISC keys retained while trees are still assembled internally. None of them
100
+ # reach the published columns: finalize_publication_rows lifts them into the
101
+ # separate native_syntax audit column and clears MISC.
102
  SAFE_CONLLU_MISC_KEYS = {"NativeRel", "NativeHead", "HeadRepair", "SpaceAfter"}
103
 
104
 
 
2002
  row["split"] = split
2003
 
2004
 
2005
+ def finalize_publication_rows(rows: list[dict]) -> dict:
2006
+ """Reduce every row to the scheme-neutral model-facing representation.
2007
+
2008
+ This is the single choke point at which authorship-identifying annotation
2009
+ conventions are removed. It runs after deduplication and splitting so that
2010
+ the published author inventory, split assignment and chunk boundaries are
2011
+ unchanged by it.
2012
+ """
2013
+ stats = Counter()
2014
+ for row in rows:
2015
+ documents = []
2016
+ native = []
2017
+ for unit in source_conllu_units(row["conllu"]):
2018
+ document, unit_native = finalize_conllu_unit(unit)
2019
+ documents.append(document)
2020
+ native.append(unit_native)
2021
+ stats["units"] += 1
2022
+ stats["units_with_native_syntax"] += bool(unit_native)
2023
+ texts = []
2024
+ for unit in source_text_units(row["text"]):
2025
+ cleaned = punctuationless_text(lower_greek(unit))
2026
+ if not cleaned:
2027
+ raise ValueError(f"row {row['id']} has no text after normalization")
2028
+ texts.append(cleaned)
2029
+ row["conllu"] = encode_conllu_units(documents)
2030
+ row["text"] = encode_text_units(texts)
2031
+ row["native_syntax"] = encode_native_syntax(native)
2032
+ if "syllables" in row:
2033
+ row["syllables"] = lower_greek_syllables(row["syllables"])
2034
+ stats["rows"] += 1
2035
+ return dict(stats)
2036
+
2037
+
2038
+ def lower_greek_syllables(encoded: str) -> str:
2039
+ """Lowercase the Greek transcription inside a metre syllable annotation.
2040
+
2041
+ Accepts both the internal shape, a bare list of syllables, and the
2042
+ published shape, where syllables are grouped into line objects.
2043
+ """
2044
+ payload = json.loads(encoded)
2045
+ entries = payload if isinstance(payload, list) else [payload]
2046
+ for entry in entries:
2047
+ syllables = entry["syllables"] if "syllables" in entry else [entry]
2048
+ for syllable in syllables:
2049
+ syllable["text"] = lower_greek(syllable["text"])
2050
+ return json.dumps(payload, ensure_ascii=False)
2051
+
2052
+
2053
+ SOURCE_HELD_OUT_TARGET = 100
2054
+
2055
+
2056
+ def source_held_out_rows(rows: list[dict]) -> tuple[list[dict], dict]:
2057
+ """Build the evaluation track in which no author's test annotator is seen in training.
2058
+
2059
+ The confound this track exists to defeat is that Sphragis merges seven
2060
+ annotation projects whose author inventories do not overlap, so the
2061
+ annotation scheme itself predicts the author. Here each retained author's
2062
+ second-largest source project is held out entirely: its sentences become
2063
+ that author's validation and test data, and every other project supplies
2064
+ training. A model that has learned to recognize annotators rather than
2065
+ writers is therefore actively misled, because at evaluation time each
2066
+ author arrives in the scheme it was never trained in.
2067
+ """
2068
+ by_author = defaultdict(lambda: defaultdict(list))
2069
+ for row in rows:
2070
+ by_author[row["author"]][row["treebank_source"]].append(row)
2071
+
2072
+ selected: list[dict] = []
2073
+ decisions = {}
2074
+ rejected = {}
2075
+ for author in sorted(by_author):
2076
+ by_source = by_author[author]
2077
+ ranked = sorted(
2078
+ by_source, key=lambda source: (-len(by_source[source]), source),
2079
+ )
2080
+ if len(ranked) < 2:
2081
+ rejected[author] = {
2082
+ "reason": "only one source project",
2083
+ "sources": {source: len(by_source[source]) for source in ranked},
2084
+ }
2085
+ continue
2086
+ held_out = ranked[1]
2087
+ held_out_rows = by_source[held_out]
2088
+ train_rows = [
2089
+ row for source in ranked if source != held_out
2090
+ for row in by_source[source]
2091
+ ]
2092
+ evaluation = len(held_out_rows) // 2
2093
+ if (
2094
+ evaluation < SOURCE_HELD_OUT_TARGET
2095
+ or len(train_rows) < SOURCE_HELD_OUT_TARGET
2096
+ ):
2097
+ rejected[author] = {
2098
+ "reason": "held-out source too small for a 100-row validation and test split",
2099
+ "held_out_source": held_out,
2100
+ "sources": {source: len(by_source[source]) for source in ranked},
2101
+ }
2102
+ continue
2103
+
2104
+ rng = random.Random(f"{RANDOM_SEED}:source-held-out:{author}")
2105
+ shuffled = sorted(held_out_rows, key=lambda row: row["id"])
2106
+ rng.shuffle(shuffled)
2107
+ assignment = {
2108
+ **{row["id"]: "validation" for row in shuffled[:evaluation]},
2109
+ **{row["id"]: "test" for row in shuffled[evaluation:evaluation * 2]},
2110
+ }
2111
+ for row in train_rows:
2112
+ selected.append({**row, "split": "train", "held_out_source": held_out})
2113
+ for row in shuffled:
2114
+ split = assignment.get(row["id"])
2115
+ if split is not None:
2116
+ selected.append({**row, "split": split, "held_out_source": held_out})
2117
+ decisions[author] = {
2118
+ "held_out_source": held_out,
2119
+ "training_sources": [source for source in ranked if source != held_out],
2120
+ "source_rows": {source: len(by_source[source]) for source in ranked},
2121
+ "rows": {
2122
+ "train": len(train_rows),
2123
+ "validation": evaluation,
2124
+ "test": evaluation,
2125
+ },
2126
+ }
2127
+ selected.sort(key=lambda row: row["id"])
2128
+ return selected, {
2129
+ "policy": (
2130
+ "hold out each author's second-largest source project entirely; its "
2131
+ "sentences form that author's validation and test data and every "
2132
+ "other project supplies training"
2133
+ ),
2134
+ "seed": RANDOM_SEED,
2135
+ "minimum_rows_per_split": SOURCE_HELD_OUT_TARGET,
2136
+ "retained_authors": sorted(decisions),
2137
+ "author_decisions": decisions,
2138
+ "excluded_authors": rejected,
2139
+ }
2140
+
2141
+
2142
  def write_parquet(
2143
  rows: list[dict], output_root: Path, config: str, schema: pa.Schema | None = None,
2144
  ) -> dict:
 
2154
  return stats
2155
 
2156
 
2157
+ def row_treebank_sources(row: dict) -> set[str]:
2158
+ """Every source project actually represented in a row, chunk or atomic."""
2159
+ provenance = row.get("constituent_provenance")
2160
+ if provenance:
2161
+ return {
2162
+ record["treebank_source"] for record in json.loads(provenance)
2163
+ if record.get("treebank_source")
2164
+ }
2165
+ return {row["treebank_source"]}
2166
+
2167
+
2168
+ def validate_source_held_out(config: str, rows: list[dict]) -> dict:
2169
+ """Assert that no author's evaluation annotator appears in its training data.
2170
+
2171
+ This is the property the whole track exists for. If it ever fails, the
2172
+ track has silently become another in-domain split and its scores mean
2173
+ nothing more than the main track's.
2174
+ """
2175
+ by_author = defaultdict(lambda: defaultdict(set))
2176
+ for row in rows:
2177
+ by_author[row["author"]][row["split"]] |= row_treebank_sources(row)
2178
+ summary = {}
2179
+ for author in sorted(by_author):
2180
+ splits = by_author[author]
2181
+ held_out = {row["held_out_source"] for row in rows if row["author"] == author}
2182
+ assert len(held_out) == 1, (
2183
+ f"{config}: author {author} has inconsistent held_out_source {held_out}"
2184
+ )
2185
+ held_out_source = held_out.pop()
2186
+ evaluation = splits["validation"] | splits["test"]
2187
+ assert evaluation == {held_out_source}, (
2188
+ f"{config}: {author} evaluation data is annotated by {sorted(evaluation)}, "
2189
+ f"expected only the held-out {held_out_source!r}"
2190
+ )
2191
+ assert held_out_source not in splits["train"], (
2192
+ f"{config}: {author} trains on its held-out source {held_out_source!r}"
2193
+ )
2194
+ assert splits["train"], f"{config}: {author} has no training data"
2195
+ summary[author] = {
2196
+ "held_out_source": held_out_source,
2197
+ "training_sources": sorted(splits["train"]),
2198
+ }
2199
+ return summary
2200
+
2201
+
2202
  def validate_publication(
2203
  rows_by_config: dict[str, list[dict]], publication: str,
2204
  ) -> dict:
2205
  """Validate final repository-level rows after the publication split."""
2206
+ suffixes = ("1", "10", "50", "100")
2207
+ if publication == "sentence":
2208
+ expected_configs = (
2209
+ *(f"sentence_{suffix}" for suffix in suffixes),
2210
+ *(f"source_held_out_{suffix}" for suffix in suffixes),
2211
+ )
2212
+ else:
2213
+ expected_configs = tuple(f"verse_{suffix}" for suffix in suffixes)
2214
  assert set(rows_by_config) == set(expected_configs)
2215
  report = {}
2216
  for config in expected_configs:
 
2256
  }
2257
  if publication == "sentence":
2258
  report[config]["genres"] = sorted({row["genre"] for row in rows})
2259
+ if config.startswith("source_held_out"):
2260
+ report[config]["held_out_sources"] = validate_source_held_out(config, rows)
2261
 
2262
  atomic = rows_by_config[expected_configs[0]]
2263
  if publication == "metre":
 
2270
  feature_authors[feature].add(row["author"])
2271
  assert feature_authors["caesura"] == authors
2272
  assert feature_authors["hiatus"] == authors
2273
+ for track_prefix in sorted({
2274
+ config.rsplit("_", 1)[0] for config in expected_configs
2275
+ }):
2276
+ track_atomic = rows_by_config[f"{track_prefix}_1"]
2277
+ for config in expected_configs:
2278
+ if config == f"{track_prefix}_1" or not config.startswith(f"{track_prefix}_"):
2279
+ continue
2280
+ for split in ("train", "validation", "test"):
2281
+ expected_ids = {
2282
+ row["id"] for row in track_atomic if row["split"] == split
2283
+ }
2284
+ represented_ids = [
2285
+ row_id
2286
+ for row in rows_by_config[config]
2287
+ if row["split"] == split
2288
+ for row_id in row["constituent_ids"]
2289
+ ]
2290
+ assert len(represented_ids) == len(set(represented_ids))
2291
+ assert set(represented_ids) == expected_ids
2292
  report["checks"] = {
2293
  "expected_configurations": True,
2294
  "identical_source_rows_across_task_sizes": True,
 
2368
  for row in rows:
2369
  row_text_units = load_text_units(row["text"])
2370
  for conllu_index, conllu in enumerate(load_conllu_units(row["conllu"])):
2371
+ check_model_facing_conllu(conllu, f"{config}, row {row['id']}")
2372
+ assert syntax_text_normalize("".join(
2373
+ line.split("\t")[1] for line in conllu.splitlines() if line
2374
+ )) == syntax_text_normalize(row_text_units[conllu_index]), (
2375
+ f"CoNLL-U forms do not reconstruct the text column in "
2376
+ f"{config}, row {row['id']}"
2377
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2378
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
2379
  if digest in checked_conllu:
2380
  continue
 
2540
  sentence_input, sentence_curation = curate_sentences(sentence_input)
2541
  sentences, dedup_stats = deduplicate_sentences(sentence_input)
2542
  assign_splits(sentences)
2543
+ sentence_finalization = finalize_publication_rows(sentences)
2544
+ held_out_sentences, source_held_out_report = source_held_out_rows(sentences)
2545
 
2546
  hyp = load_hypotactic(args.sources / "hypotactic", all_files=True)
2547
  verse_input, verse_curation = curate_sentences(agdt_verse + pedalion_verse)
 
2577
  # only while consuming the established RNG sequence, then publish machine
2578
  # rows alone. This preserves every existing benchmark split and chunk.
2579
  assign_splits([*verse_metre, *split_rng_padding])
2580
+ metre_finalization = finalize_publication_rows(verse_metre)
2581
  stoicheia_stats["split_rng_padding_gold_rows_not_published"] = len(
2582
  split_rng_padding
2583
  )
2584
  sentence_rows, sentence_variant_report = make_dataset_variants(
2585
+ {"sentence": sentences, "source_held_out": held_out_sentences}
2586
  )
2587
  metre_rows, metre_variant_report = make_dataset_variants(
2588
  {"verse_metre": verse_metre}
 
2592
 
2593
  sentence_stats = {}
2594
  sentence_schema = pa.Table.from_pylist(sentences).schema
2595
+ held_out_schema = (
2596
+ pa.Table.from_pylist(held_out_sentences).schema
2597
+ if held_out_sentences
2598
+ else sentence_schema
2599
+ )
2600
  for config, rows in sentence_rows.items():
2601
+ base_schema = (
2602
+ held_out_schema
2603
+ if config.startswith("source_held_out")
2604
+ else sentence_schema
2605
+ )
2606
  schema = (
2607
+ base_schema if config.endswith("_1") else variant_schema(base_schema)
 
 
2608
  )
2609
  sentence_stats[config] = write_parquet(rows, args.output, config, schema)
2610
  metre_stats = {}
 
2650
  "treebank_sentence_input": sentence_curation,
2651
  },
2652
  "deduplication": dedup_stats,
2653
+ "model_facing_normalization": {
2654
+ "rationale": (
2655
+ "Sphragis merges seven annotation projects whose author "
2656
+ "inventories do not overlap, so any convention that "
2657
+ "distinguishes those projects also identifies the author. "
2658
+ "Every published column is reduced to one shared "
2659
+ "representation; the project-specific annotation is retained "
2660
+ "for audit in the native_syntax column."
2661
+ ),
2662
+ "conllu_comments": "removed; the text column carries the text",
2663
+ "misc": "cleared; NativeRel, NativeHead and HeadRepair move to native_syntax",
2664
+ "punctuation": (
2665
+ "editorial punctuation tokens are removed from CoNLL-U and from "
2666
+ "text, because UD PROIEL does not tokenize punctuation at all"
2667
+ ),
2668
+ "case": (
2669
+ "word forms, lemmas and text are lowercased with "
2670
+ "grc_utils.lower_grc"
2671
+ ),
2672
+ "deprel_inventory": sorted(CORE_DEPRELS - {"punct"}),
2673
+ "feats_inventory": sorted(CORE_FEATS),
2674
+ "upos_inventory": sorted(CORE_UPOS),
2675
+ "xpos_part_of_speech_inventory": sorted(
2676
+ set(CORE_XPOS_POS.values()) - {"u"}
2677
+ ),
2678
+ "statistics": sentence_finalization,
2679
+ },
2680
+ "source_held_out_track": source_held_out_report,
2681
  "splitting": {
2682
  "seed": RANDOM_SEED,
2683
  "strategy": "independent row-level 80/10/10 stratification by author and work",
 
2725
  "disputed_verse_passages": passage_curation,
2726
  },
2727
  "splitting": sentence_report["splitting"],
2728
+ "model_facing_normalization": {
2729
+ **sentence_report["model_facing_normalization"],
2730
+ "statistics": metre_finalization,
2731
+ },
2732
  "alignment": alignment_stats,
2733
  "automatic_syntax": stoicheia_stats,
2734
  "metrical_representation": {
scripts/build_sqlite_mirror.py CHANGED
@@ -15,7 +15,10 @@ import pyarrow as pa
15
  import pyarrow.parquet as pq
16
 
17
  SPLITS = ("train", "validation", "test")
18
- CONFIGS = tuple(f"sentence_{suffix}" for suffix in ("1", "10", "50", "100"))
 
 
 
19
  INDEX_COLUMN = "_split_row_index"
20
 
21
 
@@ -215,13 +218,13 @@ def main() -> None:
215
  )
216
  parser.add_argument("--check", action="store_true")
217
  args = parser.parse_args()
218
- base = "sentence" if args.publication == "sentence" else "verse"
219
- suffixes = (
220
- ("1", "10", "50", "100")
 
221
  if args.publication == "sentence"
222
- else ("1", "10", "50", "100")
223
  )
224
- CONFIGS = tuple(f"{base}_{suffix}" for suffix in suffixes)
225
  if not args.check:
226
  build(args.data, args.output)
227
  validate(args.data, args.output)
 
15
  import pyarrow.parquet as pq
16
 
17
  SPLITS = ("train", "validation", "test")
18
+ CONFIGS = (
19
+ tuple(f"sentence_{suffix}" for suffix in ("1", "10", "50", "100"))
20
+ + tuple(f"source_held_out_{suffix}" for suffix in ("1", "10", "50", "100"))
21
+ )
22
  INDEX_COLUMN = "_split_row_index"
23
 
24
 
 
218
  )
219
  parser.add_argument("--check", action="store_true")
220
  args = parser.parse_args()
221
+ suffixes = ("1", "10", "50", "100")
222
+ CONFIGS = (
223
+ tuple(f"sentence_{suffix}" for suffix in suffixes)
224
+ + tuple(f"source_held_out_{suffix}" for suffix in suffixes)
225
  if args.publication == "sentence"
226
+ else tuple(f"verse_{suffix}" for suffix in suffixes)
227
  )
 
228
  if not args.check:
229
  build(args.data, args.output)
230
  validate(args.data, args.output)
scripts/dataset_variants.py CHANGED
@@ -12,24 +12,28 @@ import pyarrow as pa
12
 
13
  try:
14
  from scripts.conllu_units import encode_conllu_units, source_conllu_units
 
15
  from scripts.metre_units import syllable_line
16
  from scripts.metrical_lines import load_public_metrical_lines
17
  from scripts.text_units import encode_text_units, source_text_units
18
  except ModuleNotFoundError: # Direct execution from the scripts directory.
19
  from conllu_units import encode_conllu_units, source_conllu_units
 
20
  from metre_units import syllable_line
21
  from metrical_lines import load_public_metrical_lines
22
  from text_units import encode_text_units, source_text_units
23
 
24
 
25
- BASE_CONFIGS = ("sentence", "verse_metre")
26
  SPLITS = ("train", "validation", "test")
27
  CHUNK_TARGETS_BY_BASE = {
28
  "sentence": (10, 50, 100),
 
29
  "verse_metre": (10, 50, 100),
30
  }
31
  PUBLIC_CONFIG_PREFIX = {
32
  "sentence": "sentence",
 
33
  "verse_metre": "verse",
34
  }
35
  BOTTLENECK_TARGET = 100
@@ -170,8 +174,8 @@ def _ordered_unique(values: list[Any]) -> list[Any]:
170
  def _provenance(row: dict) -> dict:
171
  keys = (
172
  "id", "work", "work_id", "cts_urn", "passage", "treebank_source",
173
- "book", "poem_sequence", "line_number", "hypotactic_file",
174
- "syntax_annotation",
175
  )
176
  return {key: row.get(key) for key in keys if key in row}
177
 
@@ -218,6 +222,10 @@ def _aggregate_chunk(base_config: str, rows: list[dict], target: int, split: str
218
  "conllu": encode_conllu_units([
219
  unit for row in rows for unit in source_conllu_units(row["conllu"])
220
  ]),
 
 
 
 
221
  "cts_urn": rows[0]["cts_urn"] if len({row["cts_urn"] for row in rows}) == 1 else None,
222
  "passage": (
223
  rows[0]["passage"]
@@ -243,6 +251,9 @@ def _aggregate_chunk(base_config: str, rows: list[dict], target: int, split: str
243
  "chunk_is_mixed_work": mixed_work,
244
  })
245
 
 
 
 
246
  if base_config == "verse_sentence":
247
  chunk.update({
248
  "alignment_component_id": None,
 
12
 
13
  try:
14
  from scripts.conllu_units import encode_conllu_units, source_conllu_units
15
+ from scripts.model_facing import encode_native_syntax, load_native_syntax
16
  from scripts.metre_units import syllable_line
17
  from scripts.metrical_lines import load_public_metrical_lines
18
  from scripts.text_units import encode_text_units, source_text_units
19
  except ModuleNotFoundError: # Direct execution from the scripts directory.
20
  from conllu_units import encode_conllu_units, source_conllu_units
21
+ from model_facing import encode_native_syntax, load_native_syntax
22
  from metre_units import syllable_line
23
  from metrical_lines import load_public_metrical_lines
24
  from text_units import encode_text_units, source_text_units
25
 
26
 
27
+ BASE_CONFIGS = ("sentence", "source_held_out", "verse_metre")
28
  SPLITS = ("train", "validation", "test")
29
  CHUNK_TARGETS_BY_BASE = {
30
  "sentence": (10, 50, 100),
31
+ "source_held_out": (10, 50, 100),
32
  "verse_metre": (10, 50, 100),
33
  }
34
  PUBLIC_CONFIG_PREFIX = {
35
  "sentence": "sentence",
36
+ "source_held_out": "source_held_out",
37
  "verse_metre": "verse",
38
  }
39
  BOTTLENECK_TARGET = 100
 
174
  def _provenance(row: dict) -> dict:
175
  keys = (
176
  "id", "work", "work_id", "cts_urn", "passage", "treebank_source",
177
+ "held_out_source", "book", "poem_sequence", "line_number",
178
+ "hypotactic_file", "syntax_annotation",
179
  )
180
  return {key: row.get(key) for key in keys if key in row}
181
 
 
222
  "conllu": encode_conllu_units([
223
  unit for row in rows for unit in source_conllu_units(row["conllu"])
224
  ]),
225
+ # One audit record per CoNLL-U unit, in the same constituent order.
226
+ "native_syntax": encode_native_syntax([
227
+ unit for row in rows for unit in load_native_syntax(row["native_syntax"])
228
+ ]),
229
  "cts_urn": rows[0]["cts_urn"] if len({row["cts_urn"] for row in rows}) == 1 else None,
230
  "passage": (
231
  rows[0]["passage"]
 
251
  "chunk_is_mixed_work": mixed_work,
252
  })
253
 
254
+ if base_config == "source_held_out":
255
+ held_out = {row["held_out_source"] for row in rows}
256
+ assert len(held_out) == 1
257
  if base_config == "verse_sentence":
258
  chunk.update({
259
  "alignment_component_id": None,
scripts/model_facing.py ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Produce the scheme-neutral, identifier-free CoNLL-U that models are given.
2
+
3
+ Sphragis draws on seven annotation projects whose author inventories do not
4
+ overlap. Every convention that separates those projects therefore separates
5
+ authors as well, and a model can score highly by recognizing the annotator
6
+ instead of the writer. This module reduces every published tree to one shared
7
+ representation and lifts the project-specific material into a separate audit
8
+ column.
9
+
10
+ The transformation, in order:
11
+
12
+ * editorial punctuation tokens are removed and the tree is re-indexed, because
13
+ UD PROIEL does not tokenize punctuation at all and its absence alone
14
+ identifies its single author;
15
+ * word forms and lemmas are lowercased with ``grc_utils.lower_grc``, because
16
+ capitalization marks sentence openings and proper nouns inconsistently
17
+ across projects and editions;
18
+ * XPOS, UPOS, FEATS and DEPREL are collapsed onto the shared inventories in
19
+ :mod:`syntax_normalization`;
20
+ * MISC is cleared, because ``NativeRel``/``NativeHead``/``HeadRepair`` mark the
21
+ natively converted projects on every token and ``SpaceAfter`` marks UD
22
+ Perseus alone;
23
+ * the ``# text`` comment is dropped, because the ``text`` column already
24
+ carries it.
25
+
26
+ Everything removed from MISC is returned as a compact ``native_syntax``
27
+ record so the original annotation stays auditable and remappable.
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ import json
33
+ import re
34
+ import unicodedata
35
+ from typing import Iterable
36
+
37
+ from grc_utils import lower_grc, vowel
38
+
39
+ try:
40
+ from scripts.syntax_normalization import (
41
+ CORE_XPOS_POS,
42
+ CORE_XPOS_TO_UPOS,
43
+ core_deprel,
44
+ core_feats,
45
+ core_upos,
46
+ core_xpos,
47
+ is_editorial_punctuation,
48
+ punctuationless_tokens,
49
+ )
50
+ except ModuleNotFoundError: # Direct execution from the scripts directory.
51
+ from syntax_normalization import (
52
+ CORE_XPOS_POS,
53
+ CORE_XPOS_TO_UPOS,
54
+ core_deprel,
55
+ core_feats,
56
+ core_upos,
57
+ core_xpos,
58
+ is_editorial_punctuation,
59
+ punctuationless_tokens,
60
+ )
61
+
62
+
63
+ TOKEN_ID = re.compile(r"\d+")
64
+ AUDIT_MISC_KEYS = ("NativeRel", "NativeHead", "HeadRepair")
65
+
66
+
67
+ # Elision is written differently by every project, and the difference alone
68
+ # identifies the source. AGDT and UD Perseus mark it with a trailing combining
69
+ # comma (δ̓, ἀλλ̓); Gorman uses three different apostrophe characters in the same
70
+ # corpus (᾽, ʼ, ’); Pedalion and PROIEL use ’. Stripping the mark leaves the
71
+ # same truncated word form everywhere, which is the only scheme-neutral choice.
72
+ SMOOTH_BREATHING = "\u0313"
73
+ ROUGH_BREATHING = "\u0314"
74
+ KORONIS = "\u0343"
75
+ ELISION_MARKS = frozenset((SMOOTH_BREATHING, ROUGH_BREATHING, KORONIS))
76
+ RHO = "\u03c1"
77
+
78
+
79
+ def strip_elision(value: str) -> str:
80
+ """Remove a word-final elision mark written as a combining breathing.
81
+
82
+ A breathing on a vowel is ordinary orthography (ὁ, οὐ, εἰ), so only a
83
+ trailing mark whose base letter is a consonant can be an elision. Rho is
84
+ the one consonant that carries a breathing in its own right: the rough
85
+ breathing of ῥ is kept, while a smooth breathing on rho is the elision
86
+ convention (ἄῤ for ἄρα). Elided ῥα appears as ῥ̓ in some sources and as ῤ̓
87
+ in others, so marks are removed to a fixed point rather than one at a
88
+ time: ῥ̓ keeps the rough breathing rho is entitled to, while ῤ̓ loses both.
89
+ Reaching a fixed point is what makes this idempotent, which
90
+ check_model_facing_conllu relies on to verify every published form.
91
+ """
92
+ decomposed = unicodedata.normalize("NFD", value)
93
+ while len(decomposed) > 1 and decomposed[-1] in ELISION_MARKS:
94
+ base = next(
95
+ (
96
+ character for character in reversed(decomposed[:-1])
97
+ if not unicodedata.combining(character)
98
+ ),
99
+ None,
100
+ )
101
+ elided = base is not None and not vowel(base) and not (
102
+ base == RHO and decomposed[-1] == ROUGH_BREATHING
103
+ )
104
+ if not elided:
105
+ break
106
+ decomposed = decomposed[:-1]
107
+ return unicodedata.normalize("NFC", decomposed)
108
+
109
+
110
+ def normalize_form(value: str) -> str:
111
+ """Return a word form or lemma in the shared orthography.
112
+
113
+ Order matters. Bracketed and hyphenated forms go first, so that an elision
114
+ mark inside them ([τ̓]) is word-final by the time it is looked for, and NFC
115
+ goes last, because lowercasing a capital that has no precomposed polytonic
116
+ form (Ρ̓ῶμε) leaves a decomposed string that would not compare equal to its
117
+ own normalization.
118
+ """
119
+ if not value or value == "_":
120
+ return value
121
+ cleaned = "".join(punctuationless_tokens(value))
122
+ if not cleaned:
123
+ return value
124
+ return unicodedata.normalize("NFC", lower_greek(strip_elision(cleaned)))
125
+
126
+
127
+ def lower_greek(value: str) -> str:
128
+ """Lowercase Greek without disturbing ``_`` placeholders or markup.
129
+
130
+ ``grc_utils.lower_grc`` handles the precomposed polytonic letters, which
131
+ ``str.lower`` gets wrong; it does not cover a handful of bare capitals
132
+ (Ι, Ρ, Ά) or the stray Latin letters a few source files contain, so those
133
+ fall back to ``str.lower`` character by character.
134
+ """
135
+ if not value or value == "_":
136
+ return value
137
+ return "".join(
138
+ character if not character.isupper() else character.lower()
139
+ for character in lower_grc(value)
140
+ )
141
+
142
+
143
+ def is_punctuation_token(form: str) -> bool:
144
+ """Decide from the form alone whether a token is editorial punctuation.
145
+
146
+ The tag is deliberately not consulted. Some upstream trees have their tag
147
+ column offset against their forms, so that real words carry ``PUNCT`` and
148
+ the commas beside them carry word tags; trusting the tag there deletes the
149
+ words and keeps the commas. A form with no letter or digit in it is
150
+ punctuation whatever it was tagged.
151
+ """
152
+ return not any(character.isalnum() for character in form)
153
+
154
+
155
+ def punctuationless_text(text: str) -> str:
156
+ """Return a text unit in the same orthography as its CoNLL-U forms."""
157
+ cleaned = "".join(
158
+ " " if is_editorial_punctuation(character) else character
159
+ for character in text
160
+ )
161
+ return " ".join(strip_elision(word) for word in cleaned.split())
162
+
163
+
164
+ def _rows(conllu: str) -> list[list[str]]:
165
+ rows = []
166
+ for line in conllu.splitlines():
167
+ if not line or line.startswith("#"):
168
+ continue
169
+ columns = line.split("\t")
170
+ if len(columns) != 10:
171
+ raise ValueError(f"CoNLL-U line does not have ten columns: {line!r}")
172
+ if not TOKEN_ID.fullmatch(columns[0]):
173
+ raise ValueError(
174
+ f"published CoNLL-U must contain only integer token rows: {columns[0]!r}"
175
+ )
176
+ rows.append(columns)
177
+ if not rows:
178
+ raise ValueError("cannot finalize an empty CoNLL-U document")
179
+ return rows
180
+
181
+
182
+ def _native_record(index: int, source_id: int, misc: str) -> dict | None:
183
+ if not misc or misc == "_":
184
+ return None
185
+ values = {}
186
+ for item in misc.split("|"):
187
+ key, _, value = item.partition("=")
188
+ if key in AUDIT_MISC_KEYS:
189
+ values[key] = value
190
+ if not values:
191
+ return None
192
+ # ``i`` indexes the published token; ``src`` and ``head`` are the source
193
+ # document's own numbering, which ``NativeHead`` refers to.
194
+ record = {"i": index, "src": source_id}
195
+ if "NativeRel" in values:
196
+ record["rel"] = values["NativeRel"]
197
+ if "NativeHead" in values:
198
+ record["head"] = values["NativeHead"]
199
+ if values.get("HeadRepair") == "Yes":
200
+ record["repair"] = True
201
+ return record
202
+
203
+
204
+ def finalize_conllu(conllu: str) -> tuple[str, list[dict]]:
205
+ """Return the model-facing document and its native-annotation audit record.
206
+
207
+ Punctuation tokens are dropped and every dependent that hung from one is
208
+ re-attached to that token's nearest surviving ancestor, so the result is
209
+ still a single connected tree.
210
+ """
211
+ rows = _rows(conllu)
212
+ by_id = {int(row[0]): row for row in rows}
213
+ dropped = {int(row[0]) for row in rows if is_punctuation_token(row[1])}
214
+ kept = [row for row in rows if int(row[0]) not in dropped]
215
+ if not kept:
216
+ raise ValueError("removing punctuation left no tokens")
217
+
218
+ kept_ids = {int(row[0]) for row in kept}
219
+
220
+ def surviving_ancestor(token_id: int) -> int:
221
+ head = int(by_id[token_id][6])
222
+ seen = {token_id}
223
+ while head and head not in kept_ids:
224
+ if head in seen or head not in by_id:
225
+ return 0
226
+ seen.add(head)
227
+ head = int(by_id[head][6])
228
+ return head
229
+
230
+ resolved = {int(row[0]): surviving_ancestor(int(row[0])) for row in kept}
231
+ roots = [token_id for token_id, head in resolved.items() if head == 0]
232
+ primary_root = roots[0] if roots else int(kept[0][0])
233
+ id_map = {int(row[0]): new_id for new_id, row in enumerate(kept, 1)}
234
+
235
+ native: list[dict] = []
236
+ output: list[str] = []
237
+ for row in kept:
238
+ old_id = int(row[0])
239
+ record = _native_record(id_map[old_id], old_id, row[9])
240
+ if record is not None:
241
+ native.append(record)
242
+
243
+ head = resolved[old_id]
244
+ if old_id == primary_root:
245
+ new_head, relation = 0, "root"
246
+ else:
247
+ # A source tree with more than one root, or one whose root was the
248
+ # punctuation token just removed, still has to publish exactly one.
249
+ new_head = id_map[head] if head else id_map[primary_root]
250
+ relation = core_deprel(row[7])
251
+ if relation in {"root", "punct"}:
252
+ relation = "dep"
253
+
254
+ xpos = core_xpos(row[4])
255
+ if xpos[0] == "u":
256
+ # A surviving token tagged as punctuation comes from a tree whose
257
+ # tag column is offset; its real part of speech is unknown.
258
+ xpos = "x" + xpos[1:]
259
+ output.append("\t".join([
260
+ str(id_map[old_id]),
261
+ normalize_form(row[1]),
262
+ normalize_form(row[2]),
263
+ core_upos(xpos),
264
+ xpos,
265
+ core_feats(row[5]),
266
+ str(new_head),
267
+ relation,
268
+ "_",
269
+ "_",
270
+ ]))
271
+ return "\n".join(output) + "\n\n", native
272
+
273
+
274
+ def conllu_blocks(unit: str) -> list[str]:
275
+ """Split a published CoNLL-U unit into its sentence blocks."""
276
+ return [block for block in unit.split("\n\n") if block.strip()]
277
+
278
+
279
+ def finalize_conllu_unit(unit: str) -> tuple[str, list[dict]]:
280
+ """Finalize every sentence block in one published CoNLL-U unit.
281
+
282
+ A Sphragis Metre line can span a sentence boundary, in which case its unit
283
+ holds two or more blocks, each numbered from 1. They must be finalized
284
+ separately: merging them would collide their token ids, point heads across
285
+ a sentence boundary and leave the unit with more than one root. Records
286
+ from a multi-block unit carry ``b``, the block index, so that ``i`` stays
287
+ unambiguous.
288
+ """
289
+ blocks = conllu_blocks(unit)
290
+ if not blocks:
291
+ raise ValueError("cannot finalize an empty CoNLL-U unit")
292
+ documents = []
293
+ native: list[dict] = []
294
+ for index, block in enumerate(blocks):
295
+ document, block_native = finalize_conllu(block)
296
+ documents.append(document)
297
+ for record in block_native:
298
+ native.append(
299
+ {**record, "b": index} if len(blocks) > 1 else record
300
+ )
301
+ return "".join(documents), native
302
+
303
+
304
+ def encode_native_syntax(units: Iterable[list[dict]]) -> str:
305
+ """Serialize the per-unit native annotation audit records."""
306
+ return json.dumps(list(units), ensure_ascii=False)
307
+
308
+
309
+ def load_native_syntax(encoded: str) -> list[list[dict]]:
310
+ """Load the native annotation audit column as one record list per unit."""
311
+ units = json.loads(encoded)
312
+ if not isinstance(units, list):
313
+ raise ValueError("native_syntax must encode a JSON list")
314
+ for unit in units:
315
+ if not isinstance(unit, list) or not all(
316
+ isinstance(record, dict) for record in unit
317
+ ):
318
+ raise ValueError("every native_syntax unit must be a list of records")
319
+ return units
320
+
321
+
322
+ CORE_UPOS = frozenset(CORE_XPOS_TO_UPOS.values()) - {"PUNCT"}
323
+
324
+
325
+ def check_model_facing_conllu(conllu: str, where: str) -> None:
326
+ """Assert every invariant the model-facing representation guarantees.
327
+
328
+ Each of these removes a channel through which the annotating project, and
329
+ therefore the author, could be recognized without reading the Greek.
330
+ """
331
+ assert not any(
332
+ line.startswith("#") for line in conllu.splitlines()
333
+ ), f"{where}: CoNLL-U comments are not published; the text column carries the text"
334
+ blocks = conllu_blocks(conllu)
335
+ assert blocks, f"{where}: CoNLL-U unit contains no sentence block"
336
+ for index, block in enumerate(blocks):
337
+ _check_block(block, f"{where}, block {index}")
338
+
339
+
340
+ def _check_block(conllu: str, where: str) -> None:
341
+ seen_ids = []
342
+ heads = []
343
+ for line in conllu.splitlines():
344
+ if not line:
345
+ continue
346
+ columns = line.split("\t")
347
+ assert len(columns) == 10, f"{where}: expected ten columns, got {len(columns)}"
348
+ token_id, form, lemma, upos, xpos, feats, head, relation, deps, misc = columns
349
+ assert TOKEN_ID.fullmatch(token_id), f"{where}: non-integer token id {token_id!r}"
350
+ seen_ids.append(int(token_id))
351
+ heads.append(int(head))
352
+ assert misc == "_", f"{where}: MISC identifies the source project ({misc!r})"
353
+ assert deps == "_", f"{where}: DEPS is not published ({deps!r})"
354
+ assert upos in CORE_UPOS, f"{where}: UPOS {upos!r} is outside the shared inventory"
355
+ assert xpos != "_" and len(xpos) == 9, f"{where}: XPOS must be nine positions"
356
+ assert xpos[0] in CORE_XPOS_POS and CORE_XPOS_POS[xpos[0]] == xpos[0], (
357
+ f"{where}: XPOS part of speech {xpos[0]!r} is outside the shared inventory"
358
+ )
359
+ assert xpos[0] != "u", f"{where}: punctuation tokens are not published"
360
+ assert core_deprel(relation) == relation and relation != "punct", (
361
+ f"{where}: DEPREL {relation!r} is outside the shared inventory"
362
+ )
363
+ assert core_feats(feats) == feats, (
364
+ f"{where}: FEATS {feats!r} is outside the shared inventory"
365
+ )
366
+ for column, name in ((form, "FORM"), (lemma, "LEMMA")):
367
+ if column == "_":
368
+ continue
369
+ assert column == normalize_form(column), (
370
+ f"{where}: {name} {column!r} is not in the shared orthography"
371
+ )
372
+ assert seen_ids == list(range(1, len(seen_ids) + 1)), f"{where}: token ids are not contiguous"
373
+ assert heads.count(0) == 1, f"{where}: expected exactly one root, got {heads.count(0)}"
scripts/syntax_normalization.py CHANGED
@@ -74,3 +74,96 @@ def canonical_stoicheia_deprel(relation: str | None, upos: str, head: int) -> st
74
 
75
  def is_universal_deprel(relation: str) -> bool:
76
  return relation.split(":", 1)[0] in UNIVERSAL_DEPRELS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  def is_universal_deprel(relation: str) -> bool:
76
  return relation.split(":", 1)[0] in UNIVERSAL_DEPRELS
77
+
78
+
79
+ # ---------------------------------------------------------------------------
80
+ # Scheme-neutral model-facing normalization.
81
+ #
82
+ # Sphragis merges seven annotation projects whose author inventories do not
83
+ # overlap, so any convention that distinguishes those projects also identifies
84
+ # the author. The mappings below reduce every source to one shared inventory,
85
+ # so that a category boundary the projects disagree about cannot be used as an
86
+ # authorship feature. See metadata/leakage_report.json for the measured effect.
87
+ # ---------------------------------------------------------------------------
88
+
89
+ # AGDT nine-position part of speech (XPOS position 1) after normalization.
90
+ # ``l``/``p`` (article, pronoun) and ``d``/``g``/``c``/``b`` (adverb, particle,
91
+ # conjunction) are merged because the projects disagree about exactly these
92
+ # boundaries for the highest-frequency Greek function words: δέ is a particle
93
+ # in AGDT, an adverb in Gorman and a coordinator in UD Perseus; καί is a
94
+ # subordinator in the AGDT lineage and a coordinator in UD.
95
+ CORE_XPOS_POS = {
96
+ "n": "n", "v": "v", "t": "v", "a": "a",
97
+ "p": "p", "l": "p",
98
+ "d": "d", "g": "d", "c": "d", "b": "d",
99
+ "r": "r", "m": "m", "i": "i",
100
+ "u": "u",
101
+ "x": "x", "e": "x", "z": "x", "-": "x",
102
+ }
103
+
104
+ CORE_XPOS_TO_UPOS = {
105
+ "n": "NOUN", "v": "VERB", "a": "ADJ", "p": "PRON", "d": "ADV",
106
+ "r": "ADP", "m": "NUM", "i": "INTJ", "u": "PUNCT", "x": "X",
107
+ }
108
+
109
+ # Morphological features every source project expresses. ``VerbForm`` is
110
+ # dropped because it is absent from all natively converted trees and is already
111
+ # carried uniformly by XPOS position 5; ``PronType``, ``Definite``, ``Aspect``,
112
+ # ``Polarity``, ``Poss`` and ``Reflex`` occur in one project only.
113
+ CORE_FEATS = ("Case", "Degree", "Gender", "Mood", "Number", "Person", "Tense", "Voice")
114
+
115
+ # Shared dependency inventory. Relations are merged wherever the projects
116
+ # express one analysis with different labels: ``det`` joins the attributive
117
+ # bucket because the AGDT lineage annotates the article as an attribute, and
118
+ # ``cc``/``cop``/``aux`` join the functional bucket because native schemes
119
+ # never produce them.
120
+ CORE_DEPREL = {
121
+ "root": "root",
122
+ "nsubj": "nsubj", "csubj": "nsubj",
123
+ "obj": "obj", "iobj": "obj",
124
+ "ccomp": "ccomp", "xcomp": "ccomp",
125
+ "obl": "obl",
126
+ "nmod": "nmod", "amod": "nmod", "nummod": "nmod", "det": "nmod",
127
+ "advmod": "advmod", "acl": "advmod", "advcl": "advmod",
128
+ "case": "case", "mark": "case", "cc": "case", "cop": "case", "aux": "case",
129
+ "conj": "conj",
130
+ "appos": "appos",
131
+ "vocative": "vocative",
132
+ "discourse": "discourse", "dislocated": "discourse",
133
+ "punct": "punct",
134
+ }
135
+
136
+ CORE_DEPRELS = frozenset(CORE_DEPREL.values()) | {"dep"}
137
+
138
+
139
+ def core_deprel(relation: str) -> str:
140
+ """Collapse a relation onto the inventory every source project shares."""
141
+ base = (relation or "dep").split(":", 1)[0].lower()
142
+ return CORE_DEPREL.get(base, "dep")
143
+
144
+
145
+ def core_feats(feats: str) -> str:
146
+ """Retain only the morphological features every source project expresses."""
147
+ if not feats or feats == "_":
148
+ return "_"
149
+ retained = [
150
+ item for item in feats.split("|")
151
+ if item.split("=", 1)[0] in CORE_FEATS
152
+ ]
153
+ return "|".join(sorted(retained)) or "_"
154
+
155
+
156
+ def core_xpos(xpos: str) -> str:
157
+ """Merge the part-of-speech position onto the shared inventory."""
158
+ if not xpos or xpos == "_":
159
+ return xpos
160
+ if len(xpos) != 9:
161
+ raise ValueError(f"XPOS must have exactly nine positions, got {xpos!r}")
162
+ return CORE_XPOS_POS.get(xpos[0], "x") + xpos[1:]
163
+
164
+
165
+ def core_upos(xpos: str) -> str:
166
+ """Derive UPOS from the normalized XPOS so both columns share one scheme."""
167
+ if not xpos or xpos == "_":
168
+ return "X"
169
+ return CORE_XPOS_TO_UPOS.get(CORE_XPOS_POS.get(xpos[0], "x"), "X")
scripts/validate_publication.py CHANGED
@@ -14,6 +14,7 @@ import unicodedata
14
 
15
  import pyarrow.parquet as pq
16
 
 
17
  try:
18
  from scripts.conllu_units import load_conllu_units
19
  from scripts.metre_units import load_metre_units, load_syllable_units
@@ -23,6 +24,12 @@ try:
23
  is_universal_deprel,
24
  syntax_text_normalize,
25
  )
 
 
 
 
 
 
26
  from scripts.vendor.conll18_ud_eval import UDError, load_conllu
27
  except ModuleNotFoundError:
28
  from conllu_units import load_conllu_units
@@ -33,11 +40,42 @@ except ModuleNotFoundError:
33
  is_universal_deprel,
34
  syntax_text_normalize,
35
  )
 
 
 
 
 
 
36
  from vendor.conll18_ud_eval import UDError, load_conllu
37
 
38
 
39
  SPLITS = ("train", "validation", "test")
40
- SAFE_MISC_KEYS = {"NativeRel", "NativeHead", "HeadRepair", "SpaceAfter"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  def normalize(value: str) -> str:
@@ -51,9 +89,13 @@ def normalize(value: str) -> str:
51
 
52
 
53
  def configs(publication: str) -> tuple[str, ...]:
54
- base = "sentence" if publication == "sentence" else "verse"
55
  suffixes = (1, 10, 50, 100)
56
- return tuple(f"{base}_{suffix}" for suffix in suffixes)
 
 
 
 
 
57
 
58
 
59
  def read_config(root: Path, config: str) -> list[dict]:
@@ -71,30 +113,25 @@ def read_config(root: Path, config: str) -> list[dict]:
71
 
72
 
73
  def validate_conllu(config: str, row: dict, checked: set[bytes]) -> None:
74
- for conllu in load_conllu_units(row["conllu"]):
75
- comments = [line for line in conllu.splitlines() if line.startswith("#")]
76
- assert all(line.startswith("# text = ") for line in comments)
77
- for line in conllu.splitlines():
78
- if not line or line.startswith("#"):
79
- continue
80
- columns = line.split("\t")
81
- assert len(columns) == 10
82
- if config.startswith("verse_"):
83
- assert is_universal_deprel(columns[7])
84
- assert not any(
85
- is_editorial_punctuation(character) for character in columns[1]
86
- )
87
- assert columns[2] == "_" or not any(
88
- is_editorial_punctuation(character) for character in columns[2]
89
- )
90
- misc_keys = {
91
- item.split("=", 1)[0]
92
- for item in columns[9].split("|")
93
- if item != "_"
94
  }
95
- assert misc_keys <= SAFE_MISC_KEYS
96
- if config.startswith("verse_"):
97
- assert misc_keys <= {"HeadRepair"}
 
 
98
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
99
  if digest in checked:
100
  continue
@@ -172,6 +209,16 @@ def main() -> None:
172
  and re.fullmatch(r"\d+", line.split("\t", 1)[0])
173
  )
174
  assert syntax_text_normalize(forms) == syntax_text_normalize(text)
 
 
 
 
 
 
 
 
 
 
175
  print(config, len(rows), dict(Counter(row["split"] for row in rows)))
176
 
177
  atomic = rows_by_config[expected_configs[0]]
@@ -191,17 +238,23 @@ def main() -> None:
191
  "derived boundary feature author coverage",
192
  {feature: len(covered) for feature, covered in feature_authors.items()},
193
  )
194
- for config in expected_configs[1:]:
195
- for split in SPLITS:
196
- expected_ids = {row["id"] for row in atomic if row["split"] == split}
197
- represented_ids = [
198
- constituent_id
199
- for row in rows_by_config[config]
200
- if row["split"] == split
201
- for constituent_id in row["constituent_ids"]
202
- ]
203
- assert len(represented_ids) == len(set(represented_ids))
204
- assert set(represented_ids) == expected_ids
 
 
 
 
 
 
205
 
206
  print("validated unique CoNLL-U documents", len(checked_conllu))
207
  print("all publication checks passed")
 
14
 
15
  import pyarrow.parquet as pq
16
 
17
+
18
  try:
19
  from scripts.conllu_units import load_conllu_units
20
  from scripts.metre_units import load_metre_units, load_syllable_units
 
24
  is_universal_deprel,
25
  syntax_text_normalize,
26
  )
27
+ from scripts.model_facing import (
28
+ check_model_facing_conllu,
29
+ conllu_blocks,
30
+ load_native_syntax,
31
+ lower_greek,
32
+ )
33
  from scripts.vendor.conll18_ud_eval import UDError, load_conllu
34
  except ModuleNotFoundError:
35
  from conllu_units import load_conllu_units
 
40
  is_universal_deprel,
41
  syntax_text_normalize,
42
  )
43
+ from model_facing import (
44
+ check_model_facing_conllu,
45
+ conllu_blocks,
46
+ load_native_syntax,
47
+ lower_greek,
48
+ )
49
  from vendor.conll18_ud_eval import UDError, load_conllu
50
 
51
 
52
  SPLITS = ("train", "validation", "test")
53
+
54
+
55
+ def check_source_held_out(config: str, rows: list[dict]) -> None:
56
+ """Assert no author is evaluated on an annotation project it trained on."""
57
+ by_author: dict[str, dict[str, set[str]]] = {}
58
+ for row in rows:
59
+ provenance = row.get("constituent_provenance")
60
+ sources = (
61
+ {
62
+ record["treebank_source"]
63
+ for record in json.loads(provenance)
64
+ if record.get("treebank_source")
65
+ }
66
+ if provenance
67
+ else {row["treebank_source"]}
68
+ )
69
+ splits = by_author.setdefault(row["author"], {})
70
+ splits.setdefault(row["split"], set()).update(sources)
71
+ splits.setdefault("held_out", set()).add(row["held_out_source"])
72
+ for author, splits in sorted(by_author.items()):
73
+ assert len(splits["held_out"]) == 1, (config, author, splits["held_out"])
74
+ held_out = next(iter(splits["held_out"]))
75
+ evaluation = splits.get("validation", set()) | splits.get("test", set())
76
+ assert evaluation == {held_out}, (config, author, sorted(evaluation), held_out)
77
+ assert held_out not in splits.get("train", set()), (config, author, held_out)
78
+ assert splits.get("train"), (config, author)
79
 
80
 
81
  def normalize(value: str) -> str:
 
89
 
90
 
91
  def configs(publication: str) -> tuple[str, ...]:
 
92
  suffixes = (1, 10, 50, 100)
93
+ if publication == "sentence":
94
+ return (
95
+ *(f"sentence_{suffix}" for suffix in suffixes),
96
+ *(f"source_held_out_{suffix}" for suffix in suffixes),
97
+ )
98
+ return tuple(f"verse_{suffix}" for suffix in suffixes)
99
 
100
 
101
  def read_config(root: Path, config: str) -> list[dict]:
 
113
 
114
 
115
  def validate_conllu(config: str, row: dict, checked: set[bytes]) -> None:
116
+ text_units = load_text_units(row["text"])
117
+ native_units = load_native_syntax(row["native_syntax"])
118
+ conllu_units = load_conllu_units(row["conllu"])
119
+ assert len(native_units) == len(conllu_units)
120
+ for index, conllu in enumerate(conllu_units):
121
+ check_model_facing_conllu(conllu, f"{config}, row {row['id']}")
122
+ forms = "".join(
123
+ line.split("\t")[1] for line in conllu.splitlines() if line
124
+ )
125
+ assert syntax_text_normalize(forms) == syntax_text_normalize(text_units[index])
126
+ blocks = [
127
+ {
128
+ int(line.split("\t")[0]) for line in block.splitlines() if line
 
 
 
 
 
 
 
129
  }
130
+ for block in conllu_blocks(conllu)
131
+ ]
132
+ for record in native_units[index]:
133
+ block = blocks[record.get("b", 0)]
134
+ assert record["i"] in block, (config, row["id"], record)
135
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
136
  if digest in checked:
137
  continue
 
209
  and re.fullmatch(r"\d+", line.split("\t", 1)[0])
210
  )
211
  assert syntax_text_normalize(forms) == syntax_text_normalize(text)
212
+ for row in rows:
213
+ for unit in load_text_units(row["text"]):
214
+ assert unit == lower_greek(unit), (
215
+ f"{config}, row {row['id']}: text is not lowercased"
216
+ )
217
+ assert not any(
218
+ is_editorial_punctuation(character) for character in unit
219
+ ), f"{config}, row {row['id']}: text retains editorial punctuation"
220
+ if config.startswith("source_held_out"):
221
+ check_source_held_out(config, rows)
222
  print(config, len(rows), dict(Counter(row["split"] for row in rows)))
223
 
224
  atomic = rows_by_config[expected_configs[0]]
 
238
  "derived boundary feature author coverage",
239
  {feature: len(covered) for feature, covered in feature_authors.items()},
240
  )
241
+ for track in sorted({config.rsplit("_", 1)[0] for config in expected_configs}):
242
+ track_atomic = rows_by_config[f"{track}_1"]
243
+ for config in expected_configs:
244
+ if config == f"{track}_1" or not config.startswith(f"{track}_"):
245
+ continue
246
+ for split in SPLITS:
247
+ expected_ids = {
248
+ row["id"] for row in track_atomic if row["split"] == split
249
+ }
250
+ represented_ids = [
251
+ constituent_id
252
+ for row in rows_by_config[config]
253
+ if row["split"] == split
254
+ for constituent_id in row["constituent_ids"]
255
+ ]
256
+ assert len(represented_ids) == len(set(represented_ids))
257
+ assert set(represented_ids) == expected_ids
258
 
259
  print("validated unique CoNLL-U documents", len(checked_conllu))
260
  print("all publication checks passed")
slurm/rebuild_dataset.slurm CHANGED
@@ -48,6 +48,13 @@ srun --kill-on-bad-exit=1 "$python" -u scripts/build_dataset.py \
48
  --metre-output "$metre_stage/data" --metre-metadata "$metre_stage/metadata" \
49
  --stoicheia-conllu "$stoicheia_conllu"
50
 
 
 
 
 
 
 
 
51
  echo "[$(date --iso-8601=seconds)] independently validating both staged publications"
52
  srun --kill-on-bad-exit=1 "$python" -u scripts/validate_publication.py \
53
  --publication sentence --data "$stage/data"
 
48
  --metre-output "$metre_stage/data" --metre-metadata "$metre_stage/metadata" \
49
  --stoicheia-conllu "$stoicheia_conllu"
50
 
51
+ # scripts/audit_leakage.py is the only build step that needs scikit-learn.
52
+ "$python" -m pip install --quiet --disable-pip-version-check "scikit-learn>=1.4"
53
+
54
+ echo "[$(date --iso-8601=seconds)] measuring residual scheme-only leakage on the staged data"
55
+ srun --kill-on-bad-exit=1 "$python" -u scripts/audit_leakage.py \
56
+ --data "$stage/data" --metadata "$stage/metadata"
57
+
58
  echo "[$(date --iso-8601=seconds)] independently validating both staged publications"
59
  srun --kill-on-bad-exit=1 "$python" -u scripts/validate_publication.py \
60
  --publication sentence --data "$stage/data"
tests/test_conllu_well_formed.py CHANGED
@@ -12,6 +12,7 @@ from scripts.syntax_normalization import (
12
  is_universal_deprel,
13
  syntax_text_normalize,
14
  )
 
15
 
16
 
17
  REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -19,9 +20,9 @@ DATA_ROOT = REPO_ROOT / "data"
19
  METRE_DATA_ROOT = REPO_ROOT.parent / "sphragis-metre" / "data"
20
  CONFIGS = tuple(
21
  [(DATA_ROOT, f"sentence_{suffix}") for suffix in ("1", "10", "50", "100")]
 
22
  + [(METRE_DATA_ROOT, f"verse_{suffix}") for suffix in ("1", "10", "50", "100")]
23
  )
24
- SAFE_MISC_KEYS = {"NativeRel", "NativeHead", "HeadRepair", "SpaceAfter"}
25
 
26
 
27
  def test_all_conllu_documents_are_well_formed_and_identifier_free() -> None:
@@ -37,43 +38,9 @@ def test_all_conllu_documents_are_well_formed_and_identifier_free() -> None:
37
  for row in batch.to_pylist():
38
  conllu_units = load_conllu_units(row["conllu"])
39
  for conllu in conllu_units:
40
- comments = [
41
- line for line in conllu.splitlines()
42
- if line.startswith("#")
43
- ]
44
- assert all(line.startswith("# text = ") for line in comments), (
45
- config,
46
- split,
47
- row["id"],
48
- comments,
49
  )
50
- for line in conllu.splitlines():
51
- if not line or line.startswith("#"):
52
- continue
53
- columns = line.split("\t")
54
- assert len(columns) == 10
55
- misc_keys = {
56
- item.split("=", 1)[0]
57
- for item in columns[9].split("|")
58
- if item != "_"
59
- }
60
- assert misc_keys <= SAFE_MISC_KEYS, (
61
- config,
62
- split,
63
- row["id"],
64
- misc_keys,
65
- )
66
- if config.startswith("verse_"):
67
- assert misc_keys <= {"HeadRepair"}
68
- assert is_universal_deprel(columns[7])
69
- assert not any(
70
- is_editorial_punctuation(character)
71
- for character in columns[1]
72
- )
73
- assert columns[2] == "_" or not any(
74
- is_editorial_punctuation(character)
75
- for character in columns[2]
76
- )
77
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
78
  if digest in checked:
79
  continue
 
12
  is_universal_deprel,
13
  syntax_text_normalize,
14
  )
15
+ from scripts.model_facing import check_model_facing_conllu
16
 
17
 
18
  REPO_ROOT = Path(__file__).resolve().parents[1]
 
20
  METRE_DATA_ROOT = REPO_ROOT.parent / "sphragis-metre" / "data"
21
  CONFIGS = tuple(
22
  [(DATA_ROOT, f"sentence_{suffix}") for suffix in ("1", "10", "50", "100")]
23
+ + [(DATA_ROOT, f"source_held_out_{suffix}") for suffix in ("1", "10", "50", "100")]
24
  + [(METRE_DATA_ROOT, f"verse_{suffix}") for suffix in ("1", "10", "50", "100")]
25
  )
 
26
 
27
 
28
  def test_all_conllu_documents_are_well_formed_and_identifier_free() -> None:
 
38
  for row in batch.to_pylist():
39
  conllu_units = load_conllu_units(row["conllu"])
40
  for conllu in conllu_units:
41
+ check_model_facing_conllu(
42
+ conllu, f"{config}/{split}, row {row['id']}",
 
 
 
 
 
 
 
43
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  digest = hashlib.sha256(conllu.encode("utf-8")).digest()
45
  if digest in checked:
46
  continue
tests/test_model_facing.py ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The scheme-neutral representation is the benchmark's anti-leakage guarantee.
2
+
3
+ Sphragis merges seven annotation projects whose author inventories do not
4
+ overlap, so any convention that separates the projects also separates authors.
5
+ These tests pin the transformation that removes those conventions.
6
+ """
7
+
8
+ import json
9
+ from pathlib import Path
10
+
11
+ import pyarrow.parquet as pq
12
+ import pytest
13
+
14
+ from scripts.model_facing import (
15
+ check_model_facing_conllu,
16
+ conllu_blocks,
17
+ finalize_conllu,
18
+ finalize_conllu_unit,
19
+ lower_greek,
20
+ normalize_form,
21
+ punctuationless_text,
22
+ )
23
+ from scripts.syntax_normalization import core_deprel, core_feats, core_upos, core_xpos
24
+
25
+
26
+ REPO_ROOT = Path(__file__).resolve().parents[1]
27
+ DATA_ROOT = REPO_ROOT / "data"
28
+
29
+ NATIVE_DOCUMENT = (
30
+ "# text = Ἀλλὰ καί, ὦ φίλε.\n"
31
+ "1\tἈλλὰ\tἀλλά\tPART\tg--------\t_\t3\tadvmod\t_\tNativeRel=AuxY|NativeHead=3\n"
32
+ "2\tκαί\tκαί\tSCONJ\tc--------\t_\t3\tcc\t_\tNativeRel=AuxC|NativeHead=3|HeadRepair=Yes\n"
33
+ "3\t,\t,\tPUNCT\tu--------\t_\t5\tpunct\t_\t_\n"
34
+ "4\tὦ\tὦ\tINTJ\ti--------\t_\t5\tdiscourse\t_\tNativeRel=AuxZ|NativeHead=5\n"
35
+ "5\tφίλε\tφίλος\tNOUN\tn-s---mv-\tCase=Voc|Gender=Masc|Number=Sing|VerbForm=Fin"
36
+ "\t0\troot\t_\tSpaceAfter=No\n"
37
+ "6\t.\t.\tPUNCT\tu--------\t_\t5\tpunct\t_\t_\n"
38
+ )
39
+
40
+
41
+ def test_finalize_removes_every_source_identifying_channel() -> None:
42
+ document, native = finalize_conllu(NATIVE_DOCUMENT)
43
+ check_model_facing_conllu(document, "unit test")
44
+ rows = [line.split("\t") for line in document.splitlines() if line]
45
+ assert [row[0] for row in rows] == ["1", "2", "3", "4"], "punctuation is dropped"
46
+ assert [row[1] for row in rows] == ["ἀλλὰ", "καί", "ὦ", "φίλε"]
47
+ assert all(row[9] == "_" for row in rows), "MISC identifies the project"
48
+ assert "VerbForm" not in document, "VerbForm is absent from native schemes"
49
+ assert not document.startswith("#"), "the text column carries the text"
50
+ # The head of token 1 was 3, which was punctuation; it re-attaches to the
51
+ # punctuation token's own surviving ancestor rather than dangling.
52
+ assert rows[0][6] == "4"
53
+ assert [record["src"] for record in native] == [1, 2, 4]
54
+ assert native[1] == {"i": 2, "src": 2, "rel": "AuxC", "head": "3", "repair": True}
55
+
56
+
57
+ def test_exactly_one_root_survives_a_multi_root_source_tree() -> None:
58
+ document, _ = finalize_conllu(
59
+ "1\tἀρχόμενος\tἄρχω\tVERB\tv-sppemn-\t_\t0\troot\t_\t_\n"
60
+ "2\tσέο\tσύ\tPRON\tp-s---mg-\t_\t1\tobj\t_\t_\n"
61
+ "3\tΦοῖβε\tΦοῖβος\tNOUN\tn-s---mv-\t_\t0\troot\t_\t_\n"
62
+ )
63
+ check_model_facing_conllu(document, "unit test")
64
+ rows = [line.split("\t") for line in document.splitlines() if line]
65
+ assert [row[6] for row in rows] == ["0", "1", "1"]
66
+ assert [row[7] for row in rows] == ["root", "obj", "dep"]
67
+
68
+
69
+ def test_a_root_that_was_punctuation_hands_the_root_on() -> None:
70
+ document, _ = finalize_conllu(
71
+ "1\tκαλός\tκαλός\tADJ\ta-s---mn-\t_\t2\tamod\t_\t_\n"
72
+ "2\t.\t.\tPUNCT\tu--------\t_\t0\troot\t_\t_\n"
73
+ )
74
+ check_model_facing_conllu(document, "unit test")
75
+ assert document.split("\t")[6:8] == ["0", "root"]
76
+
77
+
78
+ def test_a_misaligned_tag_column_never_deletes_a_real_word() -> None:
79
+ """Some upstream trees have their tags offset by one against their forms.
80
+
81
+ In this AGDT sentence the commas carry word tags and the words beside them
82
+ carry PUNCT, so a filter that trusts the tag deletes ὦ and τὸν and keeps
83
+ the commas. Punctuation is decided from the form instead.
84
+ """
85
+ document, _ = finalize_conllu(
86
+ "1\tγιγνώσκω\tγιγνώσκω\tADV\td--------\t_\t0\troot\t_\t_\n"
87
+ "2\t,\t,\tADV\td--------\t_\t1\tadvmod\t_\t_\n"
88
+ "3\tὦ\tὦ\tPUNCT\tu--------\t_\t1\tpunct\t_\t_\n"
89
+ "4\tτὸν\tὁ\tPUNCT\tu--------\t_\t5\tpunct\t_\t_\n"
90
+ "5\tἄνδρα\tἀνήρ\tDET\tl-s---ma-\t_\t1\tobj\t_\t_\n"
91
+ )
92
+ check_model_facing_conllu(document, "unit test")
93
+ rows = [line.split("\t") for line in document.splitlines() if line]
94
+ assert [row[1] for row in rows] == ["γιγνώσκω", "ὦ", "τὸν", "ἄνδρα"]
95
+ # A word that survives while still tagged as punctuation has no reliable
96
+ # part of speech, so it is published as X rather than as PUNCT. The other
97
+ # tags stay as the offset annotation left them: UPOS is derived from XPOS,
98
+ # so γιγνώσκω keeps the adverb tag it was wrongly given upstream.
99
+ assert [row[3] for row in rows] == ["ADV", "X", "X", "PRON"]
100
+ assert all(row[4][0] != "u" for row in rows)
101
+
102
+
103
+ def test_a_numeral_written_with_digits_is_not_treated_as_punctuation() -> None:
104
+ document, _ = finalize_conllu(
105
+ "1\tἔτη\tἔτος\tNOUN\tn-p---na-\t_\t0\troot\t_\t_\n"
106
+ "2\t12\t12\tNUM\tm--------\t_\t1\tnummod\t_\t_\n"
107
+ "3\t.\t.\tPUNCT\tu--------\t_\t1\tpunct\t_\t_\n"
108
+ )
109
+ rows = [line.split("\t") for line in document.splitlines() if line]
110
+ assert [row[1] for row in rows] == ["ἔτη", "12"]
111
+
112
+
113
+ MULTI_BLOCK_UNIT = (
114
+ "# text = μοῖραν ἀνέπλησεν\n"
115
+ "1\tμοῖραν\tμοῖρα\tNOUN\tn-s---fa-\t_\t2\tobj\t_\t_\n"
116
+ "2\tἀνέπλησεν\tἀίμπλημι\tVERB\tv3saia---\t_\t0\troot\t_\tHeadRepair=Yes\n"
117
+ "\n"
118
+ "# text = τὴν γὰρ θέμις\n"
119
+ "1\tτὴν\tὁ\tPRON\tp-s---fa-\t_\t3\tobj\t_\t_\n"
120
+ "2\tγὰρ\tγάρ\tPART\tg--------\t_\t0\troot\t_\tHeadRepair=Yes\n"
121
+ "3\tθέμις\tθέμις\tNOUN\tn-s---fn-\t_\t2\tnsubj\t_\t_\n"
122
+ )
123
+
124
+
125
+ def test_a_line_spanning_a_sentence_boundary_keeps_its_blocks_apart() -> None:
126
+ """A Sphragis Metre line can hold two sentence blocks, each numbered from 1.
127
+
128
+ Merging them collides the token ids, points heads across the sentence
129
+ boundary and leaves two roots in one tree, so each block is finalized on
130
+ its own and the unit keeps its block structure.
131
+ """
132
+ document, native = finalize_conllu_unit(MULTI_BLOCK_UNIT)
133
+ check_model_facing_conllu(document, "unit test")
134
+ blocks = conllu_blocks(document)
135
+ assert len(blocks) == 2
136
+ for block in blocks:
137
+ rows = [line.split("\t") for line in block.splitlines() if line]
138
+ assert [row[0] for row in rows] == [
139
+ str(n) for n in range(1, len(rows) + 1)
140
+ ]
141
+ assert sum(row[6] == "0" for row in rows) == 1
142
+ # ``b`` disambiguates ``i``, which restarts in every block.
143
+ assert native == [
144
+ {"i": 2, "src": 2, "repair": True, "b": 0},
145
+ {"i": 2, "src": 2, "repair": True, "b": 1},
146
+ ]
147
+
148
+
149
+ def test_a_single_block_unit_carries_no_block_index() -> None:
150
+ _, native = finalize_conllu_unit(
151
+ "1\tλόγος\tλόγος\tNOUN\tn-s---mn-\t_\t0\troot\t_\tNativeRel=PRED\n"
152
+ )
153
+ assert native == [{"i": 1, "src": 1, "rel": "PRED"}]
154
+
155
+
156
+ def test_a_tree_that_is_entirely_punctuation_is_rejected() -> None:
157
+ with pytest.raises(ValueError):
158
+ finalize_conllu("1\t,\t,\tPUNCT\tu--------\t_\t0\troot\t_\t_\n")
159
+
160
+
161
+ @pytest.mark.parametrize(
162
+ "source, expected",
163
+ [
164
+ # δέ is a particle in AGDT, an adverb in Gorman, a coordinator in UD.
165
+ ("PART", "ADV"), ("CCONJ", "ADV"), ("SCONJ", "ADV"), ("ADV", "ADV"),
166
+ # The article is DET in UD and a pronoun in the AGDT lineage.
167
+ ("DET", "PRON"), ("PRON", "PRON"),
168
+ # εἰμί is AUX only in the UD conversions.
169
+ ("AUX", "VERB"), ("VERB", "VERB"),
170
+ # PROPN occurs in PROIEL alone, which supplies exactly one author.
171
+ ("PROPN", "NOUN"), ("NOUN", "NOUN"),
172
+ ],
173
+ )
174
+ def test_upos_categories_the_projects_disagree_about_are_merged(
175
+ source: str, expected: str,
176
+ ) -> None:
177
+ xpos = {
178
+ "PART": "g", "CCONJ": "b", "SCONJ": "c", "ADV": "d",
179
+ "DET": "l", "PRON": "p", "AUX": "v", "VERB": "v",
180
+ "PROPN": "n", "NOUN": "n",
181
+ }[source] + "--------"
182
+ assert core_upos(xpos) == expected
183
+
184
+
185
+ @pytest.mark.parametrize(
186
+ "source, expected",
187
+ [
188
+ # cc, cop and aux are never produced by the native conversions.
189
+ ("cc", "case"), ("cop", "case"), ("aux", "case"), ("case", "case"),
190
+ ("mark", "case"),
191
+ # iobj occurs in UD Perseus alone.
192
+ ("iobj", "obj"), ("obj", "obj"),
193
+ # PROIEL is the only source with subtyped relations.
194
+ ("nsubj:pass", "nsubj"), ("obl:arg", "obl"), ("advcl:cmp", "advmod"),
195
+ # The two conversions of the same AGDT trees disagree here.
196
+ ("amod", "nmod"), ("nmod", "nmod"), ("det", "nmod"),
197
+ ("dislocated", "discourse"), ("discourse", "discourse"),
198
+ ("orphan", "dep"), ("flat:name", "dep"), ("parataxis", "dep"),
199
+ ],
200
+ )
201
+ def test_deprels_the_projects_disagree_about_are_merged(
202
+ source: str, expected: str,
203
+ ) -> None:
204
+ assert core_deprel(source) == expected
205
+
206
+
207
+ def test_feats_are_restricted_to_the_shared_inventory() -> None:
208
+ assert core_feats(
209
+ "Aspect=Imp|Case=Nom|Definite=Def|Gender=Masc|PronType=Dem|VerbForm=Fin"
210
+ ) == "Case=Nom|Gender=Masc"
211
+ assert core_feats("_") == "_"
212
+ assert core_feats("VerbForm=Fin") == "_"
213
+
214
+
215
+ def test_greek_is_lowercased_including_what_lower_grc_leaves() -> None:
216
+ assert lower_greek("Ἀλλά") == "ἀλλά"
217
+ assert lower_greek("ΙΡΆ") == "ιρά"
218
+ assert lower_greek("_") == "_"
219
+
220
+
221
+ @pytest.mark.parametrize(
222
+ "source, expected",
223
+ [
224
+ # Every project writes elision differently, and the difference alone
225
+ # identifies the source: AGDT and UD Perseus use a combining comma,
226
+ # Gorman uses three apostrophes in one corpus, Pedalion and PROIEL use
227
+ # the right single quote.
228
+ ("ἀλλ\u0313", "ἀλλ"), ("ἀλλ’", "ἀλλ"), ("ἀλλʼ", "ἀλλ"), ("ἀλλ᾽", "ἀλλ"),
229
+ ("δ\u0313", "δ"), ("χέρσ\u0313", "χέρσ"), ("ἄῤ", "ἄρ"),
230
+ # A breathing on a vowel is ordinary orthography, not elision.
231
+ ("ὁ", "ὁ"), ("ἡ", "ἡ"), ("οὐ", "οὐ"), ("οἱ", "οἱ"), ("εἰ", "εἰ"),
232
+ # Rho is the one consonant that carries a breathing in its own right.
233
+ # Elided ῥα is written ῥ̓, two marks on one rho, and loses only the
234
+ # second; a smooth breathing on rho is itself the elision (ἄῤ = ἄρα).
235
+ ("ῥ\u0313", "ῥ"), ("ῥ", "ῥ"), ("ῥόδον", "ῥόδον"), ("ῤ", "ρ"),
236
+ # ῥα is elided as ῥ̓ in some sources and ῤ̓ in others; marks come off to
237
+ # a fixed point, so the doubled smooth breathing loses both.
238
+ ("ῤ\u0313", "ρ"),
239
+ # Gorman hyphenates and AGDT brackets; neither is a scheme-neutral fact.
240
+ ("κατα-βαίνω", "καταβαίνω"), ("[τι]", "τι"),
241
+ # Punctuation comes off first, so an elision mark inside brackets is
242
+ # word-final by the time it is looked for.
243
+ ("[τ\u0313]", "τ"),
244
+ # Lowercasing a capital with no precomposed polytonic form leaves a
245
+ # decomposed string, so NFC is reapplied last.
246
+ ("Ρ\u0313ῶμε", "ῤῶμε"),
247
+ ("Ἀλλά", "ἀλλά"), ("_", "_"),
248
+ ],
249
+ )
250
+ def test_word_forms_reach_one_shared_orthography(source: str, expected: str) -> None:
251
+ assert normalize_form(source) == expected
252
+
253
+
254
+ @pytest.mark.parametrize(
255
+ "source",
256
+ [
257
+ "ῥ\u0313", "ῥ", "ῤ", "ῤ\u0313", "ῥ\u0313\u0313", "ἄῤ", "δ\u0313",
258
+ "ἀλλ’", "ἀλλ\u0313", "ὁ", "οὐ", "εἰ", "οἱ", "ἐπ\u0313",
259
+ "χέρσ\u0313", "ῥόδον", "ἄνθρωπος", "κατα-βαίνω", "[τι]", "[τ\u0313]",
260
+ "Ρ\u0313ῶμε", "Ἀλλά",
261
+ ],
262
+ )
263
+ def test_normalizing_a_word_form_twice_changes_nothing(source: str) -> None:
264
+ """check_model_facing_conllu re-normalizes to verify, so this must hold."""
265
+ once = normalize_form(source)
266
+ assert normalize_form(once) == once
267
+
268
+
269
+ def test_editorial_punctuation_leaves_the_text_column() -> None:
270
+ assert punctuationless_text("ἀλλὰ καί, ὦ φίλε.") == "ἀλλὰ καί ὦ φίλε"
271
+ assert punctuationless_text("ἀλλ’ ὁ ἀνήρ, οὐ δ\u0313 ἔστιν.") == "ἀλλ ὁ ἀνήρ οὐ δ ἔστιν"
272
+
273
+
274
+ def _configs(prefix: str) -> list[str]:
275
+ return [f"{prefix}_{suffix}" for suffix in ("1", "10", "50", "100")]
276
+
277
+
278
+ @pytest.mark.parametrize("config", _configs("source_held_out"))
279
+ def test_no_author_is_evaluated_on_an_annotator_it_trained_on(config: str) -> None:
280
+ """The whole point of the track: the evaluation scheme is unseen in training."""
281
+ sources: dict[str, dict[str, set[str]]] = {}
282
+ held_out: dict[str, set[str]] = {}
283
+ for split in ("train", "validation", "test"):
284
+ path = DATA_ROOT / config / f"{split}-00000-of-00001.parquet"
285
+ columns = ["author", "treebank_source", "held_out_source"]
286
+ if config != "source_held_out_1":
287
+ columns.append("constituent_provenance")
288
+ for row in pq.read_table(path, columns=columns).to_pylist():
289
+ provenance = row.get("constituent_provenance")
290
+ row_sources = (
291
+ {
292
+ record["treebank_source"]
293
+ for record in json.loads(provenance)
294
+ if record.get("treebank_source")
295
+ }
296
+ if provenance
297
+ else {row["treebank_source"]}
298
+ )
299
+ sources.setdefault(row["author"], {}).setdefault(split, set()).update(
300
+ row_sources
301
+ )
302
+ held_out.setdefault(row["author"], set()).add(row["held_out_source"])
303
+
304
+ assert sources, config
305
+ for author, by_split in sorted(sources.items()):
306
+ assert held_out[author] == {next(iter(held_out[author]))}
307
+ source = next(iter(held_out[author]))
308
+ evaluation = by_split.get("validation", set()) | by_split.get("test", set())
309
+ assert evaluation == {source}, (config, author, sorted(evaluation))
310
+ assert source not in by_split.get("train", set()), (config, author)
311
+ assert by_split.get("train"), (config, author)
312
+
313
+
314
+ def test_chunking_keeps_one_audit_record_per_conllu_unit() -> None:
315
+ """Every column that is a per-unit list has to be merged when chunking."""
316
+ from scripts.conllu_units import load_conllu_units
317
+ from scripts.dataset_variants import _aggregate_chunk
318
+ from scripts.model_facing import encode_native_syntax, load_native_syntax
319
+ from scripts.text_units import encode_text_units
320
+
321
+ def row(index: int) -> dict:
322
+ document, native = finalize_conllu(
323
+ f"1\tλόγος{index}\tλόγος\tNOUN\tn-s---mn-\t_\t0\troot\t_\tNativeRel=PRED\n"
324
+ )
325
+ return {
326
+ "id": f"s-{index:04d}", "author": "Plato", "work": "Gorgias",
327
+ "work_id": "tlg0059.tlg023", "genre": "prose", "split": "train",
328
+ "text": encode_text_units([f"λόγος{index}"]),
329
+ "conllu": json.dumps([document], ensure_ascii=False),
330
+ "native_syntax": encode_native_syntax([native]),
331
+ "cts_urn": "", "passage": "", "treebank_source": "agdt",
332
+ "source_records": "[]", "licenses": ["CC-BY-SA-3.0-US"],
333
+ "dedup_key": f"k{index}",
334
+ }
335
+
336
+ rows = [row(index) for index in range(10)]
337
+ chunk = _aggregate_chunk("sentence", rows, 10, "train")
338
+ assert len(load_conllu_units(chunk["conllu"])) == 10
339
+ assert len(load_native_syntax(chunk["native_syntax"])) == 10
340
+ assert load_native_syntax(chunk["native_syntax"])[3] == [
341
+ {"i": 1, "src": 1, "rel": "PRED"}
342
+ ]
tests/test_split_stratification.py CHANGED
@@ -23,8 +23,15 @@ METRE_ROOT = REPO_ROOT.parent / "sphragis-metre"
23
  SPLITS = ("train", "validation", "test")
24
  PUBLICATIONS = (
25
  (REPO_ROOT, "sentence", (1, 10, 50, 100)),
 
26
  (METRE_ROOT, "verse", (1, 10, 50, 100)),
27
  )
 
 
 
 
 
 
28
  TREEBANK_SOURCES = {
29
  "agdt", "ud_perseus", "ud_proiel", "ud_ptnk", "gorman", "pedalion",
30
  "harrington",
@@ -63,6 +70,11 @@ def test_readme_configuration_counts_match_parquet_rows() -> None:
63
  flags=re.MULTILINE,
64
  )
65
  }
 
 
 
 
 
66
  expected_configs = {f"{base}_{suffix}" for suffix in suffixes}
67
  assert set(table_rows) == expected_configs
68
  for config in sorted(expected_configs):
@@ -77,7 +89,7 @@ def test_readme_configuration_counts_match_parquet_rows() -> None:
77
 
78
 
79
  def test_readme_author_unit_counts_and_shares_match_atomic_parquets() -> None:
80
- for root, base, _suffixes in PUBLICATIONS:
81
  readme = (root / "README.md").read_text(encoding="utf-8")
82
  documented = {
83
  match.group("author"): {
 
23
  SPLITS = ("train", "validation", "test")
24
  PUBLICATIONS = (
25
  (REPO_ROOT, "sentence", (1, 10, 50, 100)),
26
+ (REPO_ROOT, "source_held_out", (1, 10, 50, 100)),
27
  (METRE_ROOT, "verse", (1, 10, 50, 100)),
28
  )
29
+ # The per-author unit table in each README documents the main track only; the
30
+ # source-held-out track's per-author counts live in build_report.json, because
31
+ # two tables of the same shape in one README cannot be told apart by pattern.
32
+ README_AUTHOR_TABLES = tuple(
33
+ publication for publication in PUBLICATIONS if publication[1] != "source_held_out"
34
+ )
35
  TREEBANK_SOURCES = {
36
  "agdt", "ud_perseus", "ud_proiel", "ud_ptnk", "gorman", "pedalion",
37
  "harrington",
 
70
  flags=re.MULTILINE,
71
  )
72
  }
73
+ # One README documents both sentence tracks, so match on this base.
74
+ table_rows = {
75
+ config: counts for config, counts in table_rows.items()
76
+ if config.rsplit("_", 1)[0] == base
77
+ }
78
  expected_configs = {f"{base}_{suffix}" for suffix in suffixes}
79
  assert set(table_rows) == expected_configs
80
  for config in sorted(expected_configs):
 
89
 
90
 
91
  def test_readme_author_unit_counts_and_shares_match_atomic_parquets() -> None:
92
+ for root, base, _suffixes in README_AUTHOR_TABLES:
93
  readme = (root / "README.md").read_text(encoding="utf-8")
94
  documented = {
95
  match.group("author"): {
tests/test_verse_character_coverage.py CHANGED
@@ -29,6 +29,7 @@ def normalized_character_count(root: Path, config: str) -> int:
29
  def test_each_publication_has_equal_character_counts_across_task_sizes() -> None:
30
  publications = (
31
  (REPO_ROOT, "sentence", (1, 10, 50, 100)),
 
32
  (REPO_ROOT.parent / "sphragis-metre", "verse", (1, 10, 50, 100)),
33
  )
34
  for root, genre, suffixes in publications:
 
29
  def test_each_publication_has_equal_character_counts_across_task_sizes() -> None:
30
  publications = (
31
  (REPO_ROOT, "sentence", (1, 10, 50, 100)),
32
+ (REPO_ROOT, "source_held_out", (1, 10, 50, 100)),
33
  (REPO_ROOT.parent / "sphragis-metre", "verse", (1, 10, 50, 100)),
34
  )
35
  for root, genre, suffixes in publications: