Matching Networks Architecture
What you'll learn: How Matching Networks use attention mechanisms to compare a query example with labeled support examples for few-shot classification.
The Core Problem
In few-shot learning, you have very few labeled examples (the support set) and need to classify new query examples. While Prototype Networks compute a single prototype per class, Matching Networks take a more flexible approach: they learn to match the query directly against individual support examples using attention weights.
How Matching Networks Work
Think of Matching Networks like asking multiple experts (support examples) for their opinion, then weighing each expert's vote based on how similar they are to your question (query).
The architecture has three key components:
1. Embedding Functions
- An encoder
fembeds the query example - An encoder
gembeds each support example - These can be the same network or different
2. Attention Mechanism
For a query embedding and each support embedding, compute an attention weight using cosine similarity (or a learned metric):
a(query, support_i) = softmax(cosine_similarity(f(query), g(support_i)))
This tells you "how relevant is support example i to this query?"
3. Weighted Voting
The final prediction is a weighted combination of support labels:
P(y|query) = Σ a(query, support_i) × one_hot(label_i)
Examples similar to the query get higher voting weight.
Why Attention Matters
Unlike fixed prototypes, attention lets the model dynamically focus on the most relevant support examples for each specific query, making predictions more context-aware and adaptive.
Key Takeaway: Matching Networks use attention-based matching to let each support example "vote" on the query's label, with votes weighted by learned similarity—enabling flexible, instance-level comparisons for few-shot classification.