Emergence of Latent Binary Encoding in Deep Neural Network Classifiers
We investigate the emergence of binary encoding within the latent space of
deep-neural-network classifiers. Such binary encoding is induced by the
introduction of a linear penultimate layer, which employs during training a
loss function specifically designed to compress the latent representations. As
a result of a trade-off between compression and information retention, the
network learns to assume only one of two possible values for each dimension in
the latent space. The binary encoding is provoked by the collapse of all
representations of the same class to the same point, which corresponds to the
vertex of a hypercube. By analyzing several datasets of increasing complexity,
we provide empirical evidence that the emergence of binary encoding
dramatically enhances robustness while also significantly improving the
reliability and generalization of the network.
Luigi Sbailò, Luca Ghiringhelli
# Emergence of Latent Binary Encoding in Deep Neural Network Classifiers

###### Abstract

We observe the emergence of binary encoding within the latent space of deep-neural-network classifiers. Such binary encoding is induced by introducing a linear penultimate layer, which is equipped during training with a loss function that grows as \(\exp(\vec{x}^{2})\), where \(\vec{x}\) are the coordinates in the latent space. The phenomenon we describe represents a specific instance of a well-documented occurrence known as _neural collapse_, which arises in the terminal phase of training and entails the collapse of latent class means to the vertices of a simplex equiangular tight frame (ETF). We show that binary encoding accelerates convergence toward the simplex ETF and enhances classification accuracy.

## I Introduction

In tasks like images classification, deep neural networks have achieved levels of performance that surpass human capabilities. Nevertheless, there is a general lack of understanding regarding the theoretical mechanisms behind these outstanding results.

In the last years, there has been a growing interest in studying the geometrical structures that emerge in the latent space of deep neural networks. Notably, it has been noticed that the class means in the penultimate layers collapse to the vertices of a simplex equiangular tight frame (ETF) in the terminal phase of training [1]. This phenomenon known as _neural collapse_ has been linked to transfer learning [2] and incremental learning [3].

In this work, we develop a method for generating a binary encoding for the latent representations found in the penultimate layer of deep neural networks. Within each dimension of the penultimate layer, latent representations are in practice trained to assume one of two possible values. In the tests that we perform all data points belonging to the same class adopt an identical binary encoding. This implies that data points within the same class ultimately converge to the vertices of a simplex constructed on the vertexes of a binary hypercube. Notably, our work represents a specific instance of _neural collapse_. In our case, the phenomenon extends beyond just the class means collapsing to simplex vertices; rather, it encompasses all data points within the same class. Furthermore, our findings demonstrate that this method enhances accuracy of neural-networks prediction.

## II Binary Encoding

Given a labeled dataset \(\left\{\vec{x},\vec{\overline{y}}\right\}\), we deal with the problem of predicting the labels with a deep neural network. For an input point \(\vec{x}\), we can break down the process of producing the neural network's output \(\vec{f}(\vec{x})\) into two distinct steps. Firstly, the non-linear component of the neural network generates a latent representation \(\vec{h}(\vec{x})\). Following this, a linear classifier, characterized by weights \(\vec{W}\) and biases \(\vec{b}\) operates on this latent representation to compute \(\vec{f}(\vec{x})=\vec{W}\vec{h}(\vec{x})+\vec{b}\). The predicted label \(\vec{y}\) is finally determined by applying a softmax function to the network's output. The neural network is trained through the minimization of the cross-entropy loss function \(\mathcal{L}_{\text{CE}}\left(\vec{f}(\vec{x}),\vec{\overline{y}}\right)\), which measures the disparity between the network's predictions and the ground truth labels.

Here, we propose the introduction of an additional linear layer prior to the classifier, defined as \(\vec{x}_{bin}=\vec{W}_{bin}\vec{h}(\vec{x})+\vec{b}_{bin}\). This layer serves as the penultimate step in the network architecture, with classification being subsequently determined through another linear operation, \(\vec{f}(\vec{x})=\vec{W}\vec{x}_{bin}+\vec{b}\). In addition to the cross-entropy loss applied to the network's output, we incorporate a loss function into the penultimate layer defined as: \(\mathcal{L}_{\text{Bin}}(\mathbf{x}_{\text{bin}})=e^{\vec{x}_{\text{bin}}^{ \text{fin}}}\). The resulting loss function is thus composed of two terms:

\[\mathcal{L}=\mathcal{L}_{\text{CE}}+\gamma\,\mathcal{L}_{\text{Bin}}, \tag{1}\]

where \(\gamma\) is a hyperparameter.

The latent binary encoding emerges as a result of balancing two conflicting tendencies coming from the two components of the loss function. The exponential loss function pushes towards having all latent representations closer to zero, while the minimization of the cross-entropy induces differentiation among the different latent representations. This dynamics naturally leads to a configuration where, for each latent dimension, most of the latent values cluster around two opposing peaks in relation to the origin. The presence of these two peaks facilitates the necessary differentiation for distinguishing various representations, and they tend to be in close proximity to zero due to the influence of the exponential loss. Assuming
the concentrated distribution of points only around the two peaks, it becomes evident that the latent representation effectively approximates only two distinct values: either positive or negative.

## III Experiments

To evaluate the impact of incorporating a binary encoding layer, we conducted experiments with four distinct neural network architectures, all of which share a common base network responsible for generating the latent representation \(\vec{h}(\vec{x})\). Nevertheless, these networks diverge in their subsequent steps for classification.

One network architecture, referred as _Binary encoding_, implements a linear penultimate layer with loss function as in Eq (1). The _Linear penultimate_ architecture features a linear penultimate layer as well, but is trained using only the cross-entropy loss function. The _Non-linear penultimate_ architecture implements a non-linear layer that acts on \(\vec{h}(\vec{x})\) before linear classification. The fourth _No penultimate_ architecture performs linear classification directly on the \(\vec{h}(\vec{x})\) latent representation.

We note that the _Binary encoding_, _Linear penultimate_ and _Non-linear penultimate_ architectures have the same number of layers and parameters but differ for activation and loss functions, while the _No penultimate_ architecture has one layer less with respect to the others. These 4 different architectures are tested on MNIST and FashionMNIST. Details about training and architecture of the network used to generate the latent representation \(\vec{h}(\vec{x})\) are given in Appendix A.

In order to test the binarity hypothesis, which we define as the assumption that each dimension in the latent representation can assume approximately only one of two values, we fit a Gaussian mixture model with 2 modes on the _Binary encoding_ latent representation \(\mathbf{x}_{\text{Bin}}\). A different fit is performed on each dimension over all values of the training set. In each dimension, the average log-likelihood score of the training set is computed and averaged over all dimensions. Also the standard deviation of the two posterior distributions are collected and averaged over all dimensions. These values are plotted in Fig. 3, where we can see that during training the score increases while the standard deviation decreases. This observation supports our binarity hypothesis, as it aligns with the notion that a Gaussian distribution with a standard deviation approaching zero implies that all data points converge to a single position. The same analysis is performed for the _Linear penultimate_ architecture as it also features a linear layer before classification. However, we can see that in this architecture the binarity hypothesis does not hold.

As we assume that each latent representation \(\vec{x}_{\text{Bin}}\) is encoded into a binary representation, we expect that points with the same label present the same encoding. We then generate a binary encoding of the penultimate layer in each of the network architectures we study. This encoding is generated giving 1 to all positive values and 0 to values equal to or lower than 0. In Fig. 3, we show the fraction of points that share the same encoding and belong to the same class. Notably, we observe that this assumption holds true exclusively for the _Binary encoding_ architecture. All points belonging to the same class are in fact placed on a vertex of the simplex designed on the vertices of a hypercube. Binary encoding also accelerates _neural collapse_ as discussed in Appendix B.

Finally, we can see in Fig. 3 that the implementation of a _binary encoding layer_ has the effect of improving the accuracy of neural network classification both on the train and test set, while the other three architectures show comparable performance.

Figure 1: Average log-likelihood scores and standard deviations for Gaussian mixture models with two modes on each dimension of the penultimate layer. Averages of different training outcomes are shown, and line shadows represent the standard deviations. If not visible standard deviations are small for the image resolution.

Figure 2: Fraction of points belonging to the same class which share the same binary encoding. Averages of different training outcomes are shown, and line shadows represent the standard deviations. If not visible standard deviations are small.
Conclusion and limitations

We have discussed a method to generate a binary encoding in the latent space, which is accomplished by adding a penultimate _binary encoding layer_, i.e. a linear layer that incorporates an exponentially growing loss function. The emergence of this phenomenon is shown to accelerate convergence toward the vertices of a simplex equiangular tight frame, and to enhance the network accuracy. Although results seem to be promising to suggest that binary encoding should be used to enhance network performance, more comprehensive tests on more complex datasets and with more expressive deep neural networks are still to be done.

## Appendix A Training and architecture details

To generate the latent representation \(\vec{h}(\vec{x})\), two distinct neural network architectures were employed for the two different datasets. For MNIST classification, a fully connected neural network with three layers, each consisting of 2048 nodes, along with two dropout layers, was utilized. In the case of FashionMNIST, a convolutional neural network was employed, featuring five convolutional layers with specified input and output channel configurations ([1,64],[64,128],[128,256],[256,256], [256,512]), a kernel size of 3, and padding of 1. Additionally, three max pool layers with a kernel size of 2 and a stride of 2 were applied in the following sequence: Conv2D, MaxPool, Conv2D, MaxPool, Conv2D, MaxPool, Conv2D. Furthermore, two fully connected layers, each comprising 1024 nodes, were employed after the convolutional layers, and two dropout layers were included. A nonlinear activation function was consistently applied following each convolutional layer.

Both architectures incorporated a dropout rate of 0.5 and utilized ReLU activation functions. In the context of the CNN network applied to FashionMNIST, the _Binary encoding_, _Linear penultimate_, and _Non-linear penultimate_ architectures included an additional fully connected layer consisting of 128 nodes. Conversely, for the fully connected network applied to MNIST, this penultimate layer contained 64 nodes. The _Non-linear penultimate_ architecture incorporated a ReLU activation function within this penultimate layer.

The training process utilized the Adam optimizer with default settings as specified in the PyTorch implementation, employing a learning rate of \(10^{-4}\). The learning rate was reduced by half after every 20 epochs. For the MNIST dataset, a batch size of 64 was employed, whereas for the FashionMNIST dataset, a batch size of 128 was utilized. The loss function employed for the 'Binary encoding' architecture was as in Eq. (1) with \(\gamma=10\). Each network architecture has undergone training three times with distinct initial conditions, and the quantities displayed in plots represent the averages and standard deviations of these outcomes.

## Appendix B Convergence to simplex equiangular tight frame

In the terminal phase of training the vectors of the class means are known to converge to a simplex equiangular tight frame (ETF) as manifestation of a phenomenon known as _neural collapse_. The class mean vectors converge to having equal lengths, resulting in uniform angles between any given pair of vectors. The ETF configuration represents the maximum pairwise distance while adhering to the aforementioned properties.

In Figure 2, we illustrate this convergence of class means towards the vertexes of the simplex ETF. Notably, we observe that this convergence occurs more rapidly when employing a _binary encoding layer_. In this figure the within class variation is computed using the within class covariance compared with the between class covariance. The collapse of variability becomes apparent when contrasting with the between-class covariance. However, in the lower plot, which displays the average within-class covariance matrix, we observe an interesting trend. The average within-class covariance matrix itself, without comparison to the between-class covariance matrix, shows an increase during training, unless the _binary encoding layer_ is integrated into the network. This implies that, when using the _binary encoding layer_, not only the

Figure 4: Plots demonstrating convergence to the vertices of a simplex equiangular tight frame. From top to bottom: ’Equinorm’ as variation of the mean classes norms; ’Equian-gularity’ as variation of the angle between all class means pairs; ’Max Angle’ as distance from the max angle class means can have; ’Tr(Sw/Sb)/C’ as weighted within-class variance; ’Within class covariance’ is the average of the within-class covariance matrix. More details about the quantities plotted can be found in Ref. [1].
class means but also all data points within the dataset converge towards the vertexes of a simplex ETF.
