Home Data Hands-On One-shot Learning with Python

Hands-On One-shot Learning with Python

By Shruti Jadon , Ankush Garg
books-svg-icon Book
eBook $29.99 $20.98
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $29.99 $20.98
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introduction to One-shot Learning
About this book
One-shot learning has been an active field of research for scientists trying to develop a cognitive machine that mimics human learning. With this book, you'll explore key approaches to one-shot learning, such as metrics-based, model-based, and optimization-based techniques, all with the help of practical examples. Hands-On One-shot Learning with Python will guide you through the exploration and design of deep learning models that can obtain information about an object from one or just a few training samples. The book begins with an overview of deep learning and one-shot learning and then introduces you to the different methods you can use to achieve it, such as deep learning architectures and probabilistic models. Once you've got to grips with the core principles, you'll explore real-world examples and implementations of one-shot learning using PyTorch 1.x on datasets such as Omniglot and MiniImageNet. Finally, you'll explore generative modeling-based methods and discover the key considerations for building systems that exhibit human-level intelligence. By the end of this book, you'll be well-versed with the different one- and few-shot learning methods and be able to use them to build your own deep learning models.
Publication date:
April 2020
Publisher
Packt
Pages
156
ISBN
9781838825461

 

Introduction to One-shot Learning

Humans can learn new things with a small set of examples. When presented with stimuli, humans seem to be able to understand new concepts quickly and then recognize variations of those concepts in the future. A child can learn to recognize a dog from a single picture, but a machine learning system needs a lot of examples to learn the features of a dog and recognize them in the future. Machine learning, as a field, has been highly successful at a variety of tasks, such as classification and web searching, as well as image and speech recognition. Often, however, these models do not perform well without a large amount of data (examples) to learn from. The primary motivation behind this book is to train a model with very few examples that is capable of generalizing to unfamiliar categories without extensive retraining.

Deep learning has played an important...

 

Technical requirements

 

The human brain – overview

The human brain has been a subject of research since the beginning of civilization. If we look into the development of a child, we will observe that as they grow, their ability to learn also grows. First, they learn about food, then they learn to identify faces. Every time a child learns something, information is encoded into some portion of the brain. Still, the real question remains, how does information get stored in our brains? Why is some information hardcoded, yet other information is easily forgotten?

How the human brain learns

Most of the information on how the brain trains itself to process data is unknown, but there are various theories that explore it. If we look into the structure...

 

Machine learning – historical overview

Machine learning is a program that, given a task (loss function), learns through experience (training data). With experience, that program learns to perform the given task to a desirable standard. During the 1960s, machine learning was majorly focused on creating different forms of data preprocessing filters. With the introduction of image filters, the focus then shifted toward computer vision, and major research work was undertaken in this domain during the 1990s and 2000s. After some stability in terms of traditional machine learning algorithms being developed, researchers moved to the probabilistic domain, as it became more promising with the introduction of high-dimensional data. Deep learning bloomed when it won the ImageNet Challenge in 2012, and has since taken on an important role in the field of data science.

Machine learning...

 

One-shot learning – overview

One-shot learning can be seen as an approach to train machines in a way that is similar to how humans learn. One-shot learning is an approach to learn a new task using limited supervised data with the help of strong prior knowledge. The first work published that resulted in high accuracy for the image classification problem dates back to the 2000s by Dr. Fei Fei Li—although, in recent years, researchers have made good progress tackling it through different deep learning architectures and optimization algorithms, such as matching networks, model agnostic meta-learning, and memory-augmented neural networks. One-shot learning has a lot of applications in several industriesthe medical and manufacturing industries in particular. In medicine, we can use one-shot learning when there is limited data available, for example, when working...

 

Setting up your environment

In this section, we will set up a virtual environment for our coding exercise and questions using the following steps:

  1. Clone the repository by going into the directory of your choice and running the following command in the Git Bash command line:
git clone https://github.com/Packt-Publishing/Hands-on-One-Shot-Learning.git
  1. Go to the Chapter01 directory of the cloned repository:
cd Hands-on-One-Shot-Learning/Chapter01
  1. Then, open a Terminal and use the following command to install Anaconda for Python, version 3.6 (https://docs.anaconda.com/anaconda/install/), and create a virtual environment:
conda create --name environment_name python=3.6
In steps 3 and 4, you can replace environment_name with an easy name to remember, such as one_shot, or a name of your choice.
  1. Activate the environment using the following command:
source activate environment_name...
 

Coding exercise

In this section, we will explore a basic one-shot learning approach. As humans, we have a hierarchical way of thinking. For example, if we see something unknown to us, we look for its similarity to objects we already know. Similarly, in this exercise, we will use a nonparametric kNN approach to find classes. We will also compare its performance to the basic neural network architecture.

kNN – basic one-shot learning

In this exercise, we will compare kNN to neural networks where we have a small dataset. We will be using the iris dataset imported from the scikit-learn library.

To begin, we will first discuss the basics of kNN. The kNN classifier is a nonparametric classifier that simply stores the training...

 

Summary

Deep learning has revolutionized the field of data science and it is still making progress, but there are still major industries that are yet to experience all of the advantages of deep learning, such as the medical and manufacturing industries. The zenith of human achievement will be to create a machine that can learn as humans do and that can become an expert in the same way humans can. Successful deep learning, though, usually comes with the prerequisite of having very large datasets to work from. Fortunately, this book focuses on architectures that can do away with this prerequisite.

In this chapter, we learned about the human brain and how the structure of an artificial neural network is close to the structure of our brain. We introduced the basic concepts of machine learning and deep learning, along with their challenges. We also discussed one-shot learning and its...

 

Questions

  • Why does a kNN work better than a newly trained artificial neural network for a one-shot learning task?
  • What are nonparametric machine learning algorithms?
  • Are decision trees a parametric or nonparametric algorithm?
  • Experiment with other classification algorithms as a coding exercise and compare the results.
About the Authors
  • Shruti Jadon

    Shruti Jadon is currently working as a Machine Learning Software Engineer at Juniper Networks, Sunnyvale and visiting Researcher at Rhode Island Hospital (Brown University). She has obtained her master's degree in Computer Science from University of Massachusetts, Amherst. Her research interests include deep learning architectures, computer vision, and convex optimization. In the past, she has worked at Autodesk, Quantiphi, SAP Labs, and Snapdeal.

    Browse publications by this author
  • Ankush Garg

    Ankush Garg is currently working as a Software Engineer in the auto-translation team at Google, Mountain View. He has obtained his master's degree in Computer Science from the University of Massachusetts, Amherst and Bachelor's at NSIT, Delhi. His research interests include language modeling, model compression, and optimization. In the past, he has worked as a Software Engineer at Amazon, India.

    Browse publications by this author
Hands-On One-shot Learning with Python
Unlock this book and the full library FREE for 7 days
Start now