7-One Shot Learning

🧠 One-Shot Learning vs Traditional Classification: A Beginner’s Guide with Python Example

🎯 Understanding the Problem: Classification vs One-Shot Learning

Imagine you’re trying to identify whether a poem was written by Lucas or not.
You could train a regular classification model where each poet is a separate class.

If you already have poems from multiple authors, your model might learn to classify new poems among K authors. But when you add Lucas as a new author, you’d now have K + 1 classes — meaning you’d need to retrain your model every time a new author appears.

That’s not ideal — especially when new authors (or identities) keep appearing and you only have one example of their work.

This is where One-Shot Learning comes in.

Hello, let's say that you are trying to identify whether the author for a certain poem is Lucas or not. You can either take all of Lucas's poems and put them into data sets and instead of predicting K classes, you'll now predicts K plus one classes. All the previous poems of other authors plus Lucas. So that's why it's K plus one. Or you can compare one of Lucas's poems to another poem and that is where one shot learning comes in.

🔍 What Is One-Shot Learning?

One-Shot Learning is a type of machine learning where a model learns to recognize something after seeing just one example.

Instead of predicting which class an input belongs to, it focuses on measuring how similar two inputs are.

In our earlier example:

  • A traditional classifier would say, “This poem belongs to class X (Lucas).”

  • A one-shot learner would say, “This poem is similar to Lucas’s previous poem by 92%.”

✒️ A Real-World Analogy: Signature Verification

Banks face a similar challenge when verifying signatures.

A traditional classifier trained on thousands of known signatures could work well — until a new customer joins. It’s not practical to retrain the whole model for every new signature.

Instead, banks use a similarity-based approach:

  • They compare a new signature to a stored one.

  • If the similarity score exceeds a certain threshold (say, 0.85), the system concludes both signatures belong to the same person.

This is exactly what Siamese Networks are built for.

In this blog, I'll show you how you can do that.  To understand the difference between classification and one shot learning. First consider identifying or classifying signatures based on one through K possible classes. You might use some kind of classification model trained on the K classes probably with a softmax function at the end to find the maximum probability. Then at recognition time classify the input signature to one of those corresponding classes.

That's great if you have a signature list that's rarely changes. But what if you get a new signature to classify? It would be expensive to retrain the model every time this happens. And besides, unless you have a great many examples of that new signature model training won't work very well in one shot learning, you need to be able to recognize a signature repeatedly from just one example. You can do this with a learned similarity function, then you can test a similarity score against some threshold to see if two signatures are the same. So the problem changes to determining which class to instead measuring similarity between two classes. And this is very useful especially in banks. For example, every time there's a new signature, you can't retrain your entire system to classify the signatures into K possible outputs. So instead you just learn a similarity function that can be used to calculate a similarity score. That can in turn be used to identify whether two signatures are the same. You already did this using cosine similarity as the similarity function. If the result was greater than some threshold tau, you determine the inputs to be the same. In the case of comparing signatures, if the similarity is less than or equal to tau, then the signatures are different. >> In this video, I spoke about one shot learning and I told you why it is a very effective technique. One shot learning makes use of Siamese networks. In the next video, I'll show you how you can train and test your Siamese network.

🧩 Siamese Networks — The Core of One-Shot Learning

A Siamese Network consists of two identical neural networks that share weights.
Both process different inputs (say, two signatures or two images) and then output embeddings — numerical representations of each input.

The model learns a similarity function that measures how close or far apart those embeddings are.

If the distance between embeddings is small → they’re likely from the same class.
If it’s large → they’re likely different.

Mathematically, you can use metrics like:

  • Cosine Similarity

  • Euclidean Distance

đź§  Why One-Shot Learning Matters

One-shot learning is powerful for cases where labeled data is scarce, such as:

  • 👤 Face Recognition (e.g., FaceID on iPhones)

  • ✍️ Signature Verification

  • 🩺 Medical Imaging (rare disease detection)

  • 🎨 Art or Writer Identification (like our “Lucas” example)

Instead of retraining on new data, models compare — making them flexible and efficient.

Last modified: Sunday, 2 November 2025, 8:57 AM