Zero-Shot Learning: How to Classify Unseen Data with Advanced Techniques

Allan Kouidri
-
6/12/2024
Zero-shot learning illustration

Zero-Shot Learning (ZSL) is a machine learning paradigm that enables models to classify data into categories they have never encountered during training

If you've ever tried to gather large quantities of labeled data, you know it's a tough job. Really tough.

Things get even trickier when you have countless different categories (like every possible type of vehicle) that your model needs to learn.

So, what's the solution?

One approach is to reduce our dependency on labeled data. This brings us to zero-shot learning (ZSL), where the model learns to classify categories it has never seen before.

Car collage

Imagine a vehicle classification model that can identify a "hovercraft," even though it never saw a labeled example of one during training.

Sound incredible?

In the next section, we’ll dive into how this seemingly magical method works, using examples of models that operate on a zero-shot learning framework.

How Zero-Shot Learning Works

Zero-Shot Learning (ZSL) is fundamentally a subfield of Transfer Learning. The general idea behind ZSL is to leverage the knowledge acquired from the training instances (seen classes) and apply it to the task of classifying unseen instances (unseen classes). This transfer of knowledge enables the model to make predictions on categories it has never encountered during training.

Transfer Learning and Zero-Shot Learning

  • Homogeneous Transfer Learning: This common form involves fine-tuning a pre-trained model on a problem with similar feature and label spaces. 
  • Heterogeneous Transfer Learning: In contrast, ZSL falls under this category, where the feature and label spaces are disparate [1].

illustation Homogeneous  vs hetegeneous transfer learning
[1]

Key Concepts in Zero-Shot Learning

  1. Seen Classes: Data classes used to train the deep learning model. These classes provide the foundational knowledge the model relies on.
  2. Unseen Classes: Data classes on which the model needs to generalize without having seen any examples during training.
  3. Auxiliary Information: Essential for bridging the gap between seen and unseen classes, auxiliary information includes descriptions, semantic information, or word embeddings. This information helps the model understand and identify features of unseen categories [2].
ZSL auxiliary information
[2]

Different Approaches to Zero-Shot Learning

Zero-Shot Learning (ZSL) can be approached in various ways, each with its own strengths and applications. Here are some of the primary methods used:

1. Attribute-Based ZSL

This method relies on semantic attributes that are shared among different categories. These attributes act as a bridge between seen and unseen classes by providing a common set of features that can be used for classification [3].

Example: Identifying animals based on shared attributes like "has fur" or "can fly." If a model knows these attributes for known animals (seen classes), it can infer the presence of these attributes in unknown animals (unseen classes) and classify them accordingly.

Strengths:

  • Allows for fine-grained classification.
  • Can be applied in scenarios where attribute information is readily available.

Applications:

  • Wildlife monitoring and species identification.
  • Medical diagnosis based on shared symptoms.

2. Transfer Learning

This approach involves using knowledge from related tasks or domains to classify new categories. The model is pre-trained on a related task and then adapted to the new task with minimal additional training [4].

Example: Applying a model trained on vehicle types to classify new transportation modes. If the model has learned to identify cars, bikes, and buses, it can transfer this knowledge to recognize new categories like electric scooters or autonomous drones.

Strengths:

  • Efficient in terms of training time and resources.
  • Leverages existing models to handle new tasks.

Applications:

  • Autonomous driving and transportation systems.
  • Cross-domain image and text classification.

3. Generative Models

Generative models create synthetic data for unseen categories based on learned attributes and features. These models can generate examples of new classes, allowing the classifier to learn from this synthetic data [5].

Example: Using a generative adversarial network (GAN) to create images of new animal species based on learned features from existing species.

Strengths:

  • Enhances the model's ability to classify new categories by providing synthetic training data.
  • Can handle highly varied and complex data distributions.

Applications:

  • Augmented reality and virtual reality applications.
  • Creative industries, such as art and design.

4. Graph-Based Methods

Graph-based methods use knowledge graphs to represent relationships between known and unknown categories. These methods leverage relational data to aid classification [6].

ZSL Graph-Based Methods
[6]

Example: A knowledge graph representing relationships between different animal species, including shared habitats, dietary habits, and phylogenetic relationships. This graph helps the model infer the category of an unseen animal based on its relationship to known animals.

Strengths:

  • Utilizes rich relational information for more accurate classification.
  • Can integrate diverse types of data (e.g., textual, visual, and relational).

Applications:

  • Knowledge management and organization.
  • Complex network analysis and recommendation systems.

OpenAI's CLIP - Practicale example

Let’s take a practical example; OpenAI's CLIP (Contrastive Language-Image Pretraining) is a powerful example of Zero-Shot Learning in action. CLIP is trained on an extensive dataset comprising image-text pairs, enabling it to connect specific phrases with corresponding visual patterns. When making predictions, CLIP leverages its learned associations to classify new images by matching them with its extensive database of image-text relationships [7].

The Role of Contrastive Learning

The core technique driving CLIP's success is contrastive learning. This method focuses on minimizing the differences between the digital representations of images and their textual descriptions. By aligning image features with text elements, contrastive learning enhances the model's ability to classify new images based on conceptual similarities rather than relying solely on exact label matches.

Key Aspects of Contrastive Learning in CLIP:

  • Alignment of Modalities: Ensures that similar concepts are close to each other in the shared embedding space, regardless of whether they originate from text or images
  • Generalization: Allows the model to generalize well to new, unseen categories by leveraging the learned associations between text and images.
Summary CLIP
[7]
The Training Process

CLIP undergoes a rigorous training process that involves several critical steps:

  1. Text Parsing
    • Objective: To refine the model's ability to understand and extract meaningful information from textual descriptions.
    • Process: CLIP parses descriptive texts associated with images, extracting key features and linking them with visual elements. Over time, the model learns to associate specific phrases and terminologies with corresponding visual patterns.

  1. Feature Alignment
    • Objective: To continuously align image and text features through contrastive learning.
    • Process: By comparing pairs of images and their associated texts, the model learns to minimize the distance between the vector representations of matching pairs while maximizing the distance for non-matching pairs. This alignment improves the model's capability to recognize and categorize new images.

  1. Similarity Metrics
    • Objective: To accurately classify new images by comparing them to learned text-image pairings.
    • Process: During prediction, CLIP uses similarity metrics like cosine similarity to assess how closely a new image's features align with the features of various text descriptions in its database. Cosine similarity measures the cosine of the angle between two vectors, providing an effective way to gauge similarity in high-dimensional spaces.

Example Workflow in CLIP:

  1. Image-Text Pairing: The model is trained on pairs such as an image of a "golden retriever" and the text "a dog playing in the park."
  2. Embedding Generation: Both the image and text are converted into vector representations.
  3. Contrastive Objective: The training process adjusts the embeddings so that the vector for the image of the golden retriever is close to the vector for "a dog playing in the park" and far from unrelated pairs.
  4. Inference: When presented with a new image, such as a picture of a "hovercraft," CLIP uses its learned embeddings to find the text description that best matches the new image, even if "hovercraft" was not explicitly labeled in the training data.

Zero-Shot Inference

During the inference phase, Zero-Shot Learning (ZSL) models apply their trained knowledge to classify new, unseen data. This process involves several key steps to ensure accurate and efficient classification:

1. Label Encoding

The first step in zero-shot inference involves creating a comprehensive list of potential categories, each represented by an encoded label. This is done using a pretrained text encoder that can understand and convert textual descriptions of categories into a vector representation.

Process:

  • Textual Descriptions: Collecting descriptive text for each potential category (e.g., "hovercraft," "segway," "drone").
  • Text Encoding: Using a pretrained text encoder (like BERT or GPT) to transform these descriptions into high-dimensional vectors.
  • Label Vector Database: Storing these encoded vectors in a database for quick retrieval during the similarity assessment phase.

Outcome: A robust set of encoded category labels that capture the semantic essence of each category.

2. Image Encoding

The next step is encoding the new, unseen image using a pretrained image encoder. This encoder converts the visual information from the image into a vector representation that can be compared with the label encodings.

Process:

  • Image Preprocessing: Normalizing and preparing the image for encoding (e.g., resizing, color adjustments).
  • Image Encoding: Using a pretrained image encoder (such as ResNet, VGG, or a custom CNN) to extract features from the image and convert them into a high-dimensional vector.
  • Feature Vector Extraction: Generating a feature vector that encapsulates the essential visual characteristics of the image.

Outcome: A detailed vector representation of the new image that is ready for comparison with the label vectors.

3. Similarity Assessment

With both the image and label vectors prepared, the next step is to assess the similarity between the encoded image and each encoded label. This is typically done using a similarity metric, such as cosine similarity, which measures the cosine of the angle between two vectors.

Process:

  • Similarity Calculation: Computing the similarity score between the image vector and each label vector. Cosine similarity is a common choice due to its efficiency and effectiveness in high-dimensional spaces.
  • Ranking: Sorting the similarity scores to identify the label vectors that are most similar to the image vector.

Outcome: A ranked list of category labels based on their similarity to the new image.

4. Classification

The final step is to classify the new image into the category it most closely resembles based on the similarity assessment.

Process:

  • Top Similarity Score: Selecting the category label with the highest similarity score as the predicted class for the image.
  • Thresholding (Optional): Applying a threshold to the similarity score to determine if the confidence in the classification is sufficient. If the highest score is below the threshold, the model may abstain from making a prediction or consider alternative approaches.

Outcome: The new image is assigned to the most similar category, completing the zero-shot classification process.

Takeways

  • Zero-Shot Learning (ZSL) represents a significant advancement in the field of machine learning, enabling models to identify and classify a wide array of categories without requiring labeled examples for each one. This innovative approach greatly reduces the need for extensive labeled datasets, saving both time and resources.
  • ZSL enhances the versatility and power of machine learning models, allowing them to adapt to ever-changing real-world scenarios. 
  • By leveraging auxiliary information and sophisticated training techniques, ZSL models can achieve accurate predictions and classifications, surpassing the limitations of traditional methods and opening up new possibilities for practical applications across various domains.

References

[1] Mignone, P., Pio, G., Džeroski, S. et al. Multi-task learning for the simultaneous reconstruction of the human and mouse gene regulatory networks. Sci Rep 10, 22295 (2020). https://doi.org/10.1038/s41598-020-78033-7

[2] Y. Xian, C. Lampert, B. Schiele and Z. Akata, "Zero-Shot Learning—A Comprehensive Evaluation of the Good, the Bad and the Ugly" in IEEE Transactions on Pattern Analysis & Machine Intelligence, vol. 41, no. 09, pp. 2251-2265, 2019.doi: 10.1109/TPAMI.2018.2857768

[3] C. H. Lampert, H. Nickisch and S. Harmeling, "Attribute-Based Classification for Zero-Shot Visual Object Categorization," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 36, no. 3, pp. 453-465, March 2014, doi: 10.1109/TPAMI.2013.140. 

[4] Socher, Richard et al. “Zero-Shot Learning Through Cross-Modal Transfer.” Neural Information Processing Systems (2013).

[5] Mishra, Ashish et al. “A Generative Model for Zero Shot Learning Using Conditional Variational Autoencoders.” 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW) (2017): 2269-22698.

[6] Kampffmeyer, Michael C. et al. “Rethinking Knowledge Graph Propagation for Zero-Shot Learning.” 2019 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2018): 11479-11488.

[7] Radford, Alec et al. “Learning Transferable Visual Models From Natural Language Supervision.” International Conference on Machine Learning (2021).

Arrow
Arrow
No items found.
#API

Build with Python API

#STUDIO

Create with STUDIO app

#SCALE

Deploy with SCALE