Skip to main content

Thank you for visiting nature.com. You are using a browser version with limited support for CSS. To obtain the best experience, we recommend you use a more up to date browser (or turn off compatibility mode in Internet Explorer). In the meantime, to ensure continued support, we are displaying the site without styles and JavaScript.

  • Article
  • Published:

Contextual feature extraction hierarchies converge in large language models and the brain

A preprint version of the article is available at arXiv.

Abstract

Recent advancements in artificial intelligence have sparked interest in the parallels between large language models (LLMs) and human neural processing, particularly in language comprehension. Although previous research has demonstrated similarities between LLM representations and neural responses, the computational principles driving this convergence—especially as LLMs evolve—remain elusive. Here we used intracranial electroencephalography recordings from neurosurgical patients listening to speech to investigate the alignment between high-performance LLMs and the language-processing mechanisms of the brain. We examined a diverse selection of LLMs with similar parameter sizes and found that as their performance on benchmark tasks improves, they not only become more brain-like, reflected in better neural response predictions from model embeddings, but they also align more closely with the hierarchical feature extraction pathways of the brain, using fewer layers for the same encoding. Additionally, we identified commonalities in the hierarchical processing mechanisms of high-performing LLMs, revealing their convergence towards similar language-processing strategies. Finally, we demonstrate the critical role of contextual information in both LLM performance and brain alignment. These findings reveal converging aspects of language processing in the brain and LLMs, offering new directions for developing models that better align with human cognitive processing.

This is a preview of subscription content, access via your institution

Access options

Buy this article

Prices may be subject to local taxes which are calculated during checkout

Fig. 1: Mapping LLM embeddings to the brain.
Fig. 2: Peak brain correlations and layers related to LLM performance.
Fig. 3: Better LLMs display more brain-like hierarchical processing.
Fig. 4: Comparison of feature extraction hierarchies between LLMs.
Fig. 5: Effect of contextual information.

Similar content being viewed by others

Data availability

Although the iEEG recordings used in this study cannot be made publicly available due to patient privacy restrictions, they can be requested from the author (N.M.). A single electrode of example data is available alongside the code demo via Code Ocean at https://doi.org/10.24433/CO.0003780.v1 (ref. 80). Source data are provided with this paper.

Code availability

The code for preprocessing neural recordings, including extracting the high-gamma envelope and identifying responsive electrodes, is available in the naplib-python package81. The code for computing brain similarity scores with ridge regression is available via Code Ocean at https://doi.org/10.24433/CO.0003780.v1 (ref. 80).

References

  1. Toneva, M. & Wehbe, L. Interpreting and improving natural-language processing (in machines) with natural language-processing (in the brain). In Advances in Neural Information Processing Systems 32 (eds Wallach, H. et al.) (NeurIPS, 2019).

  2. Abnar, S., Beinborn, L., Choenni, R. & Zuidema, W. Blackbox meets blackbox: representational similarity and stability analysis of neural language models and brains. Preprint at https://arxiv.org/abs/1906.01539 (2019).

  3. Schrimpf, M. et al. The neural architecture of language: integrative modeling converges on predictive processing. Proc. Natl Acad. Sci. USA 118, e2105646118 (2021).

    Article  Google Scholar 

  4. Hosseini, E. A. et al. Artificial neural network language models predict human brain responses to language even after a developmentally realistic amount of training. Neurobiol. Lang. 5, 43–63 (2024).

    Article  Google Scholar 

  5. Anderson, A. J. et al. Deep artificial neural networks reveal a distributed cortical network encoding propositional sentence-level meaning. J. Neurosci. 41, 4100–4119 (2021).

    Article  Google Scholar 

  6. Caucheteux, C., Gramfort, A. & King, J.-R. Disentangling syntax and semantics in the brain with deep networks. In Proc. 38th International Conference on Machine Learning (eds Meila, M. & Zhang, T.) 1336–1348 (Proceedings of Machine Learning Research, 2021).

  7. Caucheteux, C. & King, J.-R. ́ Brains and algorithms partially converge in natural language processing. Commun. Biol. 5, 134 (2022).

    Article  Google Scholar 

  8. Sun, J., Wang, S., Zhang, J. & Zong, C. Neural encoding and decoding with distributed sentence representations. IEEE Trans. Neural Networks Learn. Syst. 32, 589–603 (2020).

    Article  Google Scholar 

  9. Goldstein, A. et al. Shared computational principles for language processing in humans and deep language models. Nat. Neurosci. 25, 369–380 (2022).

    Article  Google Scholar 

  10. Caucheteux, C., Gramfort, A. & King, J.-R. ́ Evidence of a predictive coding hierarchy in the human brain listening to speech. Nat. Hum. Behav. 7, 430–441 (2023).

    Article  Google Scholar 

  11. Antonello, R., Vaidya, A. & Huth, A. G. Scaling laws for language encoding models in fmri. Adv. Neural Inf. Process. Syst. 36, 21895–21907 (2023).

    Google Scholar 

  12. Antonello, R. & Huth, A. Predictive coding or just feature discovery? An alternative account of why language models fit brain data. Neurobiol. Lang. 5, 64–79 (2024).

    Google Scholar 

  13. Hickok, G. & Poeppel, D. The cortical organization of speech processing. Nat. Rev. Neurosci. 8, 393–402 (2007).

    Article  Google Scholar 

  14. Hasson, U., Yang, E., Vallines, I., Heeger, D. J. & Rubin, N. A hierarchy of temporal receptive windows in human cortex. J. Neurosci. 28, 2539–2550 (2008).

    Article  Google Scholar 

  15. Lerner, Y., Honey, C. J., Silbert, L. J. & Hasson, U. Topographic mapping of a hierarchy of temporal receptive windows using a narrated story. J. Neurosci. 31, 2906–2915 (2011).

    Article  Google Scholar 

  16. Ding, N. et al. Characterizing neural entrainment to hierarchical linguistic units using electroencephalography (EEG). Front. Hum. Neurosci. 11, 481 (2017).

    Article  Google Scholar 

  17. Ethayarajh, K. How contextual are contextualized word representations? Comparing the geometry of BERT, ELMo, and GPT-2 embeddings. Preprint at https://arxiv.org/abs/1909.00512 (2019).

  18. Tenney, I., Das, D. & Pavlick, E. BERT rediscovers the classical NLP pipeline. In Proc. 57th Annual Meeting of the Association for Computational Linguistics (eds Korhonen, A.) 4593–4601 (Association for Computational Linguistics, 2019).

  19. Touvron, H. et al. Llama 2: open foundation and fine-tuned chat models. Preprint at https://arxiv.org/abs/2307.09288 (2023).

  20. Holm, S. A simple sequentially rejective multiple test procedure. Scand. J. Stat. 6, 65–70 (1979).

    MathSciNet  Google Scholar 

  21. Honey, C. J. et al. Slow cortical dynamics and the accumulation of information over long timescales. Neuron 76, 423–434 (2012).

    Article  Google Scholar 

  22. Chang, C. H. C., Nastase, S. A. & Hasson, U. Information flow across the cortical timescale hierarchy during narrative construction. Proc. Natl Acad. Sci. USA 119, e2209307119 (2022).

    Article  Google Scholar 

  23. Sharpee, T. O., Atencio, C. A. & Schreiner, C. E. Hierarchical representations in the auditory cortex. Curr. Opin. Neurobiol. 21, 761–767 (2011).

    Article  Google Scholar 

  24. Morosan, P. et al. Human primary auditory cortex: cytoarchitectonic subdivisions and mapping into a spatial reference system. NeuroImage 13, 684–701 (2001).

    Article  Google Scholar 

  25. Baumann, S., Petkov, C. I. & Griffiths, T. D. A unified framework for the organization of the primate auditory cortex. Front. Syst. Neurosci. 7, 11 (2013).

    Article  Google Scholar 

  26. Norman-Haignere, S. V. & McDermott, J. H. Neural responses to natural and model-matched stimuli reveal distinct computations in primary and nonprimary auditory cortex. PLoS Biol. 16, e2005127 (2018).

    Article  Google Scholar 

  27. Mischler, G., Keshishian, M., Bickel, S., Mehta, A. D. & Mesgarani, N. Deep neural networks effectively model neural adaptation to changing background noise and suggest nonlinear noise filtering methods in auditory cortex. NeuroImage 266, 119819 (2023).

    Article  Google Scholar 

  28. Kumar, S. et al. Shared functional specialization in transformer-based language models and the human brain. Nat. Commun. 15, 5523 (2024).

    Article  Google Scholar 

  29. Nonaka, S., Majima, K., Aoki, S. C. & Kamitani, Y. Brain hierarchy score: which deep neural networks are hierarchically brain-like? iScience 24, 103013 (2021).

    Article  Google Scholar 

  30. Kornblith, S., Norouzi, M., Lee, H. & Hinton, G. Similarity of neural network representations revisited. In Proc. 36th International Conference on Machine Learning (eds Chaudhuri, K. & Salakhutdinov, R.) 3519–3529 (Proceedings of Machine Learning Research, 2019).

  31. Caucheteux, C., Gramfort, A. & King, J.-R. ́ Deep language algorithms predict semantic comprehension from brain activity. Sci. Rep. 12, 16327 (2022).

    Article  Google Scholar 

  32. Costafreda, S. G. et al. A systematic review and quantitative appraisal of fMRI studies of verbal fluency: role of the left inferior frontal gyrus. Hum. Brain Mapp. 27, 799–810 (2006).

    Article  Google Scholar 

  33. Arana, S., Marquand, A., Hultén, A., Hagoort, P. & Schoffe-len, J.-M. Sensory modality-independent activation of the brain network for language. J. Neurosci. 40, 2914–2924 (2020).

    Article  Google Scholar 

  34. Sheng, J. et al. The cortical maps of hierarchical linguistic structures during speech perception. Cereb. Cortex 29, 3232–3240 (2019).

    Article  Google Scholar 

  35. Keshishian, M. et al. Joint, distributed and hierarchically organized encoding of linguistic features in the human auditory cortex. Nat. Hum. Behav. 7, 740–753 (2023).

    Article  Google Scholar 

  36. Giordano, B. L., Esposito, M., Valente, G. & Formisano, E. Intermediate acoustic-to-semantic representations link behavioral and neural responses to natural sounds. Nat. Neurosci. 26, 664–672 (2023).

    Article  Google Scholar 

  37. Tuckute, G., Feather, J., Boebinger, D. & McDermott, J. H. Many but not all deep neural network audio models capture brain responses and exhibit correspondence between model stages and brain regions. PLoS Biol. 21, e3002366 (2023).

    Article  Google Scholar 

  38. Kriegeskorte, N. Deep neural networks: a new framework for modeling biological vision and brain information processing. Annu. Rev. Vision Sci. 1, 417–446 (2015).

    Article  Google Scholar 

  39. Cichy, R. M., Khosla, A., Pantazis, D., Torralba, A. & Oliva, A. Comparison of deep neural networks to spatio-temporal cortical dynamics of human visual object recognition reveals hierarchical correspondence. Sci. Rep. 6, 27755 (2016).

    Article  Google Scholar 

  40. Sexton, N. J. & Love, B. C. Reassessing hierarchical correspondences between brain and deep networks through direct interface. Sci. Adv. 8, eabm2219 (2022).

    Article  Google Scholar 

  41. Horikawa, T. & Kamitani, Y. Hierarchical neural representation of dreamed objects revealed by brain decoding with deep neural network features. Front. Comput. Neurosci. 11, 4 (2017).

    Article  Google Scholar 

  42. Vaswani, A. et al. Attention is all you need. In Advances in Neural Information Processing Systems 30 (eds Guyon, I. et al.) (NeurIPS, 2017).

  43. O’Connor, J. & Andreas, J. What context features can transformer language models use? Preprint at https://arxiv.org/abs/2106.08367 (2021).

  44. Clark, K., Khandelwal, U., Levy, O. & Manning, C. D. What does BERT look at? An analysis of BERT’s attention. Preprint at https://arxiv.org/abs/1906.04341 (2019).

  45. Skrill, D. & Norman-Haignere, S. V. Large language models transition from integrating across position-yoked, exponential windows to structure-yoked, power-law windows. In Proc. 37th International Conference on Neural Information Processing Systems (eds Oh, A. et al.) 638–654 (Curran Associates, Inc., 2023).

  46. Norman-Haignere, S. V. et al. Multiscale temporal integration organizes hierarchical computation in human auditory cortex. Nat. Hum. Behav. 6, 455–469 (2022).

    Article  Google Scholar 

  47. de Heer, W. A., Huth, A. G., Griffiths, T. L., Gallant, J. L. & Theunissen, F. E. The hierarchical cortical organization of human speech processing. J. Neurosci. 37, 6539–6557 (2017).

    Article  Google Scholar 

  48. Di Liberto, G. M. et al. Neural representation of linguistic feature hierarchy reflects second-language proficiency. NeuroImage 227, 117586 (2021).

    Article  Google Scholar 

  49. Gong, X. L. et al. Phonemic segmentation of narrative speech in human cerebral cortex. Nat. Commun. 14, 4309 (2023).

    Article  Google Scholar 

  50. Ivanova, M. V., Zhong, A., Turken, A., Baldo, J. V. & Dronkers, N. F. Functional contributions of the arcuate fasciculus to language processing. Front. Hum. Neurosci. 15, 672665 (2021).

    Article  Google Scholar 

  51. Dick, A. S. & Tremblay, P. Beyond the arcuate fasciculus: consensus and controversy in the connectional anatomy of language. Brain 135, 3529–3550 (2012).

    Article  Google Scholar 

  52. Oosterhof, N. N., Wiestler, T., Downing, P. E. & Diedrichsen, J. A comparison of volume-based and surface-based multi-voxel pattern analysis. NeuroImage 56, 593–600 (2011).

    Article  Google Scholar 

  53. Naveed, H. et al. A comprehensive overview of large language models. Preprint at https://arxiv.org/abs/2307.06435 (2023).

  54. Raffel, C. et al. Exploring the limits of transfer learning with a unified text-to-text transformer. J. Mach. Learn. Res. 21, 5485–5551 (2020).

    MathSciNet  Google Scholar 

  55. Lee, K. et al. Deduplicating training data makes language models better. Preprint at https://arxiv.org/abs/2107.06499 (2021).

  56. Huth, A. G., De Heer, W. A., Griffiths, T. L., Theunissen, F. E. & Gallant, J. L. Natural speech reveals the semantic maps that tile human cerebral cortex. Nature 532, 453–458 (2016).

    Article  Google Scholar 

  57. Murphy, E. et al. The spatiotemporal dynamics of semantic integration in the human brain. Nat. Commun. 14, 6336 (2023).

    Article  Google Scholar 

  58. Xiong, W. et al. Effective long-context scaling of foundation models. Preprint at https://arxiv.org/abs/2309.16039 (2023).

  59. Liu, N. F. et al. Lost in the middle: how language models use long contexts. Trans. Assoc. Comput. Linguist. 12, 157–173 (2024).

    Article  Google Scholar 

  60. Pinker, S. & Bloom, P. Natural language and natural selection. Behav. Brain Sci. 13, 707–727 (1990).

    Article  Google Scholar 

  61. Deacon, T. W. The Symbolic Species: The Co-Evolution of Language and the Brain (W. W. Norton & Company, 1997).

  62. Hamilton, L. S. & Huth, A. G. The revolution will not be controlled: natural stimuli in speech neuroscience. Lang. Cognit. Neurosci. 35, 573–582 (2020).

    Article  Google Scholar 

  63. Edwards, E. et al. Comparison of time–frequency responses and the event-related potential to auditory speech stimuli in human cortex. J. Neurophysiol. 102, 377–386 (2009).

    Article  Google Scholar 

  64. Ray, S. & Maunsell, J. H. R. Different origins of gamma rhythm and high-gamma activity in macaque visual cortex. PLoS Biol. 9, e1000610 (2011).

    Article  Google Scholar 

  65. Steinschneider, M., Fishman, Y. I. & Arezzo, J. C. Spectrotemporal analysis of evoked and induced electroencephalographic responses in primary auditory cortex (A1) of the awake monkey. Cereb. Cortex 18, 610–625 (2008).

    Article  Google Scholar 

  66. Mesgarani, N., Cheung, C., Johnson, K. & Chang, E. F. Phonetic feature encoding in human superior temporal gyrus. Science 343, 1006–1010 (2014).

    Article  Google Scholar 

  67. Bouchard, K. E., Mesgarani, N., Johnson, K. & Chang, E. F. Functional organization of human sensorimotor cortex for speech articulation. Nature 495, 327–332 (2013).

    Article  Google Scholar 

  68. Wolf, T. et al. HuggingFace’s transformers: state-of-the-art natural language processing. Preprint at https://arxiv.org/abs/1910.03771 (2019).

  69. Gao, L. et al. A framework for few-shot language model evaluation (v0.0.1). Zenodo https://doi.org/10.5281/zenodo.5371629 (2021).

  70. Rajpurkar, P., Jia, R. & Liang, P. Know what you don’t know: unanswerable questions for squad. Preprint at https://arxiv.org/abs/1806.03822 (2018).

  71. Clark, C. et al. BoolQ: exploring the surprising difficulty of natural yes/no questions. Preprint at https://arxiv.org/abs/1905.10044 (2019).

  72. Mihaylov, T., Clark, P., Khot, T. & Sabharwal, A. Can a suit of armor conduct electricity? A new dataset for open book question answering. Preprint at https://arxiv.org/abs/1809.02789 (2018).

  73. Bisk, Y. et al. PIQA: reasoning about physical commonsense in natural language. Proc. AAAI Conference on Artificial Intelligence 34, 7432–7439 (2020).

  74. Zellers, R., Holtzman, A., Bisk, Y., Farhadi, A. & Choi, Y. HellaSwag: can a machine really finish your sentence? Preprint at https://arxiv.org/abs/1905.07830 (2019).

  75. Sakaguchi, K., Le Bras, R., Bhagavatula, C. & Choi, Y. WinoGrande: an adversarial winograd schema challenge at scale. Commun. ACM 64, 99–106 (2021).

    Article  Google Scholar 

  76. Pedregosa, F. et al. Scikit-learn: machine learning in python. J. Mach. Learn. Res. 12, 2825–2830 (2011).

    MathSciNet  Google Scholar 

  77. Groppe, D. M. et al. iELVis: an open source MATLAB toolbox for localizing and visualizing human intracranial electrode data. J. Neurosci. Methods 281, 40–48 (2017).

    Article  Google Scholar 

  78. Fischl, B. et al. Automatically parcellating the human cerebral cortex. Cereb. Cortex 14, 11–22 (2004).

    Article  Google Scholar 

  79. Margulies, D. S., Falkiewicz, M. & Huntenburg, J. M. A cortical surface-based geodesic distance package for Python. GigaScience 5, https://doi.org/10.1186/s13742-016-0147-0-q (2016).

  80. Mischler, G., Aaron Li, Y., Bickel, S., Mehta, A. D. & Mesgarani, N. Contextual feature extraction hierarchies converge in large language models and the brain. Code Ocean https://doi.org/10.24433/CO.0003780.v1 (2024).

  81. Mischler, G., Raghavan, V., Keshishian, M. & Mesgarani, N. Naplib-python: neural acoustic data processing and analysis tools in python. Softw. Impacts 17, 100541 (2023).

    Article  Google Scholar 

  82. Taylor, R. et al. Galactica: a large language model for science. Preprint at https://arxiv.org/abs/2211.09085 (2022).

  83. Dey, N. et al. Cerebras-GPT: open compute-optimal language models trained on the Cerebras wafer-scale cluster. Preprint at https://arxiv.org/abs/2304.03208 (2023).

  84. Biderman, S. et al. Pythia: a suite for analyzing large language models across training and scaling. In Proc. 40th International Conference on Machine Learning (eds Krause, A. et al.) 2397–2430 (Proceedings of Machine Learning Research, 2023).

  85. Zhang, S. et al. Opt: open pre-trained transformer language models. Preprint at https://arxiv.org/abs/2205.01068 (2022).

  86. Artetxe, M. et al. Efficient large scale language modeling with mixtures of experts. Preprint at https://arxiv.org/abs/2112.10684 (2021).

  87. LAION. LeoLM: Linguistically Enhanced Open Language Model. Hugging Face https://huggingface.co/LeoLM/leo-hessianai-13b (accessed 1 October 2023).

  88. MosaicML NLP Team. Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs. DataBricks (May, 2023) www.mosaicml.com/blog/mpt-7b

  89. Almazrouei, E. et al. The falcon series of open language models. Preprint at https://arxiv.org/abs/2311.16867 (2023).

  90. Touvron, H. et al. LlaMA: open and efficient foundation language models. Preprint at https://arxiv.org/abs/2302.13971 (2023).

  91. Xwin-LM: Powerful, Stable, and Reproducible LLM Alignment. Hugging Face https://huggingface.co/Xwin-LM/Xwin-LM-7B-V0.2 (accessed 1 October 2023).

  92. Jiang, A. Q. et al. Mistral 7b. Preprint at https://arxiv.org/abs/2310.06825 (2023).

Download references

Acknowledgements

This study was funded by the National Institute on Deafness and Other Communication Disorders (R01DC014279 to N.M.) and the National Science Foundation Graduate Research Fellowship Program (DGE-2036197 to G.M.). The funders had no role in the study design, data collection and analysis, decision to publish and manuscript preparation.

Author information

Authors and Affiliations

Authors

Contributions

G.M. and Y.A.L. contributed to the conceptualization, methodology, data analysis and writing of the manuscript. S.B. and A.D.M. contributed to data collection. N.M. supervised the project and contributed to the conceptualization, methodology and revision of the manuscript.

Corresponding author

Correspondence to Nima Mesgarani.

Ethics declarations

Competing interests

The authors declare no competing interests.

Peer review

Peer review information

Nature Machine Intelligence thanks Samuel Nastase and the other, anonymous, reviewer(s) for their contribution to the peer review of this work.

Additional information

Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Supplementary information

Supplementary Information

Supplementary Figs. 1–6.

Reporting Summary

Supplementary Data 1

Supplementary data for supplementary figures.

Source data

Source Data Fig. 2

LLM brain prediction scores over layers, LLM performance metrics and electrode distances.

Source Data Fig. 3

Normalized binned scores by distance from HG.

Source Data Fig. 4

Grouped and averaged CCA similarity scores between model groups and average diagonal similarity scores between models.

Source Data Fig. 5

Alignment by context, contextual content scores and score improvement from the addition of context, along with FreeSurfer average brain coordinates.

Rights and permissions

Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Mischler, G., Li, Y.A., Bickel, S. et al. Contextual feature extraction hierarchies converge in large language models and the brain. Nat Mach Intell 6, 1467–1477 (2024). https://doi.org/10.1038/s42256-024-00925-4

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue date:

  • DOI: https://doi.org/10.1038/s42256-024-00925-4

This article is cited by

Search

Quick links

Nature Briefing AI and Robotics

Sign up for the Nature Briefing: AI and Robotics newsletter — what matters in AI and robotics research, free to your inbox weekly.

Get the most important science stories of the day, free in your inbox. Sign up for Nature Briefing: AI and Robotics