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.
Figure B.2 Illustration of the hierarchical organization of the TensorFlow framework
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.
Transfer Learning for Natural Language Processing ebook for free