{"id":18439463,"url":"https://github.com/idiap/sparch","last_synced_at":"2025-10-26T14:40:36.769Z","repository":{"id":144962733,"uuid":"523391451","full_name":"idiap/sparch","owner":"idiap","description":"PyTorch based toolkit for developing spiking neural networks (SNNs) by training and testing them on speech command recognition tasks","archived":false,"fork":false,"pushed_at":"2024-05-03T02:29:20.000Z","size":24,"stargazers_count":23,"open_issues_count":3,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-23T01:01:51.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSES/BSD-3-Clause.txt","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-08-10T15:11:02.000Z","updated_at":"2025-01-10T08:18:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"060506b7-f0e9-4529-ac2a-8c8e950a7e75","html_url":"https://github.com/idiap/sparch","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/idiap%2Fsparch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fsparch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fsparch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiap%2Fsparch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiap","download_url":"https://codeload.github.com/idiap/sparch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247732686,"owners_count":20986902,"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":[],"created_at":"2024-11-06T06:24:52.315Z","updated_at":"2025-10-26T14:40:36.687Z","avatar_url":"https://github.com/idiap.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: Copyright © 2022 Idiap Research Institute \u003ccontact@idiap.ch\u003e\n\nSPDX-FileContributor: Alexandre Bittar \u003cabittar@idiap.ch\u003e\n\nSPDX-License-Identifier: BSD-3-clause\n\nThis file is part of the sparch package\n---\u003e\n\n# SpArch: Spiking Architectures for Speech Technology\n\nThis [PyTorch](https://pytorch.org/) based toolkit is for developing spiking neural networks (SNNs) by training and testing them on speech command recognition tasks. It was published as part of the following paper: [A Surrogate Gradient Spiking Baseline for Speech Command Recognition](https://doi.org/10.3389/fnins.2022.865897) by A. Bittar and P. Garner (2022).\n\n\n## Data\n\n### Spiking data sets\n\nIn order to rectify the absence of free spike-based benchmark datasets, [Cramer et al. (2020)](https://doi.org/10.1109/TNNLS.2020.3044364) have recently released two spiking datasets for speech command recognition using [LAUSCHER](https://github.com/electronicvisions/lauscher), a biologically plausible model to convert audio waveforms into spike trains based on physiological processes.\n\n- The Spiking Heidelberg Digits (SHD) dataset contains spoken digits from 0 to 9 in both English and German (20 classes). The train and test sets contain 8332 and 2088 examples respectively (there is no validation set).\n\n- The Spiking Speech Commands (SSC) dataset is based on the Google Speech Commands v0.2 dataset and contains 35 classes from a larger number of speakers. The number of examples in the train, validation and test splits are 75466, 9981 and 20382 respectively.\n\nBoth data sets can be downloaded from the [Zenke Lab website](https://zenkelab.org/resources/spiking-heidelberg-datasets-shd/).\n\n### Non-spiking data sets\n\nThe original, non-spiking versions of the SHD and SSC datasets are also available and can be used in this framework. With our approach, acoustic features are extracted from the waveforms and directly fed into spiking neural networks. The conversion from filterbank features to spike trains therefore happens in a trainable fashion inside the neuronal dynamics of the first hidden layer. Moreover, the initial (non-trainable) transformation of the audio waveforms into filterbank features is fast enough to be performed during training, so that no preliminary processing of the audio is required.\n\n- The Heidelberg Digits (HD) data set can also be downloaded from the same [website](https://zenkelab.org/resources/spiking-heidelberg-datasets-shd/) as its spiking counterpart.\n\n- The second version of the (non-spiking) Google Speech Command (SC) data set, introduced by [Warden (2018)](https://arxiv.org/abs/1804.03209), can be found on the [TensorFlow website](https://www.tensorflow.org/datasets/catalog/speech_commands).\n\nNote that the training/validation/testing splits are different for the SC and SSC data sets. The SC has a 80% / 10% / 10% partition instead of 70% / 10% / 20% for the SSC, which makes a direct comparison impossible between the accuracies on the two tasks.\n\n## Installation\n\n    git clone https://github.com/idiap/sparch.git\n    cd sparch\n    pip install -r requirements.txt\n    python setup.py install\n\n### Run experiments\n\nAll experiments on the speech command recognition datasets can be run from the `run_exp.py` script. The experiment configuration can be specified using parser arguments. Run the command `python run_exp.py -h` to get the descriptions of all possible options. For instance, if you want to run a new SNN experiment with adLIF neurons on the SC dataset,\n\n    python run_exp.py --model_type adLIF --dataset_name sc \\\n        --data_folder \u003cPATH-TO-DATASET-FOLDER\u003e --new_exp_folder \u003cOUTPUT-PATH\u003e\n\nYou can also continue training from a checkpoint\n\n    python run_exp.py --use_pretrained_model 1 --load_exp_folder \u003cOUTPUT-PATH\u003e \\\n        --dataset_name sc --data_folder \u003cPATH-TO-DATASET-FOLDER\u003e \\\n        --start_epoch \u003cLAST-EPOCH-OF-PREVIOUS-TRAINING\u003e\n\n\n## Usage\n\nSpiking neural networks (SNNs) based on the surrogate gradient approach are defined in `sparch/models/snn_models.py` as PyTorch modules. We distinguish between four types of spiking neuron models based on the linear Leaky Integrate and Fire (LIF),\n\n- LIF: LIF neurons without layer-wise recurrent connections\n- RLIF: LIF neurons with layer-wise recurrent connections\n- adLIF: adaptive LIF neurons without layer-wise recurrent connections\n- RadLIF: adaptive LIF neurons with layer-wise recurrent connections.\n\nAn SNN can then be simply implemented as a PyTorch module:\n\n    from sparch.models.snns import SNN\n\n    # Build input\n    batch_size = 4\n    nb_steps = 100\n    nb_inputs = 20\n    x = torch.Tensor(batch_size, nb_steps, nb_inputs)\n    nn.init.uniform_(x)\n\n    # Define model\n    model = SNN(\n        input_shape=(batch_size, nb_steps, nb_inputs),\n        neuron_type=\"adLIF\",\n        layer_sizes=[128, 128, 10],\n        normalization=\"batchnorm\",\n        dropout=0.1,\n        bidirectional=False,\n        use_readout_layer=False,\n        )\n\n    # Pass input through SNN\n    y, firing_rates = model(x)\n\n\nand used for other tasks. Note that by default, the last layer of the SNN is a readout layer that produces non-sequential outputs. For sequential outputs, simply set `use_readout_layer=False`. Moreover, the inputs do not have to be binary spike trains.\n\nStandard artificial neural networks (ANNs) with non-spiking neurons are also defined in `sparch/models/ann_models.py`, in order to have a point of comparison for the spiking baseline. We implemented the following types of models: MLPs, RNNs, [LiGRUs](https://doi.org/10.1109/TETCI.2017.2762739) and [GRUs](https://doi.org/10.48550/arXiv.1406.1078).\n\n## Structure of the git repository\n\n```\n.\n├── sparch\n│   ├── dataloaders\n|   |   ├── nonspiking_datasets.py\n│   │   └── spiking_datasets.py\n│   ├── models\n|   |   ├── anns.py\n│   │   └── snns.py\n│   ├── parsers\n|   |   ├── model_config.py\n│   │   └── training_config.py\n│   └── exp.py\n|\n└── run_exp.py\n```\n\n## Citation\nIf you use this framework in your research, please cite it as\n```\n@article{bittar2022surrogate,\n  title={A surrogate gradient spiking baseline for speech command recognition},\n  author={Bittar, Alexandre and Garner, Philip N},\n  journal={Frontiers in Neuroscience},\n  volume={16},\n  year={2022},\n  publisher={Frontiers},\n  doi={10.3389/fnins.2022.865897}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiap%2Fsparch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiap%2Fsparch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiap%2Fsparch/lists"}