Pre-Trained Large Language Models Learn to Predict Hidden Markov Models In-Context

Abstract

Hidden Markov Models (HMMs) are fundamental tools for modeling sequential data with latent states that follow Markovian dynamics. However, they present significant challenges in model fitting and computational efficiency on real-world datasets. In this work, we demonstrate that pre-trained large language models (LLMs) can effectively model data generated by HMMs through in-context learning (ICL) — their ability to learn patterns from examples within the input context. We evaluate LLMs' performance on diverse synthetic HMMs, showing that their prediction accuracy converges to the theoretical optimum. We discover novel scaling trends influenced by HMM properties and provide theoretical conjectures for these empirical observations. Furthermore, we present practical guidelines for scientists on using ICL as a diagnostic tool for complex data. Applied to real-world animal decision-making tasks, ICL achieves competitive performance with models designed by human experts. Our results demonstrate potential for advancing understanding of LLMs' capabilities while opening new avenues for scientific discovery of biological mechanisms and hidden structures in real-world phenomena.

Cite

Text

Dai et al. "Pre-Trained Large Language Models Learn to Predict Hidden Markov Models In-Context." Advances in Neural Information Processing Systems, 2025.

Markdown

[Dai et al. "Pre-Trained Large Language Models Learn to Predict Hidden Markov Models In-Context." Advances in Neural Information Processing Systems, 2025.](https://mlanthology.org/neurips/2025/dai2025neurips-pretrained/)

BibTeX

@inproceedings{dai2025neurips-pretrained,
  title     = {{Pre-Trained Large Language Models Learn to Predict Hidden Markov Models In-Context}},
  author    = {Dai, Yijia and Gao, Zhaolin and Sattar, Yahya and Dean, Sarah and Sun, Jennifer J.},
  booktitle = {Advances in Neural Information Processing Systems},
  year      = {2025},
  url       = {https://mlanthology.org/neurips/2025/dai2025neurips-pretrained/}
}