The Brain Encoding Response Generator (BERG) is a resource consisting of multiple pre-trained encoding models of the brain and an accompanying Python package to generate accurate in silico neural responses to arbitrary stimuli with just a few lines of code.
In silico neural responses from encoding models increasingly resemble in vivo responses recorded from real brains, enabling the novel research paradigm of in silico neuroscience. In silico neural responses are quick and cheap to generate, allowing researchers to explore and test scientific hypotheses across vastly larger solution spaces than possible in vivo. Novel findings from large-scale in silico experimentation are then validated through targeted small-scale in vivo data collection, in this way optimizing research resources. Thus, in silico neuroscience scales beyond what is possible with in vivo data, and democratizes research across groups with diverse data collection infrastructure and resources. To catalyze this emerging research paradigm, we introduce the Brain Encoding Response Generator (BERG), a resource consisting of multiple pre-trained encoding models of the brain and an accompanying Python package to generate accurate in silico neural responses to arbitrary stimuli with just a few lines of code. BERG includes a growing, well documented library of encoding models trained on different neural data acquisition modalities, datasets, subjects, stimulation types, and brain areas, offering broad versatility for addressing a wide range of research questions through in silico neuroscience.
For additional information on BERG, you can check out our paper and documentation.
We warmly welcome contributions to improve and expand BERG, including:
- Encoding models with higher prediction accuracies.
- Encoding models for new neural data recording modalities (e.g., MEG/ECoG/animal).
- Encoiding models from new neural dataset.
- Encoding models of neural responses for new stimulus types (e.g., videos, audio, language, multimodal).
- Suggestions to improve BERG.
For more information on how to contribute, please refer to our documentation. If you have questions or would like to discuss your contribution before submitting, please contact us at brain.berg.info@gmail.com. All feedback and help is strongly appreciated!
To install BERG
run the following command on your terminal:
pip install -U git+https://github.com/gifale95/BERG.git
You will additionally need to install the Python dependencies found in requirements.txt.
BERG is hosted as a public AWS S3 bucket via the AWS Open Data Program. You do not need an AWS account to browse or download the data.
IMPORTANT: By downloading the data you agree to BERG's Terms and Conditions.
To download the full BERG dataset into a local folder named brain-encoding-response-generator
, use the AWS CLI:
aws s3 sync --no-sign-request s3://brain-encoding-response-generator ./brain-encoding-response-generator
You can also download specific subfolders, for example:
aws s3 sync --no-sign-request s3://brain-encoding-response-generator/encoding_models/modality-fmri ./modality-fmri
Or, you can also downlaod specific files:
aws s3 cp --no-sign-request s3://brain-encoding-response-generator/encoding_models/../model_weights.npy ./modality-fmri
For detailed instructions and folder structure, see the documentation.
The following table shows the encoding models currently available in BERG. For more details on these models, please refer to the documentation.
Model ID | Training dataset | Acquisition device | Species | Stimuli |
---|---|---|---|---|
fmri-nsd_fsaverage-huze | NSD (surface space) | fMRI | Human | Images |
fmri-nsd_fsaverage-vit_b_32 | NSD (surface space) | fMRI | Human | Images |
fmri-nsd-fwrf | NSD (volume space) | fMRI | Human | Images |
eeg-things_eeg_2-vit_b_32 | THINGS EEG2 | EEG | Human | Images |
To use BERG
's functions, you first need to import BERG
and create a berg_object
.
from berg import BERG
# Initialize BERG with the path to the toolkit
berg = BERG(berg_dir="path/to/brain-encoding-response-generator")
Step 1: Load an encoding model of your choice using the get_encoding_model
function.
# Load an example fMRI encoding model
fmri_model = berg.get_encoding_model("fmri-nsd-fwrf",
subject=1,
selection={"roi": "V1"},
device="cpu")
# Load an example EEG encoding model
eeg_model = berg.get_encoding_model("eeg-things_eeg_2-vit_b_32",
subject=1,
device="auto")
Step 2: Generate in silico neural responses to stimuli using the encode
function.
# Encode fMRI responses to images with metadata
insilico_fmri, insilico_fmri_metadata = berg.encode(fmri_model,
images,
return_metadata=True) # if needed
# Encode EEG responses to images without metadata
insilico_eeg = berg.encode(eeg_model,
images)
For more detailed information on how to use these functions and which parameters are available, please refer to the Tutorials below β¬οΈ.
We provide several tutorials to help you get started with BERG:
Using BERG:
- Quickstart Tutorial - Quick Guide on how to generate in silico neural responses
- fMRI Tutorial - Learn how to generate in silico fMRI responses.
- EEG Tutorial - Learn how to generate in silico EEG responses.
- Adding New Models - Guide on how to implement and contribute your own encoding models to BERG.
Example Application - Relational Neural Control (RNC):
We used BERG to develop Relational Neural Control, a neural control algorithm to move from an atomistic understanding of visual cortical areas (i.e., What does each area represent?) to a network-level understanding (i.e., What is the relationship between representations in different areas?). Through RNC we discovered controlling images that align or disentangle responses across areas, thus indicating their shared or unique representational content. Closing the empirical cycle, we validated the in silico discoveries on in vivo fMRI responses from independent subjects. Following are RNC tutorials based on in silico fMRI responses generated through BERG:
The folder ../BERG/berg_creation_code/
contains the code used to train the encoding models in BERG, divided in the following sub-folders:
../01_prepare_data/
: prepare the neural responses in the right format for encoding model training.../02_train_encoding_models/
: train the encoding models, and save their weights.../03_test_encoding_models/
: test the encoding models (i.e., compute and plot their encoding accuracy).
If you come across problems with this Python package, please submit an issue!
If you use the Brain Encoding Response Generator, please cite:
Gifford AT, Bersch D, Janini D, Roig G, Cichy RM. 2025. The Brain Encoding Response Generator. In preparation. https://github.com/gifale95/BERG