Matching Networks
What you'll learn: How Matching Networks use attention-based metric learning to weigh support examples when classifying new query instances in few-shot settings.
The Core Idea
Matching Networks solve few-shot classification by treating it as a weighted voting problem. Instead of computing a single prototype per class (like Prototypical Networks), Matching Networks compute an attention weight between your query image and every support example. The query's label is predicted by letting all support examples "vote," weighted by how similar they are to the query.
Think of it like asking multiple experts for advice: you don't just take the average opinion—you weight each expert's input by how relevant their expertise is to your specific question.
How Attention Works Here
Given a query embedding q and support set embeddings {s₁, s₂, ..., sₙ}:
- Compute attention weights: a(q, sᵢ) = softmax(cosine(q, sᵢ))
- Predict label as weighted sum: ŷ = Σ a(q, sᵢ) · yᵢ
The softmax ensures all attention weights sum to 1, creating a proper probability distribution over support examples. Support examples very similar to the query get high attention; dissimilar ones contribute little.
Why This Matters
Unlike nearest-neighbor (which picks one example) or prototypes (which average all examples per class), Matching Networks adaptively weight each individual support example. This flexibility helps when support sets are small or noisy—some examples naturally carry more "voting power" than others.
The attention mechanism is differentiable, so the entire network learns to embed queries and support examples in a space where attention-weighted predictions work well.
Key Takeaway: Matching Networks use attention-based metric learning to create a soft, weighted voting system over support examples, enabling flexible few-shot classification that adapts to each query's relationship with individual support instances.