{'fraction_non_alphanumeric': 0.02475900558092339, 'fraction_numerical': 0.006697108066971081, 'mean_word_length': 5.395846852693056, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Explicitly Trained Spiking Sparsity in Spiking Neural Networks with Backpropagation

Spiking Neural Networks (SNNs) are being explored for their potential energy efficiency resulting from sparse, event-driven computations. Many recent works have demonstrated effective backpropagation for deep Spiking Neural Networks (SNNs) by approximating gradients over discontinuous neuron spikes or firing events. A beneficial side-effect of these surrogate gradient spiking backpropagation algorithms is that the spikes, which trigger additional computations, may now themselves be directly considered in the gradient calculations. We propose an explicit inclusion of spike counts in the loss function, along with a traditional error loss, causing the backpropagation learning algorithms to optimize weight parameters for both accuracy and spiking sparsity. As supported by existing theory of over-parameterized neural networks, there are many solution states with effectively equivalent accuracy. As such, appropriate weighting of the two loss goals during training in this multi-objective optimization process can yield an improvement in spiking sparsity without a significant loss of accuracy. We additionally explore a simulated annealing-inspired loss weighting technique to increase the weighting for sparsity as training time increases. Our preliminary results on the Cifar-10 dataset show up to 70.1% reduction in spiking activity with iso-accuracy compared to an equivalent SNN trained only for accuracy and up to 73.3% reduction in spiking activity if allowed a trade-off of 1% reduction in classification accuracy.


INTRODUCTION
Spiking Neural Networks (SNNs) are a type of Artificial Neural Network (ANN) being explored in machine learning in part for their potential energy efficiency benefits due to the inherent computational sparsity that comes from event-driven computation (Han et al. (2018)). The computational energy consumed in a spiking network during inference is highly correlated with the number of spikes that occur because each spike at a given neuron induces accumulation computations in each of that neuron's fan-out neurons as well as a membrane reset computation. Thus, reducing spiking activity is an important part of improving energy efficiency in an SNN.
Until recently, training large-scale SNNs for complicated datasets was a difficult task because discontinuous neuron activations are non-differentiable, preventing direct backpropagation. One of the first workarounds to this problem was converting a pre-trained, non-spiking ANN to an SNN (Sengupta et al. (2019)). This approach allowed for competitive inference on an SNN for complicated tasks like ImageNet, but it failed to capture the energy efficiency benefits of sparsity. This failure was because the networks were trained in a highly precise, deterministic environment, and switching to the stochastic environment of an SNN reduces resolution at small time scales, requiring a larger inference time to accurately distinguish between close activation values. This larger inference time results in a significant number of spiking operations, limiting energy efficiency benefits.
However, more recent works have demonstrated effective methods at backpropagating directly in a spiking environment, e.g. Neftci et al. (2019), Lee et al. (2019). These methods approximate the gradients over the discontinuous spiking activations, allowing for backpropagation through a deep SNN. Lee et al. (2019) have shown that this method of spiking backpropagation significantly reduces the inference time required, and, with that, the total number of spikes and computations that occur per inference, further improving the energy efficiency.
A beneficial side effect of these approximate spiking gradient techniques is that spikes themselves may now be included in these surrogate backpropagation learning algorithms. Since spiking sparsity is an energy goal of SNNs, we propose including spiking activity directly in the loss function, explicitly training the SNNs to be more sparse in a multi-objective optimization process. We additionally explore a simulated annealing-inspired loss function, providing backpropagation with a dynamic weighting of the two optimization goals (accuracy and sparsity), which may help avoid local minima or solution states that significantly sacrifice accuracy. Our preliminary results show that compared to training only for accuracy, explicitly including spiking sparsity in the loss function can achieve around 60-70% reduction in spiking activity on Cifar10 with on-par accuracy.

Using Surrogate Gradients for Backpropagation in Spiking Neural Networks
In SNNs, a spiking activation is often modeled as inducing an instantaneous weighted potentiation in the membrane potentials of fan-out neurons. Neftci et al. (2019) have analyzed the effectiveness of various "surrogate" or approximate gradients over spiking activations, including fast-sigmoid, linear, and exponential surrogates, and have developed open-source code for easy backpropagation in PyTorch using these surrogate gradients, called SpyTorch (Zenke (2019)). These approximate gradients allow us to choose any criterion for the loss function, L(), based on final classification error, e.g. mean squared error, cross entropy, etc., and let the automatic software tools perform backpropagation.

Adding Spiking Activity to the Loss Functions
Poggio and Liao (2018) have shown that the global minima for over-parameterized networks often reside in flat valleys or basins within the optimization space. This means that many neighboring solutions have effectively equivalent accuracy. These flat regions provide flexibility. Our goal is to let the optimizer find solutions within those flat basins that have less spiking activity without compromising accuracy.
Being able to differentiate over spiking events enables gradient descent based on a loss that includes a measure of those spikes. The total loss, then, can be a combination of both the classification accuracy goal and the spiking sparsity goal: where σ() is a weighting function that scales the spike count loss to provide appropriate balancing between the two loss components in (2).

The Sparsity Loss Function, σ()
The most trivial approach for σ() would be to use a constant scalar: We consider a potential problem from adding in a sparsity loss function. When we change the optimization topography, if the optimizer is constrained for sparsity too much, too early in the training process, the gradients in the new landscape may not allow the system to reach solution states that also reside in the basins of the classification landscape, causing a significant reduction or complete failure of the classification accuracy. So for the constant sparsity loss scaling function, σ 0 must be small enough to allow the classification loss to dominate the total gradient direction if classification accuracy is to be maintained. However, letting the classification loss dominate too much, even after reaching the basins, may fail to achieve the best sparsity.
We explore a potential solution to this problem, inspired by simulated annealing-allow the optimizer to disregard sparsity early in the training process and then slowly increase the constraints for spiking sparsity as training continues. This approach makes σ() a function of training time, or more simply, the current training epoch. In addition to the constant sparsity loss function, we evaluate four annealing-inspired sparsity loss functions that increase the sparsity constraint over time. These include a linear increase (equation (5)) and a quadratic increase (equation (6)). The other two loss functions alternate between excluding and including the sparsity loss function throughout the training process, where the portion of epochs in which the sparsity loss is included increases linearly during training from zero-inclusion during the first epoch to always-included in the last epoch. The first of these alternating loss functions uses a constant σ 0 when it the sparsity loss is included (equation (7)), and the other uses a linearly increasing σ 0 when it is included (equation (8)).
σ alternating linear (spikeCount, where A() is a binary value following the the alternating function discussed above.

Experimental Methodology
Experiments were conducted in PyTorch with SpyTorch using backpropagation with piece-wise linear surrogate gradients on the Cifar-10 dataset with the LeNet architecture. (This paper will be updated with results from larger and deeper architectures.) Cross entropy was chosen as the classification loss function. For each of the sparsity loss functions discussed above, we performed a hyperparameter search to discover the largest σ 0 that still provides acceptable classification accuracy based on the validation set. We set aside 20% of the training set as a validation set and trained with the remaining 80%. Both the sparsity loss scaling constant, σ 0 , and the number of training epochs were determined based on the validation results.

RESULTS
Using the hyperparameters for each method that gave the best spiking sparsity with zero increase in validation error, we report the testing results in Table 1. Using the hyperparameters for each method that gave the best spiking sparsity with less than 1% reduction in validation classification accuracy, we report the testing results in Table 2.

DISCUSSION
Discussion forthcoming. (Results are very preliminary and further experiments are underway.) Note that baseline accuracy values are low because these preliminary results are on LeNet and for the reduced training set (with the validation set removed). We expect that moving to better networks and re-including the removed validation set into training (after hyperparameter selection) will significantly improve results.