Ways to obtain embedding vectors
In general, there are many ways of obtaining embedding vectors, including:- Word embeddings
- Autoencoder Embeddings
- Generative Adversarial Networks (GANs)
- Pre-trained Embeddings
Use Case Examples
Once established the choice of models to generate embeddings, the question is: *how? *The way you generate your embedding must be such that the resulting vector represents your input according to your use case.- CV Image Classification
- NLP Classification
- NLP Named Entity Recognition
If you are working on image classification, the model will take an image and classify it into a given set of categories. Each of our embedding vectors should be representative of the corresponding entire image input.First, we need to use a Then, we pass the results from the It is imperative that these outputs contain the activation values of the hidden layers of the model since you will be using them to construct your embeddings. In this scenario, we will use just the last hidden layer.Finally, since we want the embedding vector to represent the entire image, we will average across the second dimension, representing the areas of the image.
feature_extractor that will take an image and prepare it for the large pre-trained image model.feature_extractor to our model. In PyTorch, we use torch.no_grad() since we don’t need to compute the gradients for backward propagation, we are not training the model in this example.Additional Resources
Check out our tutorials on how to generate embeddings for different use cases using large, pre-trained models.| Use-Case | Code |
|---|---|
| NLP Multi-Class Sentiment Classification using Hugging Face | Colab Link |
| NLP Multi-Class Sentiment Classification using OpenAI | Colab Link |
| NLP Named Entity Recognition using Hugging Face | Colab Link |
| CV Image Classification using Hugging Face | Colab Link |