Course contentsShow
← Machine Learning and Deep Learning
Lesson 2602 of 3,53856. Few-Shot and Meta-LearningFree lesson

Relation Networks

Master learnable similarity metrics where a neural network explicitly computes relation scores between example pairs.

Relation Networks

What you'll learn: How to train a neural network to directly compute similarity scores between pairs of examples, letting the model learn what "similar" means instead of relying on fixed distance metrics.

The Core Idea

In previous approaches like Prototypical and Matching Networks, we compute similarity using fixed distance functions (Euclidean distance, cosine similarity). Relation Networks take a different approach: they use a learnable neural network to compare examples.

Think of it like learning to judge "similarity" the way a human might. Instead of measuring literal pixel-by-pixel distance, you learn what features matter for deciding if two images belong to the same class. Maybe shape matters more than color, or texture more than size—the network figures this out during training.

How It Works

Given two embedded examples (from your support and query sets), you concatenate their embeddings and feed them through a small neural network called the relation module. This network outputs a relation score between 0 and 1, indicating how related the two examples are.

The architecture has two components:

  1. Embedding module: Encodes images into feature vectors (like before)
  2. Relation module: A small neural network (typically a few convolutional or fully-connected layers) that takes concatenated embeddings and outputs a similarity score

During episode-based training, you compare each query image against all support set examples, and the relation module learns to output higher scores for matching classes.

Why This Matters

Unlike fixed metrics, the relation module can learn complex, non-linear similarity functions tailored to your specific task. It might discover that certain feature combinations are highly discriminative, even if standard distance metrics would miss them.

Key Takeaway: Relation Networks replace hand-crafted distance metrics with a learnable neural network that explicitly computes relation scores, allowing the model to discover what "similarity" truly means for your few-shot task.