k* Distribution: Evaluating the Latent Space of Deep Neural Networks using Local Neighborhood Analysis
Shashank Kotyan, Tatsuya Ueda, Danilo Vasconcellos Vargas
TL;DR
The paper tackles the problem that traditional latent-space visualizations based on dimensionality reduction distort local neighborhood structure, complicating class-wise interpretation. It introduces the k* distribution, where $k^*$ is the index of the nearest neighbor from a different class in the latent space, and summarizes per-class distributions with $\mu_{k^*}$, $\sigma_{k^*}$, and $\gamma_{k^*}$ to reveal three patterns: Pattern A (Fractured), Pattern B (Overlapped), and Pattern C (Clustered). The approach is model-agnostic and is validated through extensive experiments across architectures, network layers, training data distributions, adversarial robustness, and input transformations, with extensions to NLP and speech tasks. Key findings show that higher $\mu_{k^*}$ and lower $\gamma_{k^*}$ correlate with better accuracy, adversarial training tends to fracture latent space, and input perturbations consistently fragment local neighborhoods, illustrating the utility of k* distribution as a diagnostic tool for latent-space structure and robustness across domains.
Abstract
Most examinations of neural networks' learned latent spaces typically employ dimensionality reduction techniques such as t-SNE or UMAP. These methods distort the local neighborhood in the visualization, making it hard to distinguish the structure of a subset of samples in the latent space. In response to this challenge, we introduce the {k*~distribution} and its corresponding visualization technique This method uses local neighborhood analysis to guarantee the preservation of the structure of sample distributions for individual classes within the subset of the learned latent space. This facilitates easy comparison of different k*~distributions, enabling analysis of how various classes are processed by the same neural network. Our study reveals three distinct distributions of samples within the learned latent space subset: a) Fractured, b) Overlapped, and c) Clustered, providing a more profound understanding of existing contemporary visualizations. Experiments show that the distribution of samples within the network's learned latent space significantly varies depending on the class. Furthermore, we illustrate that our analysis can be applied to explore the latent space of diverse neural network architectures, various layers within neural networks, transformations applied to input samples, and the distribution of training and testing data for neural networks. Thus, the k* distribution should aid in visualizing the structure inside neural networks and further foster their understanding. Project Website is available online at https://shashankkotyan.github.io/k-Distribution/.
