{"id":18850942,"url":"https://github.com/igitugraz/memorydependentcomputation","last_synced_at":"2025-04-14T09:51:37.431Z","repository":{"id":38819518,"uuid":"485830606","full_name":"IGITUGraz/MemoryDependentComputation","owner":"IGITUGraz","description":"Code for Limbacher, T., Özdenizci, O., \u0026 Legenstein, R. (2022). Memory-enriched computation and learning in spiking neural networks through Hebbian plasticity. arXiv preprint arXiv:2205.11276.","archived":false,"fork":false,"pushed_at":"2023-03-28T11:55:10.000Z","size":3806,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-27T23:11:13.919Z","etag":null,"topics":["associations","babi-tasks","cross-modal-learning","hebbian-learning","memory-networks","neural-networks","one-shot-learning","python","pythorch","question-answering","recurrent-neural-networks","reinforcement-learning","spiking-neural-networks"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IGITUGraz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-26T14:52:12.000Z","updated_at":"2025-03-22T01:53:15.000Z","dependencies_parsed_at":"2024-11-08T03:33:56.130Z","dependency_job_id":"0b5ea217-f18b-46e3-a59d-dec967d98bdc","html_url":"https://github.com/IGITUGraz/MemoryDependentComputation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IGITUGraz%2FMemoryDependentComputation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IGITUGraz%2FMemoryDependentComputation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IGITUGraz%2FMemoryDependentComputation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IGITUGraz%2FMemoryDependentComputation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IGITUGraz","download_url":"https://codeload.github.com/IGITUGraz/MemoryDependentComputation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248859655,"owners_count":21173337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["associations","babi-tasks","cross-modal-learning","hebbian-learning","memory-networks","neural-networks","one-shot-learning","python","pythorch","question-answering","recurrent-neural-networks","reinforcement-learning","spiking-neural-networks"],"created_at":"2024-11-08T03:32:44.016Z","updated_at":"2025-04-14T09:51:37.399Z","avatar_url":"https://github.com/IGITUGraz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/memory-enriched-computation-and-learning-in/question-answering-on-babi)](https://paperswithcode.com/sota/question-answering-on-babi?p=memory-enriched-computation-and-learning-in)\n\n# Memory-enriched computation and learning in spiking neural networks through Hebbian plasticity\nThis is the official code for the paper \"Memory-enriched computation and learning in spiking neural networks through\nHebbian plasticity\" ([[Abstract] arxiv.org](https://arxiv.org/abs/2205.11276),\n[[PDF] arxiv.org](https://arxiv.org/pdf/2205.11276.pdf)).\n\n## Setup\nYou need [PyTorch](https://pytorch.org) to run this code. We tested it on PyTorch version 1.7.0.\nAdditional dependencies are listed in [environment.yml](environment.yml). If you use\n[Conda](https://docs.conda.io/en/latest/), run\n```bash\nconda env create --file=environment.yml\n```\nto install the required packages and their dependencies.\n\n## Usage\nBelow you will find a short description of each task presented in the paper and instructions on how to reproduce the\nresults.\n\n### Memorizing associations\nIn this task we tested the ability of our model to one-shot memorize associations and to use these associations later\nwhen needed. The task requires to form associations between random continuous-valued vectors and integer labels that\nwere sequentially presented to the network.\n\n#### Training\nTo start training on the association task, run\n```bash\npython memorizing_associations_task.py [optional arguments]\n```\nSet the command line argument `--sequence_length` to set the number of vector-label pairs (in the paper we used\nsequences ranging from 1 to 55). Here, the command line argument `--num_classes` should be set to the same value.\n\nTo test the out-of-distribution capability of our model in this task, set `--sequence_length` \u003c `--num_classes` and then\ntest the model with 2 \u003c `--sequence_length` \u003c= `--num_classes`.\n\n#### Testing\nTo evaluate a trained model on the test data set, run:\n```bash\npython memorizing_associations_task.py --resume='PATH_TO_CHECKPOINT_FILE' --evaluate [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n#### Plotting\nTo plot the network activity and the model's output after training, run:\n```bash\npython plot_memorizing_associations_task.py --checkpoint_path='PATH_TO_CHECKPOINT_FILE' [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n### One-shot Learning\nHere we applied our model to the problem of 1-shot 5-way classification on the\n[Omniglot](https://github.com/brendenlake/omniglot) data set. We used a CNN as input encoder for the Omniglot images,\nwhich was pre-trained using the prototypical loss and then converted into a spiking CNN by using a threshold-balancing \nalgorithm. The checkpoint of this CNN is available\n[here](results/checkpoints/omniglot-one-shot-task-protonet-checkpoint.pth.tar) in this repository.\n\n#### Training\nTo start training on the Omniglot 1-shot task, run\n```bash\npython omniglot_one_shot_task.py [optional arguments]\n```\n\n#### Testing\nTo evaluate a trained model on the test data set, run:\n```bash\npython omniglot_one_shot_task.py --resume='PATH_TO_CHECKPOINT_FILE' --evaluate [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n#### Plotting\nTo plot the network activity and the model's output after training, run:\n```bash\npython plot_omniglot_one_shot_task.py --checkpoint_path='PATH_TO_CHECKPOINT_FILE' [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n### Cross-modal associations\nIn this task we asked whether Hebbian plasticity can enable SNNs to perform cross-modal associations. We trained our\nmodel in an autoencoder-like fashion. We used the [FSDD](https://github.com/Jakobovski/free-spoken-digit-dataset) and\nthe [MNIST](http://yann.lecun.com/exdb/mnist/) data set in this task. We used two CNNs as input\nencoder which were pre-trained on FSDD/MNIST classification respectively and then converted into spiking CNNs by using\nthe threshold-balancing algorithm. The checkpoints of these CNNs are available\n[here](results/checkpoints/cross-modal-associations-task-audio-protonet-checkpoint.tar) and\n[here](results/checkpoints/cross-modal-associations-task-image-protonet-checkpoint.tar) in this repository.\n\n#### Training\nTo start training on the cross-modal associations task, run\n```bash\npython cross_modal_associations_task.py [optional arguments]\n```\n\n#### Testing\nTo evaluate a trained model on the test data set, run:\n```bash\npython cross_modal_associations_task.py --resume='PATH_TO_CHECKPOINT_FILE' --evaluate [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n#### Plotting\nTo plot the network activity and the model's output after training, run:\n```bash\npython plot_cross_modal_associations_task.py --checkpoint_path='PATH_TO_CHECKPOINT_FILE' [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n### Question Answering\nIn this task we applied our model to the [bAbI](https://research.facebook.com/downloads/babi/) data set. We used 10k\ntraining examples and trained models on each of the 20 tasks individually.\n\n#### Training\nTo start training on bAbI task 1 in the 10k training examples setting, run\n```bash\npython question_answering_task.py [optional arguments]\n```\nSet the command line argument `--task` to train on other tasks. To set the synaptic delay in the feedback loop, use the\ncommand line argument `--readout_delay` (in the paper we have used 1ms and 30ms).\n\n#### Testing\nTo evaluate a trained model on the test data set, run:\n```bash\npython question_answering_task.py --resume='PATH_TO_CHECKPOINT_FILE' --evaluate [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n#### Plotting\nTo plot the network activity and the model's output after training, run:\n```bash\npython plot_question_answering_task.py --checkpoint_path='PATH_TO_CHECKPOINT_FILE' [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n### Reinforcement Learning\nHere we evaluated our model on an episodic reinforcement learning task. The task is based on the popular children’s game\n[Concentration](https://en.wikipedia.org/wiki/Concentration_(card_game)). We consider a one-player solitaire version of\nthe game. In this version of the game the objective is to find all matching pairs with as few card flips as possible.\n\n#### Training\nTo start training on the Concentration game with a deck of four cards, run\n```bash\npython reinforcement_learning_task.py --decay_lr_linearly [optional arguments]\n```\nUse the command line argument `--num_cells` to set the number of cards (in the paper we have used 4 and 6). You will\nalso need to adjust `--num_steps` (we have used `--num_steps=10` for the 4-cards game and `--num_steps=100` for the\n6-cards game). To use a new deck of cards for each game use `--resample_cards`.\n\n#### Testing\nTo evaluate a trained model, run:\n```bash\npython reinforcement_learning_task.py --decay_lr_linearly --resume='PATH_TO_CHECKPOINT_FILE' --evaluate [optional arguments]\n```\nThe optional arguments must be set to the same values as during training, otherwise an error is thrown.\n\n## Multiprocessing Distributed Data Parallel Training\nModel training can be distributed across multiple GPUs and multiple nodes (see below for examples). You should always\nuse the NCCL backend for multiprocessing distributed training since it currently provides the best distributed training\nperformance.\n\n### Single node, multiple GPUs:\n```bash\npython SOME_SCRIPT.py --dist_url 'tcp://127.0.0.1:FREE_PORT' --dist_backend 'nccl' --multiprocessing_distributed --world_size 1 --rank 0 [optional arguments]\n```\n\n### Multiple nodes:\nNode 0:\n```bash\npython SOME_SCRIPT.py --dist_url 'tcp://IP_OF_NODE0:FREE_PORT' --dist_backend 'nccl' --multiprocessing_distributed --world_size 2 --rank 0 [optional arguments]\n```\n\nNode 1:\n```bash\npython SOME_SCRIPT.py --dist_url 'tcp://IP_OF_NODE0:FREE_PORT' --dist_backend 'nccl' --multiprocessing_distributed --world_size 2 --rank 1 [optional arguments]\n```\n\n## Reference\nIf you use this code or models in your research and find it helpful, please cite the following paper:\n```\n@article{limbacher2022memory,\n  title={Memory-enriched computation and learning in spiking neural networks through Hebbian plasticity},\n  author={Limbacher, Thomas and {\\\"O}zdenizci, Ozan and Legenstein, Robert},\n  journal={arXiv preprint arXiv:2205.11276},\n  year={2022}\n}\n```\n\n## Acknowledgments\nAuthors of this work are affiliated with Graz University of Technology, Institute of Theoretical Computer Science,\nand Silicon Austria Labs, TU Graz - SAL Dependable Embedded Systems Lab, Graz, Austria. This work was supported by the\nCHIST-ERA grant CHIST-ERA-18-ACAI-004, by the Austrian Science Fund (FWF) project number I 4670-N (project SMALL), and\nby the \"University SAL Labs\" initiative of Silicon Austria Labs (SAL). We thank Wolfgang Maass and Arjun Rao for\ninitial discussions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figitugraz%2Fmemorydependentcomputation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figitugraz%2Fmemorydependentcomputation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figitugraz%2Fmemorydependentcomputation/lists"}