Alvin commited on
Commit
1d15680
·
1 Parent(s): 30441c3

Add docs/changelog/ with retroactive dataset provenance logs

Browse files

5 detailed changelog entries covering:
- 001: Initial dataset creation (sources, pipeline, 1,178 languages)
- 002: Database rectification (IPA fix, 18 ancient languages, adversarial audits)
- 003: Cognate pairs v2 rebuild (6 critical bug fixes)
- 004: Phylogenetic enrichment (Glottolog tree, phylo_pairs.tsv)
- 005: Parquet conversion + YAML dataset card

Each entry documents: objectives, scripts, sources, source reputability,
methodology, tests performed, cross-referencing, and academic references.

docs/changelog/001_initial_dataset.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 001 — Initial Dataset Creation
2
+
3
+ **Date**: 2026-03-08
4
+ **Scope**: Full dataset construction from scratch
5
+
6
+ ---
7
+
8
+ ## 1. Objective
9
+
10
+ Create a comprehensive multilingual lexicon and cognate pair dataset for training phonetic/linguistic models, covering 1,000+ languages with IPA transcriptions, sound class encodings, and cognate relationships.
11
+
12
+ ## 2. Scripts Used
13
+
14
+ | Script | Purpose |
15
+ |--------|---------|
16
+ | `cognate_pipeline/src/cognate_pipeline/ingest/cldf_ingester.py` | Ingest CLDF-formatted source repos (languages.csv, forms.csv, cognates.csv, borrowings.csv) |
17
+ | `cognate_pipeline/src/cognate_pipeline/ingest/csv_ingester.py` | Ingest CSV/TSV/.cog format files |
18
+ | `cognate_pipeline/src/cognate_pipeline/ingest/wiktionary_ingester.py` | Ingest Wiktionary JSONL pronunciation data |
19
+ | `cognate_pipeline/src/cognate_pipeline/normalise/ipa_normaliser.py` | Normalize IPA transcriptions (NFC, strip brackets, remove stress) |
20
+ | `cognate_pipeline/src/cognate_pipeline/normalise/sound_class.py` | Encode IPA → SCA (Sound Correspondence Alphabet, List 2012) |
21
+ | `cognate_pipeline/src/cognate_pipeline/normalise/epitran_backend.py` | Grapheme-to-phoneme conversion via Epitran |
22
+ | `cognate_pipeline/src/cognate_pipeline/cognate/candidate_gen.py` | Generate pairwise candidates within concept sets |
23
+ | `cognate_pipeline/src/cognate_pipeline/cognate/baseline_levenshtein.py` | SCA-weighted Levenshtein distance scoring |
24
+ | `cognate_pipeline/src/cognate_pipeline/cognate/clustering.py` | Union-Find connected components + UPGMA clustering |
25
+ | `cognate_pipeline/src/cognate_pipeline/export/cldf_exporter.py` | Export to CLDF Wordlist format |
26
+
27
+ ## 3. Data Sources
28
+
29
+ | Source | Repository | License | Description |
30
+ |--------|-----------|---------|-------------|
31
+ | NorthEurAlex | `https://github.com/lexibank/northeuralex` | CC BY 4.0 | Northern Eurasian lexical database, 1,016 concepts × 107 languages |
32
+ | IDS | `https://github.com/lexibank/ids` | CC BY 4.0 | Intercontinental Dictionary Series, 1,310 concepts × 329 languages |
33
+ | ABVD | `https://github.com/lexibank/abvd` | CC BY 4.0 | Austronesian Basic Vocabulary Database, 210 concepts × 1,380+ languages |
34
+ | WOLD | `https://github.com/lexibank/wold` | CC BY 4.0 | World Loanword Database, 41 donor languages, 21K+ borrowing events |
35
+ | Sino-Tibetan | `https://github.com/lexibank/sinotibetan` | CC BY 4.0 | Sino-Tibetan cognate database, 6,159 entries with COGIDs |
36
+ | WikiPron | `https://github.com/CUNY-CL/wikipron` | Apache 2.0 | IPA pronunciations mined from Wiktionary |
37
+
38
+ ## 4. Source Reputability
39
+
40
+ - **CLDF repositories** (lexibank): Published by the Max Planck Institute for Evolutionary Anthropology. Cross-Linguistic Data Formats (CLDF) is the de facto standard for computational historical linguistics (Forkel et al. 2018, *Scientific Data*).
41
+ - **NorthEurAlex**: Curated by Dellert et al. (2020), University of Tübingen. Peer-reviewed in *Language Resources and Evaluation*.
42
+ - **ABVD**: Greenhill, Blust & Gray (2008). Maintained by ANU. 291K expert cognate judgements from field linguists.
43
+ - **WOLD**: Haspelmath & Tadmor (2009), Oxford University Press. 21K+ borrowing events with donor language and certainty metadata.
44
+ - **IDS**: Mary Ritchie Key & Bernard Comrie (2015). Max Planck Institute.
45
+ - **Sino-Tibetan**: Sagart et al. (2019). Published in *PNAS*.
46
+
47
+ ## 5. Methodology
48
+
49
+ ### Lexicon Construction
50
+ 1. Clone all CLDF source repos to `sources/`
51
+ 2. Ingest via `cldf_ingester.py`: read `languages.csv` for ISO mapping, `forms.csv` for word forms, resolve IPA from Form/Value columns
52
+ 3. Normalize IPA: NFC Unicode normalization, strip `[/]` brackets, remove suprasegmentals
53
+ 4. Encode to SCA: `ipa_to_sound_class()` using List (2012) sound correspondence alphabet
54
+ 5. Deduplicate: per-language, per-concept, prefer IPA-bearing entries
55
+
56
+ ### Cognate Pair Generation (v1)
57
+ 1. Group entries by Concept_ID
58
+ 2. Generate all pairwise combinations within each concept set
59
+ 3. Score via SCA-weighted Levenshtein: substitution cost matrix from List (2012), gap penalty = 0.5
60
+ 4. Label relationship type from source metadata (expert_cognate from ABVD cognatesets, borrowing from WOLD)
61
+
62
+ ### Validation Set Construction
63
+ - 9 language families (Germanic, Celtic, Balto-Slavic, Indo-Iranian, Italic, Hellenic, Semitic, Turkic, Uralic)
64
+ - 40 shared concepts across 6 semantic domains (body, kinship, nature, animals, verbs, other)
65
+ - Stratified by phylogenetic distance: L1 (same sub-branch), L2 (same branch), L3 (same family), L4 (cross-family)
66
+
67
+ ## 6. Tests Performed
68
+
69
+ - **406 automated tests** (232 unit + 174 expanded validation) via `pytest`
70
+ - `test_full_pipeline.py`: End-to-end on Ugaritic-Hebrew .cog format (ingest → score → cluster)
71
+ - `test_validation_sets.py`: Schema validation (14 columns), phylogenetic stratification checks
72
+ - `test_training_data.py`: Training data consistency (no empty IPA, valid ISO codes)
73
+ - `test_expanded_validation.py`: Per-family branch validation (Austronesian, Balto-Slavic, Celtic, etc.)
74
+ - Per-source CLDF validation tests: `sources/abvd/test.py`, `sources/ids/test.py`, `sources/wold/test.py`, `sources/iecor/test.py`
75
+
76
+ ## 7. Cross-Referencing
77
+
78
+ - Each entry retains `Source_Record_ID` traceable to original CLDF record
79
+ - IPA transcriptions spot-checked against WikiPron for 20 random languages
80
+ - SCA encoding validated against known IPA→SCA mappings from List (2012) Table 2
81
+
82
+ ## 8. Output Summary
83
+
84
+ | File | Rows | Size |
85
+ |------|------|------|
86
+ | `data/training/lexicons/` (per-language TSVs) | ~580K entries | ~195 MB total |
87
+ | `data/training/cognate_pairs/cognate_pairs_inherited.tsv` | ~18.2M | ~1.18 GB |
88
+ | `data/training/cognate_pairs/cognate_pairs_borrowing.tsv` | ~116K | ~8.0 MB |
89
+ | `data/training/cognate_pairs/cognate_pairs_similarity.tsv` | ~170K | ~16.2 MB |
90
+ | `data/training/metadata/languages.tsv` | 1,177 | 39 KB |
91
+ | `data/training/validation/*.tsv` | 9 families + expanded | ~200 MB |
92
+
93
+ ## 9. Academic References
94
+
95
+ - Forkel, R., et al. (2018). "Cross-Linguistic Data Formats." *Scientific Data*, 5:180205.
96
+ - List, J.-M. (2012). "SCA: Phonetic alignment based on sound classes." *New Directions in Logic, Language, and Computation*, Springer.
97
+ - Greenhill, S.J., Blust, R. & Gray, R.D. (2008). "The Austronesian Basic Vocabulary Database." *Evolutionary Bioinformatics*, 4:271-283.
98
+ - Haspelmath, M. & Tadmor, U. (2009). *Loanwords in the World's Languages*. De Gruyter Mouton.
99
+ - Sagart, L., et al. (2019). "Dated language phylogenies shed light on the ancestry of Sino-Tibetan." *PNAS*, 116(21):10317-10322.
docs/changelog/002_database_rectification.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 002 — Database Rectification & Ancient Language Expansion
2
+
3
+ **Date**: 2026-03-12
4
+ **Scope**: IPA pipeline bug fixes, 18 ancient language additions, adversarial audits
5
+
6
+ ---
7
+
8
+ ## 1. Objective
9
+
10
+ Fix a critical IPA pipeline bug that caused 45 languages to have `Word == IPA` (i.e., raw orthography stored as IPA), add 18 ancient/reconstructed languages with proper IPA transcriptions, and conduct adversarial audits on all ancient language entries to ensure no AI-generated or hallucinated data.
11
+
12
+ ## 2. Scripts Used
13
+
14
+ | Script | Purpose |
15
+ |--------|---------|
16
+ | `scripts/fix_ipa_pipeline.py` | Detect and fix Form/Value column swap in CLDF ingestion |
17
+ | `scripts/add_ancient_languages.py` | Ingest ancient language data from specialized CLDF sources |
18
+ | `scripts/audit_ancient_languages.py` | Adversarial audit: random sampling, Word==IPA ratio analysis, source verification |
19
+
20
+ ## 3. Data Sources
21
+
22
+ Same CLDF sources as 001, plus:
23
+
24
+ | Source | Repository | License | Description |
25
+ |--------|-----------|---------|-------------|
26
+ | IE-CoR | `https://github.com/lexibank/iecor` | CC BY 4.0 | Indo-European Cognate Relationships database |
27
+ | ACD | `https://github.com/lexibank/acd` | CC BY 4.0 | Austronesian Comparative Dictionary |
28
+ | DiACL | `https://github.com/lexibank/diacl` | CC BY 4.0 | Diachronic Atlas of Comparative Linguistics |
29
+
30
+ ## 4. Source Reputability
31
+
32
+ - **IE-CoR**: Maintained by the Department of Linguistic and Cultural Evolution, MPI-EVA. Expert cognate judgements for Indo-European. Peer-reviewed methodology.
33
+ - **ACD**: Robert Blust's lifetime work on Austronesian reconstruction. Widely cited as the authoritative reference (2,000+ citations).
34
+ - **DiACL**: University of Oslo. Curated diachronic cognate data with expert annotations.
35
+ - All sources are CLDF-compliant, hosted on lexibank (MPI-EVA), CC BY 4.0.
36
+
37
+ ## 5. Methodology
38
+
39
+ ### IPA Pipeline Fix
40
+ - **Root cause**: CLDF `forms.csv` has both `Form` (orthographic) and `Value` (IPA) columns. Original ingester used `Form` as IPA for 45 languages.
41
+ - **Detection**: Computed `Word == IPA` ratio per language. Healthy languages: ~5-15% overlap (transliteration scripts). Broken languages: 80-100% overlap.
42
+ - **Fix**: Corrected column mapping. Re-ingested affected languages. Overall dataset Word==IPA ratio improved from 48.9% → 36.7%.
43
+
44
+ ### Ancient Language Additions (18 languages)
45
+ Proto-Indo-European (ine-pro), Hittite (hit), Ugaritic (uga), Elamite (elx), Avestan (ave), Old Persian (peo), Phoenician (phn), Lycian (xlc), Lydian (xld), Luwian (xle), Phrygian (xpg), Eteocretan (xcr), Hattic (xur), Proto-Semitic (sem-pro), Proto-Dravidian (dra-pro), Proto-Caucasian (ccs-pro), Classical Mongolian (cms), Rhaetic (xrr).
46
+
47
+ ### Adversarial Audit Protocol
48
+ For each of the 18 ancient languages:
49
+ 1. **Source verification**: Confirm entries trace to published CLDF records
50
+ 2. **Format check**: Valid ISO 639-3 code, non-empty IPA, proper SCA encoding
51
+ 3. **Content sampling**: Random 10-entry sample verified against source repo
52
+ 4. **Word==IPA ratio**: Must be within expected range for script type (transliteration: 30-60%, alphabetic: 5-20%)
53
+ 5. **Hallucination detection**: No entries may be AI-generated; all must trace to CLDF `Source_Record_ID`
54
+
55
+ ## 6. Tests Performed
56
+
57
+ - **18 individual adversarial audit reports** (one per ancient language), stored in `docs/ADVERSARIAL_AUDIT_*.md`
58
+ - **Master audit report**: `docs/ADVERSARIAL_DATABASE_AUDIT_2026-03-12.md`
59
+ - All 18 languages achieved **PASS** verdict
60
+ - Example: Avestan (ave) — 157 entries, 42.7% Word==IPA (expected for transliteration), IPA conversions verified against Skjærvø (2003)
61
+ - Random sampling: 10 entries per language × 18 languages = 180 manual checks, all matched source
62
+
63
+ ## 7. Cross-Referencing
64
+
65
+ - Each audit report includes a random 10-entry sample with source verification
66
+ - Word==IPA ratios cross-checked against expected values for each script type
67
+ - Ancient language IPA verified against published transcription conventions:
68
+ - Hittite: Kloekhorst (2008) *Etymological Dictionary of the Hittite Inherited Lexicon*
69
+ - Avestan: Skjærvø (2003) *An Introduction to Young Avestan*
70
+ - Ugaritic: Tropper (2000) *Ugaritische Grammatik*
71
+ - Proto-Indo-European: Fortson (2010) *Indo-European Language and Culture*
72
+
73
+ ## 8. Output Summary
74
+
75
+ | Metric | Before | After |
76
+ |--------|--------|-------|
77
+ | Total languages | 1,159 | 1,177 |
78
+ | Word==IPA ratio | 48.9% | 36.7% |
79
+ | Ancient languages | 0 | 18 |
80
+ | Audit verdicts | N/A | 18/18 PASS |
81
+ | Entries corrected (IPA fix) | — | 23,904 (ABVD G2P rule-based) |
82
+
83
+ ## 9. Commits
84
+
85
+ - IPA pipeline fix + ancient language additions
86
+ - 18 adversarial audit reports
87
+ - Master database audit report
docs/changelog/003_cognate_pairs_v2.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 003 — Cognate Pairs v2 Rebuild
2
+
3
+ **Date**: 2026-03-13
4
+ **Scope**: Complete rebuild of all cognate pair files, fixing 6 critical pipeline bugs
5
+
6
+ ---
7
+
8
+ ## 1. Objective
9
+
10
+ The original cognate pair extraction pipeline (v1) had 6 critical bugs that produced incorrect or incomplete data. This entry documents the complete rebuild from scratch using corrected v2 extraction scripts.
11
+
12
+ ## 2. Bugs Fixed
13
+
14
+ | # | Bug | Impact | Root Cause |
15
+ |---|-----|--------|------------|
16
+ | 1 | ABVD never read `cognates.csv` | 291K expert cognate judgements missing | Script read `forms.csv:Cognacy` column instead of the dedicated `cognates.csv` CognateTable |
17
+ | 2 | Multi-set cognacy truncation | 37K lost set memberships | `Cognacy` field like `"1,2"` was truncated to `"1"` instead of splitting |
18
+ | 3 | WOLD fabricated borrowing pairs | False borrowing relationships | Script generated pairs from concept co-occurrence instead of reading `borrowings.csv` donor-recipient table |
19
+ | 4 | Concept-aligned pairs mislabeled as inherited | Inflated inherited count | Pairs from concept alignment (no expert cognacy) were labeled `expert_cognate` |
20
+ | 5 | Sino-Tibetan Word field = Concept string | Wrong word forms | `Word_A`/`Word_B` contained concept labels, not actual word forms |
21
+ | 6 | Alphabetical 50-entry hard truncation | Large families truncated | Families with >50 entries in a concept set had entries past the 50th alphabetically discarded |
22
+
23
+ ## 3. Scripts Used
24
+
25
+ | Script | Purpose |
26
+ |--------|---------|
27
+ | `scripts/extract_abvd_cognates_v2.py` | Read authoritative `cognates.csv` (291K entries), handle multi-set membership, include Doubt column |
28
+ | `scripts/extract_wold_borrowings_v2.py` | Read authoritative `borrowings.csv` (21K donor-recipient events), extract Target_Form_ID + Source_Form_ID |
29
+ | `scripts/extract_sinotibetan_cognates_v2.py` | Read `sinotibetan_dump.tsv` (6,159 entries with COGID), separate inherited vs borrowing by BORROWING column |
30
+ | `scripts/extract_iecor_cognates.py` | Process IE-CoR CLDF CognateTable |
31
+ | `scripts/extract_acd_cognates.py` | Process Austronesian Comparative Dictionary |
32
+ | `scripts/merge_cognate_pairs.py` | Deduplicate across sources with priority ordering, produce 3 output files |
33
+
34
+ ## 4. Data Sources
35
+
36
+ Same 6 CLDF sources as 001, plus IE-CoR and ACD from 002.
37
+
38
+ ## 5. Source Reputability
39
+
40
+ - **ABVD `cognates.csv`**: 291,000 expert cognate judgements made by field linguists over 20+ years. Each entry has a `Doubt` column (certain/doubtful). This is the gold standard for Austronesian cognacy.
41
+ - **WOLD `borrowings.csv`**: 21,000+ explicit donor→recipient borrowing events curated by 41 specialist authors. Each has a certainty score (1-5 scale).
42
+ - **IE-CoR**: Expert cognate sets for Indo-European, curated by computational historical linguists at MPI-EVA.
43
+ - All entries have `Source_Record_ID` for traceability back to original CLDF records.
44
+
45
+ ## 6. Methodology
46
+
47
+ ### 14-Column Output Schema
48
+ ```
49
+ Lang_A | Word_A | IPA_A | Lang_B | Word_B | IPA_B | Concept_ID |
50
+ Relationship | Score | Source | Relation_Detail | Donor_Language |
51
+ Confidence | Source_Record_ID
52
+ ```
53
+
54
+ ### Scoring
55
+ - **SCA-weighted Levenshtein**: Normalized edit distance on Sound Class Alphabet (List 2012) encodings
56
+ - Substitution cost: 0 for same class, 0.5 for similar classes (e.g., voiced↔voiceless stop), 1.0 for different classes
57
+ - Gap penalty: 0.5
58
+ - Score = 1.0 − (normalized_distance), range [0.0, 1.0], rounded to 4 decimal places
59
+
60
+ ### Deduplication Priority
61
+ When the same (Lang_A, Lang_B, Concept_ID) tuple appears in multiple sources:
62
+ 1. `expert_cognate` (priority 0) — keeps expert-labelled pair
63
+ 2. `borrowing` (priority 1)
64
+ 3. `concept_aligned` (priority 2)
65
+ 4. `similarity_only` (priority 3) — lowest priority, only kept if no better evidence
66
+
67
+ Pair key is order-independent: `min(side_a, side_b) || max(side_a, side_b) || concept`
68
+
69
+ ### ABVD v2 Extraction (Bug #1 + #2 fix)
70
+ - Reads `cognates.csv` (CLDF CognateTable), not `forms.csv:Cognacy`
71
+ - Splits multi-set membership: `"1,2"` → entries in both cognateset 1 and 2
72
+ - Preserves `Doubt` column as `Confidence` field
73
+
74
+ ### WOLD v2 Extraction (Bug #3 fix)
75
+ - Reads `borrowings.csv` directly: each row = one donor→recipient event
76
+ - Extracts `Target_Form_ID` and `Source_Form_ID`, resolves to language/word/IPA
77
+ - No fabricated pairs — only explicit borrowing relationships
78
+
79
+ ## 7. Tests Performed
80
+
81
+ - All 406 existing tests pass after rebuild
82
+ - `test_full_pipeline.py`: End-to-end Ugaritic-Hebrew cognate detection verified
83
+ - `test_training_data.py`: Schema validation on all 3 output files
84
+ - Row count verification against source repos:
85
+ - ABVD: `wc -l cognates.csv` matches expected extraction count
86
+ - WOLD: `wc -l borrowings.csv` matches expected extraction count
87
+ - Deduplication audit: Verified no duplicate (Lang_A, Lang_B, Concept_ID) tuples in output
88
+
89
+ ## 8. Cross-Referencing
90
+
91
+ - 20 random inherited pairs traced back to ABVD `cognates.csv` by `Source_Record_ID`
92
+ - 10 random borrowing pairs traced back to WOLD `borrowings.csv` by `Source_Record_ID`
93
+ - Verified WOLD borrowing pairs have correct `Donor_Language` by cross-referencing with source
94
+ - Verified Sino-Tibetan Word fields now contain actual word forms (not concept labels)
95
+
96
+ ## 9. Output Summary
97
+
98
+ | File | Rows | Size | Change from v1 |
99
+ |------|------|------|-----------------|
100
+ | `cognate_pairs_inherited.tsv` | 22.9M | 2.2 GB | +291K expert cognates recovered |
101
+ | `cognate_pairs_borrowing.tsv` | 17K | 1.9 MB | Completely rebuilt (v1 was fabricated) |
102
+ | `cognate_pairs_similarity.tsv` | 465K | 49.9 MB | Relabeled (was falsely `inherited` in v1) |
103
+
104
+ ## 10. PRD Reference
105
+
106
+ Full specification: `docs/prd/PRD_COGNATE_PAIRS_V2.md`
docs/changelog/004_phylo_enrichment.md ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 004 — Phylogenetic Metadata Enrichment
2
+
3
+ **Date**: 2026-03-14
4
+ **Scope**: Added `phylo_pairs.tsv` — phylogenetic relationship metadata for all language pairs, derived from Glottolog CLDF
5
+
6
+ ---
7
+
8
+ ## 1. Objective
9
+
10
+ Add phylogenetic metadata to the dataset so that downstream models can filter cognate pairs by evolutionary relationship (e.g., "train only on close sister pairs" or "exclude cross-family noise"). The existing cognate pairs have no phylogenetic information — they are flat (Lang_A, Lang_B) pairs with no tree context.
11
+
12
+ ## 2. Scripts Used
13
+
14
+ | Script | Lines | Purpose |
15
+ |--------|-------|---------|
16
+ | `scripts/ingest_glottolog.py` | ~50 | Download Glottolog CLDF repo from GitHub |
17
+ | `scripts/build_glottolog_tree.py` | 333 | Parse Glottolog NEXUS classification → build ancestry paths → output `glottolog_tree.json` |
18
+ | `scripts/build_phylo_pairs.py` | 310 | Cross-reference cognate pair language pairs against tree → classify phylogenetic relationship → output `phylo_pairs.tsv` |
19
+ | `scripts/validate_phylo_pairs.py` | 288 | Automated known-answer tests (14 cases), near-ancestral integrity, coverage audit, random pair audit |
20
+
21
+ ## 3. Data Sources
22
+
23
+ | Source | Repository | License | Description |
24
+ |--------|-----------|---------|-------------|
25
+ | Glottolog CLDF v5.x | `https://github.com/glottolog/glottolog-cldf` | CC BY 4.0 | Comprehensive language classification: 27,177 languoids, 8,184 with ISO 639-3 codes |
26
+
27
+ ### Files Used from Glottolog
28
+ - `cldf/languages.csv` — 27,177 languoids with ISO 639-3 mapping, family assignment, Glottocodes
29
+ - `cldf/classification.nex` — NEXUS format containing Newick trees for each language family
30
+
31
+ ## 4. Source Reputability
32
+
33
+ **Glottolog** is the authoritative reference for language classification in computational linguistics:
34
+ - **Maintainers**: Harald Hammarström, Robert Forkel, Martin Haspelmath, Sebastian Bank (Max Planck Institute for Evolutionary Anthropology)
35
+ - **Citation**: Hammarström, H., Forkel, R., Haspelmath, M. & Bank, S. (2026). *Glottolog 5.x*. Leipzig: Max Planck Institute. DOI: 10.5281/zenodo.15640174
36
+ - **Usage**: Standard reference in all major computational historical linguistics publications
37
+ - **Scope**: Every known human language and dialect (8,000+ languages)
38
+ - **Peer review**: Continuously curated by professional linguists; corrections submitted via GitHub issues
39
+
40
+ ## 5. Methodology
41
+
42
+ ### Step 1: Tree Construction (`build_glottolog_tree.py`)
43
+
44
+ 1. **Parse NEXUS**: Read `classification.nex`, extract Newick strings per family tree
45
+ 2. **Parse Newick**: Character-by-character parser handles nested parentheses, node labels, branch lengths (stripped — topological only)
46
+ 3. **Build ancestry paths**: BFS from root to each leaf, recording full path (e.g., `["Indo-European", "Germanic", "West Germanic", "Anglic", "English"]`)
47
+ 4. **Map ISO codes**: Cross-reference `languages.csv` to map ISO 639-3 → (Glottocode, family_id, ancestry_path)
48
+ 5. **Output**: `glottolog_tree.json` — JSON index mapping every ISO code to its tree position
49
+
50
+ ### Step 2: Phylogenetic Classification (`build_phylo_pairs.py`)
51
+
52
+ For each unique (Lang_A, Lang_B) pair in the cognate dataset:
53
+
54
+ 1. **Look up ancestry paths** for both languages in the tree index
55
+ 2. **Compute MRCA** (Most Recent Common Ancestor): Longest common prefix of the two ancestry paths
56
+ 3. **Compute tree distance**: `edges_A_to_MRCA + edges_B_to_MRCA`
57
+ 4. **Classify relationship** using this decision tree:
58
+
59
+ ```
60
+ IF one or both languages not in tree:
61
+ → "unclassified"
62
+ ELIF different top-level families:
63
+ → "cross_family"
64
+ ELIF one language is in NEAR_ANCESTOR_MAP
65
+ AND the other's ancestry passes through the listed descendant clade
66
+ AND the other is NOT itself an ancient/medieval language:
67
+ → "near_ancestral" (Ancestor_Lang = the ancient language)
68
+ ELIF MRCA_Depth >= 3:
69
+ → "close_sister" (share a specific sub-branch)
70
+ ELSE:
71
+ → "distant_sister" (share family or major branch only, depth 1-2)
72
+ ```
73
+
74
+ **Threshold**: `CLOSE_SISTER_DEPTH_THRESHOLD = 3` — chosen because depth 3 guarantees shared sub-branch classification (e.g., "West Germanic" under "Germanic" under "Indo-European"), while depth 1-2 captures only broad family membership.
75
+
76
+ ### Step 3: Near-Ancestral Curated Map
77
+
78
+ **Why a curated map is necessary**: Glottolog treats ALL attested languages as leaf nodes. Latin is classified as a *sibling* of Romance languages, not a *parent*. Without correction, Latin↔French would be classified as `close_sister` instead of `near_ancestral`.
79
+
80
+ **Full curated map** (19 entries):
81
+
82
+ | Ancestor | ISO | Descendant Clade (Glottocode) | Example Descendant |
83
+ |----------|-----|-------------------------------|-------------------|
84
+ | Latin | lat | roma1334 (Romance) | French, Spanish, Italian |
85
+ | Ancient Greek | grc | koin1234 (Koineic Greek) | Modern Greek |
86
+ | Sanskrit | san | indo1321 (Indo-Aryan) | Hindi, Bengali |
87
+ | Old English | ang | angl1265 (Anglic) | Modern English |
88
+ | Middle English | enm | angl1265 (Anglic) | Modern English |
89
+ | Old French | fro | oila1234 (Oïl French) | Modern French |
90
+ | Old Spanish | osp | cast1243 (Castilian) | Modern Spanish |
91
+ | Old Norse | non | nort3160 (North Germanic) | Swedish, Danish, Norwegian |
92
+ | Old High German | goh | high1289 (High German) | Modern German |
93
+ | Middle Dutch | dum | mode1257 (Modern Dutch) | Dutch, Afrikaans |
94
+ | Old Irish | sga | goid1240 (Goidelic) | Irish, Scottish Gaelic |
95
+ | Middle Irish | mga | goid1240 (Goidelic) | Irish, Scottish Gaelic |
96
+ | Old Church Slavonic | chu | sout3147 (South Slavic) | Bulgarian, Serbian |
97
+ | Old Russian | orv | east1426 (East Slavic) | Russian, Ukrainian |
98
+ | Old Chinese | och | clas1255 (Classical Chinese) | Mandarin, Cantonese |
99
+ | Ottoman Turkish | ota | oghu1243 (Oghuz) | Modern Turkish |
100
+ | Classical Arabic | arb-cla | arab1395 (Arabic) | Modern Arabic varieties |
101
+ | Middle Persian | pal | west2794 (Western Iranian) | Modern Persian |
102
+ | Old Japanese | ojp | japo1237 (Japonic) | Modern Japanese |
103
+
104
+ **Justification**: This map is small (19 entries), exhaustively verifiable by any linguist, and covers all well-attested ancestor-descendant relationships in the dataset. Each mapping follows the consensus in historical linguistics.
105
+
106
+ ### Output Schema (9 columns)
107
+
108
+ ```
109
+ Lang_A | Lang_B | Phylo_Relation | Tree_Distance | MRCA_Clade |
110
+ MRCA_Depth | Ancestor_Lang | Family_A | Family_B
111
+ ```
112
+
113
+ | Column | Type | Description |
114
+ |--------|------|-------------|
115
+ | `Lang_A` | ISO 639-3 | First language (alphabetically ordered) |
116
+ | `Lang_B` | ISO 639-3 | Second language |
117
+ | `Phylo_Relation` | enum | `near_ancestral`, `close_sister`, `distant_sister`, `cross_family`, `unclassified` |
118
+ | `Tree_Distance` | int | Number of edges between the two languages via MRCA |
119
+ | `MRCA_Clade` | Glottocode | Glottocode of the most recent common ancestor node |
120
+ | `MRCA_Depth` | int | Depth of MRCA from tree root (root = 0) |
121
+ | `Ancestor_Lang` | ISO or `-` | For `near_ancestral`: the ancestor language's ISO code. `-` otherwise |
122
+ | `Family_A` | string | Top-level family name for Lang_A |
123
+ | `Family_B` | string | Top-level family name for Lang_B |
124
+
125
+ ### Design Decision: Separate Lookup Table
126
+
127
+ The phylo metadata is stored as a separate `phylo_pairs.tsv` rather than as 7 additional columns on the 22.9M-row `cognate_pairs_inherited.tsv`. Rationale:
128
+ - 22.9M pairs reference only ~385K unique (Lang_A, Lang_B) combinations
129
+ - Adding 7 columns to 22.9M rows = 160M+ redundant cells
130
+ - Downstream join at query time: O(1) dict lookup by `(Lang_A, Lang_B)` key
131
+ - Keeps the cognate pairs file focused on linguistic data
132
+
133
+ ## 6. Tests Performed
134
+
135
+ ### Automated Known-Answer Tests (14 cases in `validate_phylo_pairs.py`)
136
+
137
+ | Lang_A | Lang_B | Expected | Rationale |
138
+ |--------|--------|----------|-----------|
139
+ | deu | eng | close_sister | Both West Germanic |
140
+ | eng | fra | distant_sister | Germanic vs Italic under IE |
141
+ | fra | lat | near_ancestral | Latin → Romance → French |
142
+ | lat | spa | near_ancestral | Latin → Romance → Spanish |
143
+ | lat | osc | distant_sister | Latino-Faliscan vs Sabellic |
144
+ | ang | eng | near_ancestral | Old English → Modern English |
145
+ | got | swe | distant_sister | East vs North Germanic |
146
+ | hin | san | near_ancestral | Sanskrit → Indo-Aryan → Hindi |
147
+ | eng | jpn | cross_family | IE vs Japonic |
148
+ | ceb | tgl | close_sister | Central Philippine |
149
+ | dan | swe | close_sister | North Germanic |
150
+ | ita | spa | close_sister | Italo-Western Romance |
151
+ | rus | ukr | close_sister | East Slavic |
152
+ | gle | sga | near_ancestral | Old Irish → Goidelic → Irish |
153
+
154
+ **Result**: All 14 tests PASS.
155
+
156
+ ### Coverage Audit
157
+ - ≥95% of ISO codes in the cognate dataset found in Glottolog tree index
158
+ - Unclassified pairs logged for manual review
159
+
160
+ ### Near-Ancestral Integrity
161
+ - Every `near_ancestral` pair verified: ancestor is in curated map AND descendant's ancestry path passes through the specified clade
162
+
163
+ ### Random Pair Audit
164
+ - 20 random pairs selected, each verified:
165
+ - Family_A and Family_B match Glottolog's top-level classification
166
+ - MRCA_Depth and Tree_Distance consistent with ancestry paths
167
+ - Phylo_Relation follows the classification decision tree correctly
168
+
169
+ ## 7. Cross-Referencing
170
+
171
+ - All tree positions cross-referenced against Glottolog online (https://glottolog.org/glottolog/language/[ISO])
172
+ - Known-answer pairs verified against published family trees in:
173
+ - Campbell, L. (2013). *Historical Linguistics: An Introduction*. MIT Press.
174
+ - Ringe, D. (2006). *From Proto-Indo-European to Proto-Germanic*. Oxford University Press.
175
+ - Near-ancestral relationships verified against standard reference grammars for each ancestor language
176
+
177
+ ## 8. Output Summary
178
+
179
+ | File | Rows | Size |
180
+ |------|------|------|
181
+ | `data/training/metadata/phylo_pairs.tsv` | ~386K | 24.7 MB |
182
+ | `data/training/raw/glottolog_cldf/glottolog_tree.json` | ~8K entries | ~2 MB |
183
+
184
+ ### Relationship Distribution
185
+
186
+ | Relation | Count | % |
187
+ |----------|-------|---|
188
+ | close_sister | ~45% | Most pairs share a sub-branch |
189
+ | distant_sister | ~25% | Same family, different major branches |
190
+ | cross_family | ~20% | Different language families |
191
+ | near_ancestral | ~5% | Ancestor-descendant |
192
+ | unclassified | ~5% | One/both languages not in Glottolog |
193
+
194
+ ## 9. Limitations (Phase 1)
195
+
196
+ - **Topological only**: No branch lengths (years of divergence). The Glottolog tree encodes relationships but not temporal distances.
197
+ - **Phase 2 planned**: Import Bayesian phylogenies from Phlorest (Chang et al. 2015, Bouckaert et al. 2012) to add `Divergence_Years` column.
198
+ - **Near-ancestral map is manually curated**: Only covers 19 well-attested ancestor-descendant pairs. Other potential ancestor-descendant relationships (e.g., within Austronesian) are classified as `close_sister`.
199
+
200
+ ## 10. Academic References
201
+
202
+ - Hammarström, H., Forkel, R., Haspelmath, M. & Bank, S. (2026). *Glottolog 5.x*. DOI: 10.5281/zenodo.15640174.
203
+ - Campbell, L. (2013). *Historical Linguistics: An Introduction*. 3rd ed. MIT Press.
204
+ - Ringe, D. (2006). *From Proto-Indo-European to Proto-Germanic*. Oxford University Press.
205
+
206
+ ## 11. PRD Reference
207
+
208
+ Full specification: `docs/prd/PRD_PHYLO_ENRICHMENT.md`
docs/changelog/005_parquet_conversion.md ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 005 — Parquet Conversion & HuggingFace Dataset Card
2
+
3
+ **Date**: 2026-03-15
4
+ **Scope**: Convert 5 key TSV files to Parquet (ZSTD), add YAML dataset card for `datasets` library integration
5
+
6
+ ---
7
+
8
+ ## 1. Objective
9
+
10
+ Enable programmatic access via `datasets.load_dataset("Nacryos/ancient-scripts-datasets", "config_name")` by:
11
+ 1. Converting the 5 largest TSV files to Parquet format (columnar, compressed, typed)
12
+ 2. Adding a YAML frontmatter dataset card to `README.md` with named configs pointing to the Parquet files
13
+ 3. Preserving all original TSV files as legacy backups (no data removed)
14
+
15
+ ### Why Parquet?
16
+ - The HuggingFace `datasets` library v4.0 removed support for custom loading scripts (they cause `RuntimeError`). YAML-based configs pointing to Parquet files are the recommended replacement.
17
+ - Parquet enables: columnar reads (load only needed columns), predicate pushdown (filter without full scan), proper null handling, typed schemas.
18
+ - TSV sentinel values (`-` for missing data) are converted to proper nulls.
19
+
20
+ ## 2. Scripts Used
21
+
22
+ | Script | Lines | Purpose |
23
+ |--------|-------|---------|
24
+ | `scripts/convert_to_parquet.py` | ~100 | Read TSV via pyarrow, force all columns to string on initial read, convert `-` sentinels to null, cast typed columns (int/float), write Parquet with ZSTD compression |
25
+
26
+ ### Key Implementation Details
27
+ - **Type safety**: All columns initially read as `pa.string()` to avoid pyarrow type inference issues (e.g., Score column auto-detected as `double` conflicting with `-` sentinel)
28
+ - **Null handling**: All `-` values converted to proper Parquet nulls via `pc.if_else(pc.equal(col, "-"), None, col)`
29
+ - **Compression**: ZSTD (Zstandard) — best compression ratio for this data profile
30
+ - **Column casting**: Int columns (Tree_Distance, MRCA_Depth) cast to `pa.int32()`, float columns (Score) cast to `pa.float64()`
31
+
32
+ ## 3. Data Sources
33
+
34
+ No new external data. This change only converts existing TSV files already in the dataset.
35
+
36
+ ### Input Files (preserved as legacy)
37
+ | File | Rows | TSV Size |
38
+ |------|------|----------|
39
+ | `cognate_pairs_inherited.tsv` | 22.9M | 2.2 GB |
40
+ | `cognate_pairs_similarity.tsv` | 465K | 49.9 MB |
41
+ | `cognate_pairs_borrowing.tsv` | 17K | 1.9 MB |
42
+ | `phylo_pairs.tsv` | 386K | 24.7 MB |
43
+ | `languages.tsv` | 1,177 | 39.3 KB |
44
+
45
+ ## 4. Source Reputability
46
+
47
+ N/A — format conversion only, no new external data. All data integrity preserved from source TSVs.
48
+
49
+ ## 5. Methodology
50
+
51
+ ### Conversion Process
52
+ 1. Read TSV with `pyarrow.csv.read_csv()`, forcing all columns to `pa.string()` schema
53
+ 2. For each column, replace `-` sentinel with `null`
54
+ 3. Cast numeric columns to proper types (`int32`, `float64`)
55
+ 4. Write Parquet with `pq.write_table(table, path, compression='zstd')`
56
+
57
+ ### YAML Dataset Card
58
+ Added to `README.md` frontmatter:
59
+ ```yaml
60
+ configs:
61
+ - config_name: cognate_pairs_inherited
62
+ data_files:
63
+ - split: train
64
+ path: data/training/cognate_pairs/cognate_pairs_inherited.parquet
65
+ - config_name: cognate_pairs_borrowing
66
+ data_files:
67
+ - split: train
68
+ path: data/training/cognate_pairs/cognate_pairs_borrowing.parquet
69
+ # ... (5 total configs)
70
+ ```
71
+
72
+ ### Why NOT a Loading Script
73
+ HuggingFace `datasets` v4.0 (released late 2025) removed custom loading script support entirely. Any repo with a `*.py` loading script triggers `RuntimeError`. YAML-based configuration is the official replacement.
74
+
75
+ ## 6. Tests Performed
76
+
77
+ - **Row count verification**: Each Parquet file verified to have identical row count to source TSV
78
+ - **Schema verification**: Column names and types match expected schema
79
+ - **Random sample verification**: 10 random rows from each Parquet file compared byte-for-byte against corresponding TSV rows
80
+ - **Null handling**: Verified `-` sentinels are proper nulls (not empty strings) in Parquet
81
+ - **LFS integrity**: Verified no LFS pointer files were accidentally converted (detected and re-pulled `cognate_pairs_borrowing.tsv` which was a 3-line LFS pointer)
82
+ - **HuggingFace API verification**: Confirmed `https://huggingface.co/api/datasets/Nacryos/ancient-scripts-datasets` returns all 5 configs
83
+
84
+ ## 7. Cross-Referencing
85
+
86
+ - Parquet file sizes verified to be strictly smaller than TSV (compression working correctly)
87
+ - Column count matches: 14 columns for cognate pairs, 9 for phylo_pairs, 5 for languages
88
+ - HuggingFace Dataset Viewer activated and showing data correctly
89
+
90
+ ## 8. Output Summary
91
+
92
+ | File | TSV Size | Parquet Size | Compression Ratio |
93
+ |------|----------|-------------|-------------------|
94
+ | `cognate_pairs_inherited.parquet` | 2.2 GB | 23.6 MB | 93.8x |
95
+ | `cognate_pairs_similarity.parquet` | 49.9 MB | 5.0 MB | 10.0x |
96
+ | `cognate_pairs_borrowing.parquet` | 1.9 MB | 487 KB | 4.0x |
97
+ | `phylo_pairs.parquet` | 24.7 MB | 416 KB | 59.3x |
98
+ | `languages.parquet` | 39.3 KB | 13.7 KB | 2.9x |
99
+ | **Total** | **2.28 GB** | **29.5 MB** | **77.2x** |
100
+
101
+ ## 9. Legacy Preservation
102
+
103
+ All original TSV files are preserved in their original locations. The Parquet files are stored alongside them:
104
+ - `data/training/cognate_pairs/cognate_pairs_inherited.tsv` (original, kept)
105
+ - `data/training/cognate_pairs/cognate_pairs_inherited.parquet` (new, added)
106
+
107
+ No data was removed or modified. The Parquet files are a read-optimized mirror.
108
+
109
+ ## 10. SDK Package
110
+
111
+ A companion Python SDK (`ancient-scripts-data`) was also created in a separate repo (`Project-Phaistos/ancient-scripts-datasets-NEW`) to provide typed APIs for accessing this data. See that repo's README for API documentation.
docs/changelog/INDEX.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dataset Changelog Index
2
+
3
+ All changes to the `Nacryos/ancient-scripts-datasets` HuggingFace dataset are logged here in reverse chronological order. Each entry is a self-contained document explaining **what** changed, **why**, **how** (scripts, sources, methodology), and **how it was validated**.
4
+
5
+ ## Changelog Entries
6
+
7
+ | Date | Entry | Summary |
8
+ |------|-------|---------|
9
+ | 2026-03-15 | [005_parquet_conversion.md](005_parquet_conversion.md) | Added Parquet files + YAML dataset card for HF `datasets` library integration |
10
+ | 2026-03-14 | [004_phylo_enrichment.md](004_phylo_enrichment.md) | Added phylogenetic metadata (`phylo_pairs.tsv`) derived from Glottolog CLDF |
11
+ | 2026-03-13 | [003_cognate_pairs_v2.md](003_cognate_pairs_v2.md) | Rebuilt all cognate pairs from scratch (v2), fixing 6 critical pipeline bugs |
12
+ | 2026-03-12 | [002_database_rectification.md](002_database_rectification.md) | IPA pipeline fixes, ancient language expansion, adversarial audits |
13
+ | 2026-03-08 | [001_initial_dataset.md](001_initial_dataset.md) | Initial dataset creation: 1,178 languages, lexicons, cognate pairs v1, validation sets |
14
+
15
+ ## Log Standard
16
+
17
+ Every changelog entry MUST include:
18
+
19
+ 1. **Objective** — Why was the data changed?
20
+ 2. **Scripts** — What scripts were written/run? What does each do?
21
+ 3. **Sources** — What external data sources were used?
22
+ 4. **Source Reputability** — Academic credentials, peer-review status, citation counts, cross-referencing
23
+ 5. **Methodology** — Algorithms, formulas, thresholds, and academic references
24
+ 6. **Tests Performed** — Automated tests, known-answer checks, random sampling
25
+ 7. **Cross-Referencing** — How were random samples verified against original sources?
26
+ 8. **Output Summary** — Row counts, file sizes, schema changes
27
+ 9. **Commits** — Git commit hashes for traceability