Urdatorn commited on
Commit
726fc64
·
verified ·
1 Parent(s): 02001e5

OGA macronizer diagnostics: module contributions and abstentions on the HF silver data

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ analysis/oga_abstained_forms.tsv filter=lfs diff=lfs merge=lfs -text
analysis/logs/oga-rerun-diag-5715083.out ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [2026-11-24T20:32:35+01:00] job_start job=5715083 host=n119 cpus=32 grc-macronizer=diagnostics-logging@fa0e923 dirty=0
2
+ The following modules were not unloaded:
3
+ (Use "module --force purge" to unload all):
4
+
5
+ 1) hpc_sysenv/.1 2) hpc/.2.2.0
6
+ grc_macronizer /nobackup/proj/flash/dionysus/personal/cleland/grc-macronizer-logging/grc_macronizer/__init__.py spacy 3.7.5
7
+ [2026-11-24T20:32:50+01:00] 1. smoke test
8
+
9
+ Done in 0.1 min. Overall macronization ratio: 84.43%
10
+ Output: /scratch/local/oga-rerun-5715083/smoke/out/oga_macronized.txt
11
+ PASS output identical to the a949b76 run for 7 files
12
+ PASS module counts identical to the a949b76 run
13
+ PASS 5 log files (one per process), every timestamped line has a pid (5 pids)
14
+ PASS CHUNK START/END lines: 7/7 for 7 chunks
15
+ PASS 7 traces named <stem>.<chunk>
16
+ PASS still_ambiguous files named by tag
17
+ PASS credits add up to before-after for 94/94 tokens (100.0000%)
18
+ PASS sentence indices within a chunk (max 4)
19
+ credits: [('wiktionary', 42), ('hypotactic', 21), ('custom', 13), ('accent_rules', 10), ('nominal_forms', 7), ('oxytonization', 4), ('case_ending_recursion', 4), ('lsj', 3), ('reversed_elision_recursion', 1), ('double_accent_recursion', 1), ('prefix', 1), ('decapitalization', 1)]
20
+ ALL OK
21
+ [2026-11-24T20:32:56+01:00] 2. full run -> /nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun
22
+
23
+ Done in 35.8 min. Overall macronization ratio: 76.57%
24
+ Output: /nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun/oga_macronized.txt
25
+ chunk errors: 0
26
+ 'Integration corrupted' warnings: 20 (20 expected, as in the a949b76 run)
27
+ numerator 12865364
28
+ denominator 16802201
29
+ ratio 0.7657
30
+ module tokens_helped top_level_tokens top_level_dichrona
31
+ wiktionary 3919577 5219287
32
+ custom 3595424 4555585
33
+ nominal_forms 906910 935272
34
+ double_accent_recursion 48529 61369
35
+ accent_rules 828722 828722
36
+ hypotactic 401357 477095
37
+ lsj 319755 371904
38
+ decapitalization 44011 50187
39
+ oxytonization 424603 510121
40
+ case_ending_recursion 235862 282136
41
+ prefix 554703 554703
42
+ verbal_forms 6501 6501
43
+ reversed_elision_recursion 22908 23755
44
+ accent_rules_final 360 360
45
+ 25G /scratch/local/oga-rerun-5715083/full/diagnostics/logs
46
+ 382M /scratch/local/oga-rerun-5715083/full/diagnostics/modules
47
+ 189M /scratch/local/oga-rerun-5715083/full/diagnostics/still_ambiguous
48
+ 1.3G /scratch/local/oga-rerun-5715083/full/diagnostics/traces
49
+ [2026-11-24T21:08:48+01:00] 3. compare with the a949b76 run
50
+ {
51
+ "lines": 2234754,
52
+ "identical": 2234754,
53
+ "text_differs": 0,
54
+ "marks_only_differ": 0,
55
+ "files_with_line_count_mismatch": 0
56
+ }
57
+ oga_macronized.txt byte-identical
58
+ [2026-11-24T21:08:54+01:00] 4. archive diagnostics
59
+ diagnostics-job5715083.tar.zst: OK
60
+ -rw-rw-r-- 1 cleland pg_dionysus 1831547404 Nov 24 21:09 /nobackup/proj/disk/dionysus/personal/cleland/oga-macronized-2026-11-diagnostics/diagnostics-job5715083.tar.zst
61
+ -rw-rw-r-- 1 cleland pg_dionysus 1831547404 Nov 24 21:09 /nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun/diagnostics-archive/diagnostics-job5715083.tar.zst
62
+ [2026-11-24T21:09:32+01:00] job_complete
analysis/logs/oga-rerun-stats-5715543.out ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [2026-11-24T21:13:27+01:00] start job=5715543 host=n185
2
+ The following modules were not unloaded:
3
+ (Use "module --force purge" to unload all):
4
+
5
+ 1) hpc_sysenv/.1 2) hpc/.2.2.0
6
+ [2026-11-24T21:13:27+01:00] unpacking /nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun/diagnostics-archive/diagnostics-job5715083.tar.zst
7
+ Warning : decompression does not support multi-threading
8
+ 25G /scratch/local/oga-rerun-stats-5715543/diagnostics/logs
9
+ 383M /scratch/local/oga-rerun-stats-5715543/diagnostics/modules
10
+ 189M /scratch/local/oga-rerun-stats-5715543/diagnostics/still_ambiguous
11
+ 1.3G /scratch/local/oga-rerun-stats-5715543/diagnostics/traces
12
+ [2026-11-24T21:13:42+01:00] analysis
13
+ logs: 33 files, 283,914,813 lines, 5685 chunks
14
+ membership: {'hf_sentences': 2096720, 'matched': 2096720, 'unmatched_hf_lines': 0, 'chunks_with_line_count_mismatch': [], 'n_mismatch': 0}
15
+ ratio: {'all': {'lines': 2234754, 'dichrona': 16899759, 'unmarked': 3954399, 'marked': 12945360, 'ratio': 0.7660085566900687}, 'hf': {'lines': 2096720, 'dichrona': 16890517, 'unmarked': 3952307, 'marked': 12938210, 'ratio': 0.7660043798540921}}
16
+ traces 0/5685
17
+ traces 500/5685
18
+ traces 1000/5685
19
+ traces 1500/5685
20
+ traces 2000/5685
21
+ traces 2500/5685
22
+ traces 3000/5685
23
+ traces 3500/5685
24
+ traces 4000/5685
25
+ traces 4500/5685
26
+ traces 5000/5685
27
+ traces 5500/5685
28
+ done
29
+ total 32717
30
+ drwxrwsr-x 2 cleland pg_dionysus 4096 Nov 24 21:17 .
31
+ drwxrwsr-x 5 cleland pg_dionysus 4096 Nov 24 21:13 ..
32
+ -rw-rw-r-- 1 cleland pg_dionysus 48280737 Nov 24 21:17 abstained_forms_hf.tsv
33
+ -rw-rw-r-- 1 cleland pg_dionysus 424274 Nov 24 21:17 stats.json
34
+ [2026-11-24T21:17:16+01:00] done
analysis/oga_abstained_forms.tsv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e58c08950d5662dfb4692d75f960bc62e0201447041231caa5f4fa54b0ac9ac3
3
+ size 48280737
analysis/oga_diagnostics_stats.json ADDED
The diff for this file is too large to render. See raw diff
 
analysis/oga_macronized_modules.tsv ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module tokens_helped top_level_tokens top_level_dichrona
2
+ custom 3812637 3595424 4555585
3
+ wiktionary 4324174 3919577 5219287
4
+ lsj 571982 319755 371904
5
+ nominal_forms 1008296 906910 935272
6
+ verbal_forms 6947 6501 6501
7
+ accent_rules 1020879 828722 828722
8
+ prefix 579231 554703 554703
9
+ double_accent_recursion 48906 48529 61369
10
+ case_ending_recursion 249437 235862 282136
11
+ reversed_elision_recursion 22930 22908 23755
12
+ oxytonization 469280 424603 510121
13
+ decapitalization 58113 44011 50187
14
+ hypotactic 482600 401357 477095
15
+ accent_rules_final 360 360
analysis/oga_macronizer_diagnostics.md ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # What the rule-based macronizer does on OGA: module contributions and abstentions
2
+
3
+ Statistics from the diagnostics of the rule-based grc-macronizer on the Opera Graeca
4
+ Adnotata corpus, restricted to exactly the sentences of
5
+ [Urdatorn/oga-macronized-no-norma](https://huggingface.co/datasets/Urdatorn/oga-macronized-no-norma)
6
+ (revision `5d737f8`, 2,096,720 sentences), i.e. the silver data the models are trained on.
7
+ All-OGA figures (2,234,754 sentences) differ by less than 0.1% and are given only where
8
+ the HF subset cannot be isolated.
9
+
10
+ ## Provenance
11
+
12
+ | | |
13
+ |---|---|
14
+ | macronizer | grc-macronizer `a949b76` (the code that produced the HF data) plus the diagnostics-logging branch ([PR #12](https://github.com/Urdatorn/grc-macronizer/pull/12), `fa0e923`), which changes no output |
15
+ | settings | `Macronizer(make_prints=False, doc_from_file=False, no_hypotactic=False, lowercase=False)`, OGA's own CoNLL-U annotation as `custom_doc` (no odyCy inference) |
16
+ | run | job 5715083, 1,999 CoNLL-U files, 500-sentence chunks, 32 workers |
17
+ | check | output byte-identical to the run behind the HF data (job 5709453): 2,234,754 lines, 0 differences |
18
+ | HF subset | each output line matched to the HF parquet (multiset matching): all 2,096,720 matched, no chunk with a line-count mismatch |
19
+ | analysis | `scripts/analyze_rerun.py` (job 5715543); raw numbers in `oga_diagnostics_stats.json`, every abstained form in `oga_abstained_forms.tsv` |
20
+
21
+ Per-token traces record, for every token sent to the modules, its sentence, lemma, POS
22
+ and morphology, its unmarked open-syllable dichrona before and after, and the
23
+ **top-level credit** of each module: how many dichrona it resolved for that token. A
24
+ recursive pass (e.g. oxytonizing `στρατηγὸν` to `στρατηγόν` and re-running the cascade)
25
+ is credited to the recursion module that started it, not to the modules inside it, so the
26
+ credits of a token add up to what the cascade resolved for it (checked for every token).
27
+ This differs from the module counts in the earlier logs (`tokens_helped`), which count
28
+ successes at every recursion depth and overlap (Appendix A).
29
+
30
+ **Two levels of counting.** Token-level figures count each word in isolation, as the
31
+ macronizer sees it. The corpus-level macronization ratio counts the running text in
32
+ synapheia, where a word-final vowel before a consonant-initial word is in a closed
33
+ syllable and not counted. The two denominators therefore differ (17.71M vs 16.89M
34
+ dichrona); both are given below.
35
+
36
+ ## 1. Headline numbers
37
+
38
+ | | |
39
+ |---|---:|
40
+ | sentences | 2,096,720 |
41
+ | tokens considered (all OGA) | 39,270,335 |
42
+ | tokens sent to the modules | 12,978,560 |
43
+ | unmarked open-syllable dichrona in those tokens (word in isolation) | 17,708,350 |
44
+ | resolved by the modules | 13,869,433 (**78.3%**) |
45
+ | left unresolved | 3,838,917 (21.7%) |
46
+ | tokens with at least one dichronon left (abstentions) | 2,743,163 (**21.1%** of tokens sent) |
47
+ | corpus-level ratio (running text, synapheia) | 12,938,210 / 16,890,517 = **76.6%** |
48
+ | marks added: short `^` / long `_` | 12,961,270 / 1,798,025 (**12.2% long**) |
49
+
50
+ ### Token funnel (all OGA)
51
+
52
+ | tokens considered | 39,270,335 | 100% |
53
+ |---|---:|---:|
54
+ | no dichronon in an open syllable | 20,548,018 | 52.3% |
55
+ | not in the diagnostic word list (almost all punctuation tokens) | 5,381,930 | 13.7% |
56
+ | Greek numerals | 341,777 | 0.9% |
57
+ | final sigma mid-word (OCR damage) | 7,400 | |
58
+ | pathological accents/breathings | 5,448 | |
59
+ | **sent to the modules** | **12,985,762** | **33.1%** |
60
+
61
+ The stop list is empty in this version, so no token is skipped as a stop word. Only 34
62
+ macronized words could not be written back into the text ("Could not find occurrence").
63
+
64
+ ## 2. Contribution of each module
65
+
66
+ Share of the 13,869,433 resolved dichrona, by top-level credit, in cascade order:
67
+
68
+ | module | type | tokens | dichrona resolved | **share** | long marks* |
69
+ |---|---|---:|---:|---:|---:|
70
+ | custom | lexical (hand-made) | 3,593,725 | 4,553,470 | **32.8%** | 7.8% |
71
+ | wiktionary | lexical | 3,917,440 | 5,216,459 | **37.6%** | 17.6% |
72
+ | lsj | lexical | 319,535 | 371,641 | 2.7% | 7.4% |
73
+ | nominal_forms | rules | 906,327 | 934,675 | 6.7% | 10.8% |
74
+ | verbal_forms | rules | 6,498 | 6,498 | 0.05% | 0% |
75
+ | accent_rules | rules | 828,244 | 828,244 | 6.0% | 3.2% |
76
+ | prefix | rules | 554,453 | 554,453 | 4.0% | 0.2% |
77
+ | double_accent_recursion | recursion | 48,494 | 61,320 | 0.4% | 12.4% |
78
+ | reversed_elision_recursion | recursion | 22,811 | 23,651 | 0.2% | 6.0% |
79
+ | case_ending_recursion | recursion | 235,718 | 281,967 | 2.0% | 12.8% |
80
+ | oxytonization | recursion | 424,348 | 509,824 | 3.7% | 18.8% |
81
+ | decapitalization | recursion | 43,991 | 50,165 | 0.4% | 17.6% |
82
+ | hypotactic | lexical (verse) | 401,045 | 476,706 | 3.4% | 18.6% |
83
+ | accent_rules (final pass) | rules | 360 | 360 | <0.01% | – |
84
+
85
+ \* Share of long marks among the marks added to tokens that this module alone resolved
86
+ (tokens credited to a single module), i.e. how often the module's answer is "long".
87
+
88
+ **By type:** lexical lookups 76.6% (custom + Wiktionary 70.4%, LSJ 2.7%, hypotactic 3.4%),
89
+ morphological and accent rules 16.8%, recursive normalizations 6.7%.
90
+
91
+ **Observations**
92
+
93
+ - Two lexical sources do most of the work: Wiktionary (37.6%) and the hand-made custom
94
+ list (32.8%) resolve 70% of all dichrona. Custom is large because it covers the most
95
+ frequent function words: 1.39M of its dichrona are prepositions (ADP), 0.71M adverbs,
96
+ 0.41M articles, 0.34M pronouns (e.g. `πα^ρὰ^`, `κα^τὰ^`, `γὰ^ρ`, `τὰ^`, `ἂ^ν`).
97
+ Wiktionary carries the content words: 1.86M verbal, 1.49M nominal, 1.26M adjectival
98
+ dichrona.
99
+ - The rule modules matter for nouns (nominal_forms 0.49M, accent rules 0.45M dichrona in
100
+ NOUN) and prefixed verbs (prefix 0.32M in VERB). The verbal-forms rules almost never
101
+ fire (6,498 dichrona).
102
+ - The recursive normalizations add 6.7%, mostly through oxytonizing graves (3.7%) and
103
+ case-ending changes (2.0%). Their long-mark shares (13-19%) are close to Wiktionary's,
104
+ since they re-run the lexical lookups on a normalized form.
105
+ - The final, overwriting accent-rules pass changes almost nothing (360 dichrona); it is a
106
+ safety net, not a contributor.
107
+ - Hypotactic (scanned verse) is last in the cascade and still adds 3.4%.
108
+ - 96.6% of the tokens with any credit were resolved by a single module (10,557,625 of
109
+ 10,928,032; two modules 365,857, three 4,550). The cascade is in practice a sequence of
110
+ fallbacks, not a combination.
111
+ - Long marks are rare overall (12.2%). Modules that decide by rule rather than lookup give
112
+ "short" almost always: prefix 99.8% short (all dichronic prefixes are short), accent
113
+ rules 96.8% short.
114
+
115
+ ## 3. Abstentions: which words are hard
116
+
117
+ 2,743,163 tokens (21.1% of those sent) keep at least one unmarked dichronon: 501,814
118
+ distinct forms of 193,542 lemmas. 887,267 of them (32%) are partially marked. 68.5% have
119
+ one unresolved dichronon, 24.1% two, 7.4% three or more.
120
+
121
+ ### By part of speech (abstention rate = abstained / sent)
122
+
123
+ | POS | abstained | sent | rate |
124
+ |---|---:|---:|---:|
125
+ | NOUN | 1,183,364 | 3,996,868 | **29.6%** |
126
+ | VERB | 927,615 | 3,220,012 | **28.8%** |
127
+ | ADJ | 480,988 | 2,020,177 | 23.8% |
128
+ | ADV | 83,494 | 1,115,595 | 7.5% |
129
+ | NUM | 2,755 | 43,234 | 6.4% |
130
+ | PRON | 26,214 | 567,501 | 4.6% |
131
+ | CCONJ | 7,382 | 390,137 | 1.9% |
132
+ | ADP | 20,612 | 1,142,813 | 1.8% |
133
+ | DET | 3,650 | 426,430 | 0.9% |
134
+ | X (unknown) | 4,877 | 9,865 | 49.4% |
135
+ | INTJ | 1,963 | 5,305 | 37.0% |
136
+
137
+ Closed classes are almost solved (custom covers them); the open classes carry 94% of the
138
+ abstentions.
139
+
140
+ ### By morphology
141
+
142
+ | feature | rate | | feature | rate |
143
+ |---|---:|---|---|---:|
144
+ | VERB participle | **37.8%** | | VERB finite | 21.9% |
145
+ | VERB passive | **43.9%** | | VERB active | 24.2% |
146
+ | VERB middle | 37.7% | | VERB indicative | 20.9% |
147
+ | VERB future | 34.6% | | VERB present | 24.0% |
148
+ | VERB participle, genitive | **55.1%** | | VERB infinitive | 32.2% |
149
+ | ADJ superlative | **48.7%** | | ADJ comparative | 39.7% |
150
+ | NOUN singular | 33.1% | | NOUN plural | 19.0% |
151
+ | NOUN vocative | 36.0% | | | |
152
+
153
+ The hard verb forms are the long, derived ones (participles, passives, futures,
154
+ especially oblique-case participles), which a form lexicon is least likely to list and
155
+ for which the verbal-forms rules almost never fire. The same holds for comparatives and
156
+ superlatives among adjectives.
157
+
158
+ ### By word shape
159
+
160
+ | shape | abstained / sent | rate |
161
+ |---|---:|---:|
162
+ | **lunate sigma** (`ϲ`) | 194,388 / 235,202 | **82.6%** |
163
+ | capitalized (mostly proper names) | 494,720 / 958,620 | **51.6%** |
164
+ | elided (`'`) | 16,372 / 107,184 | 15.3% |
165
+ | all tokens | 2,743,163 / 12,978,560 | 21.1% |
166
+
167
+ - **Lunate sigma** is the single strongest predictor. Texts printed with `ϲ` (`πόλιϲ`,
168
+ `τὰϲ`, `ἔϲτι`, `τιϲ`) miss the lexicons, which use `σ`/`ς`: even `τὰϲ` (2,786
169
+ occurrences) is abstained on 99.9% of the time, while `τὰς` is never abstained on. Normalizing `ϲ`
170
+ before lookup would recover most of these.
171
+ - **Proper names** are abstained on more than half the time and dominate the most frequent
172
+ abstentions: `Ἰησοῦς` (all forms 10,172, 100%), `Ἀλέξανδρος` (7,532, 100%),
173
+ `Ἀριστοτέλης` (6,655, 100%), `Ἰουδαῖος` (7,094, 98.9%), `Ἰωάννης`, `Ἀχιλλεύς`,
174
+ `Ἀπόλλων`, `Ἰερουσαλήμ`, `Δαβίδ`. Many have a word-initial `Ἀ-`/`Ἰ-` that no module
175
+ covers.
176
+
177
+ ### Where in the word the unresolved vowel is
178
+
179
+ | | share of unresolved dichrona |
180
+ |---|---:|
181
+ | α / ι / υ | 54.6% / 33.5% / 11.9% |
182
+ | antepenult or earlier | **64.9%** |
183
+ | penult | 24.0% |
184
+ | ultima | 11.1% |
185
+ | unaccented / acute / grave | 79.2% / 19.2% / 1.6% |
186
+
187
+ The largest cells are α before the penult (37.6% of all unresolved dichrona), ι before the
188
+ penult (17.9%) and ι in the penult (13.3%). The accent rules can only decide penults and
189
+ ultimas (from the accent's position relative to the ultima), so vowels earlier in the word
190
+ depend entirely on the lexicons. Unresolved ultimas are rare (11%).
191
+
192
+ ### Most frequent abstentions
193
+
194
+ | form | abstained | of | note |
195
+ |---|---:|---:|---|
196
+ | `ἀφ'` | 7,955 | 7,955 | elided `ἀπό` before a rough breathing; `ἀπ'` is handled |
197
+ | `δραχ` | 6,228 | 6,228 | abbreviation of δραχμή (Galen, medical recipes) |
198
+ | `Ἰησοῦ`, `Ἰησοῦς`, `Ἰησοῦν` | 10,464 | 10,464 | proper name |
199
+ | `Ἀριστοτέλης`, `-ους` | 5,467 | 5,467 | proper name |
200
+ | `Ἰουδαίων`, `-οι`, `-οις`, `-ους` | 6,994 | 6,994 | ethnic |
201
+ | `πόλιϲ`, `τὰϲ`, `ἔϲτι`, `ἐϲτι`, `ἐϲτιν`, `τιϲ` | 14,104 | 14,112 | lunate sigma |
202
+ | `ι` | 3,280 | 3,603 | single letter (numeral or label) |
203
+ | `Ἀλέξανδρος`, `-ον`, `Ἀλεξά^νδρου` | 6,286 | 6,286 | proper name |
204
+ | `ἀγὼ`, `ἀκεῖνο`, `ἀκεῖ`, `ἀκεῖνος` | 5,012 | 5,012 | probably crasis forms (κἀγώ, κἀκεῖνο) whose κ was split off in tokenization |
205
+ | `ἀποθα^νεῖν` | 1,753 | 1,753 | prefix `ἀ-` unresolved (see below) |
206
+ | `ἐπι^θυ_μί^αν` | 1,255 | 1,255 | ultima `-αν` |
207
+
208
+ Lemmas with at least 2,000 tokens that are almost never resolved include, besides names,
209
+ prefixed verbs (`ἀποδείκνυμι` 99.8%, `ἀπολαμβάνω` 100%, `διαβάλλω` 100%, `ἀποθνήσκω`
210
+ 98.8%, `ὑπερέχω` 97.0%, `διατίθημι` 97.5%), logical terminology (`κατάφασις`,
211
+ `καταφατικός` 100%, `ἀποφατικός` 97.4%, `ἄτομος` 100%, `ἀσώματος` 99.9%) and `ἀγάπη`
212
+ (99.7%), `ἀνατολή` (99.7%), `μάθημα` (100%). The prefixed verbs are hard because the
213
+ prefix module only marks a prefix when the lemma minus the prefix is an LSJ headword.
214
+
215
+ ### How concentrated the abstentions are
216
+
217
+ | most frequent abstained forms | share of all abstentions |
218
+ |---:|---:|
219
+ | 10 | 1.6% |
220
+ | 100 | 5.0% |
221
+ | 1,000 | 18.2% |
222
+ | 10,000 | 46.2% |
223
+ | 100,000 | 79.9% |
224
+
225
+ 292,034 of the 501,814 abstained forms (58%) occur once. Adding the 1,000 most frequent
226
+ abstained forms to the custom list would resolve about 18% of the abstentions, 10,000
227
+ about 46%; beyond that it is a long tail.
228
+
229
+ ## 4. Coverage by text
230
+
231
+ | collection | sentences | dichrona | ratio |
232
+ |---|---:|---:|---:|
233
+ | First1KGreek (1st1K) | 1,354,959 | 10,398,907 | 76.1% |
234
+ | Perseus | 557,173 | 4,992,187 | 77.7% |
235
+ | PTA (Patristic Text Archive) | 115,631 | 909,479 | 75.9% |
236
+ | OPP | 68,269 | 584,510 | 76.4% |
237
+
238
+ Median per work: 78.0% (1,999 works). Authors with at least 100,000 dichrona:
239
+
240
+ | highest | ratio | | lowest | ratio |
241
+ |---|---:|---|---|---:|
242
+ | Homer (tlg0012) | **94.6%** | | Suda (tlg9010) | **48.6%** |
243
+ | Aristotle (tlg0086) | 84.3% | | Aelius Herodianus (tlg0087) | **50.4%** |
244
+ | Alexander of Aphrodisias (tlg0732) | 84.1% | | tlg3135 | 69.4% |
245
+ | Plato (tlg0059) | 83.5% | | tlg4090 | 69.9% |
246
+ | tlg4015 | 83.2% | | Athenaeus (tlg0008) | 72.3% |
247
+ | Simplicius (tlg4013) | 83.0% | | Josephus (tlg0526) | 72.4% |
248
+ | tlg2001 | 82.7% | | Septuagint (tlg0527) | 73.0% |
249
+ | Aelius Aristides (tlg0284) | 81.7% | | Strabo (tlg0099) | 73.1% |
250
+ | Xenophon (tlg0032) | 80.7% | | Polybius (tlg0543) | 73.3% |
251
+
252
+ Single works: Odyssey and Apollonius' Argonautica 95.2%, Iliad 94.1%. (Author names are
253
+ given only where the TLG number is certain; the rest are left as IDs.)
254
+
255
+ - **Epic is easiest** (Homer, Apollonius ~95%): its vocabulary is what Wiktionary and the
256
+ scanned-verse hypotactic lexicon cover best.
257
+ - **Philosophical prose** (Aristotle, Plato and the commentators) is well above average.
258
+ - **Lexica and grammarians are hardest** (Suda 48.6%, Herodian 50.4%): they consist of
259
+ headwords, rare forms, accent paradigms and abbreviations.
260
+ - **Name-dense historiography, geography and the Septuagint** (Josephus, Athenaeus,
261
+ Strabo, Polybius, Diodorus, Septuagint) sit at 72-74%, in line with the 51.6%
262
+ abstention rate on capitalized words.
263
+
264
+ ## 5. Quick wins suggested by the data
265
+
266
+ | fix | expected gain |
267
+ |---|---|
268
+ | normalize lunate `ϲ` to `σ`/`ς` before the lookups | most of 194k abstained tokens (82.6% abstention) |
269
+ | add `ἀφ'` (and other aspirated elisions) to the elision handling | 7,955 tokens |
270
+ | proper names: a name list with lengths (e.g. from the hypotactic or Wiktionary proper nouns) | a large part of the 495k abstained capitalized tokens |
271
+ | prefix module: fall back to the token's stem when the unprefixed lemma is not an LSJ headword | prefixed verbs such as `ἀποθνήσκω` |
272
+ | top 1,000 / 10,000 abstained forms into the custom list | 18% / 46% of abstentions |
273
+ | skip or expand abbreviations such as `δραχ` | 6,228 tokens |
274
+
275
+ ## Appendix A. Old module counts vs top-level credits
276
+
277
+ `tokens_helped` (the `oga_macronized_modules.tsv` of the HF data) counts success events
278
+ at any recursion depth, and counts custom only when it resolves the whole word. The
279
+ credits are what Section 2 uses. All OGA:
280
+
281
+ | module | tokens_helped (events) | top-level tokens | top-level dichrona |
282
+ |---|---:|---:|---:|
283
+ | custom | 3,812,637 | 3,595,424 | 4,555,585 |
284
+ | wiktionary | 4,324,174 | 3,919,577 | 5,219,287 |
285
+ | lsj | 571,982 | 319,755 | 371,904 |
286
+ | nominal_forms | 1,008,296 | 906,910 | 935,272 |
287
+ | verbal_forms | 6,947 | 6,501 | 6,501 |
288
+ | accent_rules | 1,020,879 | 828,722 | 828,722 |
289
+ | prefix | 579,231 | 554,703 | 554,703 |
290
+ | double_accent_recursion | 48,906 | 48,529 | 61,369 |
291
+ | case_ending_recursion | 249,437 | 235,862 | 282,136 |
292
+ | reversed_elision_recursion | 22,930 | 22,908 | 23,755 |
293
+ | oxytonization | 469,280 | 424,603 | 510,121 |
294
+ | decapitalization | 58,113 | 44,011 | 50,187 |
295
+ | hypotactic | 482,600 | 401,357 | 477,095 |
296
+ | accent_rules (final pass) | (in accent_rules) | 360 | 360 |
297
+
298
+ LSJ and the accent rules are inflated most by the event count (they fire inside
299
+ recursive passes that are credited to the recursion modules).
300
+
301
+ ## Appendix B. Files
302
+
303
+ | file | content |
304
+ |---|---|
305
+ | `analysis/oga_macronizer_diagnostics.md` | this report |
306
+ | `analysis/oga_diagnostics_stats.json` | all numbers, HF subset and all OGA (`hf`, `all`, `funnel_all_oga`, `ratio`, `works`, `membership`) |
307
+ | `analysis/oga_abstained_forms.tsv` | every abstained form in the HF subset: count abstained, tokens with that form sent to the modules, lemma, POS, morph |
308
+ | `analysis/scripts/analyze_rerun.py`, `analyze_diagnostics.py` | the analysis |
309
+ | `analysis/slurm/rerun_diagnostics.slurm`, `analyze_rerun.slurm` | the jobs (rerun with smoke test and comparison; analysis) |
310
+ | `analysis/logs/` | job logs 5715083 (rerun) and 5715543 (analysis) |
311
+
312
+ The full diagnostics (33 per-process logs, 25 GB; per-token traces, 1.3 GB; module
313
+ result files; still-ambiguous tables) are archived outside the repository
314
+ (`diagnostics-job5715083.tar.zst`, 1.8 GB).
analysis/scripts/analyze_diagnostics.py ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Statistics from the grc-macronizer diagnostics of the OGA run (job 5709453).
2
+
3
+ Inputs (an unpacked diagnostics/ directory):
4
+ logs/*.log debug log; 32 worker processes wrote into one file, so lines are
5
+ interleaved and only line-local facts are used
6
+ modules/*_<module>_results.txt per Macronizer() call (one per 500-sentence chunk): every token
7
+ form a module helped macronize (a "success event"; recursive
8
+ passes re-run the cascade, so events overlap across modules)
9
+ still_ambiguous/*.tsv per call: count, form, lemma, POS, morph of every token that kept
10
+ an unmarked dichronon in an open syllable (abstentions)
11
+ plus the run's parts/*.done files (per-work numerator/denominator).
12
+
13
+ Usage: python analyze_diagnostics.py DIAG_DIR PARTS_DIR OUT_DIR WORKERS
14
+ """
15
+ import collections, glob, json, os, re, sys, unicodedata
16
+ from multiprocessing import Pool
17
+
18
+ from grc_utils import (count_dichrona_in_open_syllables, open_syllable_in_word, syllabifier,
19
+ word_with_real_dichrona)
20
+
21
+ C = collections.Counter
22
+ MODULE_ORDER = ["custom", "wiktionary", "lsj", "nominal_forms", "verbal_forms", "accent_rules",
23
+ "prefix", "double_accent_recursion", "reversed_elision_recursion",
24
+ "case_ending_recursion", "oxytonization", "decapitalization", "hypotactic"]
25
+ # names as they appear in the log's ✅/❌ lines -> module
26
+ LOG_MODULE = {"Custom": "custom", "Wiktionary": "wiktionary", "LSJ": "lsj",
27
+ "Nominal forms": "nominal_forms", "Verbal forms": "verbal_forms",
28
+ "Accent rules": "accent_rules", "Prefix macronization": "prefix",
29
+ "Double accent macronization": "double_accent_recursion",
30
+ "Reversed elision": "reversed_elision_recursion",
31
+ "Wrong-case-ending (D2)": "case_ending_recursion",
32
+ "Wrong-case-ending (D1)": "case_ending_recursion",
33
+ "Oxytonizing": "oxytonization", "Decapitalization": "decapitalization",
34
+ "Hypotactic": "hypotactic"}
35
+
36
+ R_TOKEN = re.compile(r"^(Considering token|\tAppended: \tToken): (.*?)\tLemma: (.*?)\tPOS: (.*?)\tMorph: (.*)$")
37
+ R_MOD = re.compile(r"^\t(✅|❌) (.+?)(?: with [αει] helped| with [αει] did not help| helped| did not help|:)")
38
+ R_ARROW = re.compile(r" (\S+) => (\S+), with (\d+) left")
39
+ R_LEFT = re.compile(r"(\d+) left")
40
+ R_PASS = re.compile(r"^🔄 Macronizing(?: \((.*?)\))?: ")
41
+ SKIPS = [("no dichrona", "has no dichrona"), ("not in diagnostic word list", "not in diagnostic word list"),
42
+ ("Greek numeral", "is a Greek numeral"), ("general stop word", "General stop word"),
43
+ ("epic stop word", "Epic stop word"), ("final sigma mid-word", "final sigma mid-word"),
44
+ ("pathological accents/breathings", "Pathological word")]
45
+
46
+
47
+ def word_shape(form):
48
+ f = form
49
+ return dict(lunate="ϲ" in f, capitalized=bool(f) and f[0].isupper(), elided=f.endswith("'"))
50
+
51
+
52
+ def parse_log_range(args):
53
+ path, start, end = args
54
+ out = dict(considered_pos=C(), sent_pos=C(), sent_feat=C(), sent_shape=C(), sent_form=C(),
55
+ sent_lemma=C(), skips=C(), stop_forms=C(), notdiag_forms=C(), passes=C(),
56
+ mod_try=C(), mod_ok=C(), mod_full=C(), mod_added=C(), mod_example=collections.defaultdict(C),
57
+ odycy_fail=0, sent_total=0, lines=0, other=C())
58
+ with open(path, "rb") as fh:
59
+ fh.seek(start)
60
+ if start:
61
+ fh.readline()
62
+ while fh.tell() <= end:
63
+ raw = fh.readline()
64
+ if not raw:
65
+ break
66
+ out["lines"] += 1
67
+ s = raw.decode("utf-8", "replace").rstrip("\n")
68
+ parts = s.split(" - ", 1)
69
+ if len(parts) < 2:
70
+ continue
71
+ msg = parts[1]
72
+ m = R_TOKEN.match(msg)
73
+ if m:
74
+ kind, tok, lemma, pos, morph = m.groups()
75
+ if kind == "Considering token":
76
+ out["considered_pos"][pos] += 1
77
+ else:
78
+ out["sent_total"] += 1
79
+ out["sent_pos"][pos] += 1
80
+ out["sent_form"][tok] += 1
81
+ out["sent_lemma"][(lemma, pos)] += 1
82
+ for kv in morph.split("|"):
83
+ if "=" in kv:
84
+ out["sent_feat"][(pos, kv)] += 1
85
+ for k, v in word_shape(tok).items():
86
+ if v:
87
+ out["sent_shape"][k] += 1
88
+ continue
89
+ m = R_MOD.match(msg)
90
+ if m:
91
+ ok, name = m.group(1) == "✅", m.group(2)
92
+ if name.startswith("Reversed elision"):
93
+ name = "Reversed elision"
94
+ mod = LOG_MODULE.get(name)
95
+ if mod is None:
96
+ out["other"]["module?" + name[:40]] += 1
97
+ continue
98
+ out["mod_try"][mod] += 1
99
+ if ok:
100
+ out["mod_ok"][mod] += 1
101
+ a = R_ARROW.search(msg)
102
+ if a:
103
+ old, new, left = a.group(1), a.group(2), int(a.group(3))
104
+ out["mod_added"][(mod, "^")] += max(0, new.count("^") - old.count("^"))
105
+ out["mod_added"][(mod, "_")] += max(0, new.count("_") - old.count("_"))
106
+ if left == 0:
107
+ out["mod_full"][mod] += 1
108
+ else:
109
+ l = R_LEFT.search(msg)
110
+ if l and int(l.group(1)) == 0:
111
+ out["mod_full"][mod] += 1
112
+ continue
113
+ m = R_PASS.match(msg)
114
+ if m:
115
+ out["passes"][m.group(1) or "top level / double accent"] += 1
116
+ continue
117
+ if msg.startswith("Sending to macronization_modules"):
118
+ continue
119
+ if msg.startswith("odyCy fail count:"):
120
+ out["odycy_fail"] += int(msg.split(":")[1])
121
+ continue
122
+ for name, needle in SKIPS:
123
+ if needle in msg:
124
+ out["skips"][name] += 1
125
+ w = re.search(r"'(.*?)'", msg)
126
+ if w and name in ("general stop word", "epic stop word"):
127
+ out["stop_forms"][w.group(1)] += 1
128
+ if w and name == "not in diagnostic word list":
129
+ out["notdiag_forms"][w.group(1)] += 1
130
+ break
131
+ else:
132
+ key = re.sub(r"\d+", "N", re.sub(r"[Ͱ-Ͽἀ-῿^_'’ϲ]+", "W", msg))[:60]
133
+ out["other"][key] += 1
134
+ return out
135
+
136
+
137
+ def merge(a, b):
138
+ for k, v in b.items():
139
+ if isinstance(v, collections.defaultdict):
140
+ for kk, vv in v.items():
141
+ a[k][kk].update(vv)
142
+ elif isinstance(v, C):
143
+ a[k].update(v)
144
+ else:
145
+ a[k] += v
146
+ return a
147
+
148
+
149
+ def unresolved_syllables(form):
150
+ """(vowel, syllable position from the end, accent on it) for every unmarked dichronon in an
151
+ open syllable, using the same rule as count_dichrona_in_open_syllables (word in isolation)."""
152
+ out = []
153
+ w = re.sub(r"[^\w^_']", "", unicodedata.normalize("NFC", form))
154
+ if not w:
155
+ return out
156
+ try:
157
+ syls = syllabifier(w)
158
+ except Exception:
159
+ return out
160
+ n = len(syls)
161
+ for i, s in enumerate(syls):
162
+ if word_with_real_dichrona(s) and open_syllable_in_word(s, syls) and not any(c in "^_" for c in s):
163
+ vowel, acc = "?", "none"
164
+ for ch in s:
165
+ d = unicodedata.normalize("NFD", ch)
166
+ if d and d[0].lower() in "αιυ":
167
+ vowel = d[0].lower()
168
+ if "́" in d: acc = "acute"
169
+ elif "̀" in d: acc = "grave"
170
+ elif "͂" in d: acc = "circumflex"
171
+ pos = n - i
172
+ out.append((vowel, "ultima" if pos == 1 else "penult" if pos == 2 else "antepenult+", acc))
173
+ return out
174
+
175
+
176
+ def main():
177
+ diag, parts_dir, out_dir, workers = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
178
+ os.makedirs(out_dir, exist_ok=True)
179
+ R = {}
180
+
181
+ # ---- log ----
182
+ log = glob.glob(os.path.join(diag, "logs", "*.log"))[0]
183
+ size = os.path.getsize(log)
184
+ step = size // (workers * 8) + 1
185
+ ranges = [(log, s, min(size, s + step)) for s in range(0, size, step)]
186
+ print(f"log {log}: {size/1e9:.1f} GB in {len(ranges)} ranges", flush=True)
187
+ with Pool(workers) as pool:
188
+ L = None
189
+ for i, r in enumerate(pool.imap_unordered(parse_log_range, ranges)):
190
+ L = r if L is None else merge(L, r)
191
+ if i % 32 == 0:
192
+ print(f" log ranges done {i+1}/{len(ranges)}", flush=True)
193
+ R["log"] = dict(lines=L["lines"], sent_total=L["sent_total"], odycy_fail=L["odycy_fail"],
194
+ considered_pos=L["considered_pos"].most_common(), sent_pos=L["sent_pos"].most_common(),
195
+ skips=L["skips"].most_common(), passes=L["passes"].most_common(),
196
+ sent_shape=dict(L["sent_shape"]),
197
+ modules={m: dict(tries=L["mod_try"][m], successes=L["mod_ok"][m], completed=L["mod_full"][m],
198
+ added_short=L["mod_added"][(m, "^")], added_long=L["mod_added"][(m, "_")])
199
+ for m in MODULE_ORDER},
200
+ top_stop_words=L["stop_forms"].most_common(40),
201
+ top_not_in_diag=L["notdiag_forms"].most_common(40),
202
+ other_messages=L["other"].most_common(40))
203
+
204
+ # ---- module result files ----
205
+ mods = {m: C() for m in MODULE_ORDER}
206
+ for f in glob.glob(os.path.join(diag, "modules", "*_results.txt")):
207
+ name = re.sub(r"^\d+_\d+_\d+_\d+_", "", os.path.basename(f))[:-len("_results.txt")]
208
+ with open(f, encoding="utf-8") as fh:
209
+ mods[name].update(l.rstrip("\n") for l in fh if l.strip())
210
+ R["module_files"] = {m: dict(events=sum(c.values()), unique_forms=len(c), top=c.most_common(25)) for m, c in mods.items()}
211
+
212
+ # ---- abstentions ----
213
+ amb = C(); amb_info = {}
214
+ for f in glob.glob(os.path.join(diag, "still_ambiguous", "*.tsv")):
215
+ with open(f, encoding="utf-8") as fh:
216
+ for line in fh:
217
+ p = line.rstrip("\n").split("\t")
218
+ if len(p) < 5:
219
+ continue
220
+ amb[p[1]] += int(p[0])
221
+ amb_info.setdefault(p[1], (p[2], p[3], p[4]))
222
+ tot_occ = sum(amb.values())
223
+ pos_c, feat_c, lemma_c, shape_c, syl_c, nsyl_c, partial = C(), C(), C(), C(), C(), C(), 0
224
+ unresolved_total = 0
225
+ for form, n in amb.items():
226
+ lemma, pos, morph = amb_info[form]
227
+ pos_c[pos] += n
228
+ lemma_c[(lemma, pos)] += n
229
+ for kv in morph.split("|"):
230
+ if "=" in kv:
231
+ feat_c[(pos, kv)] += n
232
+ for k, v in word_shape(form).items():
233
+ if v:
234
+ shape_c[k] += n
235
+ if "^" in form or "_" in form:
236
+ partial += n
237
+ us = unresolved_syllables(form)
238
+ k = len(us)
239
+ nsyl_c[min(k, 3)] += n
240
+ unresolved_total += max(k, count_dichrona_in_open_syllables(form)) * n
241
+ for v, where, acc in us:
242
+ syl_c[(v, where, acc)] += n
243
+ sent_pos = L["sent_pos"]
244
+ R["abstentions"] = dict(
245
+ occurrences=tot_occ, unique_forms=len(amb), unique_lemmas=len(lemma_c),
246
+ partially_marked=partial, unresolved_positions=unresolved_total,
247
+ by_pos=[(p, n, sent_pos[p], n / sent_pos[p] if sent_pos[p] else None) for p, n in pos_c.most_common()],
248
+ by_feature=sorted([(pos, kv, n, L["sent_feat"][(pos, kv)], n / L["sent_feat"][(pos, kv)] if L["sent_feat"][(pos, kv)] else None)
249
+ for (pos, kv), n in feat_c.items() if n >= 2000], key=lambda x: -x[2]),
250
+ by_shape={k: (shape_c[k], L["sent_shape"][k]) for k in ("lunate", "capitalized", "elided")},
251
+ unresolved_per_token=sorted(nsyl_c.items()),
252
+ by_vowel_position_accent=[(v, w, a, n) for (v, w, a), n in syl_c.most_common()],
253
+ top_forms=[(f, n, *amb_info[f], L["sent_form"][f]) for f, n in amb.most_common(150)],
254
+ top_lemmas=[(l, p, n, L["sent_lemma"][(l, p)]) for (l, p), n in lemma_c.most_common(150)],
255
+ )
256
+ cum, curve = 0, []
257
+ marks = [10, 100, 1000, 10000, 100000]
258
+ for i, (f, n) in enumerate(amb.most_common(), 1):
259
+ cum += n
260
+ if i in marks:
261
+ curve.append((i, cum, cum / tot_occ))
262
+ R["abstentions"]["coverage_curve"] = curve
263
+ R["abstentions"]["hapax_forms"] = sum(1 for n in amb.values() if n == 1)
264
+ # most frequent forms always vs sometimes abstained
265
+ rate = [(f, amb[f], L["sent_form"][f], amb[f] / L["sent_form"][f]) for f in L["sent_form"] if L["sent_form"][f] >= 500 and f in amb]
266
+ R["abstentions"]["frequent_forms_highest_rate"] = sorted(rate, key=lambda x: (-x[3], -x[2]))[:60]
267
+
268
+ # ---- per work ----
269
+ works = []
270
+ for d in glob.glob(os.path.join(parts_dir, "*.done")):
271
+ n_lines, num, den = map(int, open(d).read().split("\t"))
272
+ stem = os.path.basename(d)[:-5]
273
+ works.append((stem, n_lines, num, den))
274
+ R["works"] = works
275
+
276
+ with open(os.path.join(out_dir, "diagnostics_stats.json"), "w", encoding="utf-8") as f:
277
+ json.dump(R, f, ensure_ascii=False, indent=1, default=str)
278
+ with open(os.path.join(out_dir, "abstained_forms.tsv"), "w", encoding="utf-8") as f:
279
+ f.write("count\tsent_to_modules\tform\tlemma\tpos\tmorph\n")
280
+ for form, n in amb.most_common():
281
+ f.write(f"{n}\t{L['sent_form'][form]}\t{form}\t" + "\t".join(amb_info[form]) + "\n")
282
+ print("done", flush=True)
283
+
284
+
285
+ if __name__ == "__main__":
286
+ main()
analysis/scripts/analyze_rerun.py ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Statistics from the attributable diagnostics of the OGA rerun (grc-macronizer
2
+ diagnostics-logging, job 5715083), restricted to exactly the sentences in
3
+ Urdatorn/oga-macronized-no-norma (revision 5d737f8), with all-OGA figures alongside.
4
+
5
+ Sentence identity: the rerun's output line i of a work is sentence i of that work
6
+ (checked: per chunk, the number of output lines equals the number of sentences sent),
7
+ i.e. chunk i // 500, sentence i % 500, which is what the per-token traces record.
8
+ A line belongs to the HF data if its text occurs there (multiset matching).
9
+
10
+ Usage: python analyze_rerun.py DIAG_DIR RERUN_OUT HF_DATA_DIR OUT_DIR WORKERS
11
+ """
12
+ import collections, glob, json, os, re, sys, unicodedata
13
+ from multiprocessing import Pool
14
+
15
+ import pyarrow.parquet as pq
16
+ from grc_utils import count_dichrona_in_open_syllables
17
+
18
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
19
+ from analyze_diagnostics import unresolved_syllables, word_shape # noqa: E402
20
+
21
+ C = collections.Counter
22
+ CHUNK = 500
23
+ MODULES = ["custom", "wiktionary", "lsj", "nominal_forms", "verbal_forms", "accent_rules", "prefix",
24
+ "double_accent_recursion", "reversed_elision_recursion", "case_ending_recursion",
25
+ "oxytonization", "decapitalization", "hypotactic", "accent_rules_final"]
26
+
27
+ HF_KEEP = None # stem -> set of (chunk, sentence) in the HF data (set in the parent, inherited by fork)
28
+
29
+
30
+ def new_acc():
31
+ return dict(tokens=0, before=0, after=0, credit_tok=C(), credit_dich=C(), credit_pos=C(),
32
+ solo_tok=C(), solo_short=C(), solo_long=C(), n_modules=C(), first_module=C(),
33
+ sent_pos=C(), sent_feat=C(), sent_shape=C(), sent_form=C(), sent_lemma=C(),
34
+ amb_tok=0, amb_dich=0, amb_partial=0, amb_pos=C(), amb_feat=C(), amb_shape=C(),
35
+ amb_form=C(), amb_tokform=C(), amb_form_info={}, amb_lemma=C(), amb_syl=C(), amb_nunres=C(),
36
+ resolved_short=0, resolved_long=0, unresolved_vowel=C())
37
+
38
+
39
+ def add_row(a, c):
40
+ sent, token, lemma, pos, morph, before, after, result, credits = c
41
+ before, after = int(before), int(after)
42
+ a["tokens"] += 1; a["before"] += before; a["after"] += after
43
+ a["sent_pos"][pos] += 1; a["sent_form"][token] += 1; a["sent_lemma"][(lemma, pos)] += 1
44
+ feats = [kv for kv in morph.split("|") if "=" in kv]
45
+ for kv in feats:
46
+ a["sent_feat"][(pos, kv)] += 1
47
+ shape = word_shape(token)
48
+ for k, v in shape.items():
49
+ if v: a["sent_shape"][k] += 1
50
+ cr = [(kv.split("=")[0], int(kv.split("=")[1])) for kv in credits.split(",") if kv]
51
+ a["n_modules"][len(cr)] += 1
52
+ if cr: a["first_module"][cr[0][0]] += 1
53
+ added_short = max(0, result.count("^") - token.count("^"))
54
+ added_long = max(0, result.count("_") - token.count("_"))
55
+ a["resolved_short"] += added_short; a["resolved_long"] += added_long
56
+ for m, n in cr:
57
+ a["credit_tok"][m] += 1; a["credit_dich"][m] += n; a["credit_pos"][(m, pos)] += n
58
+ if len(cr) == 1:
59
+ m = cr[0][0]
60
+ a["solo_tok"][m] += 1; a["solo_short"][m] += added_short; a["solo_long"][m] += added_long
61
+ if after > 0:
62
+ a["amb_tok"] += 1; a["amb_dich"] += after
63
+ if "^" in result or "_" in result: a["amb_partial"] += 1
64
+ a["amb_pos"][pos] += 1; a["amb_form"][result] += 1; a["amb_tokform"][token] += 1; a["amb_lemma"][(lemma, pos)] += 1
65
+ a["amb_form_info"].setdefault(result, (lemma, pos, morph))
66
+ for kv in feats:
67
+ a["amb_feat"][(pos, kv)] += 1
68
+ for k, v in shape.items():
69
+ if v: a["amb_shape"][k] += 1
70
+ us = unresolved_syllables(result)
71
+ a["amb_nunres"][min(len(us), 3)] += 1
72
+ for v, where, acc in us:
73
+ a["amb_syl"][(v, where, acc)] += 1
74
+ a["unresolved_vowel"][v] += 1
75
+
76
+
77
+ def merge(a, b):
78
+ for k, v in b.items():
79
+ if isinstance(v, C): a[k].update(v)
80
+ elif isinstance(v, dict):
81
+ for kk, vv in v.items(): a[k].setdefault(kk, vv)
82
+ else: a[k] += v
83
+ return a
84
+
85
+
86
+ def do_trace(path):
87
+ tag = os.path.basename(path)[:-4]
88
+ stem, chunk = tag.rsplit(".", 1)
89
+ chunk = int(chunk)
90
+ keep = HF_KEEP.get(stem, set())
91
+ hf, allo = new_acc(), new_acc()
92
+ with open(path, encoding="utf-8") as fh:
93
+ next(fh)
94
+ for line in fh:
95
+ c = line.rstrip("\n").split("\t")
96
+ if len(c) != 9:
97
+ continue
98
+ add_row(allo, c)
99
+ if (chunk, int(c[0])) in keep:
100
+ add_row(hf, c)
101
+ return hf, allo
102
+
103
+
104
+ def do_lines(args):
105
+ stem, lines, flags = args
106
+ out = C()
107
+ for line, in_hf in zip(lines, flags):
108
+ b = count_dichrona_in_open_syllables(line.replace("^", "").replace("_", ""))
109
+ a = count_dichrona_in_open_syllables(line)
110
+ out[("all", "before")] += b; out[("all", "after")] += a; out[("all", "lines")] += 1
111
+ if in_hf:
112
+ out[("hf", "before")] += b; out[("hf", "after")] += a; out[("hf", "lines")] += 1
113
+ return stem, out
114
+
115
+
116
+ def do_log(path):
117
+ out = dict(skips=C(), considered_pos=C(), odycy_fail=0, chunk_sentences={}, lines=0)
118
+ skip_needles = [("no dichrona", "has no dichrona"), ("not in diagnostic word list", "not in diagnostic word list"),
119
+ ("Greek numeral", "is a Greek numeral"), ("stop word", "stop word"),
120
+ ("final sigma mid-word", "final sigma mid-word"), ("pathological accents/breathings", "Pathological word")]
121
+ r_cons = re.compile(r"^Considering token: .*?\tPOS: (.*?)\tMorph: ")
122
+ r_start = re.compile(r"^=== CHUNK START (\S+) sentences=(\d+) ===")
123
+ with open(path, encoding="utf-8", errors="replace") as fh:
124
+ for line in fh:
125
+ out["lines"] += 1
126
+ p = line.rstrip("\n").split(" - ", 2)
127
+ if len(p) < 3:
128
+ continue
129
+ msg = p[2]
130
+ m = r_cons.match(msg)
131
+ if m:
132
+ out["considered_pos"][m.group(1)] += 1; continue
133
+ m = r_start.match(msg)
134
+ if m:
135
+ out["chunk_sentences"][m.group(1)] = int(m.group(2)); continue
136
+ if msg.startswith("odyCy fail count:"):
137
+ out["odycy_fail"] += int(msg.split(":")[1]); continue
138
+ for name, needle in skip_needles:
139
+ if needle in msg:
140
+ out["skips"][name] += 1; break
141
+ return out
142
+
143
+
144
+ def summarize(a, label):
145
+ tot_dich = sum(a["credit_dich"].values())
146
+ mods = []
147
+ for m in MODULES:
148
+ mods.append(dict(module=m, tokens=a["credit_tok"][m], dichrona=a["credit_dich"][m],
149
+ share_of_resolved=a["credit_dich"][m] / tot_dich if tot_dich else 0,
150
+ solo_tokens=a["solo_tok"][m], solo_short_marks=a["solo_short"][m], solo_long_marks=a["solo_long"][m],
151
+ first_in_cascade=a["first_module"][m]))
152
+ sp = a["sent_pos"]
153
+ amb_by_pos = [(p, n, sp[p], n / sp[p]) for p, n in a["amb_pos"].most_common()]
154
+ feat = sorted([(pos, kv, n, a["sent_feat"][(pos, kv)], n / a["sent_feat"][(pos, kv)])
155
+ for (pos, kv), n in a["amb_feat"].items() if a["sent_feat"][(pos, kv)] >= 20000],
156
+ key=lambda x: -x[4])
157
+ cum, curve, tot_amb = 0, [], a["amb_tok"]
158
+ for i, (f, n) in enumerate(a["amb_form"].most_common(), 1):
159
+ cum += n
160
+ if i in (10, 100, 1000, 10000, 100000):
161
+ curve.append((i, cum, cum / tot_amb if tot_amb else 0))
162
+ freq_rate = sorted([(f, a["amb_tokform"][f], a["sent_form"][f], a["amb_tokform"][f] / a["sent_form"][f])
163
+ for f in a["sent_form"] if a["sent_form"][f] >= 1000 and a["amb_tokform"][f]],
164
+ key=lambda x: (-x[3], -x[2]))[:60]
165
+ lem_rate = sorted([(l, p, a["amb_lemma"][(l, p)], a["sent_lemma"][(l, p)], a["amb_lemma"][(l, p)] / a["sent_lemma"][(l, p)])
166
+ for (l, p) in a["sent_lemma"] if a["sent_lemma"][(l, p)] >= 2000 and a["amb_lemma"][(l, p)]],
167
+ key=lambda x: -x[4])[:60]
168
+ return dict(
169
+ label=label, tokens_sent=a["tokens"], dichrona_in_tokens_sent=a["before"], resolved=a["before"] - a["after"],
170
+ unresolved=a["after"], credited=tot_dich, marks_added_short=a["resolved_short"], marks_added_long=a["resolved_long"],
171
+ modules=mods, modules_per_token=sorted(a["n_modules"].items()),
172
+ credit_by_module_pos=[(m, p, n) for (m, p), n in a["credit_pos"].most_common(80)],
173
+ abstentions=dict(tokens=a["amb_tok"], unresolved_dichrona=a["amb_dich"], partially_marked=a["amb_partial"],
174
+ rate=a["amb_tok"] / a["tokens"] if a["tokens"] else 0,
175
+ unique_forms=len(a["amb_form"]), unique_lemmas=len(a["amb_lemma"]),
176
+ hapax_forms=sum(1 for n in a["amb_form"].values() if n == 1),
177
+ by_pos=amb_by_pos, by_feature=feat,
178
+ by_shape={k: (a["amb_shape"][k], a["sent_shape"][k]) for k in ("lunate", "capitalized", "elided")},
179
+ unresolved_syllables_per_token=sorted(a["amb_nunres"].items()),
180
+ by_vowel=a["unresolved_vowel"].most_common(),
181
+ by_vowel_position_accent=[(*k, n) for k, n in a["amb_syl"].most_common()],
182
+ top_forms=[(f, n, *a["amb_form_info"][f], a["sent_form"].get(f.replace("^", "").replace("_", ""), 0)) for f, n in a["amb_form"].most_common(150)],
183
+ top_lemmas=[(l, p, n, a["sent_lemma"][(l, p)]) for (l, p), n in a["amb_lemma"].most_common(150)],
184
+ coverage_curve=curve, frequent_forms_highest_rate=freq_rate, frequent_lemmas_highest_rate=lem_rate))
185
+
186
+
187
+ def main():
188
+ global HF_KEEP
189
+ diag, rerun, hf_dir, out_dir, workers = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5])
190
+ os.makedirs(out_dir, exist_ok=True)
191
+ R = {}
192
+
193
+ # 1. logs: funnel and sentences per chunk
194
+ logs = sorted(glob.glob(os.path.join(diag, "logs", "*.log")))
195
+ with Pool(workers) as pool:
196
+ L = None
197
+ for r in pool.imap_unordered(do_log, logs):
198
+ if L is None: L = r; continue
199
+ L["skips"].update(r["skips"]); L["considered_pos"].update(r["considered_pos"])
200
+ L["odycy_fail"] += r["odycy_fail"]; L["chunk_sentences"].update(r["chunk_sentences"]); L["lines"] += r["lines"]
201
+ print(f"logs: {len(logs)} files, {L['lines']:,} lines, {len(L['chunk_sentences'])} chunks", flush=True)
202
+
203
+ # 2. HF membership per output line
204
+ hf = C()
205
+ for f in sorted(glob.glob(os.path.join(hf_dir, "*.parquet"))):
206
+ hf.update(pq.read_table(f, columns=["macronized"]).column(0).to_pylist())
207
+ n_hf = sum(hf.values())
208
+ keep, line_jobs, mism = {}, [], []
209
+ for f in sorted(glob.glob(os.path.join(rerun, "parts", "*.txt"))):
210
+ stem = os.path.basename(f)[:-4]
211
+ lines = open(f, encoding="utf-8").read().splitlines()
212
+ rows = [r.split("\t") for r in open(os.path.join(rerun, "parts", stem + ".progress"), encoding="utf-8").read().splitlines()]
213
+ for r in rows:
214
+ exp = L["chunk_sentences"].get(f"{stem}.{int(r[0]):05d}")
215
+ if exp is not None and exp != int(r[2]):
216
+ mism.append((stem, int(r[0]), exp, int(r[2])))
217
+ flags = []
218
+ s = set()
219
+ for i, line in enumerate(lines):
220
+ ok = hf[line] > 0
221
+ if ok:
222
+ hf[line] -= 1
223
+ s.add((i // CHUNK, i % CHUNK))
224
+ flags.append(ok)
225
+ keep[stem] = s
226
+ line_jobs.append((stem, lines, flags))
227
+ unmatched = sum(v for v in hf.values() if v > 0)
228
+ R["membership"] = dict(hf_sentences=n_hf, matched=n_hf - unmatched, unmatched_hf_lines=unmatched,
229
+ chunks_with_line_count_mismatch=mism[:50], n_mismatch=len(mism))
230
+ print("membership:", R["membership"], flush=True)
231
+ HF_KEEP = keep
232
+
233
+ # 3. dichrona ratios per line (HF and all), per work
234
+ per_work = {}
235
+ with Pool(workers) as pool:
236
+ tot = C()
237
+ for stem, c in pool.imap_unordered(do_lines, line_jobs, chunksize=4):
238
+ per_work[stem] = c; tot.update(c)
239
+ R["ratio"] = {k: dict(lines=tot[(k, "lines")], dichrona=tot[(k, "before")], unmarked=tot[(k, "after")],
240
+ marked=tot[(k, "before")] - tot[(k, "after")],
241
+ ratio=(tot[(k, "before")] - tot[(k, "after")]) / tot[(k, "before")]) for k in ("all", "hf")}
242
+ R["works"] = {s: dict(lines=c[("hf", "lines")], dichrona=c[("hf", "before")], unmarked=c[("hf", "after")],
243
+ all_lines=c[("all", "lines")]) for s, c in per_work.items()}
244
+ print("ratio:", R["ratio"], flush=True)
245
+ del line_jobs
246
+
247
+ # 4. traces
248
+ traces = sorted(glob.glob(os.path.join(diag, "traces", "*.tsv")))
249
+ with Pool(workers) as pool:
250
+ H = A = None
251
+ for i, (h, a) in enumerate(pool.imap_unordered(do_trace, traces, chunksize=8)):
252
+ H = h if H is None else merge(H, h); A = a if A is None else merge(A, a)
253
+ if i % 500 == 0: print(f" traces {i}/{len(traces)}", flush=True)
254
+ R["hf"] = summarize(H, "Urdatorn/oga-macronized-no-norma (5d737f8)")
255
+ R["all"] = summarize(A, "all OGA sentences")
256
+ R["funnel_all_oga"] = dict(considered=sum(L["considered_pos"].values()), considered_pos=L["considered_pos"].most_common(),
257
+ skips=L["skips"].most_common(), odycy_fail=L["odycy_fail"], sent=A["tokens"])
258
+ mods_tsv = os.path.join(rerun, "oga_macronized_modules.tsv")
259
+ R["module_events_all_oga"] = open(mods_tsv, encoding="utf-8").read() if os.path.exists(mods_tsv) else None
260
+
261
+ with open(os.path.join(out_dir, "stats.json"), "w", encoding="utf-8") as f:
262
+ json.dump(R, f, ensure_ascii=False, indent=1, default=str)
263
+ with open(os.path.join(out_dir, "abstained_forms_hf.tsv"), "w", encoding="utf-8") as f:
264
+ f.write("abstained\tsent_to_modules\tform\tlemma\tpos\tmorph\n")
265
+ for form, n in H["amb_form"].most_common():
266
+ plain = form.replace("^", "").replace("_", "")
267
+ f.write(f"{n}\t{H['sent_form'].get(plain, 0)}\t{form}\t" + "\t".join(H["amb_form_info"][form]) + "\n")
268
+ print("done", flush=True)
269
+
270
+
271
+ if __name__ == "__main__":
272
+ main()
analysis/scripts/check_logging_smoke.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Smoke checks for the diagnostics-logging branch on a few OGA files.
2
+ Usage: python check_logging_smoke.py WORK_DIR NEW_OUT OLD_OUT"""
3
+ import collections, glob, os, re, sys
4
+ work, new, old = sys.argv[1:4]
5
+ ok = True
6
+ def check(cond, msg):
7
+ global ok
8
+ print(("PASS " if cond else "FAIL ") + msg); ok &= bool(cond)
9
+ stems = [os.path.basename(f)[:-5] for f in glob.glob(f"{new}/parts/*.done")]
10
+ same = all(open(f"{new}/parts/{s}.txt", encoding="utf-8").read() == open(f"{old}/parts/{s}.txt", encoding="utf-8").read() for s in stems)
11
+ check(same, f"output identical to the a949b76 run for {len(stems)} files")
12
+ def modcols(p):
13
+ tot = collections.Counter()
14
+ for row in open(p, encoding="utf-8"):
15
+ cols = row.rstrip("\n").split("\t")
16
+ if len(cols) >= 6 and cols[5]:
17
+ for kv in cols[5].split(","):
18
+ k, v = kv.split("="); tot[k] += int(v)
19
+ return tot
20
+ check(all(modcols(f"{new}/parts/{s}.progress") == modcols(f"{old}/parts/{s}.progress") for s in stems), "module counts identical to the a949b76 run")
21
+ logs = glob.glob(f"{work}/diagnostics/logs/*.log")
22
+ pids = set()
23
+ bad_fmt = 0; starts = ends = 0
24
+ for lg in logs:
25
+ for line in open(lg, encoding="utf-8", errors="replace"):
26
+ m = re.match(r"^\d{4}-\d\d-\d\d [\d:,]+ - (\d+) - ", line)
27
+ if m: pids.add(m.group(1))
28
+ elif line.startswith("20"): bad_fmt += 1
29
+ starts += "=== CHUNK START" in line; ends += "=== CHUNK END" in line
30
+ check(len(logs) >= 2 and bad_fmt == 0, f"{len(logs)} log files (one per process), every timestamped line has a pid ({len(pids)} pids)")
31
+ n_chunks = sum(1 for s in stems for _ in open(f"{new}/parts/{s}.progress"))
32
+ check(starts == ends == n_chunks, f"CHUNK START/END lines: {starts}/{ends} for {n_chunks} chunks")
33
+ traces = glob.glob(f"{work}/diagnostics/traces/*.tsv")
34
+ check(len(traces) == n_chunks and all(re.search(r"\.\d{5}\.tsv$", t) for t in traces), f"{len(traces)} traces named <stem>.<chunk>")
35
+ check(len(glob.glob(f"{work}/diagnostics/still_ambiguous/still_ambiguous_*.?????.tsv")) == n_chunks, "still_ambiguous files named by tag")
36
+ rows = match = 0; maxsent = 0; credit_tot = collections.Counter()
37
+ for t in traces:
38
+ for i, line in enumerate(open(t, encoding="utf-8")):
39
+ if i == 0: continue
40
+ c = line.rstrip("\n").split("\t")
41
+ rows += 1; maxsent = max(maxsent, int(c[0]))
42
+ s = sum(int(kv.split("=")[1]) for kv in c[8].split(",") if kv)
43
+ for kv in c[8].split(","):
44
+ if kv: credit_tot[kv.split("=")[0]] += int(kv.split("=")[1])
45
+ match += (s == int(c[5]) - int(c[6]))
46
+ check(rows > 0 and match / rows > 0.99, f"credits add up to before-after for {match}/{rows} tokens ({match/rows:.4%})")
47
+ check(maxsent < 500, f"sentence indices within a chunk (max {maxsent})")
48
+ print("credits:", credit_tot.most_common())
49
+ print("ALL OK" if ok else "SOME CHECKS FAILED")
50
+ sys.exit(0 if ok else 1)
analysis/scripts/compare_runs.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compare two macronize_oga_corpus.py runs line by line (same input, same chunking).
2
+
3
+ Usage: python3 compare_runs.py OLD_OUT_DIR NEW_OUT_DIR
4
+ """
5
+ import collections, glob, json, os, sys
6
+ old, new = sys.argv[1:3]
7
+ strip = lambda s: s.replace("^", "").replace("_", "")
8
+ n = same = text_diff = marks_only = count_mismatch = 0
9
+ ex = collections.defaultdict(list)
10
+ for f in sorted(glob.glob(os.path.join(new, "parts", "*.txt"))):
11
+ a = open(os.path.join(old, "parts", os.path.basename(f)), encoding="utf-8").read().splitlines()
12
+ b = open(f, encoding="utf-8").read().splitlines()
13
+ if len(a) != len(b):
14
+ count_mismatch += 1; ex["count_mismatch"].append((os.path.basename(f), len(a), len(b))); continue
15
+ for x, y in zip(a, b):
16
+ n += 1
17
+ if x == y: same += 1
18
+ elif strip(x) != strip(y):
19
+ text_diff += 1
20
+ if len(ex["text"]) < 40: ex["text"].append((x, y))
21
+ else:
22
+ marks_only += 1
23
+ if len(ex["marks"]) < 40: ex["marks"].append((x, y))
24
+ s = dict(lines=n, identical=same, text_differs=text_diff, marks_only_differ=marks_only, files_with_line_count_mismatch=count_mismatch)
25
+ print(json.dumps(s, indent=2))
26
+ json.dump(dict(summary=s, examples=ex), open(os.path.join(new, "compare_to_previous.json"), "w"), ensure_ascii=False, indent=1)
analysis/slurm/analyze_rerun.slurm ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #SBATCH --job-name=oga-rerun-stats
3
+ #SBATCH --account=naiss2026-3-353-gpu
4
+ #SBATCH --partition=gpu
5
+ #SBATCH --nodes=1
6
+ #SBATCH --ntasks=1
7
+ #SBATCH --cpus-per-task=32
8
+ #SBATCH --gpus=1
9
+ #SBATCH --mem=128G
10
+ #SBATCH --time=02:00:00
11
+ #SBATCH --output=logs/%x-%j.out
12
+ #SBATCH --error=logs/%x-%j.out
13
+ # Statistics from the attributable diagnostics of the OGA rerun (scripts/analyze_rerun.py),
14
+ # restricted to the sentences of Urdatorn/oga-macronized-no-norma (5d737f8, = final/data)
15
+ # with all-OGA figures alongside. The archive is unpacked on node-local scratch. CPU only.
16
+ set -Eeuo pipefail
17
+ trap 'status=$?; printf "[%s] ERROR line=%s command=%q status=%s\n" "$(date --iso-8601=seconds)" "$LINENO" "$BASH_COMMAND" "$status"; exit "$status"' ERR
18
+ out=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11
19
+ rerun=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun
20
+ venv=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronizer-char-code/.venv
21
+ stamp() { printf '[%s] %s\n' "$(date --iso-8601=seconds)" "$*"; }
22
+ stamp "start job=$SLURM_JOB_ID host=$(hostname)"
23
+ module purge; module load GPU/Python/3.13.5-bare-gcc-2025b-eb
24
+ export PYTHONUNBUFFERED=1
25
+ work=${SNIC_TMP:-/scratch/local}/oga-rerun-stats-$SLURM_JOB_ID; mkdir -p "$work"
26
+ arch=$(ls "$rerun"/diagnostics-archive/diagnostics-job*.tar.zst | head -1)
27
+ stamp "unpacking $arch"
28
+ zstd -dc -T8 "$arch" | tar -C "$work" -xf -
29
+ du -sh "$work/diagnostics"/* | sed 's/^/ /'
30
+ stamp "analysis"
31
+ "$venv/bin/python" "$out/scripts/analyze_rerun.py" "$work/diagnostics" "$rerun" "$out/final/data" "$rerun/analysis" "$SLURM_CPUS_PER_TASK"
32
+ ls -la "$rerun/analysis"
33
+ stamp "done"
analysis/slurm/rerun_diagnostics.slurm ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #SBATCH --job-name=oga-rerun-diag
3
+ #SBATCH --account=naiss2026-3-353-gpu
4
+ #SBATCH --partition=gpu
5
+ #SBATCH --nodes=1
6
+ #SBATCH --ntasks=1
7
+ #SBATCH --cpus-per-task=32
8
+ #SBATCH --gpus=1
9
+ #SBATCH --mem=48G
10
+ #SBATCH --time=03:00:00
11
+ #SBATCH --output=logs/%x-%j.out
12
+ #SBATCH --error=logs/%x-%j.out
13
+
14
+ # Rerun of the OGA macronization (job 5709453, grc-macronizer a949b76) with the
15
+ # diagnostics-logging branch (a949b76 + per-worker logs, chunk tags and per-token traces;
16
+ # macronization unchanged), to get attributable diagnostics for exactly the data on
17
+ # Urdatorn/oga-macronized-no-norma. Same input and chunking as before, so the output must be
18
+ # identical; the HF subset (decontaminated, non-Greek and the 29 corrupted sentences removed)
19
+ # is selected afterwards by matching output lines. Steps:
20
+ # 1. smoke test on 7 small files: identical output and module counts, per-worker logs with
21
+ # pids, chunk markers, tagged diagnostics, credits adding up (stops here on failure)
22
+ # 2. full run into oga-macronized-2026-11-rerun/ (diagnostics on node-local scratch)
23
+ # 3. line-by-line comparison with the a949b76 run (must be identical)
24
+ # 4. diagnostics archived (zstd tar, verified) to the disk tier and to flash
25
+ # CPU only; the GPU sits idle.
26
+
27
+ set -Eeuo pipefail
28
+ trap 'status=$?; printf "[%s] ERROR line=%s command=%q status=%s\n" "$(date --iso-8601=seconds)" "$LINENO" "$BASH_COMMAND" "$status"; exit "$status"' ERR
29
+
30
+ repo=/nobackup/proj/flash/dionysus/personal/cleland/grc-macronizer-logging
31
+ old=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11
32
+ new=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronized-2026-11-rerun
33
+ conllu=/nobackup/proj/flash/dionysus/personal/cleland/oga_conllu
34
+ venv=/nobackup/proj/flash/dionysus/personal/cleland/oga-macronizer-char-code/.venv-rule
35
+ disk=/nobackup/proj/disk/dionysus/personal/cleland/oga-macronized-2026-11-diagnostics
36
+ work=${SNIC_TMP:-/scratch/local}/oga-rerun-$SLURM_JOB_ID
37
+ stamp() { printf '[%s] %s\n' "$(date --iso-8601=seconds)" "$*"; }
38
+
39
+ stamp "job_start job=$SLURM_JOB_ID host=$(hostname) cpus=$SLURM_CPUS_PER_TASK grc-macronizer=$(git -C $repo rev-parse --abbrev-ref HEAD)@$(git -C $repo rev-parse --short HEAD) dirty=$(git -C $repo status --porcelain | wc -l)"
40
+ module purge; module load GPU/Python/3.13.5-bare-gcc-2025b-eb
41
+ export PYTHONUNBUFFERED=1 PYTHONPATH=$repo
42
+ "$venv/bin/python" -c "import grc_macronizer, spacy; print('grc_macronizer', grc_macronizer.__file__, 'spacy', spacy.__version__)"
43
+ mkdir -p "$work/smoke/conllu" "$new"
44
+
45
+ stamp "1. smoke test"
46
+ while read -r f; do ln -s "$conllu/$f" "$work/smoke/conllu/"; done < "$old/scripts/smoke_files.txt"
47
+ (cd "$work/smoke" && "$venv/bin/python" "$repo/scripts/macronize_oga_corpus.py" \
48
+ --conllu-glob "$work/smoke/conllu/*.conllu" --out-dir "$work/smoke/out" --workers 4 > smoke.log 2>&1)
49
+ tail -3 "$work/smoke/smoke.log"
50
+ "$venv/bin/python" "$old/scripts/check_logging_smoke.py" "$work/smoke" "$work/smoke/out" "$old"
51
+
52
+ stamp "2. full run -> $new"
53
+ mkdir -p "$work/full"; cd "$work/full" # diagnostics/ is written into the working directory
54
+ "$venv/bin/python" "$repo/scripts/macronize_oga_corpus.py" \
55
+ --conllu-glob "$conllu/*.conllu" --out-dir "$new" --workers "$SLURM_CPUS_PER_TASK" > "$new/run.log" 2>&1 || echo " WARNING: driver exited non-zero"
56
+ tail -3 "$new/run.log"
57
+ echo " chunk errors: $(grep -c 'ERROR' "$new/run.log" || true)"
58
+ echo " 'Integration corrupted' warnings: $(grep -c 'Integration corrupted' "$new/run.log" || true) (20 expected, as in the a949b76 run)"
59
+ cat "$new/oga_macronized_stats.tsv" "$new/oga_macronized_modules.tsv" || true
60
+ du -sh "$work/full/diagnostics"/* | sed "s/^/ /" || true
61
+
62
+ stamp "3. compare with the a949b76 run"
63
+ "$venv/bin/python" "$old/scripts/compare_runs.py" "$old" "$new" || echo " WARNING: comparison failed"
64
+ if cmp -s "$old/oga_macronized.txt" "$new/oga_macronized.txt"; then echo " oga_macronized.txt byte-identical"; else echo " WARNING: oga_macronized.txt DIFFERS from the a949b76 run"; fi
65
+
66
+ stamp "4. archive diagnostics"
67
+ arch=diagnostics-job$SLURM_JOB_ID.tar.zst
68
+ mkdir -p "$disk" "$new/diagnostics-archive"
69
+ (cd "$work/full" && find diagnostics -type f -printf '%s\t%P\n' | sort -k2 > "$disk/$arch.filelist.tsv")
70
+ tar -C "$work/full" -cf - diagnostics | zstd -q -T"$SLURM_CPUS_PER_TASK" -10 -o "$disk/$arch"
71
+ zstd -q -t "$disk/$arch"
72
+ [[ $(zstd -dc "$disk/$arch" | tar -t | grep -vc '/$') == $(wc -l < "$disk/$arch.filelist.tsv") ]]
73
+ (cd "$disk" && sha256sum "$arch" > "$arch.sha256")
74
+ cp -p "$disk/$arch" "$disk/$arch.filelist.tsv" "$disk/$arch.sha256" "$new/diagnostics-archive/"
75
+ (cd "$new/diagnostics-archive" && sha256sum -c "$arch.sha256")
76
+ ls -l "$disk/$arch" "$new/diagnostics-archive/$arch"
77
+ stamp "job_complete"