Neural Encoding and Decoding at Scale

Yizi Zhang, Yanchen Wang, Mehdi Azabou, Alexandre Andre, Zixuan Wang, Hanrui Lyu, The International Brain Laboratory, Eva Dyer, Liam Paninski, Cole Hurwitz

TL;DR

The paper introduces NEDS (Neural Encoding and Decoding at Scale), a multimodal transformer model that unifies neural encoding and decoding into a single framework. By leveraging a novel multi-task-masking strategy and pretraining across dozens of animals, NEDS achieves state-of-the-art performance on new, unseen subjects and naturally learns neuron embeddings that map out distinct brain regions without explicit supervision.

What Problem Does This Paper Address?

In systems neuroscience, understanding the relationship between brain activity and behavior typically falls into two categories: encoding (predicting neural spikes from behavioral inputs) and decoding (predicting behavior from neural spikes).

While recent deep learning foundation models have scaled up neural data analysis, existing large-scale models are strictly task-specific—they are engineered to perform either encoding or decoding, but not both. This one-way bottleneck prevents models from capturing the true bidirectional, closed-loop relationship between the brain and behavior. Furthermore, building a unified model is challenging due to the heterogeneous nature of neural recordings (which span different animals, sessions, and brain regions) and behavioral data (which mix continuous signals like velocity with discrete choices).

Methods

To bridge this gap, the authors present NEDS, a multimodal transformer architecture designed to seamlessly translate between neural activity and behavior.

Figure 1. Schematic illustration of NEDS . (A) Neural encoding and decoding can be interpreted as modeling the conditional probability distributions between neural activity and behavior (Schulz et al., 2025). In NEDS, we utilize a multi-task-masking approach (Tay et al., 2022; Zhang et al., 2024a) to model the conditional expectations of these distributions as well as to encourage cross-modal and within-modality representation learning. This is achieved by alternating between neural, behavioral, within-modality, and cross-modal masking during training. (B) We implement NEDS using a multimodal transformer-based architecture. We utilize modality-specific tokenizers that convert spike counts and continuous behaviors into 20ms temporal tokens and discrete behaviors into sequences of repeated tokens, aligning with the temporal resolution of the continuous data. We then add temporal, modality, and session embeddings to the tokens. We train NEDS by masking out tokens according to the masking schemes from (A) and then predicting them with modality-specific decoders. Our multimodal architecture builds on work from other domains (He et al., 2022; Mizrahi et al., 2023; Fang et al., 2024).

The core innovation is a multi-task-masking strategy applied during self-supervised pretraining. Instead of standard token masking, NEDS alternates between four distinct masking schemes:

  1. Neural Masking: Completely masks neural activity to force the model to predict spikes from behavior (learning the encoding distribution).
  2. Behavior Masking: Completely masks behavioral variables to force the model to predict actions from spikes (learning the decoding distribution).
  3. Within-Modality Random Masking: Randomly masks tokens within a single modality to capture intra-modal dependencies.
  4. Cross-Modal Random Masking: Randomly masks tokens across both modalities to encourage the model to learn joint representations.

Architecturally, NEDS tokenizes neural spike counts and behavioral variables independently using modality-specific tokenizers. These tokens are augmented with temporal, modality, and session-specific embeddings before being fed into a shared transformer encoder. Modality-specific decoders then reconstruct the original data based on the masking task.

Datasets

The primary dataset used for pretraining and evaluation is the International Brain Laboratory (IBL) repeated site dataset. This massive open-science resource contains Neuropixels recordings from 83 mice performing the same visual decision-making task. The dataset includes:

  • Neural data from 27,380 neurons across 225 brain regions.
  • Four behavioral task variables: whisker motion, wheel speed, choice (left/right), and the "block" prior.

The model was pretrained on 73 animals (74 sessions) and evaluated on 10 held-out animals. To demonstrate cross-species flexibility, the authors also validated NEDS on the MC-RTT primate motor task dataset, a benchmark involving Utah array recordings from monkeys performing a target-reaching task.

Key Insights and Ideas

  • Unification via Masking: NEDS proves that neural encoding and decoding do not require separate architectures. Treating them as conditional probability distributions that can be toggled via targeted masking allows a single transformer to excel at both.
  • The Power of Multi-Animal Scaling: Pretraining on data from dozens of animals provides a massive boost when fine-tuning on a completely new subject. The model learns generalized features of the mouse brain that transfer across individuals.
  • Emergent Anatomical Mapping: One of the most striking findings is that NEDS's learned neuron embeddings naturally cluster by anatomical brain regions. Even though the model was never given brain region labels during training, the latent space inherently organized itself by functional anatomy.

Key Results

NEDS consistently outperformed linear baselines, unimodal variants, and state-of-the-art large-scale models like POYO+ and NDT2.

Figure 2. Quantitative and qualitative evaluation of single-session and multi-session NEDS. (A) We evaluate multi-session NEDS and single-session NEDS models against our linear baselines and the single-session, unimodal variant of NEDS. Our results show that multi-session NEDS consistently outperforms all baselines across all tasks, while single-session NEDS outperforms all baselines except in block decoding. These findings demonstrate the advantages of multimodal training and cross-animal pretraining for neural encoding and decoding. Among the baseline models, RRR has the fewest parameters (1,000 ∼20,000 on average). Linear models contain approximately 40,000 to 70,000 parameters on average. Both the single-session unimodal and multimodal NEDS share the same transformer encoder size (∼3 million parameters). The multi-session NEDS is the largest model with ∼12 million parameters in its transformer encoder. (B) A scatterplot comparison of multi-session NEDS pretrained on 74 sessions vs. single-session NEDS. Each dot corresponds to an individual session. The green value in the bottom right of each subplot displays the relative improvement of the 74-session NEDS over single-session NEDS. (C) A comparison of the predicted trial-averaged firing rates for single-session and multi-session NEDS against the ground truth trial-averaged spike counts for selected neurons. Predictions from multi-session NEDS more closely matches the ground truth. (D) Each row compares single-session and multi-session NEDS predictions of single-trial variability for a neuron against the ground truth. Single-trial variability is obtained by subtracting the neuron’s peristimulus time histogram (PSTH) from its activity in each trial. Only selected trials are shown for visualization purposes. (E, F) The predicted wheel speed and whisker motion energy from both the single-session and multi-session NEDS are shown alongside ground truth behaviors for each trial.
  • Encoding & Decoding Boost: Multi-session NEDS improved decoding performance by 4–11% and spike encoding by 24% compared to its single-session counterpart.
  • Baseline Comparison: When evaluated on held-out animals, NEDS outperformed the self-supervised neural model NDT2 by 11–37% and the multi-task decoding model POYO+ by 1–13% across all decoding metrics.
  • Anatomical Classification: Linear classifiers trained on NEDS's emergent neuron embeddings predicted the correct brain region with 83% accuracy (compared to just 45-50% for unimodal versions).

Limitations and Future Work

While NEDS represents a major step toward a neural foundation model, the authors note a few key limitations:

  • Trial-Alignment Dependency: The current framework relies entirely on trial-aligned data, which restricts the volume of training data that can be ingested. Future iterations will aim to leverage unaligned, continuous recordings.
  • Compute Constraints: Due to high computational costs, extensive hyperparameter tuning was not performed during the full 73-animal pretraining phase.
  • Modality Expansion: The authors plan to extend NEDS to incorporate additional neural modalities, such as local field potentials (LFPs) and raw electrophysiological waveforms, which could unlock the ability to identify specific cell types.

Summary updated

BibTeX
@inproceedings{zhang2025neural,
  author = {Yizi Zhang and Yanchen Wang and Mehdi Azabou and Alexandre Andre and Zixuan Wang and Hanrui Lyu and The International Brain Laboratory and Eva Dyer and Liam Paninski and Cole Hurwitz},
  title = {{Neural Encoding and Decoding at Scale}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=vOdz3zhSCj},
}
Figure