Can Large Language Models Code Like a Linguist?: A Case Study in Low Resource Sound Law Induction

Atharva Naik, Kexun Zhang, Nathaniel R. Robinson, Aravind Mysore, Clayton Marr, Hong Sng, Rebecca Byrnes, Anna Cai, Kalvin Chang, David R. MortensenarXiv 2024

Abstract

Historical linguists have long written a kind of incompletely formalized "program" that converts reconstructed words in an ancestor language into words in one of its attested descendants that consist of a series of ordered string rewrite functions (called sound laws). They do this by observing pairs of words in the reconstructed language (protoforms) and the descendent language (reflexes) and constructing a program that transforms protoforms into reflexes. However, writing these programs is error-prone and time-consuming. Prior work has successfully scaffolded this process computationally, but fewer researchers have tackled Sound Law Induction (SLI), which we approach in this paper by casting it as Programming by Examples. We propose a language-agnostic solution that utilizes the programming ability of Large Language Models (LLMs) by generating Python sound law programs from sound change examples. We evaluate the effectiveness of our approach for various LLMs, propose effective methods to generate additional language-agnostic synthetic data to fine-tune LLMs for SLI, and compare our method with existing automated SLI methods showing that while LLMs lag behind them they can complement some of their weaknesses.

1. Introduction

In historical linguistics, "sound laws" represent the principled, rule-governed ways that sounds change as an ancestor language (a protoform) evolves into a descendant language (a reflex). For centuries, linguists have manually induced these rules—essentially writing mental programs to explain phonetic evolution. This process, known as Sound Law Induction (SLI), is labor-intensive and error-prone. While computational linguistics has made strides in backward reconstruction, forward reconstruction (inducing the rules of change) remains a significant challenge due to data scarcity and the "cascade" nature of changes, where ordered sequences of rules interact.

2. Methodology: PySLICoder

We propose that Sound Law Induction is fundamentally a Program Synthesis problem. To address this, we developed PySLICoder, a framework that treats historical linguistics as a "Programming by Example" task.

2.1 Prompting and the BasicAction Class

PySLICoder prompts an LLM to generate Python code using a custom BasicAction class. This class handles string manipulation (insertions, deletions, and substitutions) based on phonetic environments. The prompt structure includes task descriptions, phonetic examples (tokenized with panphon), and few-shot demonstrations to guide the model's logic.

Prompt structure for inducing sound laws using the BasicAction class.

2.2 Synthetic Data and Training

To teach the model to "think like a linguist" without massive real-world datasets, we fine-tuned a Magicoder-6.7B model on two types of synthetic data:

  • SMP (String Manipulation): Randomly sampled string rewrite rules.
  • LING (Linguistic): Rules simulating realistic phonetic changes based on articulatory features.

2.3 Inference Strategies

To handle complex multi-step changes, we implemented a beam search algorithm where the LLM proposes multiple rules, and the system iterates based on edit distance performance. Additionally, Inference Time Example Selection (ITES) was developed to filter uninformative examples and focus the model on relevant word pairs within the context window.

3. Experimental Evaluation

The study evaluates models across three settings: single law prediction (26 real-world laws from the Tangkhulic family), multi-law synthetic cascades, and final reflex prediction for Tangkhulic and Austronesian languages.

4. Results

Our results indicate that LLMs can effectively induce sound laws when framed as coders. GPT-4 achieved a perfect 100% pass rate on single sound law induction. PySLICoder, our fine-tuned open-source model, reached a 65% pass rate, which improved to 80% when ensembled with Codestral.

Performance comparison on single sound law induction across various LLMs and PySLICoder configurations.

On the Tangkhulic dataset, PySLICoder significantly outperformed zero-shot open-source baselines like Llama-3 and DeepSeekCoder. In real-world reflex prediction, the LLM-based approach proved competitive with specialized Reinforcement Learning models (such as Luo’s MCTS), showing superior performance in languages like Niue where rules are nuanced but fewer in number.

5. Conclusion and Limitations

PySLICoder demonstrates that leveraging the "coding brain" of LLMs through synthetic data fine-tuning is a viable path for low-resource linguistic tasks. However, error propagation remains a bottleneck; a single error in a multi-step cascade can lead to total failure in reflex reconstruction. Future work will explore hierarchical planning to better manage long cascades and more complex phonetic scenarios.

Summary updated

BibTeX
@misc{naik2024can,
  author = {Atharva Naik and Kexun Zhang and Nathaniel R. Robinson and Aravind Mysore and Clayton Marr and Hong Sng and Rebecca Byrnes and Anna Cai and Kalvin Chang and David R. Mortensen},
  title = {{Can Large Language Models Code Like a Linguist?: A Case Study in Low Resource Sound Law Induction}},
  year = {2024},
  eprint = {2406.12725},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.12725},
}
Figure