{'fraction_non_alphanumeric': 0.03474742418554207, 'fraction_numerical': 0.009969549076043882, 'mean_word_length': 4.804842615012107, '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}}
Combining Spiking Neural Network and Artificial Neural Network for Enhanced Image Classification

With the continued innovations of deep neural networks, spiking neural networks (SNNs) that more closely resemble biological brain synapses have attracted attention owing to their low power consumption.However, for continuous data values, they must employ a coding process to convert the values to spike trains.Thus, they have not yet exceeded the performance of artificial neural networks (ANNs), which handle such values directly.To this end, we combine an ANN and an SNN to build versatile hybrid neural networks (HNNs) that improve the concerned performance.To qualify this performance, MNIST and CIFAR-10 image datasets are used for various classification tasks in which the training and coding methods changes.In addition, we present simultaneous and separate methods to train the artificial and spiking layers, considering the coding methods of each.We find that increasing the number of artificial layers at the expense of spiking layers improves the HNN performance.For straightforward datasets such as MNIST, it is easy to achieve the same performance as ANNs by using duplicate coding and separate learning.However, for more complex tasks, the use of Gaussian coding and simultaneous learning is found to improve the accuracy of HNNs while utilizing a smaller number of artificial layers.


Introduction
Over the years, deep-learning methods have provided dramatic performance improvements for various tasks (e.g., image recognition [He et al., 2016[He et al., , 2015, natural language processing [Hu et al., 2014, Young et al., 2018, and perfectinformation gaming [Silver et al., 2016]). In fact, their performance has surpassed humans with certain tasks [Silver et al., 2016, He et al., 2015. However, deep learning continues to face challenges in terms of energy efficiency. For example, in recent machine-learning models, graphical processing units (e.g., NVIDIA Tesla V100 and A100) have been used to solve single tasks while consuming 250 W. The human brain requires only 20 W [Drubach, 2000] for the same task while also managing related and routine activities. For this reason, spiking neural networks (SNNs), which represent information between neurons as spikes that more closely resemble the synaptic activity of biological neurons, have attracted attention.
However, SNNs are inferior to artificial neural networks (ANNs) in terms of performance. There are several reasons for this. First, back-propagation cannot be directly applied to SNNs, because the spike generation mechanism is not differentiable. The main workaround is to use surrogate gradients. A few studies have shown performance improvements comparable to ANNs for limited tasks [Shrestha and Orchard, 2018, Wu et al., 2018, Neftci et al., 2019. In addition, we applied such a method to optimize weights using state-of-the-art approximated back-propagation [Fang et al., 2020] for SNNs. The second reason for the SNN inferiority is that most of the data handled by SNNs consist of continuous values, such as those represented by floating point numbers. Furthermore, SNNs represent and process information via the synaptic spikes. This type of input/output would be ideal for process information from sensors that output similar spike signals, such as event-based cameras [Orchard et al., 2015, Gallego et al., 2020. Such a task would require an SNN-oriented visual image dataset, such as that of N-MNIST [Orchard et al., 2015], so that higher accuracy and lower computation could be attained [Deng et al., 2020]. In contrast, many datasets (e.g.,  and, for that matter, data handled in the real world often have normalized continuous values in (0, 1) . Therefore, for SNNs to process the most realistic data, coding is required to convert the continuous values into spike trains. Many methods for doing this have been proposed, but their performance remains inferior to the ANNs, which process the original data directly [Deng et al., 2020].
As a novel method to address this problem, we propose the conception of hybrid neural networks (HNNs) in which an SNN are combined with an ANN. We use the ANN parts for the input and hidden layers and the SNN parts for the middle and output layers. In this way, the network can directly receive continuous-valued data via the ANN and compute them via the SNN, which is expected to realize a lower-energy and a higher-accuracy neural network. However, this structure of the network still requires the aforementioned coding process between the artificial layers (ALs) and the spiking layers (SLs), owing to the continuous values treated in the ALs and the spike signals in the SLs. The HNNs are evaluated using image classification tasks to determine whether ALs can be trained simultaneously with SLs. Furthermore, the ratio of ALs to SLs on a network and the coding methods needed between the ALs and SLs are evaluated. The results show that using more ALs improves the classification accuracy, and that the most straightforward coding method (i.e., duplicate coding) is effective in terms of network performance and computational cost.
The following summarizes the major contributions of this work: 1. Because SNNs deal with continuous-valued data, the proposed HNN combines an ANN and an SNN; their ALs and SLs are connected via coding methods and can be trained separately or simultaneously via backpropagation. 2. We show that increasing the ratio of ALs in the network improves HNN performance, which can surpass that of pure SNNs. 3. We make a technical contribution by proposing the use of differentiable Gaussian coding. HNNs that use this method can achieve higher accuracy, even when the percentage of ALs is small.

Background
In this section, we explain the theory behind SNNs while focusing on their learning algorithms and their method of informational representation.

Neural Structure
As shown in Figure 1(a), a biological neuron changes its membrane potential and internal voltage in the soma in response to an input signal from the synapse. When the membrane potential exceeds the threshold voltage, a spike signal is generated from the soma and is transmitted to the next neuron through the axon and its terminals.
As shown in Figure 1(b), in many SNN studies, synapses and neurons are treated as separate modules. Therefore, synapses receive spike signals from the pre-synaptic neurons and generate a postsynaptic potential (PSP). The PSP is weighted for each synapse and flows into the postsynaptic neuron. Biologically, this is the input current to the neuron. The membrane potential of each neuron varies with the input current (i.e., weighted PSP) over time. When this value exceeds the threshold voltage, an output spike is generated from the neuron. Immediately afterward, its membrane potential plummets to the resting voltage. Because each neuron repeats the above temporal behavior, information flows only via the spike signals, ultimately realizing lower power consumption over time.

Neuron and Synapse Model
In this study, we use the leaky integrate-and-fire (LIF) neuron model [Stein, 1965], which is the most basic and widely used phenomenological neuron model [Schuman et al., 2017]. The synapses are based on the IIR equations [Fang et al., 2020]. Because the form in the discrete-time domain, SNNs can be interpreted as a network of IIR filters: where l and i denote the index of the layer and the neuron, respectively, j denotes the input index, t is the time step, and N l is the number of neurons in the l-th layer. V l i [t] is the neuron membrane potential, and V th is the threshold. A neuron fires when its membrane potential overcomes it. I l i [t] is the weighted PSP input. R l i [t] is the reset voltage used to decrease the membrane potential to the resting voltage after the neuron fires.
is a spike function that describes the conditions of firing, and U (x) is a Heaviside step function. P and Q denote the feedback and feed-forward orders, respectively. λ, θ, α l j,p , and β l j,q are the coefficients of the neuron filter, reset filter, and synapse filter, respectively. By changing these coefficients, this model can represent various types of neurons.

Approximated Back-propagation
Because this study focuses on image classification tasks, we utilize cross-entropy loss E with the probability of each neuron in the last layer firing in a fixed-length time window, T : where y i is a one-hot vector representing the truth label, L is the number of layers of the SNN, and O L i [t] denotes the output of the last layer.
Using the chain rule, the gradient can be represented as where (4a) .
Here, U (x) is not differentiable, which is the main obstacle to SNN learning. Fang et al. assumed that when Gaussian noise N (0, σ 2 ) was nipped in, LIF neurons could be approximated by Poisson neurons [Fang et al., 2020], such that the firing rate becomes where erfc(·) represents a complementary error function. Thus, the derivative of U (x) can be approximated to [Neftci et al., 2019] ∂U

Information Representation
Although the form of the spiking signal varies per neuron type, SNNs are designed based on the assumption that information is represented by spikes. Therefore, we must consider how to represent the concerned information in this fashion.
There are two types of information coding used for this purpose: rate and time. Rate coding expresses information in terms of the frequency of the firing of spikes over time. However, the time interval between spikes is meaningless.
Conversely, time coding represents information based on the time interval of each spike.
Although the time-coding representation is valid [Kumar et al., 2010, Rullen andThorpe, 2001], we apply rate coding for this research, because it is more commonly used in this field to convert continuous-valued input data to event-driven data prior to the first layer in an SNN.

Proposal
HNNs have a coding module and two types of neural layers. Owing to the format of the data handled by the AL, in which the data are continuous values, and the SL, in which the spike trains exist along the time dimension, the data should be converted from continuous values into spike trains. There are two types of ALs that can be incorporated into an SNN: those with fixed weights and those that are trained simultaneously with SLs.
In the following sections, we detail these two points.

Learning Strategy
There are two learning methods regarding ALs and SLs for HNNs: train them separately or simultaneously.
In the separate method, the ANN is trained in advance. However, when building an HNN, the corresponding ALs are removed and connected to the SLs while maintaining the AL weights. As shown in Figure 2(a), when training the HNN, the weights of the extracted ALs are fixed, and only the weights of the SLs are updated. In this type of network, because the ALs do not need to learn with the SLs, non-differentiable coding functions can be used to convert the latent vectors from the ALs into spikes. Notably, this method requires less time.
In the simultaneous method, both ALs and SLs are combined from the beginning, and all layers are trained from scratch via back-propagation (Figure 2(b)). Between the last AL and the first SL, coding is required, and this should be differentiable to support back-propagation. Therefore, some coding methods are not available from the spatio-temporal back-propagation method (see Section 2.1.3).

Rate-based Coding
Rate-based coding is utilized at the interface between ALs and SLs, as shown in Figures 2(a) and 2(b).
Network performance in this study is evaluated using continuous-data image input direct to the ALs. Hence, the spiking layers require an additional time dimension. We explore three methods to handle this: duplicate, Gaussian, and Poisson coding. This section describes the details.

Duplication
Expanding the output vector, a, along the time axis is the most straightforward way to perform rate-based coding. The input for the first SL, which is also the coded output of the last AL, is O AL i [t] = a i . Instead of producing a spiking train, this continuous value train is the input for the spiking neurons in the first SL.

Gaussian Distribution
The duplicating method deterministically codes a continuous value to a continuous-valued train, whereas biological networks are stochastic, owing to uncertainty factors in nature (e.g., noise). This method stochastically converts the continuous values generated from the artificial layer output using a reparameterization trick [Kingma and Welling, 2014] for connectivity to back-propagation.
The last artificial layer outputs µ and ln σ instead of a vector, and the first SL receives re-parameterized continuousvalued trains, O AL i [t] ∼ N (µ, σ 2 ) (Figure 2(c)). Via the reparameterization trick, the input of the first SL is defined as where ε is an auxiliary noise variable, ε ∼ N (0, 1).
The parameterization trick makes the boundary between AL and SL differentiable. However, compared with other coding methods, it requires twice the number of neurons in the last AL to adequately measure both performances. Thus, although this coding method can theoretically be used in any form of network, SLs cannot be connected with pretrained ALs in this way.

Poisson Coding
Poisson coding, based on the Poisson-process probability theory, is a widely used coding method [Diehl and Cook, 2015, Querlioz et al., 2013, Bing, 2019] that generates a spike train from a continuous value according to the Poisson distribution, which stochastically converts a continuous value along the time dimension.
With Poisson coding, the converting function outputs a sequence of spikes such that the time difference between them follows a Poisson distribution, which is not differentiable, unlike the above two methods (Section 3.2.1 and 3.2.2). Thus, the Poisson coding cannot be used with the simultaneous learning method.

Proposed Models
As described, the two types of AL (i.e., fixed and trainable) and the three coding methods (i.e., duplicating, Gaussian, and Poisson) have limited combinations, owing to their traits. In this study, we investigate the possibility of HNNs that use the four methods described in the subsequent sections. For simplicity, we assume that all networks in this study have a feed-forward architecture.

Figures 2(a)-(d) show all of the neural networks implemented in this paper.
The main limiting factor in developing an HNN is determining whether or not the coding method is differentiable. When fixed or pretrained ALs are incorporated into the HNN, all coding methods can be adopted. Conversely, when a trainable AL is used, only differentiable methods can be adopted.
Moreover, for evaluation, the Gaussian coding implemented by the reparameterization trick cannot be combined with HNNs having pretrained ALs, because the reparameterization trick requires more neurons than are available in the basic network architecture.
Trainable ALs and SLs in a duplicate coding network are shown in Figure 2(a). Both the ALs and the SLs are trained simultaneously via back-propagation using the duplicating method for coding after the last AL.
Fixed ALs and trainable SLs within a duplicating coding network (Figure 2(b)) optimize the weights only for SLs during training. To facilitate the addition of the time dimension between the AL and the SL, the network merely copies the output from the last AL over a certain number of time steps.
As shown in Figure 2(c), the trainable ALs and SLs within the Gaussian-coding network are trained for all layers together, and, even with stochastic coding, the training phase follows a Gaussian distribution. This network takes the longest time to train, because, unlike networks having fixed ALs, all layers should be trained, and the reparameterization trick used with Gaussian coding becomes more computationally complex than the straightforward duplication.
With fixed ALs and trainable SLs within a Poisson coding network (Figure 2(d)), Poisson coding is used to generate spike trains from the latent vector rendered from the pretrained ALs. Owing to the undifferentiable coding method, only the SLs are trained.
Each network was trained with the training dataset for 100 and 150 epochs on MNIST and CIFAR-10, respectively. At the end of each epoch, network performance was evaluated using the validation dataset, and the network achieving the best performance on the validation dataset was used to compare performance based on the testing dataset.

Receiving Continuous Values
There are two ways in which a continuous value train can be inserted into a spiking neuron: as a spike train through the axon or directly.
The first was used in [Fang et al., 2020], utilizing back-propagation. The continuous-valued input is converted to a PSP through the axon and is treated as a spike train. The spiking neurons in the first layer receives the PSP.
In the second way, spiking neurons in the first layer directly receives continuous input values instead of the PSP. This is more biologically plausible, because the sensory-nerve endings in animals are sensory neurons rather than axons.
The results reveal that the axon-inputting method does not improve network performance. Therefore, we used the direct-inputting method in the following experiments.

Hybrid Neural Networks
HNNs can be regulated with rate-based coding (e.g., duplication, Poisson, and Gaussian) and trainable layers, where the SLs are combined with fixed or trainable ALs. Notably, the fixed-AL and trainable-SL network with Gaussian coding is not compared here, because it relies on the reparameterization trick and different architecture.
In the network having a fixed AL and a trainable SL, the fixed ALs were generated from a pure ANN, which has the highest accuracy when trained on the training dataset and evaluated on the validation dataset.
In Tables 1(a), 2(b), 2(a), 1(b), 3(a), and 3(b), the network architectures are shown using a notation in which An and Sm indicate a layer having n artificial neurons and m spiking neurons, respectively. Additionally, AnCk or SnCk indicate an spiking convolutional AL with kernel k × k. Here, the coding method is implicitly inserted between An-Sm.
A three-layer MLP having ALs, SLs, and a coding layer in the interface between the AL and SL was used to classify images on the MNIST dataset to consider the effect of combining ALs and SLs.
As the baseline, a pure SNN using a dual exponential post-synaptic potential kernel with the S784-S500-S10 architecture was trained. Moreover, the last row in Table 1(a) shows the result of the pure ANN fully comprising ALs. Here, the respective results of the pure SNN and ANN with separate learning cycles are not described in all tables, because they do not need to train each layer separately.
As shown in Table 1(a), the network having fixed ALs and trainable SLs using duplicating coding achieved the highest score. Notably, the A784-A500-S10 architecture recorded higher performance than did the ANN, although both networks shared weights in the first and second layers.

Separate vs. Simultaneous Training
To compare separate and simultaneous learning for classification accuracy, we conducted comparison experiments using the above networks with duplicate coding, which can be used for both types of learning.
Table 1(a) and 1(b) show the results of MLPs and convolutional neural networks (CNNs), each having the same number of neurons. However, the ratio of ALs to SLs was different. In each table, the accuracy of the pure SNN and ANN with fixed ALs is not listed, because neither had pre-training layers. Notably, the results of the pure SNN and ANN are similar to those in Table 2, because they used the same architectures with duplicate coding.
The results in both tables show that, generally, using pure networks achieves higher accuracy. Additionally, in HNNs, increasing the percentage of ALs improves performance, revealing a trade-off between computational accuracy and energy efficiency. With rate-based coding, an artificial neuron can represent more accurate information. However, a spiking neuron can reduce power consumption. Furthermore, although the separately trained networks showed higher accuracy than those with simultaneous learning, the performance of the more complex tasks (CIFAR-10) was reduced when the ratio of SLs in the trainable network was too small. Thus, for complex tasks in huge networks, training ALs and SLs at the same time gives better accuracy than using only fixed-ALs in a pure SNN.

Gaussian Coding
The results of MLPs and CNNs for MNIST and CIFAR-10, respectively, with Gaussian coding are shown in Tables 2(a) and 2(b). As mentioned, Gaussian coding can only be employed with trainable ALs, owing to the additional neurons needed for reparameterization.
Additionally, compared with the model with trainable ALs and SLs and duplicate coding (Tables 1(a) and 1(b)), the accuracies of the models with Gaussian coding (Tables 2(a) and 1(b)) were higher for lower AL ratios.
From the results in Table 3(a), even such low accuracies follow this tendency: ALs lead to higher accuracy. In contrast, the results in Table 3(b) show the opposite, and it is observed that Poisson coding generates too much noise, leading to a decrease in accuracy rather than improving the generalization. Notably, these noisy latent vectors reduce the accuracy of image recognition.

Discussion
The results (Figures 1(a)-(b)) largely delineate a tendency of improving accuracy with the increase in the percentage of ALs in the hybrid model. This was true, except for CNNs having two ALs and three SLs (i.e., A32C3-A32C3-A64C3-P2-S64C3-P2-S512-S10). This confirms our expectation that ANNs are better suited to handle continuous values.
The highest scores of the HNNs that used Gaussian coding were not greater than those using duplicate coding. However, networks having fewer ALs (Tables 2(a) and 2(b)) performed better than networks with trainable ALs and SLs using duplicate coding, especially for CIFAR-10. Therefore, although Gaussian coding did not show a clear advantage in the experiments, high performance can be expected in more complex tasks in the future.
In these experiments, we did not find any advantage from using Poisson coding. In fact, when used with an HNN, its accuracy was greatly reduced. This is probably because there was too much information missing, owing to the noise generated during the coding process. In contrast, pure SNNs showed competitive accuracy with other coding methods, as demonstrated in previous studies [Deng et al., 2020]. Interestingly, for HNNs having pretrained ALs (Figure 1(b)), the CNNs having fewer ALs outperformed those with more. This suggests that the use of a spiking conventional layer immediately after coding contributes to performance improvement, and this inclination is not seen in the MLP results.

Conclusion
In this study, we proposed hybrid neural networks that combined features of the conventional continuous-input ANN with those of the more bio-plausible, event-driven SNN. The elements comprising the HNN, including the various ALs that were combined with the SNN features and respective coding methods, were evaluated on image classification tasks using MNIST and CIFAR-10 datasets. Several HNNs exceeded the performance of pure SNNs and demonstrated notable effectiveness. Moreover, it was shown that the performance changes depended on the ratio of ALs and SLs and the coding method used to transform the continuous values to spiking trains for connecting the ALs to the SLs. Additionally, even when the most straightforward duplicate coding method was used, the performance was equal to or better than the other coding methods.
We believe that our work helps further increase the potential of SNNs, which are more energy-efficient than ANNs but are disadvantageous for handling continuous-valued data input.