Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
PyTorch Deep Learning Hands-On
PyTorch Deep Learning Hands-On

PyTorch Deep Learning Hands-On: Build CNNs, RNNs, GANs, reinforcement learning, and more, quickly and easily

Arrow left icon
Profile Icon Sherin Thomas Profile Icon Sudhanshu Passi
Arrow right icon
€8.99 €26.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (10 Ratings)
eBook Apr 2019 250 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Sherin Thomas Profile Icon Sudhanshu Passi
Arrow right icon
€8.99 €26.99
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (10 Ratings)
eBook Apr 2019 250 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

PyTorch Deep Learning Hands-On

Chapter 2. A Simple Neural Network

Learning the PyTorch way of building a neural network is really important. It is the most efficient and clean way of writing PyTorch code, and it also helps you to find tutorials and sample snippets easy to follow, since they have the same structure. More importantly, you'll end up with the efficient form of your code, which is also highly readable.

Don't worry, PyTorch is not trying to add another spike into your learning curve by implementing a brand-new methodology. If you know how to code in Python, you'll feel at home right away. However, we won't learn those building blocks as we did in the first chapter; in this chapter, we will build a simple network. Instead of choosing a typical entry-level neural network use case, we'll be teaching our network to do mathematics in the NumPy way. Then we'll convert that to a PyTorch network. By the end of this chapter, you will have the skills to become...

Introduction to the neural network

In this section, we'll go through the problem statement at hand and the dataset we are using. Then, we'll go and build a basic neural network, before building it up to a proper PyTorch network.

The problem

Have you ever played the game Fizz buzz? Don't worry if you haven't. The following is a simple explanation of what the game is about.

Note

As per Wikipedia, Fizz buzz [1] is a group word game for children that teaches them about division. Players take turns to count incrementally. Any number divisible [2] by three is replaced by the word fizz and any number divisible by five is replaced by the word buzz. Numbers divisible by both become fizz buzz.

Fizz buzz has been used in a fun example by Joel Grus, one of the research engineers at the Allen Institute of Artificial Intelligence (AI2), while writing a blog post [3] on TensorFlow. Although this particular example doesn't solve any practical problems, the blog post got quite a lot of traction and it is fun to see how a neural network learns to find a mathematical pattern from a number stream.

Dataset

Building a data pipeline is as important as the architecture of your network, especially when you train your network in real time. The data that you get from the wild is never going to be clean, and you'll have to process it before throwing it at your network. For example, if we were to collect data for predicting whether a person buys a product or not, we would end up having outliers. Outliers could be of any kind and unpredictable. Somebody could have made an order accidently, for example, or they could have given access to their friends who then made the order, and so on.

Theoretically, deep neural networks are ideal for finding patterns and solutions from your dataset because they are supposed to mimic the human brain. However, in practice, this is often not quite the case. Your network will be able to solve problems easily by finding the pattern if your data is clean and properly formatted. PyTorch gives data preprocessing wrappers out of the box...

Novice model

Now we are going to build a novice, NumPy-like model, not using any PyTorch-specific approach. Then, in the next session, we'll convert the same model to PyTorch's method. If you come from a NumPy background, you'll feel at home, but if you are an advanced deep learning practitioner who has used other frameworks, please take the liberty of skipping this session.

Autograd

So, now that we know which type our tensors should be, we can create PyTorch tensors from the NumPy array we got from get_numpy_data().

x = torch.from_numpy(trX).to(device=device, dtype=dtype)
y = torch.from_numpy(trY).to(device=device, dtype=dtype)
w1 = torch.randn(input_size, hidden_size, requires_grad=True, device=device, dtype=dtype)
w2 = torch.randn(hidden_size, output_size, requires_grad=True, device=device, dtype=dtype)
b1 = torch.zeros(1, hidden_size, requires_grad=True, device=device, dtype=dtype)
b2 = torch.zeros(1, output_size, requires_grad=True, device=device, dtype=dtype...

The PyTorch way

So far, we have developed a simple two-layer neural network in a hybrid NumPy-PyTorch style. We have coded each operation line by line, like how we do it in NumPy, and we have adopted automatic differentiation from PyTorch so that we don't have to code the backward pass.

On the way, we have learned how to wrap matrices (or tensors) in PyTorch, and that helps us with backpropagation. The PyTorch way of doing the same thing is a bit more convenient and that is what we are going to discuss in this section. PyTorch gives access to almost all the functionality required for a deep learning project inbuilt. Since PyTorch supports all the mathematical functions available in Python, it's not a tough task to build one function if it's not available in the core. You can not only build any functionality you need, but PyTorch defines the derivative function of the functionality you build implicitly.

PyTorch is helpful for people who need to know the low-level...

Summary

In this chapter, we have learned how to build a simple neural network in the most basic way and convert that to a PyTorch's way. The basic building block of deep learning starts here. Once we know how and why the methodology we follow exists, we'll be able to take the big steps. Any deep learning model, regardless of the size, usage, or algorithm, can be built with the concepts we have learned in this chapter. Because of that, understanding this chapter thoroughly is critical for going through future chapters. In the next chapter, we will dive into the deep learning workflow.

References

  1. Fizz buzz Wikipedia page, https://en.wikipedia.org/wiki/Fizz_buzz
  2. Division (mathematics) Wikipedia page, https://en.wikipedia.org/wiki/Division_(mathematics)
  3. Joel Grus, Fizz Buzz in Tensorflow, http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
  4. Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning Book, http://www.deeplearningbook.org/
Left arrow icon Right arrow icon

Key benefits

  • Internals and principles of PyTorch
  • Implement key deep learning methods in PyTorch: CNNs, GANs, RNNs, reinforcement learning, and more
  • Build deep learning workflows and take deep learning models from prototyping to production

Description

PyTorch Deep Learning Hands-On is a book for engineers who want a fast-paced guide to doing deep learning work with PyTorch. It is not an academic textbook and does not try to teach deep learning principles. The book will help you most if you want to get your hands dirty and put PyTorch to work quickly. PyTorch Deep Learning Hands-On shows how to implement the major deep learning architectures in PyTorch. It covers neural networks, computer vision, CNNs, natural language processing (RNN), GANs, and reinforcement learning. You will also build deep learning workflows with the PyTorch framework, migrate models built in Python to highly efficient TorchScript, and deploy to production using the most sophisticated available tools. Each chapter focuses on a different area of deep learning. Chapters start with a refresher on how the model works, before sharing the code you need to implement it in PyTorch. This book is ideal if you want to rapidly add PyTorch to your deep learning toolset.

Who is this book for?

Machine learning engineers who want to put PyTorch to work.

What you will learn

  • Use PyTorch to build:
  • Simple Neural Networks – build neural networks the PyTorch way, with high-level functions, optimizers, and more
  • Convolutional Neural Networks – create advanced computer vision systems
  • Recurrent Neural Networks – work with sequential data such as natural language and audio
  • Generative Adversarial Networks – create new content with models including SimpleGAN and CycleGAN
  • Reinforcement Learning – develop systems that can solve complex problems such as driving or game playing
  • Deep Learning workflows – move effectively from ideation to production with proper deep learning workflow using PyTorch and its utility packages
  • Production-ready models – package your models for high-performance production environments

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2019
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781788833431
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 30, 2019
Length: 250 pages
Edition : 1st
Language : English
ISBN-13 : 9781788833431
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 102.97
PyTorch Deep Learning Hands-On
€32.99
Deep Learning with PyTorch
€32.99
Deep Reinforcement Learning Hands-On
€36.99
Total 102.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Deep Learning Walkthrough and PyTorch Introduction Chevron down icon Chevron up icon
2. A Simple Neural Network Chevron down icon Chevron up icon
3. Deep Learning Workflow Chevron down icon Chevron up icon
4. Computer Vision Chevron down icon Chevron up icon
5. Sequential Data Processing Chevron down icon Chevron up icon
6. Generative Networks Chevron down icon Chevron up icon
7. Reinforcement Learning Chevron down icon Chevron up icon
Chapter 8. PyTorch to Production Chevron down icon Chevron up icon
Another Book You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(10 Ratings)
5 star 40%
4 star 0%
3 star 10%
2 star 10%
1 star 40%
Filter icon Filter
Top Reviews

Filter reviews by




JB.Malone Jun 18, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a good book if you want a quick dive into PyTorch and build some basic ML projects. It covers a lot of topics fast so don't expect a deep book or lots of theory, what you get is some really useful PyTorch coding templates for CNNs, RNNs, GANs, so you can create these with PyTorch. I'm now getting up and running in PyTorch, and PyTorch rocks. I recommend PyTorch if you know ML but haven't tried it yet.
Amazon Verified review Amazon
Stephan Miller May 08, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is one of the books I wish I had when I got started in machine learning. Of course, I wish the current version of PyTorch was around then too. It will definitely get you started correctly if you're a beginner, will be a great refresher if you are an expert and will widen your knowledge of machine learning techniques if your knowledge only includes a few of the modern methods of extracting answers from data.This book will walk you through setting up your development environment right before you jump right into building a simple neural network. But neural networks is not all this book covers. You will learn how to create a convolutional neural network, the secret behind computer vision. You will also dive into recurrent neural networks and use long short-term memory and gated recurrent units. You will also study generative networks and learn about autoregressive models. Then you will use OpenAI's Gym library to explore Markov decision processes, the Bellman equation and deep Q-learning. Each of these technologies are taught with hands-on step-by-step tutorials.But that is not all. Along the way you will learn how to set up a pipeline to make developing and deploying your machine learning system much simpler and hassle free. And you will learn how to deploy your deep learning system to production using Flask and RedisAI.I would recommend this book to anyone interested in learning AI and machine learning. It will get you started quick and provides a broad overview of features of PyTorch and how you can use it for your own projects.
Amazon Verified review Amazon
Akshit Shah May 06, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am a Deep Learning Practioner, I have been primarily working with TensorFlow, I was thinking to migrate to Pytorch and explore the possibilities of the framework, This book helped me a lot in easy migration. It has all the building blocks required to learn Pytorch. Its advancing difficulty makes readers stick to the book. I especially loved the explanation of GANs. It is probably by far most up to date information provided.Thank You, Authors and Packt publishing for the amazing book.Cheers!
Amazon Verified review Amazon
Jessica Apr 29, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very enjoyable to read. The content covers the several main streams of the current deep learning research: NLP, GAN, DRL, etc, and presents step-by-step tutorials on implementing the popular approaches within each field, e.g. CycleGAN, DQN, WaveNet, etc. As a deep learning researcher working primarily with pytorch, I find that this book can work as a good refresher for the fields that I already have experience with, and as a gentle introduction to areas that I am less familiar with while presenting the right amount of implementation details. A well-structured and well-presented guide to deep learning research with pytorch!
Amazon Verified review Amazon
Colin Hagemeyer Jun 04, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
On the positive, the book walks you step-by-step through the various functions of PyTorch. However, there are a number of issues (in order of importance):1) The authors often use deprecated commands, and so you have to regularly check online if the way they are doing it is how it is currently done. Since this book was published 2 months ago, there's really no excuse.2) Sometimes they'll mention a command in a small paragraph, but fail to provide syntax, an example, or any clear explanation of what it does. In these cases you once again need to go online and figure out what the command does3) The writing is full of over-the-top cliched language like "turned the whole AI community upside down" or "be ready to be blown away". I find myself rolling my eyes almost constantly while reading this book. In addition, there are some awkward sentences, so the book probably needed another pass by the proof-readerMy conclusion is that the book needs more work. It's helpful to get some guidance rather than trying to start directly from online tutorials, but it's probably not worth the quite high price tag. It's also quite interesting how all the 5 star reviews are from unverified purchases, and one of them appears to have been posted a day before the book was published. I wonder why that would be.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.