Alice's adventures in a differentiable wonderland

https://www.sscardapane.it/alice-book
Cover of Alice's Adventures in a Differentiable Wonderland

A primer on designing neural networks. Volume I: A tour of the land

Neural networks surround us, in the form of large language models, speech transcription systems, molecular discovery algorithms, robotics, and much more. Stripped of anything else, neural networks are compositions of differentiable primitives, and studying them means learning how to program and how to interact with these models, a particular example of what is called differentiable programming.

This primer is an introduction to this field, imagined for someone who, like Alice, has just ventured into this strange differentiable wonderland. I overview the basics of optimizing a function via automatic differentiation, and a selection of the most common designs for handling sequences, graphs, texts, and audio. The focus is an intuitive, self-contained introduction to the most important design techniques, including convolutional, attentional, and recurrent blocks, bridging the gap between theory and code (PyTorch and JAX) and leaving the reader able to understand some of the most advanced models out there, such as large language models and multimodal architectures.

Get the book

Free PDF

The latest version of the book, free to download.

Download the PDF · updated 29 August 2025

For the differences between the printed and the digital versions, see the errata list.

Additional chapters 2

Here I publish additional chapters on advanced material that I could not fit into the first volume. Eventually, I hope they will become part of a second volume. They are drafts and may still contain errors, so corrections and suggestions are very welcome.

Draft Updated 15 October 2026

Post-training techniques

A historical overview of post-training for large language models, from 2012 to the present, and a technical focus on reinforcement learning.

Download the PDF

Contents of Volume I

  1. Foreword and introduction
  2. Mathematical preliminaries
  3. Datasets and losses
  4. Linear models
  5. Fully-connected layers
  6. Automatic differentiation
  7. Convolutional layers
  8. Convolutions beyond images
  9. Scaling up the models
  10. Transformer models
  11. Transformers in practice
  12. Graph layers
  13. Recurrent layers
  1. Probability theory
  2. 1D universal approximation

Learn with the book

License and citation

CC BY-SA The book is released under the CC BY-SA 4.0 license. You can share, remix and adapt it in any medium or format, including for commercial use, as long as you give attribution and release the modified material under the same license.

To cite the book:

@article{scardapane2024alice,
  title   = {Alice's Adventures in a Differentiable Wonderland --
             Volume I, A Tour of the Land},
  author  = {Scardapane, Simone},
  journal = {arXiv preprint arXiv:2404.17625},
  year    = {2024}
}
{
"by": "tosh",
"descendants": 97,
"id": 40213292,
"kids": [
40214349,
40215053,
40224216,
40215080,
40213790,
40214712,
40213461
],
"score": 235,
"time": 1714496616,
"title": "Alice's adventures in a differentiable wonderland",
"type": "story",
"url": "https://www.sscardapane.it/alice-book"
}
{
"author": null,
"date": null,
"description": "A free, self-contained introduction to neural networks and differentiable programming, from automatic differentiation to transformers, with additional chapters on advanced topics.",
"image": "https://sscardapane.it/assets/alice/cover.png",
"logo": null,
"publisher": "Simone Scardapane",
"title": "Alice’s Adventures in a Differentiable Wonderland",
"url": "https://sscardapane.it/alice-book/"
}
{
"url": "https://sscardapane.it/alice-book/",
"title": "Alice's Adventures in a Differentiable Wonderland",
"description": "A primer on designing neural networks. Volume I: A tour of the land Neural networks surround us, in the form of large language models, speech transcription systems, molecular discovery algorithms,...",
"links": [
"https://sscardapane.it/alice-book/",
"https://www.sscardapane.it/alice-book"
],
"image": "https://sscardapane.it/assets/alice/cover.png",
"content": "<div>\n <article>\n <section>\n <img src=\"https://sscardapane.it/assets/alice/cover.png\" alt=\"Cover of Alice's Adventures in a Differentiable Wonderland\" />\n <div>\n <p>A primer on designing neural networks. Volume I: A tour of the land</p>\n <p>Neural networks surround us, in the form of large language models, speech transcription systems, molecular discovery algorithms, robotics, and much more. Stripped of anything else, neural networks are compositions of differentiable primitives, and studying them means learning how to program and how to interact with these models, a particular example of what is called <a target=\"_blank\" href=\"https://www.facebook.com/yann.lecun/posts/10155722686332143\">differentiable programming</a>.</p>\n <p>This primer is an introduction to this field, imagined for someone who, like Alice, has just ventured into this strange <em>differentiable</em> wonderland. I overview the basics of optimizing a function via automatic differentiation, and a selection of the most common designs for handling sequences, graphs, texts, and audio. The focus is an intuitive, self-contained introduction to the most important design techniques, including convolutional, attentional, and recurrent blocks, bridging the gap between theory and code (PyTorch and JAX) and leaving the reader able to understand some of the most advanced models out there, such as large language models and multimodal architectures.</p>\n </div>\n</section>\n<h2 id=\"get-the-book\">Get the book</h2>\n<div>\n <h3>Free PDF</h3>\n <p>The latest version of the book, free to download.</p>\n <p><a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/Alice_book_volume_1.pdf\">Download the PDF</a> · updated 29 August 2025</p>\n </div>\n<p>For the differences between the printed and the digital versions, see the <a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/errata_list.pdf\">errata list</a>.</p>\n<h2 id=\"additional-chapters\">Additional chapters <span>2</span></h2>\n<p>Here I publish additional chapters on advanced material that I could not fit into the first volume. Eventually, I hope they will become part of a second volume. They are drafts and may still contain errors, so corrections and suggestions are very welcome.</p>\n<div>\n <article>\n <p><span>Draft</span>\n <span>Updated 15 October 2026</span><span>Extends Chapter 6</span>\n </p>\n <h3><a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/Alice_volume_2_autodiff.pdf\">Advanced automatic differentiation</a></h3>\n <p>Differentiation in generic vector spaces, computational graphs, implicit differentiation (briefly), and an overview of multilinear algebra.</p>\n <p><a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/Alice_volume_2_autodiff.pdf\">Download the PDF</a></p>\n </article>\n <article>\n <p><span>Draft</span>\n <span>Updated 15 October 2026</span>\n </p>\n <h3><a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/Alice_volume_2_rl.pdf\">Post-training techniques</a></h3>\n <p>A historical overview of post-training for large language models, from 2012 to the present, and a technical focus on reinforcement learning.</p>\n <p><a target=\"_blank\" href=\"https://sscardapane.it/assets/alice/Alice_volume_2_rl.pdf\">Download the PDF</a></p>\n </article>\n</div>\n<h2 id=\"contents\">Contents of Volume I</h2>\n<ol>\n <li>Foreword and introduction</li>\n <li>Mathematical preliminaries</li>\n <li>Datasets and losses</li>\n <li>Linear models</li>\n <li>Fully-connected layers</li>\n <li>Automatic differentiation</li>\n <li>Convolutional layers</li>\n <li>Convolutions beyond images</li>\n <li>Scaling up the models</li>\n <li>Transformer models</li>\n <li>Transformers in practice</li>\n <li>Graph layers</li>\n <li>Recurrent layers</li>\n</ol>\n<ol>\n <li>Probability theory</li>\n <li>1D universal approximation</li>\n</ol>\n<h2 id=\"learn-with-the-book\">Learn with the book</h2>\n<ul>\n <li><a target=\"_blank\" href=\"https://www.notion.so/sscardapane/Guided-lab-sessions-18c25bd12a8c8068b972f7612fcde8d5\">Guided lab sessions</a> covering most of the topics in the book, in PyTorch and JAX, updated continuously.</li>\n <li>I use the book as the reference text for my <a target=\"_blank\" href=\"https://sscardapane.it/teaching/\">courses</a> on neural networks. Their slides and notebooks are on the <a target=\"_blank\" href=\"https://sscardapane.github.io/teaching-materials/\">teaching materials</a> site.</li>\n <li>An unofficial (incomplete) <a target=\"_blank\" href=\"https://github.com/GiovanniBorrelli/Traduzione-di-Alice-s-Adventures-in-a-differentiable-wonderland/tree/main\">Italian translation</a> by Giovanni Borrelli.</li>\n</ul>\n<h2 id=\"license-and-citation\">License and citation</h2>\n<p><img src=\"https://sscardapane.it/assets/images/by-sa.png\" alt=\"CC BY-SA\" /> The book is released under the <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/4.0/\">CC BY-SA 4.0 license</a>. You can share, remix and adapt it in any medium or format, including for commercial use, as long as you give attribution and release the modified material under the same license.</p>\n<p>To cite the book:</p>\n<div><pre><code><span>@article</span><span>{</span><span>scardapane2024alice</span><span>,</span>\n <span>title</span> <span>=</span> <span>{Alice's Adventures in a Differentiable Wonderland --\n Volume I, A Tour of the Land}</span><span>,</span>\n <span>author</span> <span>=</span> <span>{Scardapane, Simone}</span><span>,</span>\n <span>journal</span> <span>=</span> <span>{arXiv preprint arXiv:2404.17625}</span><span>,</span>\n <span>year</span> <span>=</span> <span>{2024}</span>\n<span>}</span>\n</code></pre></div>\n </article>\n</div>",
"author": "",
"favicon": "",
"source": "sscardapane.it",
"published": "",
"ttr": 97,
"type": "website"
}