Overview

Appendix B. Introduction to fundamental deep learning tools

This appendix offers a brief orientation to the core tools and concepts that recur throughout the book, with the main goal of helping readers new to deep learning become comfortable with the ecosystem. It emphasizes that the material is not strictly required to follow the rest of the book, but it can make the journey smoother by clarifying why these tools matter and how they fit together. The discussion focuses on five foundational components: stochastic gradient descent, TensorFlow, PyTorch, and the higher-level interfaces Keras, fast.ai, and Hugging Face transformers.

The first major idea is stochastic gradient descent, the training method at the heart of modern neural networks. The appendix explains training as the process of finding weights that make model predictions close to the training data by minimizing a loss function, then describes the repeated cycle of sampling a batch, computing predictions, measuring loss, finding gradients, and updating weights in the direction that reduces error. It also notes common improvements such as momentum, Adagrad, RMSprop, Adam, and Nadam, briefly explaining how these variants adjust learning rates or update rules to improve convergence and handle practical challenges like rare features or overly rapid decay.

The remainder of the appendix introduces TensorFlow and PyTorch as the main frameworks for building and differentiating neural network models, then shows how higher-level tools sit on top of them to simplify modeling. TensorFlow is presented through the ideas of tensors, computation graphs, and automatic differentiation, along with a contrast between its earlier graph-based style and its newer eager execution mode that is more intuitive and accessible. PyTorch is described as a flexible framework favored in research for its dynamic behavior, and the appendix closes by positioning Keras, fast.ai, and Hugging Face transformers as convenient abstractions that make neural network development easier while still relying on the underlying frameworks.

Figure B.1 Stochastic gradient descent illustrated in the overly simple case of a single weight. At each step, compute the gradient with respect to W, and take a step of a prespecified size, as determined by the learning rate, in the opposite direction of the gradient of the loss function. In this hypothetical scenario, the minimum is found at step 2.
APPB_01
Figure B.2 Illustration of the hierarchical organization of the TensorFlow framework
APPB_02

B.4 Keras, fast.ai, and Transformers by Hugging Face

As mentioned earlier in the appendix, the Keras library is a higher-level neural network modeling framework, which is also now included in TensorFlow versions 2.0 and later. By using it, you can specify neural network architectures in both TensorFlow and PyTorch from a single API—just change the backend as needed! It comes prepackaged with TensorFlow, as we illustrated in figure B.2. Its API is relatively simple compared to both TensorFlow and PyTorch, which has made it very popular. Many excellent resources exist for learning it, perhaps the best one being the author’s own book.7 This is also an excellent reference for learning TensorFlow, and about neural networks in general, and we highly recommend it if you feel you need to brush up on these topics. You can also work through some Kaggle kernels to pick up the basics, with the tutorial at https://www.kaggle.com/prashant111/keras-basics-for-beginners being just one good example.

Another popular higher-level modeling API in the field is fast.ai. This library was developed as a companion to the massive open online course (MOOC) of the same name and implements state-of-the-art methods in a way that makes them extremely easy to use. One of its motivations was democratizing these tools for the developing world. A popular feature of this library is its learning rate determination utility, which we use in chapter 9 of this book. The framework is used for both NLP and computer vision and runs on PyTorch. Naturally, the best reference for learning the library is the fast.ai MOOC8 itself. The free course covers the basics of neural networks and deep learning and is another wonderful resource that we highly recommend. The library achieves simplicity by defining its own set of data structures that handle a lot of boilerplate stuff for the user. On the other hand, this might make it harder to customize for nonstandard use cases. In this author’s experience, it is a wonderful tool to have in one’s arsenal.

Finally, transformers by Hugging Face is a higher-level modeling framework specifically for transformer-based models. These have become arguably the most important architecture for modern NLP. You will learn exactly why that is the case throughout the book. The library might be the most popular library in the space today, due to the sheer ease of using it to deploy these models. Before this library existed, deploying transformer models in Keras, TensorFlow, and/or PyTorch was quite tedious. The library simplified the process into a few lines of Python code in some cases, which led to an explosion in its popularity, and it is considered indispensable for the modern NLP practitioner. Due to the transparency and simplicity of the API, you can probably get away with just reading through the book and working through relevant examples, even without any prior experience with it. For further reference, check out the intro notebooks from the authors on GitHub9 and their official quick start10 documentation.

1. F. Chollet, Deep Learning with Python (Manning Publications, 2018).

2. S. Ruder, “An Overview of Gradient Descent Optimization Algorithms,” arXiv (2016).

7. F. Chollet, Deep Learning with Python (Manning Publications, 2018).

FAQ

What is the main purpose of Appendix B in the book?Appendix B provides a brief primer on fundamental deep learning tools and concepts used throughout the book, especially for readers new to the field. It offers a bird’s-eye view rather than an exhaustive treatment.
Why does the appendix start with stochastic gradient descent?Stochastic gradient descent is introduced first because it is the algorithmic engine behind training neural networks and much of the deep learning revolution. It is the core method used to minimize the loss function during training.
What does stochastic gradient descent try to accomplish in neural network training?It tries to find the set of weights that minimizes the loss function, so the network’s predictions are as close as possible to the training data. It does this by repeatedly updating weights in the direction opposite to the gradient of the loss.
What are the basic steps of stochastic gradient descent?The method samples a random batch of input-output data, computes predictions with the current weights, evaluates the loss, calculates the gradient of the loss with respect to the weights, and updates the weights slightly in the opposite direction of that gradient.
Why is the algorithm called “stochastic” gradient descent?It is called stochastic because it uses randomly sampled batches of training data at each step rather than the full dataset every time. This randomness helps make training efficient and practical.
What role does the learning rate play in stochastic gradient descent?The learning rate determines the size of each weight update step. It is a very important hyperparameter because it affects how quickly and how well the model converges.
What are some common variants of stochastic gradient descent mentioned in the appendix?The appendix mentions Adagrad, RMSprop, Adam, and Nadam. These variants adapt learning rates or use momentum-like ideas to improve convergence and help avoid local minima.
Why are TensorFlow and PyTorch important in deep learning?They are fundamental neural network modeling frameworks used to build and train models. They automatically compute gradients, which is essential for training large neural networks efficiently.
What is automatic differentiation in TensorFlow and PyTorch?Automatic differentiation is the process of computing gradients automatically by applying the chain rule through the operations that make up the model. This removes the need to calculate derivatives by hand for large neural networks.
How do TensorFlow and PyTorch differ in the way they are commonly used?TensorFlow historically used graph-based execution, especially in version 1.x, while TensorFlow 2 introduced eager execution for a more Pythonic workflow. PyTorch became especially popular among researchers because of its flexibility and runtime model modification, while TensorFlow has often been seen as strong for production deployment.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Transfer Learning for Natural Language Processing Transfer Learning for Natural Language Processing ebook for free