OSCR

Larger language models better align with neural representations of natural language.

Code ↔ Paper

4 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 4 matches
  1. [1] § Materials and methods › Contextual embeddings ↔ scripts/tfsemb_download.py, lines 1–45 · score 0.79 · gpt2 xl, GPT Neox, EleutherAI, OPT, models
  2. [2] § Materials and methods › Encoding models ↔ scripts/tfsenc_encoding.py, lines 148–195 · score 0.69 · RidgeCV, himalaya, alpha, OLS, fitting, PCA
  3. [3] § Results ↔ scripts/tfsemb_download.py, lines 1–45 · score 0.60 · gpt neox, MEDIUM, OPT, XL, model
  4. [4] § Materials and methods › Contextual embeddings ↔ scripts/tfsenc_config.py, lines 39–57 · score 0.60 · EleutherAI, GPT Neo, language model

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 269 lines · 7.4 KB · no license · 2 matches

  1. import os
  2. from transformers import (
  3. AutoConfig,
  4. AutoModel,
  5. AutoModelForCausalLM,
  6. AutoModelForMaskedLM,
  7. AutoModelForSeq2SeqLM,
  8. AutoTokenizer,
  9. )
  10. CAUSAL_MODELS = [
  11. "gpt2",
  12. "gpt2-large",
  13. "gpt2-xl",
  14. "EleutherAI/gpt-neo-125M",
  15. "EleutherAI/gpt-neo-1.3B",
  16. "EleutherAI/gpt-neo-2.7B",
  17. "EleutherAI/gpt-neox-20b",
  18. "facebook/opt-125m",
  19. "facebook/opt-350m",
  20. "facebook/opt-1.3b",
  21. "facebook/opt-2.7b",
  22. "facebook/opt-6.7b",
  23. "facebook/opt-30b",
  24. "bigscience/bloom",
  25. ]
  26. SEQ2SEQ_MODELS = ["facebook/blenderbot_small-90M", "facebook/blenderbot-3B"]
  27. MLM_MODELS = [
  28. # "gpt2-xl", # uncomment to run this model with MLM input
  29. # "gpt2-medium", # uncomment to run this model with MLM input
  30. "bert-base-uncased",
  31. "bert-large-uncased",
  32. "bert-base-cased",
  33. "bert-large-cased",
  34. "roberta-base",
  35. "roberta-large",
  36. ]
  37. MODEL_CLASS_MAP = {
  38. "causal": (CAUSAL_MODELS, AutoModelForCausalLM),
  39. "seq2seq": (SEQ2SEQ_MODELS, AutoModelForSeq2SeqLM),
  40. "mlm": (MLM_MODELS, AutoModelForMaskedLM),
  41. }
  42. def clean_lm_model_name(item):
  43. """Remove unnecessary parts from the language model name.
  44. Args:
  45. item (str/list): full model name from HF Hub
  46. Returns:
  47. (str/list): pretty model name
  48. Example:
  49. clean_lm_model_name(EleutherAI/gpt-neo-1.3B) == 'gpt-neo-1.3B'
  50. """
  51. if isinstance(item, str):
  52. return item.split("/")[-1]
  53. if isinstance(item, list):
  54. return [clean_lm_model_name(i) for i in item]
  55. print("Invalid input. Please check.")
  56. def get_max_context_length(model_name, tokenizer_class=None):
  57. """Return maximum possible context length for the model/tokenizer
  58. Args:
  59. model_name (str): Model name as seen on https://hugginface.co/models.
  60. tokenizer_class (Tokenizer, optional):
  61. Tokenizer class to be instantiated for the model.
  62. Defaults to None.
  63. Returns:
  64. int: Maximum allowed context for the model/tokenizer
  65. """
  66. tokenizer = download_hf_tokenizer(
  67. model_name,
  68. tokenizer_class=tokenizer_class,
  69. cache_dir=None,
  70. local_files_only=False,
  71. )
  72. return tokenizer.max_len_single_sentence
  73. def get_model_num_layers(model_name):
  74. """Return number of hidden layers in the model
  75. Args:
  76. model_name (str): Model name as seen on https://hugginface.co/models.
  77. Returns:
  78. int: value of {n_layer|num_layers|num_hidden_layers} attribute
  79. """
  80. config = AutoConfig.from_pretrained(model_name)
  81. num_layers = getattr(
  82. config,
  83. "n_layer",
  84. getattr(
  85. config,
  86. "num_layers",
  87. getattr(config, "num_hidden_layers", None),
  88. ),
  89. )
  90. if not num_layers:
  91. print(f"{model_name} has no hidden layers")
  92. exit()
  93. return num_layers
  94. def download_hf_model(
  95. model_name, model_class=None, cache_dir=None, local_files_only=False
  96. ):
  97. """Download a Huggingface model from the model repository (cache)."""
  98. if model_class is None:
  99. model_class = AutoModel
  100. if cache_dir is None:
  101. cache_dir = set_cache_dir()
  102. model = model_class.from_pretrained(
  103. model_name,
  104. output_hidden_states=True,
  105. cache_dir=cache_dir,
  106. local_files_only=local_files_only,
  107. )
  108. return model
  109. def download_hf_tokenizer(
  110. model_name, tokenizer_class=None, cache_dir=None, local_files_only=False
  111. ):
  112. """Download a Huggingface tokenizer from the model repository (cache)."""
  113. if tokenizer_class is None:
  114. tokenizer_class = AutoTokenizer
  115. if cache_dir is None:
  116. cache_dir = set_cache_dir()
  117. tokenizer = tokenizer_class.from_pretrained(
  118. model_name,
  119. add_prefix_space=True,
  120. cache_dir=cache_dir,
  121. local_files_only=local_files_only,
  122. )
  123. return tokenizer
  124. def download_tokenizer_and_model(
  125. CACHE_DIR, tokenizer_class, model_class, model_name, local_files_only
  126. ):
  127. """Cache (or load) the model and tokenizer from the model repository (or cache).
  128. Args:
  129. CACHE_DIR (str): path where the model and tokenizer will be cached.
  130. tokenizer_class (Tokenizer): Tokenizer class to be instantiated for the model.
  131. model_class (Huggingface Model): Model class corresponding to model_name.
  132. model_name (str): Model name as seen on https://hugginface.co/models.
  133. local_files_only (bool, optional): False (Default) if caching.
  134. True if loading from cache.
  135. Returns:
  136. tuple: (tokenizer, model)
  137. """
  138. print("Downloading model")
  139. model = download_hf_model(model_name, model_class, CACHE_DIR, local_files_only)
  140. print("Downloading tokenizer")
  141. tokenizer = download_hf_tokenizer(
  142. model_name, tokenizer_class, CACHE_DIR, local_files_only
  143. )
  144. return (model, tokenizer)
  145. def set_cache_dir():
  146. CACHE_DIR = os.path.join(os.path.dirname(os.getcwd()), ".cache")
  147. os.makedirs(CACHE_DIR, exist_ok=True)
  148. return CACHE_DIR
  149. def get_models_and_class(model_name):
  150. """Return the appropriate model class and model to download
  151. Args:
  152. model_name (str): Model name as seen on https://hugginface.co/models.
  153. Returns:
  154. models (list): model name or models in the same class
  155. mod_class (Huggingface Model): Model class corresponding to model_name.
  156. """
  157. models, mod_class = None, None
  158. for model_key, (model_list, model_class) in MODEL_CLASS_MAP.items():
  159. if model_name == model_key:
  160. models, mod_class = model_list, model_class
  161. break
  162. elif model_name in model_list:
  163. models, mod_class = [model_name], model_class
  164. break
  165. else:
  166. continue
  167. if not models or not model_class:
  168. print("Invalid Model List or Model Class")
  169. return models, mod_class
  170. def download_tokenizers_and_models(model_name=None, local_files_only=False, debug=True):
  171. """This function downloads the tokenizer and model for the specified model name.
  172. Args:
  173. model_name (str, optional): Model name as seen on https://hugginface.co/models.
  174. Defaults to None.
  175. local_files_only (bool, optional): False (Default) if caching.
  176. True if loading from cache.
  177. debug (bool, optional): Check if caching was successful. Defaults to True.
  178. Returns:
  179. dict: Dictionary with model name as key and (tokenizer, model) as value.
  180. """
  181. CACHE_DIR = set_cache_dir()
  182. if model_name is None:
  183. print("Input argument cannot be empty")
  184. return
  185. models, model_class = get_models_and_class(model_name)
  186. model_dict = {}
  187. for model_name in models:
  188. print(f"Model Name: {model_name}")
  189. model_dict[model_name] = download_tokenizer_and_model(
  190. CACHE_DIR,
  191. AutoTokenizer,
  192. model_class,
  193. model_name,
  194. local_files_only,
  195. )
  196. # check if caching was successful
  197. if debug:
  198. print("Checking if model has been cached successfully")
  199. try:
  200. download_tokenizer_and_model(
  201. CACHE_DIR,
  202. AutoTokenizer,
  203. model_class,
  204. model_name,
  205. True,
  206. )
  207. except:
  208. print(f"Caching of {model_name} failed")
  209. return model_dict
  210. if __name__ == "__main__":
  211. download_tokenizers_and_models("causal", local_files_only=False, debug=True)

tfsemb_download.py at commit b7a6fcb, no license · at the source

Overview

Authors: Zhuoqiao Hong1, Haocheng Wang1, Zaid Zada1, Harshvardhan Gazula2, David Turner1, Bobbi Aubrey1, Leonard Niekerken1, Werner Doyle3, Sasha Devore3, Patricia Dugan3, Daniel Friedman3, Orrin Devinsky3, Adeen Flinker3, Uri Hasson1, Samuel Nastase1, Ariel Y Goldstein4
  1. Department of Psychology and the Neuroscience Institute, Princeton University, Princeton, United States
  2. McGovern Institute for Brain Research, Massachusetts Institute of Technology, Cambridge, United States
  3. New York University Grossman School of Medicine, New York, United States
  4. Business School, Data Science Department and Cognitive Science Department, Hebrew University, Jerusalem, Israel
Journal: eLife, volume 13, article RP101204
Dates: published online 16 September 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.7554/elife.101204 · PMID 42746838 · PMCID PMC13581289 · OpenAlex W4403650892
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: intracranial EEG (iEEG / ECoG / SEEG) (modality), human (organism)
Methods: Connectivity, Statistics, Smoothing, state filtering, decompositions, Machine learning, Preprocessing, Spectral & time-frequency
Keywords: Human
MeSH: Brain*, Language*, Large Language Models*, Natural Language Processing*, Electrocorticography, Humans (* major topic)
Topic: Topic Modeling (Artificial Intelligence, Computer Science), according to OpenAlex
Funding: NIDCD NIH HHS (R01 DC022534); NIH HHS (DP1HD091948, R01NS109367, R01DC022534); NINDS NIH HHS (R01 NS109367); NICHD NIH HHS (DP1 HD091948)
Citations: not cited yet (Europe PMC); 54 references in the paper

Abstract

Recent research has used large language models (LLMs) to study the neural basis of naturalistic language processing in the human brain. LLMs have rapidly grown in complexity, leading to improved language processing capabilities. Here, we utilized several families of transformer-based LLMs to investigate the relationship between model size and their ability to capture linguistic information in the human brain. Crucially, a subset of LLMs were trained on a fixed training set, enabling us to dissociate model size from architecture and training set size. We used electrocorticography (ECoG) to measure neural activity in epilepsy patients while they listened to a 30 min naturalistic audio story. We fit electrode-wise encoding models using contextual embeddings extracted from each hidden layer of the LLMs to predict word-level neural signals. In line with prior work, we found that larger LLMs better capture the structure of natural language and better predict neural activity. We also found a logarithmic relationship where the encoding performance peaks in relatively earlier layers as model size increases. We also observed variations in the best-performing layer across different brain regions, corresponding to an organized language processing hierarchy.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 4 matches between paragraphs and lines of code.

hassonlab/247-pickling

License: none: the authors keep all their rights
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: b7a6fcb060ecb8276b5dcb090b97e6f5b2983558, 1 March 2023
Languages: Python (15), Jupyter (1), Shell (1)
Size: 23 files, 17 scripts
Software Heritage: archived
Found in: “Data availability”
Holds: README, tests, 1 notebook
Not found: license file, CITATION.cff, environment file, continuous integration, documentation
Tools: NumPy (8 files), pandas (6 files), PyTorch (3 files), Hugging Face Transformers (3 files), SciPy (2 files), scikit-learn (1 file)
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
18 files

hassonlab/247-encoding

License: MIT
State: the link answers, verified on 26 September 2026
Evidence: files inventoried
Commit: 48c27e61a9fd8629d3f5da840d9f1ec2882a365f, 4 September 2026
Languages: Python (8), Shell (1)
Size: 25 files, 9 scripts
Software Heritage: archived
Found in: the references
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (6 files), pandas (5 files), scikit-learn (3 files), PyTorch (2 files), SciPy (2 files), Numba (1 file)
Availability: 1 check, the latest on 26 September 2026: the link answers
  • 26 September 2026: the link answers
11 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 26 scripts, each with its path and the digest of its content;
  • 4 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability

We have recently made the data publicly available (Zada et al., 2025). We have also provided tutorials for preprocessing the data and training encoding models: https://hassonlab.github.io/podcast-ecog-tutorials. For this specific project, the analysis code is available at https://github.com/hassonlab/247-pickling/tree/scaling-paper-1 (copy archived at Kokaja et al., 2026) and https://github.com/hassonlab/247-encoding/tree/scaling-paper-2 (copy archived at Wang, 2026).

The following previously published dataset was used:

Zada Z, Nastase SA, Aubrey B, Jalon I, Goldstein A, Michelmann S, Wang H, Hasenfratz L, Doyle W, Friedman D, Dugan P, Melloni L, Devore S, Devinsky O, Flinker A, Hasson U. 2025. The "Podcast" ECoG dataset. OpenNeuro.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 16 authors, 1 keyword, 6 MeSH terms, 4 funders, 32 references.

Cite

This paper

Hong, Z., Wang, H., Zada, Z., Gazula, H., Turner, D., Aubrey, B., Niekerken, L., Doyle, W., Devore, S., Dugan, P., Friedman, D., Devinsky, O., Flinker, A., Hasson, U., Nastase, S., & Goldstein, A. Y. (2026). Larger language models better align with neural representations of natural language. eLife, 13, RP101204. https://doi.org/10.7554/elife.101204

BibTeX

@article{hong2026larger,
author = {Hong, Zhuoqiao and Wang, Haocheng and Zada, Zaid and Gazula, Harshvardhan and Turner, David and Aubrey, Bobbi and Niekerken, Leonard and Doyle, Werner and Devore, Sasha and Dugan, Patricia and Friedman, Daniel and Devinsky, Orrin and Flinker, Adeen and Hasson, Uri and Nastase, Samuel and Goldstein, Ariel Y},
title = {{Larger language models better align with neural representations of natural language}},
journal = {eLife},
year = {2026},
month = sep,
volume = {13},
pages = {RP101204},
publisher = {eLife Sciences Publications, Ltd},
issn = {2050-084X},
doi = {10.7554/elife.101204},
url = {https://doi.org/10.7554/elife.101204},
pmid = {42746838},
pmcid = {PMC13581289}
}

RIS

TY - JOUR
AU - Hong, Zhuoqiao
AU - Wang, Haocheng
AU - Zada, Zaid
AU - Gazula, Harshvardhan
AU - Turner, David
AU - Aubrey, Bobbi
AU - Niekerken, Leonard
AU - Doyle, Werner
AU - Devore, Sasha
AU - Dugan, Patricia
AU - Friedman, Daniel
AU - Devinsky, Orrin
AU - Flinker, Adeen
AU - Hasson, Uri
AU - Nastase, Samuel
AU - Goldstein, Ariel Y
TI - Larger language models better align with neural representations of natural language
T2 - eLife
J2 - Elife
PY - 2026
DA - 2026/09/16
VL - 13
SP - RP101204
SN - 2050-084X
PB - eLife Sciences Publications, Ltd
DO - 10.7554/elife.101204
UR - https://doi.org/10.7554/elife.101204
LA - en
ER -

CSL-JSON

{
"id": "10.7554/elife.101204",
"type": "article-journal",
"title": "Larger language models better align with neural representations of natural language",
"container-title": "eLife",
"author": [
{
"family": "Hong",
"given": "Zhuoqiao"
},
{
"family": "Wang",
"given": "Haocheng"
},
{
"family": "Zada",
"given": "Zaid"
},
{
"family": "Gazula",
"given": "Harshvardhan"
},
{
"family": "Turner",
"given": "David"
},
{
"family": "Aubrey",
"given": "Bobbi"
},
{
"family": "Niekerken",
"given": "Leonard"
},
{
"family": "Doyle",
"given": "Werner"
},
{
"family": "Devore",
"given": "Sasha"
},
{
"family": "Dugan",
"given": "Patricia"
},
{
"family": "Friedman",
"given": "Daniel"
},
{
"family": "Devinsky",
"given": "Orrin"
},
{
"family": "Flinker",
"given": "Adeen"
},
{
"family": "Hasson",
"given": "Uri"
},
{
"family": "Nastase",
"given": "Samuel"
},
{
"family": "Goldstein",
"given": "Ariel Y"
}
],
"container-title-short": "Elife",
"volume": "13",
"page": "RP101204",
"DOI": "10.7554/elife.101204",
"PMID": "42746838",
"PMCID": "PMC13581289",
"ISSN": "2050-084X",
"publisher": "eLife Sciences Publications, Ltd",
"URL": "https://doi.org/10.7554/elife.101204",
"language": "en",
"issued": {
"date-parts": [
[
2026,
9,
16
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.7554/elife.106543 [code]
Stimulus dependencies-rather than next-word prediction-can explain pre-onset brain encoding in naturalistic listening designs.
Journal: eLife
In common: Hugging Face Transformers, PyTorch, scikit-learn, 3 other tools, 7 references
[2] doi:10.1162/imag.a.1227 [code]
Large language models reveal the neural tracking of linguistic context in attended and unattended multi-talker speech.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Hugging Face Transformers, PyTorch, scikit-learn, 3 other tools, intracranial EEG (iEEG / ECoG / SEEG), 5 references
[3] doi:10.1038/s41467-026-72253-7 [code]
Spurious alignment between large language models and brains can emerge from non-robust methods and overlooked confounds.
Journal: Nature communications
In common: Hugging Face Transformers, PyTorch, scikit-learn, 3 other tools, 4 references
[4] doi:10.1038/s41467-026-73947-8 [code]
Frontal cortex organization supporting audiovisual processing during naturalistic viewing.
Journal: Nature communications
In common: PyTorch, SciPy, NumPy, intracranial EEG (iEEG / ECoG / SEEG), 1 reference, author Adeen Flinker
[5] doi:10.1162/nol.a.244 [code]
A Novel Approach to Map the Causal Impact of Brain Stimulation on Semantic Processing With Language Models.
Journal: Neurobiology of language (Cambridge, Mass.)
In common: Hugging Face Transformers, PyTorch, scikit-learn, 2 other tools, 3 references
[6] doi:10.1038/s41586-026-10691-5 [code]
Mapping the neuronal building blocks of human language with language models.
Journal: Nature
In common: scikit-learn, pandas, SciPy, 1 other tool, 4 references
[7] doi:10.1126/sciadv.aec0518 [code]
Hybrid spatial organization and evidence for magnitude-independent neural coding of linguistic information during sentence production.
Journal: Science advances
In common: intracranial EEG (iEEG / ECoG / SEEG), 2 references, author Adeen Flinker
[8] doi:10.7554/elife.100056 [code]
Multi-talker speech comprehension at different temporal scales in listeners with normal and impaired hearing.
Journal: eLife
In common: PyTorch, scikit-learn, pandas, 2 other tools, 3 references
[9] doi:10.7554/elife.109400 [code]
High-fidelity neural speech reconstruction through an efficient acoustic-linguistic dual-pathway framework.
Journal: eLife
In common: Hugging Face Transformers, PyTorch, SciPy, 1 other tool, intracranial EEG (iEEG / ECoG / SEEG), 2 references
[10] doi:10.1038/s42003-026-10957-8 [code]
Brain defence by the extracellular matrix protein Cochlin.
Journal: Communications biology
In common: Hugging Face Transformers, Numba, PyTorch, 4 other tools

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.