Learning Parities with Neural Networks
Amit Daniely, Eran Malach
Introduction
The remarkable success of neural-networks has sparked great theoretical interest in understanding their behavior. Impressively, a large number of papers have established polynomial-time learnability of various models by neural networks algorithms (i.e. gradient based methods). Yet, to the best of our knowledge, with the single exception of learning one neuron , all these results prove learnability of linear models. Namely, models that can be realized by a linear classifier, on top of a (possibly random) embedding that is fixed and does not depend on the data. This is not surprising, as the majority of these papers prove learnability via “linearization" of the network at the vicinity of the initial random weights.
While these results achieved a remarkable progress in understanding neural-networks, they are still disappointing in some sense. Indeed, in practice, neural-networks’ performance is far better than linear methods, a fact that is not explained by these works. Moreover, learning a linear classifier on top of a fixed embedding seems to completely miss the “deepness" of deep learning.
Recently, a few works have provided theoretical results demonstrating that neural-networks are stronger than random features - a linear model where the embedding map is randomly drawn from some predefined distribution . These works show problems that are easy to learn with neural-networks, while being hard to learn with random features. The work of shows that random features cannot approximate a distribution generated by a single neuron and Gaussian inputs, which is known to be learnable by a neural-network. The work of shows that neural-networks are more efficient than random features, in terms of sample complexity and run-time, for some regression problems generated by a ResNet-like network. A work by shows other family of distributions where neural-networks with quadratic activation outperform random features, when the number of features is smaller than the dimension.
Our result differs from these works in several aspects. First, and study the power of approximating a regression problems, and hence their results cannot be applied to the setting of classification, which we cover in this work. Second, we give an exponential separation, while and only give polynomial separation. Namely, the problems for which they show that networks performs better than linear methods are still poly-time learnable by linear methods.
Problem Setting
Let be some class of functions from to . We define the loss of with respect to the distribution to be the loss of the best function in :
So, measures whether can approximate the distribution .
Our target functions will be parities on bits of the input. Let be some subset of size , for some odd , and define to be the parity of the bits in , namely . For every subset , we construct a distribution on the instances that is easy to learn with neural-networks. Let be the uniform distribution on , and let be the distribution that is uniform on all the bits in , and the bits in are all w.p. and w.p. . Let be a distribution over where we samples w.p. and w.p. , and set . This defines a family of distributions .
The training algorithm.
for some choice of and .
We assume the network is initialized with a symmetric initialization: for every initialize and then initialize , initialize and and initialize and .
Main Result
Our main result shows a separation between neural-networks and any linear method (i.e., learning a linear classifier over some fixed embedding). This result is composed of two parts: first, we show that the family cannot be approximated by any polynomial-size linear method. Second, we show that neural-networks can be trained to approximate the family using gradient-descent.
The following theorem implies that the class cannot be approximated by a linear classifiers on top of a fixed embedding, unless the embedding dimension or the norm of the weights is exponential:
Fix some , and define:
Then, if , there exists some such that:
The following result shows that neural-networks can learn the family with gradient-descent. That is, for every distribution , a large enough neural-network achieves a small error when trained with gradient-descent on the distribution . Together with theorem 1, it establishes an (exponential) separation between the class of distributions that can be learned with neural-networks, and the class of distributions that can be learned by linear methods.
Fix some . Assume we run gradient-descent for iterations, with and for every . Assume that and . Fix some , and assume that the number of neurons satisfies . Then, with probability at least over the initialization, there exists such that:
Proof of Theorem 1
Let and define the objective . Observe that for every we have:
Since is a Fourier basis, we have:
Where we use the fact that . Using Jensen inequality we get:
Note that is -strongly convex, and therefore, for every we have:
Let , and so . Using the above we get:
Now, notice that is -Lipschitz, since:
Denote , and by optimality of we have:
Taking an expectation and plugging in (1) we get:
Since this is true for all , taking we get:
Therefore, there exists some with such that . Since we get the required. ∎
Proof of Theorem 2
We start by giving a rough sketch of the proof of Theorem 2. We divide the proof into two steps:
First gradient step. We show that after the first gradient step, there is a subset of “good” neurons in the first layer that approximately implement the function , for some and . Indeed, observe that the correlation between every bit outside the parity and the label is zero, and so the gradient with respect to this bit becomes very small. However, for the bits in the parity, the correlation is large, and so the gradient is large as well.
Convergence of online gradient-descent. Notice that the parity can be implemented by a linear combination of the features , when are distributed uniformly. Hence, from the previous argument, after the first gradient step there exists some choice of weights for the second layer that implements the parity (and hence, separates the distribution). Now, we show that for a sufficiently large network and sufficiently small learning rate, the weights of the first layer stay close to their value after the first iteration. Thus, a standard analysis of online gradient-descent shows that gradient-descent (on both layers) reaches a good solution.
In the rest of this section, we give a detailed proof, following the above sketch. For lack of space, some of the proofs for the technical lemmas appear in the appendix.
We want to show that for some “good” neurons, the weights are close enough to for some constant depending on . We start by showing that the irrelevant coordinates () and the bias have very small gradient. To do this, we first analyze the gradient with respect to the uniform part of the distribution , and show that it is negligible, with high probability over the initialization of a neuron:
Using a union bound on the previous lemma, we get that the above result holds for all irrelevant coordinates (and the bias), with constant probability:
of Lemma 4. Choose and use union bound on the result of Lemma 3 over all choices of and the bias. ∎
Now, we show that for neurons with , the gradient of the irrelevant coordinate and the bias is zero on the distribution (the non-uniform part of the distribution ):
Combining the above lemmas implies that for some “good” neurons, the gradient on the distribution is negligible, for the irrelevant coordinates and the bias. Now, it is left to show that for the coordinates of the parity (), the gradient on the distribution is large. To do this, we show that the gradient on the relevant coordinate is almost independent from the gradient of the activation function. Since the gradient with respect to the hinge-loss at the initialization is simply the correlation, this is sufficient to show that the gradient of the relevant coordinates is large.
From all the above, we get that with non-negligible probability, the weights of a given neuron are approximately , for some choice of depending on :
Assume and . Fix some . Then, with probability at least over the choice of , we have that: , and for some universal constants , and some depending on .
Finally, we show that the features implemented by the “good” neurons can express the parity function, using a linear separator with low norm. In the next two lemmas we show explicitly what are the features that the “good” neurons approximate:
Let , and . Denote . Let . Then, for every , with probability at least over the choice of we have , for every .
Fix and assume that and , for some universal constant . Fix , and define . Fix some . Then, with probability at least over the choice of then for we have for all .
Using the above, we show that there exists a choice for the weights for the second layer that implement the parity, with high probability over the initialization:
This concludes the analysis of the first gradient step.
2 Convergence of Gradient-Descent
Our main result in this part relies on the standard analysis of online gradient-descent. Specifically, this analysis shows that performing gradient-descent on a sequence of convex functions reaches a set of parameters that competes with the optimum (in hindsight). We give this result in general, when we optimize the functions with respect to the parameter :
(Online Gradient Descent) Fix some , and let be some sequence of convex functions. Fix some , and assume we update . Then for every the following holds:
Note that in the previous part we showed that the value of the weights of the first layer is “good” with high probability. In other words, optimizing only the second layer after the first gradient step is sufficient to achieve a good solution. However, since we optimize both layers with gradient-descent, we need to show that the weights of the first layer stay close to their value after the first initialization. We start by bounding the weights pf the second layer after the first iteration:
Assume and . Then for every we have .
Using this, we can bound how much the first layer changes after at every gradient-step:
Assume that and for every , for some fixed value . For every and every we have , and .
Using the above we bound the difference in the loss between optimizing the first layer and keeping it fixed, for every choice of for the second layer:
Finally, using all the above we can prove our main theorem:
Using Lemma 14 we get that for every we have:
From this, there exists some such that:
And since the hinge-loss upper bounds the zero-one loss, we get the required. ∎
Experiment
In section 3 we showed a family of distributions that separates linear classes from neural-networks. To validate that our theoretical results apply to a more realistic setting, we perform an experiment that imitates the parity problem using the MNIST dataset. We observe the following simple task: given a strip with random digits from the MNIST dataset, determine whether the sum of the digits is even or odd. We compare the performance of a ReLU network with one hidden-layer, against various linear models.
In the case where , the MNIST-parity task is just a simplified version of the standard MNIST classification task, where instead of classes there are only classes of numbers. In this case, we observe that both the neural-network model and the linear models obtain similar performance, with only slight advantage to the neural-network model. However, when , the task becomes much harder: it is not enough to merely memorize the digits and assign them to classes, as the model needs to compute the parity of their sum. In this case, we observe a dramatic gap between the performance of the ReLU network and the performance of the linear models. While the ReLU network achieves performance of almost accuracy, the linear models barely perform better than a chance. The results of the experiment are shown in Figure 1.
In the MNIST-parity experiment we train a neural-network model, as well as various linear models, to predict the parity of the sum of digits in the strip. Our neural-network architecture is a one-hidden layer network with ReLU activation and neurons in the hidden layer. We compare this network to a network of a similar architecture, except that we force the network to stay in the regime of the linear approximation induced by the network’s gradient - i.e., the neural-tangent-kernel (NTK) regime . To do this, we use an architecture that decouples the gating from the linearity of the ReLU funcion, and keeps the gates fixed throughout the training process (as suggested in ). Namely, we use the fact that: , and by decoupling the first and second term during the optimization, we force the network to stay in the NTK regime. We compare these architectures to standard random-features models, where we randomly initialize the first layer, but train only the second layer. Such models are known to be an efficient method for approximating kernel-SVM (see ). We use both ReLU random-features (standard random initialization with ReLU activation), and Gaussian random features, which approximate the RBF kernel. Both models have 512 features in the first layer. All models are trained with AdaDelta optimizer, for 20 epochs, with batch size 128.
Discussion and Future Work
In this work we showed exponential separation between learning neural networks with gradient-descent and learning linear models - i.e., learning linear separators over fixed representation of the data. This shows that learning neural networks is a strictly stronger learning model than any linear model, including linear classifiers, kernel methods and random features. In other words, neural networks are not just “glorified” kernel methods, as might be implied from previous works in the field. This demonstrates that our current understanding of neural networks learning is very limited, as only a few works so far have given positive results beyond the linear case.
There are various open questions which we leave for future work. The first immediate research direction is to find other distribution families that are learnable with neural networks via gradient-descent, but not using linear models. Another interesting question is finding distribution families with separation between deep and shallow networks. Specifically, finding a family of distributions that are learnable with gradient-descent using depth-three networks, but cannot be learned using depth-two networks. Finally, we believe that understanding the behavior of neural networks trained on specific “non-linear” distribution families will allow us to induce specific properties of the distributions that make them learnable using neural networks. Characterizing such distributional properties is another promising direction for future research.
Broader Impact
As the primary focus of this paper is on theoretical results and theoretical analysis, a Broader Impact discussion is not applicable.
References
Appendix A Additional Proof Details
of Lemma 3. Fix some . Denote . Let be some subset with and .
Since the above holds for all , we get that:
Fix some (with and ), and observe that, from symmetry to permutations of the uniform distribution, we have:
of Lemma 5. W.l.o.g., assume and . We will show that the conclusion of the lemma is true even if we condition of the value of . Indeed, in that case the conditional expectation of is
Similarly, the conditional expectation of is
of Lemma 6. Fix some . Denote to be the random variable . Notice that for every , the following holds:
Since the above is true for every , we get that:
of Lemma 7. Denote , . We show that with probability at least over the choice of we have:
We start by calculating the probability to get each of the above separately:
From Lemma 4, this holds with probability at least .
Now, conditioning on the event that is odd, we have:
All in all, we get that 2 holds with probability at least .
To calculate the probability that both 1,2 and 3 hold, note that 2 and 3 are independent, and therefore the probability that both of them hold is at least . Using the union bound we get that the probability that all 1-3 hold is at least .
Now, we assume that the above hold. In this case we have:
Where we use the result of Lemma 5 and the above conditions. Now, for all we have:
So, denote and note that for every we get . So, from Lemma 6 we get that for every we have:
of Lemma 9. From Lemma 7, with probability at least over the choice of , we have that: , and for some universal constants , and some depending only on . From Lemma 8, with probability at least over the choice of (and independently of the choice of ), we have for every .
Assume the results of both lemmas hold, which happens with probability at least . Now, fix some and let . Then we have:
For some universal constant . Using the assumption on concludes the proof. ∎
of Lemma 10. Fix some . Let , and from Lemma 9, with probability at least over the choice of we have:
Assume . Denote . Denote , and using Hoeffding’s inequality, with probability at least we have . Therefore, using the union bound we get that with probability at least , for every we have . Let be some subset of size . Define:
Observe that . Therefore, we have that:
Now, we have where is a universal constant. Therefore, we get that . From what we showed, such achieves the required. ∎
of Theorem 11. We follow an analysis similar to . Let , and notice that . We show by induction that for every we have:
since minimizes . Now, assume the above is true for , then we have:
And by adding to both sides we get:
Using Cauchy-Schwartz inequality and rearranging the above yields:
Finally, from convexity of we get:
of Lemma 12. W.l.o.g., assume . Denote and . Notice that since is odd, we have . From the symmetric initialization we have . By definition of the gradient-updates, we have:
And since is -Lipschitz we get:
Where we use the fact that is -Lipschitz. ∎
of Lemma 13. From Lemma 12 we have that . For every :
of Lemma 14. Denote the support of by . Then we have: