SimilarNet: Pairwise Similarity Comparator Layer for Versatile Comparison

Chungheon Yi, Ling Liu, Wonik Choi

Introduction

In deep learning, metric space learning is a fundamental technique used for tasks such as facial recognition, recommendation systems, and image retrieval. These systems rely on a model's ability to take two distinct inputs and accurately quantify their similarity. Traditionally, researchers have relied on two primary methods: fixed mathematical metrics (like Cosine Similarity) or simple vector concatenation. However, both approaches introduce significant limitations that can hinder model performance and training stability.

The Limitations of Current Comparison Methods

Fixed metrics are mathematically rigid, requiring input vectors to be identical in shape and reducing the entire comparison to a single scalar value. This creates an "information bottleneck," stripping away nuanced feature-level differences that subsequent layers could use for higher-level reasoning.

Alternatively, many practitioners use concatenation, where two vectors are joined and fed into a standard dense layer. While more flexible, this approach is highly inefficient. The network must learn from scratch that specific elements in vector A should be compared to corresponding elements in vector B. This often results in the model identifying "invalid patterns"—spurious correlations between unrelated features—which slows down convergence and can lead to training failure.

Figure 2: The concatenation approach often leads to the learning of invalid patterns between unrelated features, complicating the training process.

Introducing SimilarNet

To address these issues, researchers have developed SimilarNet, a specialized neural network layer designed to treat similarity as an element-wise operation. Instead of a standard weighted-sum neuron, SimilarNet utilizes a functional perceptron architecture.

The Cosine Activation Function

The core of SimilarNet is its multi-dimensional activation function. It performs an element-wise comparison (essentially a Hadamard product following L2 normalization) but, crucially, it preserves the result as a vector rather than collapsing it into a scalar. This allows the network to maintain a rich representation of similarities and differences across the feature space.

Figure 3: The SimilarNet architecture utilizes L2 normalization and a Cosine Activation Function to produce a similarity vector z.

Key Innovations

  • Parametric Flexibility: Similar to PReLU, the authors introduced a parametric version of the layer with a trainable parameter ($\alpha$). This enables the model to learn different weights for "similarities" versus "differences," allowing it to prioritize relevant features for specific tasks.
  • Heterogeneous Comparison: Unlike traditional distance metrics, SimilarNet can be adapted to compare vectors of different dimensions (e.g., matching a 128-dim vector against a 256-dim vector) through attention-style mechanisms.
  • Positionality: By forcing the network to compare corresponding features, SimilarNet eliminates the search for "invalid comparisons," leading to much faster and more reliable convergence.

Experimental Results

SimilarNet was evaluated across six benchmarks, including standard vision datasets (MNIST, CIFAR-10) and challenging few-shot learning tasks (Omniglot, miniImageNet). The results were decisive:

  • Accuracy Gains: SimilarNet outperformed concatenation-based models by 4.3% to 26.5%.
  • Training Stability: The "learning success rate"—the probability of a model successfully converging—improved by up to 75%. On the miniImageNet dataset, where standard concatenation models failed to learn entirely (0% success), SimilarNet achieved a 75% success rate.
  • Ablation Insights: The study confirmed that the functional perceptron logic drives accuracy, while L2 normalization is the primary factor in ensuring training stability.

Conclusion and Future Work

SimilarNet represents a significant step forward in how neural networks process pairwise data. By replacing generic concatenation with a specialized similarity layer, models can achieve higher accuracy with greater stability. Future research will focus on exploring alternative multi-dimensional activation functions for non-visual data types and scaling the architecture to massive transformer-based models.

Summary updated

BibTeX
@article{yi2023similarnet,
  author = {Chungheon Yi and Ling Liu and Wonik Choi},
  title = {{SimilarNet: Pairwise Similarity Comparator Layer for Versatile Comparison}},
  journal = {IEEE Access},
  year = {2023},
  doi = {10.1109/access.2023.3327075},
}
Figure