acore-utils 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Metadata
13
+ .DS_Store
14
+
15
+ # Libraries
16
+ clts/
17
+
18
+ # Datasets
19
+ austronesian/acd/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 David Mortensen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.5
2
+ Name: acore-utils
3
+ Version: 0.1.2
4
+ Summary: Agent-based Comparative Reconstruction library.
5
+ Project-URL: Homepage, https://github.com/changelinglab/comparative-method-agents
6
+ Project-URL: Repository, https://github.com/changelinglab/comparative-method-agents
7
+ Project-URL: Issues, https://github.com/changelinglab/comparative-method-agents/issues
8
+ Author-email: David Mortensen <dmortens@cs.cmu.edu>
9
+ Maintainer-email: David Mortensen <dmortens@cs.cmu.edu>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: comparative-method,historical-linguistics,linguistics,phonology,reconstruction
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering
21
+ Classifier: Topic :: Text Processing :: Linguistic
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.12
24
+ Requires-Dist: pandas<3,>=2.2
25
+ Requires-Dist: panphon<1,>=0.22
26
+ Provides-Extra: alignment
27
+ Requires-Dist: emalign-phonology>=0.1.0; extra == 'alignment'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # Overview
31
+
32
+ The goals of this project are to:
33
+
34
+ 1. Implement the whole Comparative Method (from historical linguistics) using LLM agents to iteratively optimize the three mutually-dependent components (represented as programs)
35
+ 2. Explore the implications for solving this type of problems using agents for agentic solutions to other types of discrete optimization problems.
36
+
37
+ Specific research questions include the following:
38
+
39
+ - **RQ1:** Can LLM agents improve on non-agentic baselines at cognate detection, forward reconstruction, and backward reconstruction (with oracles)?
40
+ - **RQ2:** Can the whole comparative method be implemented using an agentic workflow?
41
+ - **RQ3:** Do metalearning approaches allow improved performance on reconstruction tasks? How well do capabilities developed when solving other tasks generalize to comparative reconstruction?
42
+ - **RQ4:** How do changes in how agents coordinate their actions (and specialization) affect their performance on comparative reconstruction tasks?
43
+
44
+ This list will evolve as discoveries increase.
45
+
46
+ The chances of this project succeeding are quite high:
47
+
48
+ - There is an existing proof-of-concept for forward reconstruction or $\rho$ (one of the major components)
49
+ - There is good initial evidence that $\pi$ or backward reconstruction is not as difficult as $\rho$
50
+ - There is considerable prior art for $\kappa$ or cognate set induction
51
+
52
+ What has never been done is to place all of these components in a common framework and produce a comparative method implementation that can operate autonomous (or, potentially, can collaborate with a human scholar).
53
+
54
+ # Components of the Comparative Method
55
+
56
+ The Comparative Method, as implemented here, has three components, all of them functions:
57
+
58
+ - $\kappa: \mathcal L \rightarrow \mathcal K$, a function from lexicons in a set of lexicons from sister languages $\mathcal L = L_1, L_2, \dots, L_n$ to a set of cognate sets (sets of words believed to be descended from the same ancestral word or “protoform”) $\mathcal K$
59
+ - $\pi: \mathcal K \rightarrow \mathcal P$, a function from a set of cognate sets $\mathcal K$ to a set of corresponding protoforms $\mathcal P$
60
+ - $\rho: \mathcal P \rightarrow \mathcal K$, a function from a set of protoforms $\mathcal P$ to a set of corresponding cognate sets $\mathcal K$
61
+
62
+ ![The Comparative Method](comparative-method.png "The Comparative Method")
63
+
64
+ The objective is to:
65
+
66
+ - Maximize the mean proportion of $\mathcal L$ that can be reconstructed (grouped into cognate sets by $\kappa$, encoded as protoforms by $\pi$, and decoded back into cognate sets by $\rho$
67
+ - Minimize the complexity of $\pi$ (number of atoms)
68
+ - Minimize the complexity of $\rho$ (number of atoms)
69
+
70
+ More precisely, the goal is to maximize the following objective:
71
+
72
+ Let $\mathcal{L} = \{L_1, \dots, L_n\}$ be a set of lexicons, and let $\Sigma^\ast$ be the set of all strings over the alphabet $\Sigma$. Let $B(\cdot)$ denote the length in bits of an object under a fixed encoding.
73
+
74
+ - $W = \bigsqcup_{i=1}^{n} L_i$ is the set of all words.
75
+ - $\kappa$ is a function that induces a partition $\mathcal{K} = \kappa(\mathcal{L})$ of $W$ into cognate sets, such that $|C \cap L_i| \le 1$ for every $C \in \mathcal{K}$ and every $i$.
76
+ - $\mathcal{K}^\ast = \{\, C \in \mathcal{K} : |C| \ge 2 \,\}$ is the set of non-singleton cognate sets.
77
+ - $U = W \setminus \bigcup \mathcal{K}^\ast$ is the set of unexplained words.
78
+ - $\pi : \mathcal{K}^\ast \to \mathcal{P}$ maps each cognate set to a protoform, where $\mathcal{P} = \pi(\mathcal{K}^\ast)$.
79
+ - $\rho : \mathcal{P} \to 2^{\Sigma^\ast}$ maps each protoform to a set of reflexes, with at most one reflex per language.
80
+ - $E_C = \rho(\pi(C)) \setminus C$ is the set of overgenerated reflexes for $C \in \mathcal{K}^\ast$.
81
+
82
+ The objective is
83
+
84
+ ```math
85
+ \min_{\kappa,\,\pi,\,\rho}\;
86
+ B(\kappa) + B(\pi) + B(\rho)
87
+ + \sum_{p \in \mathcal{P}} B(p)
88
+ + \sum_{C \in \mathcal{K}^\ast} B(E_C)
89
+ + \sum_{w \in U} B(w)
90
+ ```
91
+
92
+ subject to
93
+
94
+ ```math
95
+ C \subseteq \rho(\pi(C)) \quad \forall\, C \in \mathcal{K}^\ast
96
+ ```
97
+
98
+ Decoding can be formalized as
99
+
100
+ ```math
101
+ W = U \,\sqcup \bigsqcup_{C \in \mathcal{K}^\ast} \big( \rho(\pi(C)) \setminus E_C \big)
102
+ ```
103
+
104
+ At first glance, it might not be clear why both $\pi$ and $\rho$ are necessary since, ideally, they are inverses of one another ($\pi = \rho^{-1}$) and therefore encode the same relationship. They are both essential, however, because $\pi$ ensures that the protoforms $\mathcal P$ contain only information that is present in $\mathcal K$ and $\rho$ ensures that $\mathcal K$ contains only information that is present in $\mathcal P$. Optimizing them jointly ensures that the protoforms approach a lossless encoding of the cognate sets. Linguists have found that such an encoding can be independently demonstrated to mirror ancestral languages (or protolanguages). The complexity penalties are also important:
105
+
106
+ - The complexity penalty on $\pi$ prevents degenerate solutions where the proposed protolanguage has an arbitrarily large number of sounds or an arbitrarily large number of insertions and deletions, compared to the cognate sets.
107
+ - The complexity penalty on $\rho$ prevents degenerate solutions where the phonemes (sounds) in the proposed protolanguage do not resemble those in the daughter languages (in the cognate sets $\mathcal K$).
108
+
109
+ ## The Regularity Principle
110
+
111
+ The Comparative Method is made possible by the Neogrammarian Principle or Regularity Principle which says that changes in phonemes are systematic. They may involve replacing one phoneme with another phoneme (e.g., d > r) or they may only apply in a certain type of context (e.g., d > r at the beginning of a word) but they are always systematic. This allows us to define $\rho$ as sequences of string rewrite rules (e.g., replace `d` with `r` at the beginning of a string). The prefixes of these sequences (from the different languages in the family) will sometimes overlap, meaning that we can construct a family tree for the language group (a phylogenetic tree). This also means that there will be regular patterns of correspondence, shared across cognate sets that make it possible to write rules that form a classifier which predicts the phonemes in a protoform from the aligned reflexes (descendant words) in the corresponding cognate set.
112
+
113
+ ## Implementing $\kappa$
114
+
115
+ Cognate set induction is the component of the Comparative Method with the most prior work, but it is still not solved. When humans are identifying cognate sets, they look at three things:
116
+
117
+ 1. Are the words pronounced similarly (are the phonological similar)?
118
+ 2. Do the words have similar meanings (are the words semantically similar)?
119
+ 3. Do the words show patterns of correspondence in their phonemes that are shared by other words?
120
+
121
+ State-of-the-art cognate set induction methods take all of these facts into account. They do not generally assume a fully-articulated $\pi$ or $\rho$, so their ability to find new true cognates and prune false cognates is somewhat hindered.
122
+
123
+ ## Implementing $\pi$
124
+
125
+ $\pi$ assumes that each cognate set is aligned to form a matrix so as to maximize the similarity in pronunciation of the phonemes in the words (with gaps to make better alignments possible, when the number of phonemes in reflexes is not the same or when phonemes are very different, e.g. *a* and *k*). $\pi$ can be represented as a set of implications with an antecedent and a consequence:
126
+
127
+ - **Antecedent:** a set of statements about phonemes that are found in the current column of the matrix and (perhaps) what phonemes are found in the preceding and following columns.
128
+ - **Consequent:** the proto-phoneme that is predicted to go in the current column in the protoform.
129
+
130
+ This program is a kind of rule-based classifier.
131
+
132
+ My lab has done a lot of earlier work with neural (specifically, sequence-to-sequence) implementations of $\pi$ (or $\pi$ jointly with $\rho$):
133
+
134
+ - [Transformed Protoform Reconstruction](https://aclanthology.org/2023.acl-short.3.pdf)
135
+ - [WikiHan: A New Comparative Dataset for Chinese Languages](https://aclanthology.org/2022.coling-1.314.pdf)
136
+ - [Semisupervised Neural Proto-Language Reconstruction](https://aclanthology.org/2024.acl-long.788.pdf)
137
+ - [Improved Neural Protoform Reconstruction via Reflex Prediction](https://aclanthology.org/2024.lrec-main.762.pdf)
138
+
139
+ ## Implementing $\rho$
140
+
141
+ $\rho$ is a cascade of string-rewrite rules (sound laws) or, in the more general case, a tree in which nodes correspond to ordered sound laws rules. It reflects the fact that changes in the pronunciation of words progress in time and that it is possible to reason about the sequences of the rules.
142
+
143
+ Some relevant readings:
144
+
145
+ - [PBEBench: A Multi-Step Programming by Examples Reasoning Benchmark inspired by Historical Linguistics](https://aclanthology.org/2026.findings-acl.432.pdf)
146
+ - [ReaComp: Compiling LLM Reasoning into Symbolic Solvers for Efficient Program Synthesis](https://arxiv.org/pdf/2605.05485)
147
+ - [Programming by example meets historical linguistics: A large language model based approach to sound law induction](https://aclanthology.org/2025.acl-long.1432.pdf)
148
+ - [Can Large Language Models Code Like a Linguist?: A Case Study in Low Resource Sound Law Induction](https://arxiv.org/pdf/2406.12725?)
149
+
150
+ # Relevance of Agents
151
+
152
+ The problem of finding optimal $\kappa$, $\pi$, and $\rho$ functions, individually, are relatively intractable search problems. It is possible to develop symbolic algorithms that will generate such programs (especially for $\pi$ and $\kappa$) if one is given $\mathcal K$ and $\mathcal P$, but it is not clear that there is a traditional search algorithm that will find an optimal $R=\langle \kappa, \pi, \rho \rangle$. Humans solve this problem by a process of iterative refinement (editing one program, then editing another, then checking the results). **LLM agents provide a way to automate this workflow.**
153
+
154
+ In the simplest case, a single agent could edit any of the files, in addition to running the whole system—$\rho(\pi(\kappa(\mathcal L)))$, inspecting errors, analyzing the training data, etc. Edits would be made synchronously. This agent would be responsible for the planning of optimization strategies and their execution.
155
+
156
+ However, there are other configurations of agents that may be better. For example, there may be one agent responsible for overall planning, other agents responsible for updates to the code, and other agents responsible for analyzing data and errors. In this case, edits would take place asynchronously and some means of coordinating the activities of the agents would have to be provided (which could range from a rigid set of protocols to a text file of notes to which the agents could write.
157
+
158
+ # A Note on Models and Harnesses
159
+
160
+ We plan on carrying out the initial experiments using Claude Opus as a model and OpenHands as a harness. We will extend the range of models after we have working prototypes of the $\kappa$, $\pi$, and $\rho$ models. We will then expand our scope to three types of models:
161
+
162
+ 1. Other frontier models (e.g., Gemini and GPT-5.x). We will have funds that can be used for Gemini, so we prioritize it.
163
+ 2. Open weights models (GLM, Qwen, etc.)
164
+ 3. Open source models (probably Horizon K2)
165
+
166
+ In some cases, we may use different models for different kinds of agents.
167
+
168
+ I prefer to stick with OpenHands as an agent harness because (1) I like it and (2) it will make it relatively easy to switch any of these models in and out without significant architectural changes. Other harnesses can be considered.
169
+
170
+ # TODO
171
+
172
+ - [ ] Add functionality to select which dataset to use
173
+
174
+ # Roadmap
175
+
176
+ - [ ] Datasets
177
+ - [ ] Austronesian
178
+ - [ ] Uralic
179
+ - [ ] Romance
180
+
181
+ ## Claude Code prototype
182
+
183
+ - [ ] Complete Claude Code version
184
+ - [ ] Develop $\rho$ execution and evaluation ability
185
+ - [ ] Evaluation (reward function)
186
+ - [ ] Code complexity
187
+ - [ ] Accuracy
188
+ - [ ] Skill for performing and interpreting evaluation
189
+ - [ ] Error reporting (after the fashion of pytest)
190
+ - [ ] Develop $\rho$-discovery capability
191
+ - [ ] Code format definitions
192
+ - [ ] Heuristic initialization of $\rho$
193
+ - [ ] Protoform-reflex alignment function
194
+ - [ ] Correspondence aggregation function
195
+ - [ ] Code generation for correspondences
196
+ - [ ] Iterative update of $\rho$
197
+ - [ ] Develop $\pi$-discovery capability
198
+ - [ ] Heuristic initialization of $\pi$
199
+ - [ ] Iterative update of $\pi$
200
+ - [ ] Develop $\mathcal K$-discovery capability
201
+
202
+ ## Open Hands prototype
@@ -0,0 +1,173 @@
1
+ # Overview
2
+
3
+ The goals of this project are to:
4
+
5
+ 1. Implement the whole Comparative Method (from historical linguistics) using LLM agents to iteratively optimize the three mutually-dependent components (represented as programs)
6
+ 2. Explore the implications for solving this type of problems using agents for agentic solutions to other types of discrete optimization problems.
7
+
8
+ Specific research questions include the following:
9
+
10
+ - **RQ1:** Can LLM agents improve on non-agentic baselines at cognate detection, forward reconstruction, and backward reconstruction (with oracles)?
11
+ - **RQ2:** Can the whole comparative method be implemented using an agentic workflow?
12
+ - **RQ3:** Do metalearning approaches allow improved performance on reconstruction tasks? How well do capabilities developed when solving other tasks generalize to comparative reconstruction?
13
+ - **RQ4:** How do changes in how agents coordinate their actions (and specialization) affect their performance on comparative reconstruction tasks?
14
+
15
+ This list will evolve as discoveries increase.
16
+
17
+ The chances of this project succeeding are quite high:
18
+
19
+ - There is an existing proof-of-concept for forward reconstruction or $\rho$ (one of the major components)
20
+ - There is good initial evidence that $\pi$ or backward reconstruction is not as difficult as $\rho$
21
+ - There is considerable prior art for $\kappa$ or cognate set induction
22
+
23
+ What has never been done is to place all of these components in a common framework and produce a comparative method implementation that can operate autonomous (or, potentially, can collaborate with a human scholar).
24
+
25
+ # Components of the Comparative Method
26
+
27
+ The Comparative Method, as implemented here, has three components, all of them functions:
28
+
29
+ - $\kappa: \mathcal L \rightarrow \mathcal K$, a function from lexicons in a set of lexicons from sister languages $\mathcal L = L_1, L_2, \dots, L_n$ to a set of cognate sets (sets of words believed to be descended from the same ancestral word or “protoform”) $\mathcal K$
30
+ - $\pi: \mathcal K \rightarrow \mathcal P$, a function from a set of cognate sets $\mathcal K$ to a set of corresponding protoforms $\mathcal P$
31
+ - $\rho: \mathcal P \rightarrow \mathcal K$, a function from a set of protoforms $\mathcal P$ to a set of corresponding cognate sets $\mathcal K$
32
+
33
+ ![The Comparative Method](comparative-method.png "The Comparative Method")
34
+
35
+ The objective is to:
36
+
37
+ - Maximize the mean proportion of $\mathcal L$ that can be reconstructed (grouped into cognate sets by $\kappa$, encoded as protoforms by $\pi$, and decoded back into cognate sets by $\rho$
38
+ - Minimize the complexity of $\pi$ (number of atoms)
39
+ - Minimize the complexity of $\rho$ (number of atoms)
40
+
41
+ More precisely, the goal is to maximize the following objective:
42
+
43
+ Let $\mathcal{L} = \{L_1, \dots, L_n\}$ be a set of lexicons, and let $\Sigma^\ast$ be the set of all strings over the alphabet $\Sigma$. Let $B(\cdot)$ denote the length in bits of an object under a fixed encoding.
44
+
45
+ - $W = \bigsqcup_{i=1}^{n} L_i$ is the set of all words.
46
+ - $\kappa$ is a function that induces a partition $\mathcal{K} = \kappa(\mathcal{L})$ of $W$ into cognate sets, such that $|C \cap L_i| \le 1$ for every $C \in \mathcal{K}$ and every $i$.
47
+ - $\mathcal{K}^\ast = \{\, C \in \mathcal{K} : |C| \ge 2 \,\}$ is the set of non-singleton cognate sets.
48
+ - $U = W \setminus \bigcup \mathcal{K}^\ast$ is the set of unexplained words.
49
+ - $\pi : \mathcal{K}^\ast \to \mathcal{P}$ maps each cognate set to a protoform, where $\mathcal{P} = \pi(\mathcal{K}^\ast)$.
50
+ - $\rho : \mathcal{P} \to 2^{\Sigma^\ast}$ maps each protoform to a set of reflexes, with at most one reflex per language.
51
+ - $E_C = \rho(\pi(C)) \setminus C$ is the set of overgenerated reflexes for $C \in \mathcal{K}^\ast$.
52
+
53
+ The objective is
54
+
55
+ ```math
56
+ \min_{\kappa,\,\pi,\,\rho}\;
57
+ B(\kappa) + B(\pi) + B(\rho)
58
+ + \sum_{p \in \mathcal{P}} B(p)
59
+ + \sum_{C \in \mathcal{K}^\ast} B(E_C)
60
+ + \sum_{w \in U} B(w)
61
+ ```
62
+
63
+ subject to
64
+
65
+ ```math
66
+ C \subseteq \rho(\pi(C)) \quad \forall\, C \in \mathcal{K}^\ast
67
+ ```
68
+
69
+ Decoding can be formalized as
70
+
71
+ ```math
72
+ W = U \,\sqcup \bigsqcup_{C \in \mathcal{K}^\ast} \big( \rho(\pi(C)) \setminus E_C \big)
73
+ ```
74
+
75
+ At first glance, it might not be clear why both $\pi$ and $\rho$ are necessary since, ideally, they are inverses of one another ($\pi = \rho^{-1}$) and therefore encode the same relationship. They are both essential, however, because $\pi$ ensures that the protoforms $\mathcal P$ contain only information that is present in $\mathcal K$ and $\rho$ ensures that $\mathcal K$ contains only information that is present in $\mathcal P$. Optimizing them jointly ensures that the protoforms approach a lossless encoding of the cognate sets. Linguists have found that such an encoding can be independently demonstrated to mirror ancestral languages (or protolanguages). The complexity penalties are also important:
76
+
77
+ - The complexity penalty on $\pi$ prevents degenerate solutions where the proposed protolanguage has an arbitrarily large number of sounds or an arbitrarily large number of insertions and deletions, compared to the cognate sets.
78
+ - The complexity penalty on $\rho$ prevents degenerate solutions where the phonemes (sounds) in the proposed protolanguage do not resemble those in the daughter languages (in the cognate sets $\mathcal K$).
79
+
80
+ ## The Regularity Principle
81
+
82
+ The Comparative Method is made possible by the Neogrammarian Principle or Regularity Principle which says that changes in phonemes are systematic. They may involve replacing one phoneme with another phoneme (e.g., d > r) or they may only apply in a certain type of context (e.g., d > r at the beginning of a word) but they are always systematic. This allows us to define $\rho$ as sequences of string rewrite rules (e.g., replace `d` with `r` at the beginning of a string). The prefixes of these sequences (from the different languages in the family) will sometimes overlap, meaning that we can construct a family tree for the language group (a phylogenetic tree). This also means that there will be regular patterns of correspondence, shared across cognate sets that make it possible to write rules that form a classifier which predicts the phonemes in a protoform from the aligned reflexes (descendant words) in the corresponding cognate set.
83
+
84
+ ## Implementing $\kappa$
85
+
86
+ Cognate set induction is the component of the Comparative Method with the most prior work, but it is still not solved. When humans are identifying cognate sets, they look at three things:
87
+
88
+ 1. Are the words pronounced similarly (are the phonological similar)?
89
+ 2. Do the words have similar meanings (are the words semantically similar)?
90
+ 3. Do the words show patterns of correspondence in their phonemes that are shared by other words?
91
+
92
+ State-of-the-art cognate set induction methods take all of these facts into account. They do not generally assume a fully-articulated $\pi$ or $\rho$, so their ability to find new true cognates and prune false cognates is somewhat hindered.
93
+
94
+ ## Implementing $\pi$
95
+
96
+ $\pi$ assumes that each cognate set is aligned to form a matrix so as to maximize the similarity in pronunciation of the phonemes in the words (with gaps to make better alignments possible, when the number of phonemes in reflexes is not the same or when phonemes are very different, e.g. *a* and *k*). $\pi$ can be represented as a set of implications with an antecedent and a consequence:
97
+
98
+ - **Antecedent:** a set of statements about phonemes that are found in the current column of the matrix and (perhaps) what phonemes are found in the preceding and following columns.
99
+ - **Consequent:** the proto-phoneme that is predicted to go in the current column in the protoform.
100
+
101
+ This program is a kind of rule-based classifier.
102
+
103
+ My lab has done a lot of earlier work with neural (specifically, sequence-to-sequence) implementations of $\pi$ (or $\pi$ jointly with $\rho$):
104
+
105
+ - [Transformed Protoform Reconstruction](https://aclanthology.org/2023.acl-short.3.pdf)
106
+ - [WikiHan: A New Comparative Dataset for Chinese Languages](https://aclanthology.org/2022.coling-1.314.pdf)
107
+ - [Semisupervised Neural Proto-Language Reconstruction](https://aclanthology.org/2024.acl-long.788.pdf)
108
+ - [Improved Neural Protoform Reconstruction via Reflex Prediction](https://aclanthology.org/2024.lrec-main.762.pdf)
109
+
110
+ ## Implementing $\rho$
111
+
112
+ $\rho$ is a cascade of string-rewrite rules (sound laws) or, in the more general case, a tree in which nodes correspond to ordered sound laws rules. It reflects the fact that changes in the pronunciation of words progress in time and that it is possible to reason about the sequences of the rules.
113
+
114
+ Some relevant readings:
115
+
116
+ - [PBEBench: A Multi-Step Programming by Examples Reasoning Benchmark inspired by Historical Linguistics](https://aclanthology.org/2026.findings-acl.432.pdf)
117
+ - [ReaComp: Compiling LLM Reasoning into Symbolic Solvers for Efficient Program Synthesis](https://arxiv.org/pdf/2605.05485)
118
+ - [Programming by example meets historical linguistics: A large language model based approach to sound law induction](https://aclanthology.org/2025.acl-long.1432.pdf)
119
+ - [Can Large Language Models Code Like a Linguist?: A Case Study in Low Resource Sound Law Induction](https://arxiv.org/pdf/2406.12725?)
120
+
121
+ # Relevance of Agents
122
+
123
+ The problem of finding optimal $\kappa$, $\pi$, and $\rho$ functions, individually, are relatively intractable search problems. It is possible to develop symbolic algorithms that will generate such programs (especially for $\pi$ and $\kappa$) if one is given $\mathcal K$ and $\mathcal P$, but it is not clear that there is a traditional search algorithm that will find an optimal $R=\langle \kappa, \pi, \rho \rangle$. Humans solve this problem by a process of iterative refinement (editing one program, then editing another, then checking the results). **LLM agents provide a way to automate this workflow.**
124
+
125
+ In the simplest case, a single agent could edit any of the files, in addition to running the whole system—$\rho(\pi(\kappa(\mathcal L)))$, inspecting errors, analyzing the training data, etc. Edits would be made synchronously. This agent would be responsible for the planning of optimization strategies and their execution.
126
+
127
+ However, there are other configurations of agents that may be better. For example, there may be one agent responsible for overall planning, other agents responsible for updates to the code, and other agents responsible for analyzing data and errors. In this case, edits would take place asynchronously and some means of coordinating the activities of the agents would have to be provided (which could range from a rigid set of protocols to a text file of notes to which the agents could write.
128
+
129
+ # A Note on Models and Harnesses
130
+
131
+ We plan on carrying out the initial experiments using Claude Opus as a model and OpenHands as a harness. We will extend the range of models after we have working prototypes of the $\kappa$, $\pi$, and $\rho$ models. We will then expand our scope to three types of models:
132
+
133
+ 1. Other frontier models (e.g., Gemini and GPT-5.x). We will have funds that can be used for Gemini, so we prioritize it.
134
+ 2. Open weights models (GLM, Qwen, etc.)
135
+ 3. Open source models (probably Horizon K2)
136
+
137
+ In some cases, we may use different models for different kinds of agents.
138
+
139
+ I prefer to stick with OpenHands as an agent harness because (1) I like it and (2) it will make it relatively easy to switch any of these models in and out without significant architectural changes. Other harnesses can be considered.
140
+
141
+ # TODO
142
+
143
+ - [ ] Add functionality to select which dataset to use
144
+
145
+ # Roadmap
146
+
147
+ - [ ] Datasets
148
+ - [ ] Austronesian
149
+ - [ ] Uralic
150
+ - [ ] Romance
151
+
152
+ ## Claude Code prototype
153
+
154
+ - [ ] Complete Claude Code version
155
+ - [ ] Develop $\rho$ execution and evaluation ability
156
+ - [ ] Evaluation (reward function)
157
+ - [ ] Code complexity
158
+ - [ ] Accuracy
159
+ - [ ] Skill for performing and interpreting evaluation
160
+ - [ ] Error reporting (after the fashion of pytest)
161
+ - [ ] Develop $\rho$-discovery capability
162
+ - [ ] Code format definitions
163
+ - [ ] Heuristic initialization of $\rho$
164
+ - [ ] Protoform-reflex alignment function
165
+ - [ ] Correspondence aggregation function
166
+ - [ ] Code generation for correspondences
167
+ - [ ] Iterative update of $\rho$
168
+ - [ ] Develop $\pi$-discovery capability
169
+ - [ ] Heuristic initialization of $\pi$
170
+ - [ ] Iterative update of $\pi$
171
+ - [ ] Develop $\mathcal K$-discovery capability
172
+
173
+ ## Open Hands prototype
@@ -0,0 +1,16 @@
1
+ Run `download.sh` to download the Austronesian dataset in CLDF format, then `preprocess.py` for processing
2
+
3
+ To be dealt with:
4
+ - Compoud forms (Multiple IDs in "Cognacy" field; see line 65 in `preprocess.py`)
5
+ - Polymorphemic forms (hypenated)
6
+ - Standalone affixes
7
+ - IPA conversion
8
+ - Archiphonemes (capital letters)
9
+ - Super/subscript numbers
10
+ - Hyphens
11
+ - ng vs. ŋ (left as is for now)
12
+ - Other digraphs (ts, dz, kh, gh, th, ...)
13
+ - `n͂ `? (as in ID 20003-efd4e5480e7002a14f894e85313656c0-1)
14
+ - `ǥ`?
15
+ - `ƚ`?
16
+ - `'`? (not necessarily glottal stop; e.g. "rə'əʔə")
@@ -0,0 +1,25 @@
1
+ # RoBoCoP database
2
+
3
+ This is a database of word etymologies and cognate pairs in 5 Romance languages: Italian, Spanish, Portuguese, French and Romanian.
4
+
5
+ The package contains the following files:
6
+
7
+ Etymologies
8
+ --------------
9
+
10
+ - `Source_languages.csv`: contains a list of all source languages (etymon languages) corresponding to etymologies of words across the 5 languages. Source languages are normalized for each dictionary and mapped to languages found in all other dictionaries using this csv. (columns correspond to Romance languages/dictionaries)
11
+ - under `etym_dictionaries`, files such as `<lang>`.csv, containing lists of words in the language's vocabulary, along with their etymology. These are organized as csv files containing the following columns:
12
+ - `word`: the word
13
+ - `source_language`: language of the etymon from which the word is derived. The value of the source language is one of the languages in the `Source_languages.csv` file and can be used as is to extract cognate/borrowing pairs by string matching
14
+ - `raw_etymon`: etymon of the given word, as found in the etymological dictionary
15
+ - `etymon`: normalized etymon (after removal of non-alphanumeric characters and normalization of some characters). This is the form of the etymon that was used in all computational experiments and can be used to extract cognates/borrowings based on string matching
16
+
17
+ Cognate pairs
18
+ --------------
19
+ - under `cognate_pairs`, files such as `cognates_<lang1>_<lang2>.csv`. These contain cognate pairs for language pair (`<lang1>`,`<lang2>`) extracted automatically based on the etymology files; detailed methodology can be found in the paper accompanying the database. These csv files contain the following columns:
20
+ - `word_<lang1>` ,`word_<lang2>`: the cognate words pair in the two languages
21
+ - `etymon`: the common etymon of the two cognate words (corresponds to `raw_etymon` in previously described etymology files)
22
+ - `normalized_etymon`: normalized etymon, corresponds to `etymon` in dictionary files, for explanation see above
23
+ - `source_language`: language of common etymon (value is one of the languages in `Source_languages.csv`)
24
+
25
+
@@ -0,0 +1,110 @@
1
+ # Romance Dataset
2
+
3
+ This directory contains the Romance data processing workflow for comparative method agents.
4
+
5
+ ## Setup
6
+
7
+ 1. Install dependencies:
8
+
9
+ ```bash
10
+ pip install pandas unidecode epitran cltk
11
+ ```
12
+
13
+ 2. The 10 cognate pair CSVs are included in `datasets/romance/cognate_pairs/`.
14
+
15
+ The expected layout is:
16
+
17
+ ```text
18
+ comparative-method-agents/
19
+ datasets/
20
+ romance/
21
+ cognate_pairs/
22
+ cognates_french_romanian.csv
23
+ cognates_italian_french.csv
24
+ ... (10 files total)
25
+ romance/
26
+ load_normalize.py
27
+ transcribe.py
28
+ build_tables.py
29
+ paths.py
30
+ utils.py
31
+ ```
32
+
33
+ Collectively, these represent cognate sets across five Romance languages; Italian, French, Spanish, Portuguese, and Italian. They are represented as ten sets of cognate pairs for each possible language pairing. They are a portion of the RoBoCoP database; the README for this can be seen at [`README.md`](../datasets/romance/cognate_pairs/README.md).
34
+
35
+ ## Pipeline
36
+
37
+ The end-to-end preparation flow is:
38
+
39
+ 1. Normalize and filter with `normalize.py` to produce `romance_cognates_normalized.csv`.
40
+ 2. Transcribe with `transcribe.py` to produce `romance_cognates_transcribed.csv`.
41
+ 3. Build the relational tables with `build_tables.py`.
42
+
43
+ Run the following from the top level folder:
44
+ ```bash
45
+ pip install pandas unidecode epitran cltk
46
+ python -m romance.load_normalize
47
+ python -m romance.transcribe
48
+ python -m romance.build_tables
49
+ ```
50
+
51
+ ### Normalize and Filter
52
+ ```bash
53
+ python -m romance.load_normalize
54
+ ```
55
+
56
+ Default inputs and outputs:
57
+
58
+ ```text
59
+ input: romance/cognate_pairs/cognates_*.csv (10 files)
60
+ output: datasets/romance/romance_cognates_normalized.csv
61
+ ```
62
+ Loads in the ten cognate set files into a single dataframe, removes proper nouns and non-Latin protoforms.
63
+
64
+ ### Transcribe
65
+
66
+ ```bash
67
+ python -m romance.transcribe
68
+ ```
69
+
70
+ Default inputs and outputs:
71
+
72
+ ```text
73
+ input: datasets/romance/romance_cognates_normalized.csv
74
+ output: datasets/romance/romance_cognates_transcribed.csv
75
+ ```
76
+
77
+ IPA transcription for attested reflexes uses [Epitran](https://github.com/dmort27/epitran) \\
78
+ IPA transcription for protoforms uses [CLTK](https://github.com/cltk/cltk) (Allen reconstruction for Classical Latin)
79
+
80
+ ### Tables
81
+ ```bash
82
+ python -m romance.build_tables
83
+ ```
84
+
85
+ Default inputs and outputs:
86
+
87
+ ```text
88
+ input: datasets/romance/romance_cognates_transcribed.csv
89
+ output: datasets/romance/romance_attested.csv
90
+ output: datasets/romance/romance_proto.csv
91
+ output: datasets/romance/romance_reflexes.csv
92
+ ```
93
+
94
+ ## Utility Functions
95
+ [`utils.py`](utils.py) provides two helper functions for manual exploration of the final tables:
96
+
97
+ - `get_protoforms(ref)` — given an attested reflex, returns all associated Latin protoforms
98
+ - `get_reflexes(prot)` — given a normalized protoform, returns all attested reflexes
99
+
100
+ Example:
101
+ ```python
102
+ from romance.utils import get_protoforms, get_reflexes
103
+
104
+ get_protoforms('alega')
105
+ get_reflexes('capra')
106
+ ```
107
+
108
+
109
+ # TODO
110
+ - [ ] Latin ipa transcription (troubles with diphthongs, spacing, etc.)