{'fraction_non_alphanumeric': 0.03694129419613076, 'fraction_numerical': 0.011716144096064043, 'mean_word_length': 4.718884120171674, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
T2FSNN: Deep Spiking Neural Networks with Time-to-first-spike Coding

Spiking neural networks (SNNs) have gained considerable interest due to their energy-efficient characteristics, yet lack of a scalable training algorithm has restricted their applicability in practical machine learning problems. The deep neural network-to-SNN conversion approach has been widely studied to broaden the applicability of SNNs. Most previous studies, however, have not fully utilized spatio-temporal aspects of SNNs, which has led to inefficiency in terms of number of spikes and inference latency. In this paper, we present T2FSNN, which introduces the concept of time-to-first-spike coding into deep SNNs using the kernel-based dynamic threshold and dendrite to overcome the aforementioned drawback. In addition, we propose gradient-based optimization and early firing methods to further increase the efficiency of the T2FSNN. According to our results, the proposed methods can reduce inference latency and number of spikes to 22% and less than 1%, compared to those of burst coding, which is the state-of-the-art result on the CIFAR-100.


I. INTRODUCTION
Recent advances in deep neural networks (DNNs) have led to state-of-the-art results in a variety of applications. These DNNs, however, demand a substantial amount of computation and power consumption, which restricts the employment of deep learning to edge devices. To overcome these challenges, many studies have focused on reducing the model size and the amount of computation through quantization [1] and pruning [2]. Despite these attempts, the complexity of the DNN models has increased rapidly, making it difficult to deploy the DNNs efficiently in resource-constrained environments, such as mobile devices [3].
Spiking neural networks (SNNs) have emerged as the next generation of neural networks for their superior energy efficiency caused by the features of integrate-and-fire and eventbased operations [4]. Although SNNs have the potential for improving energy efficiency of artificial neural networks, deep SNNs have not been widely used in many applications due to lack of scalable training algorithms. Deep SNNs have been struggling to achieve competitive results compared to DNNs. Although many studies about direct training with approximate stochastic gradient descent (SGD) have been published recently [5], [6], they have shown unsatisfactory results.
DNN-to-SNN conversion methods have been proposed in recent years [7], [8], [9], [10], [11], [12], [13] to address the issue of training deep SNNs. Using the conversion methods, * corresponding author: Sungroh Yoon (sryoon@snu.ac.kr) deep SNNs can exploit the DNNs' training performance with the pretrained synaptic weights of DNNs, which results in the competitive performance of SNNs. There are several factors affecting the efficiency of deep SNNs, including neuron types and neural coding schemes, during the conversion. Among these factors, many studies have focused on neural coding scheme, which is critical in transmitting accurate information with low energy consumption and latency [10], [11], [12], [13].
To date, various neural coding schemes have been applied to SNNs, such as rate [14] and temporal coding [10], [15], [16], [17]. Rate coding, which is a well-known and commonly used neural coding, utilizes firing rate to represent information [14]. Many DNN-to-SNN conversion methods have adopted rate coding for its simple implementation and robustness [7], [8], [9]. However rate coding generates a large number of spikes and has a slow information transmission. In the wake of rate coding, many temporal coding schemes, including phase [16] and burst [10], were introduced to deep SNNs to utilize the temporal information in the spike trains as in biological neural systems. Deep SNNs with phase coding [11] and burst coding [10] have improved the efficiency of inference with comparable results to those of DNNs. However, they still fall short of the desired performance in terms of latency and number of spikes.
To fully utilize temporal coding, time-to-first-spike (TTFS) coding has been applied to deep SNNs recently [12], [13]. The study [13], where the important information was delivered first, successfully introduced TTFS coding into deep SNNs, leading to a significant reduction in number of spikes. However, this research did not show satisfactory results. The TDSNN [12] with reverse coding, which is a kind of TTFS coding, was proposed to improve the accuracy of deep SNNs. The deep SNNs with reverse coding achieved competitive results with DNNs. However, the TDSNN does not report the number of spikes and latency, which are critical measures to evaluate the efficiency of deep SNNs. Furthermore, the additional spikes from auxiliary neurons and the reverse coding prohibited the deep SNNs from improving inference efficiency.
In this paper, we propose a novel deep SNN model, called T2FSNN, for efficient implementation of TTFS coding in deep SNNs. The T2FSNN exploits a kernel-based dynamic threshold and dendrite with TTFS coding, where the earlier spikes represent more critical information. In addition, we propose a gradient descent algorithm to optimize the kernels in the dynamic threshold and dendrite to further improve infor-mation transmission efficiency. Besides, we introduce an early firing method to further reduce inference latency. To validate the proposed approach, we conducted extensive experiments on the MNIST, CIFAR-10, and CIFAR-100, measuring the accuracy, number of spikes, and latency. According to the results, we were able to increase the accuracy as well as reduce latency and number of spikes, by applying the proposed methods to the T2FSNN. Our contributions can be summarized as follows: • T2FSNN: We propose T2FSNN, which is an SNN model with a dynamic threshold and dendrite for TTFS coding to reduce the number of spikes and latency of inference.
• Gradient-based optimization: We propose a gradientbased optimization approach for improving the efficiency of the T2FSNN.
• Early firing: We propose an early firing method to further reduce the inference latency of T2FSNN.

A. Spiking Neural Networks
The main difference between SNNs and DNNs lies in how information is transmitted between neurons. SNNs transmit information through spike trains which contain binary spikes (discrete) rather real values (continuous). The spike train S l i (t) of ith neuron in lth layer can be represented as where δ(t) is the Dirac delta function, f is an index of spike, and F l i is a set of spike times satisfying firing condition which is stated as: where u l i (t) is a membrane potential and θ l i (t) is a threshold at time t. Due to this information transmission based on the discrete spikes, SNNs have a feature of event-driven operation, which leads to improving computational energy efficiency. Please note that we will use t l i instead of t l,(f ) i in the rest of this paper for simplicity because each neuron generates only one spike in TTFS coding.
In an integrate-and-fire (IF) neuron, which is one of the widely used neuron types in SNNs, a synaptic input is integrated into a membrane potential as follows: where z l j is a sum of postsynaptic potential (PSP), which can be described as: where w l ij is a synaptic weight, d l j is a dendrite, and b l j is a bias. Only the neurons satisfying the firing condition (Eq. 2) generate spikes, which increases the sparsity of the spikes.

B. Neural Coding
Neural coding is a method of representing information with spike trains, including encoding and decoding procedures. There have been four neural coding schemes in deep SNNs: rate [7], [8], [9], phase [11], burst [10], and TTFS [12], [13], as depicted in Fig. 1. Rate coding has the advantages of simple implementation and robustness to errors by using firing rate, N T , where N is the total number of spikes in a given time window T [7], [8], [9], [14]. However, rate coding cannot utilize temporal information in spike trains and generates a large number of spikes, leading to high energy consumption and long inference latency.
Phase coding encodes temporal information into spike patterns based on a global oscillator [16], and it can significantly reduce the number of spikes in deep SNNs [11]. However, the efficiency cannot be guaranteed if the input changes dynamically and is unpredictable as hidden layers in deep SNNs [10]. Burst coding attempts to overcome this challenge by introducing burst spikes utilizing inter-spike interval [10].
Burst spikes can carry more information quickly and accurately by inducing PSP dramatically. Burst coding was able to significantly reduce the number of spikes and improve overall performance; however, it is still short of desired performance in terms of latency and efficiency.
TTFS coding has been adopted in deep SNNs to overcome such shortcomings [12], [13]. As illustrated in Fig. 2, the neurons with TTFS coding generate only one spike during inference and transmit the information using the timing of the spike. For instance, a red presynaptic neuron will be the first neuron that generates a spike in the fire phase to encode the largest amount of information (i.e., membrane potential). The postsynaptic neuron then integrates the PSP induced by the spike (red bar in u l+1 ). Note that once a neuron generates a spike, it no longer generates additional spikes by applying a sufficiently long refractory period as described in [12].
The TDSNN [12] was able to reduce number of spikes substantially with the reverse coding, which is a kind of TTFS coding. Reverse coding, however, delivers larger values later, making it difficult to improve latency in deep SNNs. In addition, the auxiliary neurons, used to implement reverse coding, generate a large number of spikes, which deteriorates the improvement by TTFS coding. Thus, a new approach to thoroughly utilize the features of TTFS coding is needed for improving the inference of deep SNNs.

III. PROPOSED METHODS
In this paper, we propose an SNN model, called T2FSNN, that efficiently implements TTFS coding in deep SNNs. We adopted the DNN-to-SNN conversion method as described in [8], [9], [10], [11]. The T2FSNN exploits the concept of kernel-based dynamic threshold and dendrite for the encoding and decoding procedure, respectively. In addition, we propose a gradient-based optimization method of the kernels and early firing method for further increasing accuracy and reducing inference latency with the feature of TTFS coding.

A. T2FSNN Model
The T2FSNN consists of IF neurons, synapses, and dendrites as depicted in Fig. 2. In the T2FSNN, each layer has two phases: one is an integration phase (decoding) and the other is a fire phase (encoding) in a time window T . In the integration phase, the neurons in the layer l + 1 decode the spike trains generated by the presynaptic neurons in the layer l, then integrate the decoded information into their membrane potential u l+1 . After the integration phase, the integrated membrane potential of a neuron is encoded into a spike.
The TDSNN [12] employs TTFS coding which leads to a substantial reduction in number of spikes. Nonetheless, performance improvement of TDSNN deteriorated due to the overhead of the auxiliary neurons with a very high firing rate. In T2FSNN, to efficiently implement TTFS coding without any auxiliary neurons, we designed the encoding and decoding process based on the kernels in the threshold and dendrite, respectively. The kernels decrease monotonically as where t l ref is a reference time that is defined as the start time of the fire phase, t l d is a time delay, and τ l is a time constant of layer l (t l d and τ l are trainable parameters of each layer). The encoding is a process of converting integrated information in the membrane potential u l into a spike time t l at the fire phase of each layer. We implemented TTFS encoding using a dynamic threshold θ l (t) described as where θ 0 is a threshold constant and l FI is a fire kernel. With Eqs. 2 and 6, we were able to obtain the encoding function, which outputs a spike time t l as follows: where u l i (t l ref − 1) is the integrated membrane potential of the neuron. We set the θ 0 to one in this paper, because the range of integrated membrane potentials (activation values in DNNs) was limited [0, 1] by the data-based normalization [8], [10]. Because of the characteristic of the dynamic threshold, the larger amount of information integrated, the earlier the membrane potential exceeds the threshold, which means the neuron generates a spike earlier.
The decoding is a process of restoring the information encoded in a spike time at the integration phase. The decoded information z l j (t) is accumulated in the form of the sum of PSP as follows: where l IN is an integration kernel. To make the decoding more accurate and effective, we set the time constant τ l and time delay t l d in the integration kernel l IN (t) to be equal to those in the fire kernel of the previous layer l−1 FI (t).

B. Gradient-Based Optimization Method
The key factors of T2FSNN are the integration and fire kernel in the dendrite and dynamic threshold, respectively. The kernels have a significant effect on the efficiency of inference in T2FSNN. The transmission error caused by the kernels mainly consists of two factors: precision error and small value encoding error. The precision error occurs because the precision of the information to be delivered is different from the precision that the kernels can represent. We can define the precision error as |x −x|, where x andx are the information before encoding and restored after decoding, respectively. With Eqs. 2, 5, and 7, we can obtain the precision error asx(exp(1/τ ) − 1). The precision error is inversely proportional to τ , which means that the error can be reduced by increasing τ .
However, because the encoding is based on the threshold operation, the information smaller than the smallest value (exp(−(T − t d )/τ )) that the kernel can express in a given time window T cannot be transmitted. To prevent this loss in transmission of small values, τ is sufficiently small to represent the values. Thus, there is a trade-off between the precision and latency of information transmission between neurons, depending on the time constant τ in the kernel.
To address such a trade-off properly, we propose loss functions, including precision loss and representation loss, considering the accuracy and latency of the inference. In addition, we propose a gradient-based optimization, which is based on supervised learning and minimizes the loss functions in a layer-wise manner. We set ground truth of the supervised learning toz, which is the value from DNN used in the DNNto-SNN conversion. The precision loss is defined as where F l is a set of spike time of all neurons in layer l,z l f , andẑ l f are the ground truth in DNN, and the decoded value in T2FSNN corresponds to the spike time f , respectively.
wherez l min is the minimum value ofz l , andẑ l min is the minimum value that the kernel can represent in a given time window T , which is exp(−(T − t l d )/τ l ). L l max is defined as wherez l max is the maximum value ofz l , andẑ l max is the maximum value that the kernel can represent, which is exp(t l d /τ l ). To minimize the proposed loss functions, we use a gradientbased optimization method. The derivative of the precision loss with respect to τ l is obtained as Because the maximum representation is most affected by t d , maximum representation loss is differentiated with respect to t d as follows: From the equations above, we can calculate the gradient of τ l and t l d , and optimize the kernel function with those gradients.

C. Early Firing Method
The integration and fire phase of T2FSNN are operated with dependencies in order, as shown in Fig. 3. In each layer of this baseline pipeline (Fig. 3-(a), T2FSNN), the integration and fire phases in a layer are executed sequentially. The integration phase of layer l is executed simultaneously with the fire phase of the previous layer l − 1 from (L − 1)T to LT time step. After the integration is finished, the fire phase begins at LT time step, generating spikes based on the integrated information. This baseline pipeline can guarantee the integration of all information from the previous layer in a given time window T before encoding, which leads to accurate information transmission to the subsequent layer. However, the dependency between integration and fire phase considerably increases inference latency in deep SNNs with many layers.
To alleviate this issue, we propose a technique called early firing, which is a method of starting the firing phase before the integration is complete at each layer. By using this method, we can overlap the integration and fire phase, which results in reducing inference latency as shown in Fig. 3-(b) (T2FSNN+EF). However, this approach causes nonguaranteed integration, where the information may not contribute to generating a spike. The information accumulated in the neurons that have already fired during the non-guaranteed integration cannot affect the spike generation, because each neuron generates at most one spike in the T2FSNN. Thus, the starting time of the early firing should be set to ensure the guaranteed integration of critical information to reduce inference latency without significant loss of accuracy.

IV. EXPERIMENTAL RESULTS
We empirically set the τ , t d , and T at the initial stage. Based on the initial configurations of T2FSNN, we applied the proposed gradient-based optimization and early firing. We used a train dataset and mini-batch SGD for the optimization. For the early firing, we set the starting time of the early firing to half of the time window T based on the experiments. We assessed the T2FSNN, including the proposed methods, and compared the other neural coding methods on various datasets.
The maximum representation loss is depicted in Fig. 4-(b). In the case of a small time constant (τ =2), the maximum representation loss L max decreases rapidly because the first spike of each layer occurs at an earlier time in each layer's fire phase. Through this experiment, we can verify that L prec and L min are trained competitively in a given time window T , and L min has a greater impact than L prec . We can also validate the effect of the gradient-based optimization by the distribution of spike time in each layer as depicted in Fig. 5. Compared to the T2FSNN (Fig. 5-(a)), the optimized T2FSNN (T2FSNN+GO, Fig. 5-(b)) can shorten the first spike time of each layer (vertical orange bar), and reduce the number of spikes. This indicates that the T2FSNN+GO enables the efficient inference that is fast and requires less computation.
We conducted an ablation study to demonstrate individual effects of the proposed methods as described in Table I. When the gradient-based optimization was applied to the T2FSNN (T2FSNN+GO), accuracy on CIFAR-10 and CIFAR-100 improved by approximately 0.01% and 0.93% compared to the T2FSNN, respectively. In addition, the number of spikes decreased by 0.2% and 1.9%. When the early firing method was applied to the T2FSNN (T2FSNN+EF), inference latency decreased by 46.9%, while accuracy increased by 2.05% on CIFAR-100. Remarkably, the T2FSNN+GO+EF achieved 46.9% reduction in inference latency while improving accuracy of 0.07% and 2.75% on CIFAR-10 and CIFAR-100, respectively. Furthermore, the number of spikes also decreased by 0.3% and 2.1%. It is interesting to note that the accuracy was improved with a lower number of spikes, despite that early firing causes non-guaranteed integration. This result can be interpreted as a generalization effect caused by the stochastic property of non-guaranteed integration that contributes to the generation of a spike depending on the state of the neuron.

B. Comparison with Other Methods
We compared our proposed approach with the other neural coding methods, including rate [7], [8], phase [11], burst coding [10]. To assess inference speed, we measured the accuracy depending on the inference time as depicted in Fig. 6. In CIFAR-10, the order of fast-to-slow inference speed is burst, phase, T2FSNN, and rate coding. When we applied the proposed optimization or early firing to the T2FSNN (T2FSNN+GO, T2FSNN+EF), the inference speed of T2FSNN+GO and T2FSNN+EF was as fast as that of phase and burst coding, respectively. In the case of T2FSNN with the optimization and early firing, T2FSNN+GO+EF showed the fastest inference speed. We observed similar tendency in the experimental results on CIFAR-100. T2FSNN+EF showed faster inference speed than burst coding, and T2FSNN+GO+EF achieved the fastest inference speed. Table II summarizes the accuracy, latency, number of spikes, and estimated energy consumption of various neural coding on MNIST, CIFAR-10, and CIFAR-100. Our method (T2FSNN+GO+EF) achieved the best accuracy with the lowest number of spikes in all datasets. Particularly, in CIFAR-100, we were able to reduce the number of spikes to less than 1% of that of burst coding, given the fact that the T2FSNN generates at most one spike per neuron. Inference latency also decreased to 22% compared to that of burst coding.
The energy consumption takes both latency and number of spikes into account, and thus it is an important metric for the efficiency of deep SNNs [10]. We estimated the energy consumption based on measured latency and spikes with dynamic and static energy consumption data from neuromorphic architecture, TrueNorth (TN) [18] and SpiNNaker (SN) [19] as in [10]. The estimated energy is defined as (# of spikes)E dyn + (latency)E sta , where E dyn and E sta are dynamic and static energy parameters depeneding on neuromorphic architecture. The energy parameters (E dyn , E sta ) are set to (0.4, 0.6) and (0.64, 0.36) for TrueNorth and SpiNNaker, respectively. According to the estimation, our method was able to reduce energy consumption to about 6% and 16% on average compared to rate and burst coding, respectively.

V. DISCUSSION
The TDSNN (reverse coding), which is a previous study in the line of our work, did not report the number of spikes and latency [12]. Instead of direct comparison to TDSNN, we compared the estimated computational cost as stated in Table III. The rate coding only requires accumulation of incoming spikes. The phase and burst coding, on the other hand, need additional non-linear functions during encoding and decoding procedure. Such extra overheads are alleviated by using a lookup table due to the limited input range of the non-linear function. Thus, these neural coding methods require multiplication and addition operations proportional to the number of spikes.
The TDSNN used auxiliary neurons called ticking neurons for implementing reverse coding. The ticking neurons generate spikes frequently, which causes numerous accumulation operations. In addition, the TDSNN adopted leaky IF neurons, which require an exponential operation at every time step. Thus, required computations are proportional to the time step and number of neurons. The estimated computational cost based on the reported data [12] is stated in Table III. In contrast, the proposed T2FSNN does not require auxiliary neurons, the computational cost of kernel function in T2FSNN can be reduced by replacing the kernel with a lookup table. According to our analysis, the T2FSNN requires significantly lower operations compared to various neural coding schemes including TDSNN.

VI. CONCLUSION
In this paper, we proposed the T2FSNN with gradient-based optimization and early firing for utilizing the TTFS coding in deep SNNs. By the extensive experiments on various tasks, we demonstrated our methods improve the inference efficiency of deep SNNs in terms of both latency and number of spikes. We expect that our methods pave the way for energy-efficient inference with deep SNNs with temporal coding.