Neural Similarity Learning

Weiyang Liu, Zhen Liu, James M. Rehg, Le Song

This NeurIPS 2019 paper, "Neural Similarity Learning" by Liu et al., challenges one of the most fundamental assumptions in Deep Learning: that the inner product is the best way to perform convolution. By rethinking how we measure the "similarity" between a neural network's filters and its input, the authors unlock new levels of flexibility and performance.

TL;DR

Neural Similarity Learning (NSL) replaces the standard inner product in convolutions with a learnable bilinear similarity measure. By allowing the network to adaptively learn how to compare kernels to inputs—either statically or dynamically—NSL significantly boosts performance in image recognition and few-shot learning tasks.

What Problem Does This Paper Address?

At the heart of every Convolutional Neural Network (CNN) is the convolution operation. Traditionally, this is treated as a simple template-matching process: you have a learnable kernel (the template) and you compute its inner product with a patch of the input.

The authors argue that this is a rigid and potentially sub-optimal assumption. While much research has focused on changing the shape of the kernel (e.g., dilated or deformable convolutions), very little has questioned the similarity measure itself. The inner product assumes a linear relationship that might not capture the complex, high-dimensional structures present in visual data. NSL aims to provide a unified framework that learns both the kernel's shape and the metric used to compare it to the data.

Methods

The core innovation is generalizing the convolution operation $W^T X$ into a bilinear form: $$f_M(W, X) = W^T M X$$ Here, $W$ is the flattened kernel, $X$ is the input patch, and $M$ is the bilinear similarity matrix. The paper explores two primary ways to implement this:

Comparison of Inner Product, Static Neural Similarity, and Dynamic Neural Similarity.
  1. Static NSL: The matrix $M$ is a set of learnable parameters that are updated during training but remain fixed during inference. Interestingly, this can be viewed as a form of weight factorization ($W_{equivalent} = M^T W$), which provides implicit regularization.
  2. Dynamic NSL: This is the more "exotic" version. Here, $M$ is not a fixed set of weights but is instead generated on-the-fly by a small auxiliary neural network based on the input $X$. This makes the CNN a "dynamic inference network," where the way it "sees" similarity changes depending on the specific image it is processing.

To keep the number of parameters manageable, the authors use a block-diagonal structure for $M$. They also introduce a stabilization technique called hyperspherical learning with identity residuals, which prevents the dynamic similarity values from exploding or becoming unstable during training.

Datasets

The authors validated their approach across several standard benchmarks:

  • Generic Visual Recognition: CIFAR-10, CIFAR-100, and ImageNet-2012.
  • Few-Shot Learning: Mini-ImageNet (a standard benchmark for testing how well a model learns from just a few examples).

Key Insights and Ideas

  • Factorization as Regularization: Even in the static case, learning $M$ and $W$ separately (factorization) encourages the network to find low-rank or minimum-nuclear-norm solutions. This "implicit bias" helps the model generalize better to unseen data.
  • Dynamic Logic: Dynamic NSL allows the network to adapt its feature extraction logic to the input. For example, the network might use a different similarity metric for a high-texture area of an image versus a smooth gradient.
  • Unified View of Kernel Shape: By factorizing $M$ into a Boolean mask $D$ and a similarity matrix $R$, the authors show that NSL can simultaneously learn which parts of a kernel to "ignore" (shape) and how to weight the remaining parts (similarity).
  • Connection to ODEs: The paper provides a theoretical link between NSL and Ordinary Differential Equations (ODEs), suggesting that certain NSL designs are equivalent to numerical schemes for solving dynamical systems.

Key Results

  • Image Recognition: On CIFAR-10, the Dynamic Neural Similarity Network (NSN) reduced the error rate from 7.78% (baseline CNN) to 6.5%. On the massive ImageNet dataset, it improved Top-1 accuracy by about 2.1% over a comparable baseline.
  • Few-Shot Learning: This is where NSL truly shined. On the Mini-ImageNet 5-shot task, the Dynamic NSN achieved 71.26% accuracy, significantly outperforming the popular MAML algorithm (63.15%) and even rivaling much larger, more complex architectures while using fewer parameters.
  • Efficiency: The authors demonstrated that a "Shared Parameterization" approach for the dynamic module could save nearly half the parameters of a disjoint approach with only a negligible hit to accuracy.

Limitations and Future Work

  • Computational Overhead: While the authors optimized the parameter count, the dynamic version of NSL still requires an auxiliary network to generate $M$ for every patch, which increases the computational cost during inference compared to standard convolutions.
  • Heuristic Optimization: The optimization of the Boolean mask $D$ (used for kernel shape) relies on a heuristic gradient approach because Boolean values are non-differentiable.
  • Scaling to Global Similarity: The authors briefly mention that self-attention mechanisms (like those in Transformers) can be viewed as a global version of dynamic neural similarity. Exploring this link further could lead to more unified architectures that blend CNN and Transformer strengths.

Summary updated

BibTeX
@inproceedings{liu2019neural,
  author = {Weiyang Liu and Zhen Liu and James M. Rehg and Le Song},
  title = {{Neural Similarity Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2019},
  url = {https://openreview.net/forum?id=lnmuLX5j2N},
}
Figure