Deep Learning
From gradient descent and tensors to transformers and fine-tuning, deep learning as told through the free samples of the Leanpub books that teach it.
Created from the free samples of 9 Leanpub books and the descriptions and tables of contents of 8 more, with every source cited.
Deep learning is the branch of machine learning that uses neural networks with many layers, whose numerical parameters are adjusted automatically from examples instead of being set by a programmer. A network is trained by measuring how wrong its outputs are and changing its parameters, a little at a time, in the direction that reduces the error. One source defines the method at the centre of this, gradient descent, as an iterative technique for finding the best set of parameters for a given model, data and loss function, starting from an initial and usually random guess.[1]
The field today is dominated by one family of models. A large language model is a neural network trained on very large amounts of text to predict the next token in a sequence, and the industry has moved from building a separate model for each task to adapting one general model to many.[2] Most of the recent books used here are accordingly about language models and the transformer architecture beneath them. The older subjects remain in the general texts: convolutional networks for images, recurrent networks for sequences, and the training mechanics common to all of them.
This article covers how a network learns, the software it is built with, the main architectures, the transformer and the language models built on it, how a trained model generates text, fine-tuning, generative models in science, and the limits of applying deep learning. Its sources are the free samples of 9 Leanpub books and the public descriptions and tables of contents of 8 more. Where a sample says something, it is cited; where a book has no sample, it is cited only for what its description and contents list say, and the note in the Sources list says so. Retrieval-augmented generation and prompt engineering have their own articles.
Where to start
A reader with no programming background can begin with Coffee Break AI (2026), a non-technical book whose opening chapter describes present-day systems as pattern-finding software pointed at narrow predictions and warns against judging a system by the fluency of its output.[8] A visual guide behind deep learning (2026) is described as a 33-page visual account, needing only school algebra and containing no code, of how a network learns from being wrong, meant to be read before a first course.[14]
For someone who can program in Python and wants to train networks, the fullest beginner's text is Deep Learning with PyTorch Step-by-Step (2024). It is written for beginners in general, not only newcomers to its framework, and expects Python, the usual numerical libraries and basic machine-learning ideas such as loss functions, the split into training, validation and test sets, and overfitting.[1] Mastering PyTorch and Lightning (2026) is a shorter book on the same framework and the training library built on it, which begins with the internals of the tensor.[6] Two general surveys have no sample: Neural Networks & Deep Learning with Python Programming (2026) is described as building networks in plain NumPy before moving to a framework,[12] and Mastering Deep Learning with PyTorch (2026) as running from the fundamentals of neural networks to five capstone projects.[13]
Readers who want language models specifically have a choice by depth. Inside Large Language Models for absolute beginners: Volume I (2026) assumes no machine-learning experience, only intermediate Python and high-school algebra, and works each idea through with numbers before giving a formula.[2] My Adventures with Large Language Models (2026) asks for working Python and some familiarity with PyTorch and neural networks,[4] and A Hands-On Guide to Fine-Tuning Large Language Models with PyTorch and Hugging Face (2025) sits at an intermediate level, for practitioners who have already trained models.[5]
History
Neural networks date from the 1950s, but they were not practical for language until the 2000s, when hardware caught up with them.[2] One sample divides the history of language modelling into three periods, and the division serves for deep learning as a whole. In the statistical period, from the 1950s to the early 2000s, hand-written rules gave way to n-gram models that counted word patterns in real text. These were fast and effective for speech recognition and simple prediction, but could look back only a few words and had no representation of meaning.[2]
The neural period ran from about the mid-2000s to 2017. Networks learned to represent words as vectors that encode meaning, a result made widely known by a word-embedding method published in 2013, and recurrent networks, later with gated memory cells, became the standard architecture for language and powered the first convincing machine translation.[2] They had two weaknesses that could not be engineered away: information from early in a sequence faded as it grew longer, and processing one token at a time prevented training from being spread across the many cores of a graphics processor.[2]
The third period began with a 2017 research paper that replaced recurrence with a mechanism called self-attention, in which every token is processed at once and each attends to every other.[2] Training could now be parallel, so models could grow, and growth brought jumps in capability and not only gradual improvement. In 2018 an encoder-only model, BERT, established the recipe of pre-training on a large body of text and then fine-tuning on a task; a decoder-only model, GPT-2, showed that the same architecture could generate coherent text; and a successor of 2020 with 175 billion parameters performed tasks from a few examples placed in its prompt.[2] The same sample dates public awareness to the end of November 2022, when a chat assistant reached a million users in five days.[2] The framework most of these books use, PyTorch, was released in October 2016.[1]
How a network learns
Training a network is a loop with a small number of steps, and the books that teach it from the beginning use the simplest model that shows them all.
Gradient descent
Deep Learning with PyTorch Step-by-Step opens with a chapter that contains no framework code at all. It fits a straight line with one input, written in NumPy, so that nothing distracts from the procedure, and it argues that the usual presentation of gradient descent as equations and rules of thumb leaves beginners without intuition.[1] The procedure has five steps: give the parameters random initial values, compute the model's predictions (the forward pass), compute the loss, compute the gradients, and update the parameters.[1]
The sample is careful about terms. An error is the difference between a prediction and the true value for a single data point, and a loss is an aggregate of errors over a set of points. Computing the loss over the whole training set at each step is batch gradient descent, over a single point stochastic gradient descent, and over anything in between mini-batch gradient descent, the last giving up a little stability for speed.[1] Because the example has only two parameters, the loss for every combination of them can be computed and drawn as a surface, which the book notes is not feasible for almost any real problem.[1] It adds practical rules along the way: the data is split into training and validation sets before any preprocessing, it is shuffled before training except in time-series problems, where shuffling leaks information, and a fixed random seed makes results repeatable, though not necessarily across versions of the framework or between processor and graphics card.[1]
Backpropagation and its mathematics
In a network with many layers the gradients are obtained by backpropagation, which applies the chain rule of calculus backwards from the loss through each layer. A framework does this automatically, and the beginner's books differ on how much of it to show. A visual guide behind deep learning is described as building each idea in pictures before naming it, following one example from a random first guess to a working model.[14] Neural Networks & Deep Learning with Python Programming is described as having the reader build perceptrons and multi-layer networks by hand to absorb weights, biases and the chain rule.[12]
Calculus for machine learning and artificial intelligence (2026) approaches from the other side, as a calculus text arranged around its uses in machine learning. Its description gives the reasons: models learn by minimising an error, which requires gradients; backpropagation depends entirely on derivatives; and minima, maxima and saddle points, the vocabulary of optimisation, are concepts of calculus.[15] Deep Learning with PyTorch Step-by-Step takes the opposite policy and avoids mathematical notation where plain language will do.[1]
Frameworks and hardware
Nearly every book here that contains code uses PyTorch. Its distinguishing feature is that the graph of computations is built as ordinary Python statements execute, so intermediate values can be inspected with standard debugging tools and the computation can vary with its input; since version 2.0 a compiler can be applied to the same code.[6] The basic object is the tensor. Mastering PyTorch and Lightning describes it as a header, holding shape, stride, data type and device, placed over a flat block of memory, and shows what follows from that: some ways of creating a tensor copy their source and others share its memory, so that a change made through one is visible through the other.[6] The choice of data type is both a performance decision and a numerical one, a sixteen-bit format using half the memory of the standard thirty-two-bit one at the cost of different rounding.[6]
As projects grow, the code that moves data between devices, runs the training loop, distributes work and logs metrics becomes entangled with the code that defines the model. The same book presents PyTorch Lightning as a structure that separates the two, so that devices, distribution and numerical precision can be changed in configuration without touching the model.[6]
Training is much faster on a graphics processor, but the introductory books do not require one. Deep Learning with PyTorch Step-by-Step designed its examples to run in minutes on an ordinary processor and points readers to free hosted notebooks,[1] and My Adventures with Large Language Models gives a small-scale variant of every chapter for readers without one.[4] The two framework books also show how setup has changed. The 2024 text says a graphics-card installation needs up-to-date drivers and separately installed vendor libraries, and the 2026 text tells readers not to install those by hand, because the official packages now include them and only the driver has to match.[1][6]
Convolutional and recurrent networks
Before the transformer, two architectures defined the field, and the general texts still teach both. A convolutional network slides small learned filters across an image, so that a pattern is recognised wherever it appears. The second part of Deep Learning with PyTorch Step-by-Step is given to computer vision, covering convolutions, deeper models, transfer learning and schemes for initialising weights,[1] and the contents of Neural Networks & Deep Learning with Python Programming list pooling and padding, data augmentation and transfer learning from published image models.[12] Machine Learning in Python for Visual and Acoustic Data-based Process Monitoring (2024) is described as a short beginner's guide that applies convolutional networks to detecting manufacturing defects from image sensors, with an introduction to predicting equipment failure from the sound a machine makes.[16] Among the capstone projects described for Mastering Deep Learning with PyTorch are pneumonia detection and object detection.[13]
A recurrent network reads a sequence one element at a time and carries a hidden state forward. The third part of Deep Learning with PyTorch Step-by-Step moves through plain recurrent networks, the gated variants, sequence-to-sequence models and attention on its way to the transformer.[1] The description of Super Study Guide: Transformers & Large Language Models (2025), an illustrated study guide, places recurrent networks in its part on embeddings, before the part on transformers.[10]
Transformers and language models
The language-model books agree on what to explain and differ in how far they go. The common sequence is: text is split into tokens, tokens are mapped to vectors, the vectors are given positional information, layers of attention and feed-forward computation transform them, and the final layer produces a score for every token in the vocabulary. The contents of The inner workings of Large Language Models (2025), a 67-page book written from a developer's own study notes, follow exactly this order and end with a reference table of the process in eight steps.[11]
Embeddings and attention
An embedding places words in a space where related words lie near each other. My Adventures with Large Language Models introduces the idea through an early method trained either to predict a word from its neighbours or the neighbours from the word, and corrects a familiar demonstration of it: the vector for king, minus man, plus woman, is in fact closest to king, and the celebrated answer of queen appears because implementations exclude the input words from the results.[4]
Attention lets each token draw on the others in proportion to their relevance. Inside Large Language Models for absolute beginners: Volume I explains it with a study group in which each member signals how useful their word is to the one being interpreted, and with the word bank, which an encoder represents by different vectors in a sentence about money and a sentence about a river.[2] The first chapter of My Adventures with Large Language Models implements the original 2017 design in full as an English-to-Hindi translator, in a dozen steps from embeddings and positional encoding through attention, layer normalisation and residual connections to training.[4]
Architecture families
Inside Large Language Models for absolute beginners: Volume I sorts models into four families. Encoders read: every token can attend to every other in both directions, which yields rich representations and rules out generation, and they are trained by hiding words and predicting them. Decoders write one token at a time and may look only backwards, a restriction called causal masking. Encoder-decoders combine the two for tasks such as translation, and auto-encoders compress data through a bottleneck and reconstruct it, the principle behind one component of image generators.[2]
The architecture has kept changing inside the decoder family. My Adventures with Large Language Models rebuilds GPT-2 and then replaces each of its components with the version used in an open-weight model of three billion parameters, changing the normalisation, the positional scheme, the activation function and the form of attention, before a last chapter on a design that adds a compressed form of attention and a mixture of expert sub-networks.[4] Its preface advises readers to swap components back and watch the loss curves, on the ground that much of the insight in model design comes from experiments that fail.[4]
Inference
Using a trained language model differs from training it, and the difference explains much of the cost of running one. During training the model sees a whole sequence and predicts the next token at every position in parallel; during generation there is no known answer to supply, so tokens are produced one at a time, each depending on all those before it.[3] Inside Large Language Models for absolute beginners: Volume II (2026) divides a request into two phases. In the first the whole prompt is processed in one parallel pass, which determines how long a user waits for the first token. In the second each new token requires a pass through the entire model, and the limit is the speed at which the weights can be read from memory, not arithmetic: for a model of seven billion parameters that is fourteen gigabytes for every token.[3]
The main remedy is a cache of the attention keys and values already computed for earlier tokens, which never change and need not be recomputed. The sample traces it by hand with small matrices.[3] The same chapter lists five ways of choosing the next token from the model's scores, from always taking the most probable to sampling within limits and beam search, which decide whether output is deterministic or varied.[3] My Adventures with Large Language Models gives the cache a chapter of its own, together with the attention variants that trade memory against expressiveness.[4]
Fine-tuning
Fine-tuning continues the training of an existing model on new data, by the same procedure as training from scratch.[5] A Hands-On Guide to Fine-Tuning Large Language Models with PyTorch and Hugging Face describes the first widespread form, instruction tuning, which changed models from completing text to answering: before it, a user had to rephrase a question as an unfinished statement for the model to complete.[5] The book concerns the commonest later use, teaching a model a specialised and fairly stable body of knowledge, such as an organisation's internal documentation or the summarising of legal texts. It recommends retrieval instead where knowledge changes in real time or is very large and varied, and suggests checking whether a much smaller model would do before using a large one for plain classification.[5]
Its central claim is that configuration can substitute for hardware: a naive fine-tuning loop may need tens of gigabytes of graphics memory, and a carefully configured one can produce a comparable model with a tenth of that.[5] Two techniques carry most of the saving. Quantisation stores the weights at lower precision, after which the quantised layers can be used but not updated. Low-rank adapters are small trainable layers attached to those frozen ones, and in the book's opening walk-through they leave about a third of one per cent of the parameters trainable.[5] The sample also records the kind of detail that defeats first attempts, such as a model whose end-of-sequence token doubles as its padding token and so is masked in training, producing output that never stops, and the observation that the maximum sequence length is likelier than anything else to exhaust memory.[5]
Inside Large Language Models for absolute beginners: Volume II covers the same methods with worked numbers and applies them in four projects, classifying contracts, assisting with legal documents, turning questions into SQL and calling functions, and it adds a part on alignment by reinforcement learning from human feedback, a subject A Hands-On Guide to Fine-Tuning Large Language Models with PyTorch and Hugging Face sets aside.[3][5] Parameter-efficient and preference tuning also appear in the description of Super Study Guide: Transformers & Large Language Models.[10]
Generative models and science
Language models are one kind of generative model. Generative AI for Science (2026) states the general distinction: traditional machine learning excels at discriminative tasks such as classification and regression, and a generative model learns the distribution underlying its data and samples from it to produce new instances.[7] Its first chapter names the technologies involved as transformers; diffusion models, which learn to reverse a gradual process of adding noise; and the earlier variational auto-encoders and generative adversarial networks, still used to learn compact representations and to make synthetic data.[7] The contents of Neural Networks & Deep Learning with Python Programming include chapters on auto-encoders, generative adversarial networks and diffusion models.[12]
The book, which grew out of a graduate course and asks for basic Python and undergraduate statistics but no prior deep learning, surveys their use in research: proposing molecules and materials, predicting protein structures, work recognised by the 2024 Nobel Prize in Chemistry, and weather forecasting, where a diffusion-based model is reported to produce a fifteen-day forecast in eight minutes.[7] It makes two points particular to science. Pre-training matters more there because labelled data is scarce and costly, and networks can be constrained by known physics, with the governing differential equations built into training.[7]
Limits and evaluation
Several sources are concerned with what a network's output is worth. Coffee Break AI makes the lay version of the point: a useful prediction is not a judgement, fluent language is not proof of comprehension, and the question to ask of any system is what narrow task it was built to predict and what kind of mistake would look plausible.[8] Inside Large Language Models for absolute beginners: Volume I promises an account of persistent limitations, hallucination among them, alongside the capabilities.[2]
Two books by one author address the question statistically. Applied Conformal Prediction:Practical Uncertainty Quantification for Real-World ML (2026), an in-progress book, is described as teaching conformal prediction, a method that wraps around any model to produce prediction sets with guaranteed coverage, with the integration of deep-learning models among its subjects.[17] The description of Mastering Modern Time Series Forecasting (2026) criticises forecasting books that apply transformer architectures with no discipline of evaluation and no account of when classical methods still win, and its sample chapter asks, before any model is built, whether a series can be forecast at all.[9] The science text likewise lists uncertainty quantification among the methods a scientific pipeline needs.[7]
Questions about Deep Learning
Which deep learning book should I start with?
A reader who can program in Python can start with Deep Learning with PyTorch Step-by-Step, which is written for beginners in general and opens with gradient descent on a one-input linear model before any framework code.[1] A reader who wants the idea before any code has A visual guide behind deep learning, described as a 33-page visual account that needs only school algebra.[14]
What is gradient descent?
Do I need a GPU to learn deep learning?
No. Deep Learning with PyTorch Step-by-Step designed its examples to run in minutes on an ordinary processor and points to free hosted notebooks,[1] and My Adventures with Large Language Models provides a small-scale variant of every chapter for readers without one.[4]
What is a large language model?
Why does a language model generate text more slowly than it reads a prompt?
Can a large language model be fine-tuned on a single consumer graphics card?
Yes, with careful configuration. A Hands-On Guide to Fine-Tuning Large Language Models with PyTorch and Hugging Face reports that a well-configured loop can match a naive one using a tenth of the graphics memory, chiefly by quantising the model and training small low-rank adapters attached to its frozen layers.[5]
Sources
Every source is a Leanpub book or course. The note after each says which part of it was read; where no sample was available, only the public description and table of contents were used.
- 1.Deep Learning with PyTorch Step-by-Step, Daniel Voigt Godoy: A Beginner's Guide Free sample: the preface, the FAQ on who the book is for, the setup guide and most of chapter 0 on gradient descent. 2024. Free sample: PDF
- 2.Inside Large Language Models for absolute beginners: Volume I, Ritesh Modi: Simple Arithmetic and beginners Python based approach Free sample: the preface and plan of both volumes, chapter 1 (what a language model is, three periods of history) and the opening of chapter 2 on architecture families. 2026. Free sample: PDF
- 3.Inside Large Language Models for absolute beginners: Volume II, Ritesh Modi: Simple Arithmetic and beginners Python based approach Free sample: the front matter shared with Volume I and the opening of chapter 10 on inference (the two phases, the key-value cache). 2026. Free sample: PDF
- 4.My Adventures with Large Language Models, Prathamesh S.: Build foundational LLMs from Transformers to DeepSeek, from scratch, in PyTorch. Free sample: the preface (the five chapters, readers, hardware) and the opening of chapter 1 on embeddings. 2026. Free sample: PDF
- 5.A Hands-On Guide to Fine-Tuning Large Language Models with PyTorch and Hugging Face, Daniel Voigt Godoy Free sample: the FAQ (who should read it, why fine-tune, fine-tuning against retrieval) and chapter 0, an end-to-end walk-through. 2025. Free sample: PDF
- 6.Mastering PyTorch and Lightning, Aghiles Kebaili: A Step-by-Step Practical Guide with QA Free sample: chapter 0 (why PyTorch, why Lightning, environment setup) and the first half of chapter 1 on tensors. 2026. Free sample: PDF
- 7.Generative AI for Science, J. Paul Liu: A Hands-On Guide for Students and Researchers Free sample: the author's note, prerequisites and chapter 1, a survey of generative models in the sciences with no code. 2026. Free sample: PDF · EPUB
- 8.Coffee Break AI, Finxter: Understand How Artificial Intelligence Really Works - One Short Chapter at a Time Free sample: the contents list and chapter 1, a non-technical definition of AI as narrow prediction. 2026. Free sample: PDF
- 9.Mastering Modern Time Series Forecasting, Valery Manokhin: A Comprehensive Guide to Statistical, Machine Learning, and Deep Learning Models in Python Free sample: chapter 2 on whether a series can be forecast; nothing on deep learning, which is cited from the description. 2026. Free sample: PDF
- 10.Super Study Guide: Transformers & Large Language Models, Afshine Amidi, Shervine Amidi No sample: from the description. 2025.
- 11.The inner workings of Large Language Models, Roger Gullhaug: how neural networks learn language No sample: from the description and table of contents. 2025.
- 12.Neural Networks & Deep Learning with Python Programming, Edgar Milvus No sample: from the description and its chapter list. 2026.
- 13.Mastering Deep Learning with PyTorch, Anshuman Mishra: From Fundamentals to Real-World Projects No sample: from the description and table of contents. 2026.
- 14.A visual guide behind deep learning, Ritesh Modi: The intuition you need before your first deep learning course No sample: from the description. 2026.
- 15.Calculus for machine learning and artificial intelligence, Anshuman Mishra: From derivatives to backpropagation No sample: from the description and table of contents. 2026.
- 16.Machine Learning in Python for Visual and Acoustic Data-based Process Monitoring, Ankur Kumar: A short beginner’s guide to deep learning-based computer vision and abnormal sound detection No sample: from the description. 2024.
- 17.Applied Conformal Prediction:Practical Uncertainty Quantification for Real-World ML, Valery Manokhin: Practical Uncertainty Quantification for Real-World ML Learn Conformal Prediction (CP), the state-of-the-art technique for building statistically valid, model-agnostic prediction intervals No sample: from the description; the book is still being written. 2026.
Further reading
Other books in the library on the same ground, not cited above.
- Generative AI with local LLM, Shamim Bhuiyan, Timur Isachenko: A comprehensive roadmap for building AI-Driven applications with local LLMs On building applications with language models run on one's own hardware, with a chapter on fine-tuning. 2025. Free sample: PDF · EPUB
- The Agentic AI book, Dr. Ryan Rad: From Language Models to Multi-Agent Systems A book on designing and operating agent systems whose early chapters cover language-model foundations. 2026.
- AI with JavaScript & TypeScript: The Edge of AI. Local LLMs (Ollama), Transformers.js, WebGPU, and Performance Optimization, Edgar Milvus On running pretrained models locally and in the browser from JavaScript and TypeScript. 2026.