Few Shot Learns From Tiny Support
Few-shot classifies a query by its nearest class prototype from a handful of support images, while zero-shot replaces the support set with text descriptions in a shared space.
Why Does This Exist?
Standard classifiers need thousands of labels per class, which fails for rare diseases, new species, or fresh factory defects where only a few images exist. Few-shot learning handles the case with 1 to 5 support images per class, and zero-shot handles the case with none at all, using class descriptions instead. Both reuse a pretrained embedding rather than training from scratch.
The shared idea is comparison, not a new classifier head. Few-shot compares the query image to support means with cosine distance, often trained episodically as 5-way 1-shot or 5-shot tasks. Zero-shot compares the query image to text embeddings from a model such as CLIP, as detailed in zero-shot classification. The embedding quality behind both comes from metric learning and transfer learning.
Think of It Like This
Naming an okapi from one photo or one paragraph
Show a friend exactly one photo of an okapi and name it, and they will spot okapis in a lineup forever after: that is few-shot. Hand them only a paragraph, striped legs like a zebra on a brown horse body with a long neck, and they can still pick one out sight unseen: that is zero-shot.
The photo is the support set and the paragraph is the text embedding. Where it stops: one blurry photo breeds false alarms on every striped animal, just as one vague paragraph matches the wrong species when attributes overlap.
How It Actually Works
Few-shot averages each class support set into one prototype: with shots the fox prototype is , and the query joins the class with the highest cosine similarity. Episodic training mimics test time by sampling many 5-way tasks with 1 or 5 shots each, so the encoder learns spaces where means separate. Zero-shot drops images entirely: each candidate label is embedded as text such as a photo of a fox, the query image is embedded beside it, and the nearest text wins.
Worked example
Take a 2-D toy space with a fox support set of , , , , and . The prototype mean is . A query at scores cosine against the fox prototype but only against a wolf prototype at , so it joins fox by a wide margin. Across standard mini-ImageNet style episodes this averaging lifts accuracy from about 58 percent at 1 shot to about 72 percent at 5 shot, a 14-point gain from four extra images per class.
Code
The point of this snippet is the prototype arithmetic, not a framework: pure Python recomputes the mean and both cosine scores with the standard library only.
import math
support = [(0.90, 0.10), (0.80, 0.20), (0.85, 0.15), (0.95, 0.05), (0.80, 0.30)]proto = (sum(x for x, _ in support) / 5, sum(y for _, y in support) / 5)print((round(proto[0], 2), round(proto[1], 2)))# -> (0.86, 0.16)
def cosine(a, b): dot = a[0] * b[0] + a[1] * b[1] return dot / (math.dist(a, (0, 0)) * math.dist(b, (0, 0)))
query, wolf = (0.88, 0.12), (0.10, 0.90)print(round(cosine(query, proto), 3), round(cosine(query, wolf), 3))# -> 0.999 0.244The query sits at 0.999 from fox and 0.244 from wolf, so nearest-prototype assignment picks fox exactly as the prose derived by hand.
Watch Out For
Reading 1-shot accuracy as a product number
The symptom is a demo at 58 percent 1-shot that collapses on the next support sample because one image carries the full class variance. Fix it by reporting episode means with confidence intervals and preferring 5-shot support wherever collection allows, since the worked 14-point gain is typical.
Vague prompts standing in for missing images
The symptom is zero-shot accuracy that swings wildly when a photo of a fox becomes a blurry photo of a fox at dusk. Fix it by ensembling several prompt templates per class and validating wording on a held-out set instead of tuning prompts against test labels.
The Quick Version
- Few-shot averages support embeddings into one prototype per class and takes the nearest.
- The worked fox prototype is , scoring versus for wolf.
- Zero-shot swaps support images for text embeddings and matches the query to the nearest description.
- Accuracy rises from about 58 percent at 1 shot to about 72 percent at 5 shot.
- Both live or die by embedding quality, not by classifier size.