# TikZ neural network and machine learning examples

> 56 machine learning figures in TikZ with code: neural networks, CNNs, LSTM and GRU cells, attention and transformers, GANs, graph networks and more.

URL: https://www.labcanvas.com/tikz/examples/machine-learning

The largest part of the library: 56 figures from Petar Veličković, Martin Thoma, Fraser Love’s *nntikz*, OpenTikZ, Janosh Riebesell and Xinyu Chen. They cover fully connected networks and single neurons, convolutions, pooling, VGG-16 and ResNet blocks, LSTM and GRU cells and backpropagation through time, self-attention and transformers (including LoRA and FlashAttention), GANs and autoencoders, graph neural networks, probabilistic models such as a hidden Markov model and plate notation, and training ideas from dropout to the bias–variance trade-off.

Most are boxes, circles and arrows: 41 of the 56 load the `positioning` library to place nodes relative to each other, and many use `calc`, `fit` (a frame around a group of nodes), `chains` and `arrows.meta`. A few plots, such as activation functions and learning curves, use pgfplots.

## Neural networks

- **Skip (residual) connection** (Neural networks): MIT licence, © Janosh Riebesell and contributors. Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/skip-connection/skip-connection.tex. Code: https://www.labcanvas.com/tikz-library/code/skip-residual-connection.tex
- **Deep belief network** (Neural networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Deep%20belief%20network/deep_belief_network.tex. Code: https://www.labcanvas.com/tikz-library/code/deep-belief-network.tex
- **Multilayer perceptron** (Neural networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Multilayer%20perceptron/multilayer_perceptron.tex. Code: https://www.labcanvas.com/tikz-library/code/multilayer-perceptron.tex
- **Relational network** (Neural networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Relational%20network/relational_network.tex. Code: https://www.labcanvas.com/tikz-library/code/relational-network.tex
- **Activation functions** (Neural networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/activation-functions/activation-functions.tex. Code: https://www.labcanvas.com/tikz-library/code/activation-functions.tex
- **Artificial neuron** (Neural networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/artificial-neuron/artificial-neuron.tex. Code: https://www.labcanvas.com/tikz-library/code/artificial-neuron.tex
- **Perceptron network for XOR** (Neural networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/perceptron-xor-task/perceptron-xor-task.tex. Code: https://www.labcanvas.com/tikz-library/code/perceptron-network-for-xor.tex
- **Self-organising map** (Neural networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/self-organizing-map/self-organizing-map.tex. Code: https://www.labcanvas.com/tikz-library/code/self-organising-map.tex
- **Fully connected network** (Neural networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/neural_network.tex. Code: https://www.labcanvas.com/tikz-library/code/fully-connected-network.tex
- **Single neuron** (Neural networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/neuron.tex. Code: https://www.labcanvas.com/tikz-library/code/single-neuron.tex
- **Encoder–decoder template** (Neural networks): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/templates/encoder-decoder/template.tex. Code: https://www.labcanvas.com/tikz-library/code/encoder-decoder-template.tex
- **Neural network template** (Neural networks): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/templates/neural-net/template.tex. Code: https://www.labcanvas.com/tikz-library/code/neural-network-template.tex

## Convolutional networks

- **2D convolution** (Convolutional networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/2D%20Convolution/2d_convolution.tex. Code: https://www.labcanvas.com/tikz-library/code/2d-convolution.tex
- **Convolutional autoencoder** (Convolutional networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Convolutional%20autoencoder/convolutional_autoencoder.tex. Code: https://www.labcanvas.com/tikz-library/code/convolutional-autoencoder.tex
- **À trous (dilated) convolutions** (Convolutional networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/%C3%80%20trous%20convolutions/a_trous_convolutions.tex. Code: https://www.labcanvas.com/tikz-library/code/a-trous-dilated-convolutions.tex
- **Cross-modal CNN (X-CNN)** (Convolutional networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/X-CNN/x-cnn.tex. Code: https://www.labcanvas.com/tikz-library/code/cross-modal-cnn-x-cnn.tex
- **Max pooling** (Convolutional networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/max-pooling/max-pooling.tex. Code: https://www.labcanvas.com/tikz-library/code/max-pooling.tex
- **Convolution layer** (Convolutional networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/convolution-layer/convolution-layer.tex. Code: https://www.labcanvas.com/tikz-library/code/convolution-layer.tex
- **VGG-16 architecture** (Convolutional networks): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/vgg-16/vgg-16.tex. Code: https://www.labcanvas.com/tikz-library/code/vgg-16-architecture.tex
- **ResNet block** (Convolutional networks): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/templates/resnet-block/template.tex. Code: https://www.labcanvas.com/tikz-library/code/resnet-block.tex

## Recurrent networks

- **Bidirectional LSTM** (Recurrent networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Bidirectional%20long%20short-term%20memory/bidirectional_long_short-term_memory.tex. Code: https://www.labcanvas.com/tikz-library/code/bidirectional-lstm.tex
- **LSTM cell** (Recurrent networks): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Long%20short-term%20memory/long_short-term_memory.tex. Code: https://www.labcanvas.com/tikz-library/code/lstm-cell.tex
- **GRU cell** (Recurrent networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/gru.tex. Code: https://www.labcanvas.com/tikz-library/code/gru-cell.tex
- **LSTM cell (detailed)** (Recurrent networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/lstm.tex. Code: https://www.labcanvas.com/tikz-library/code/lstm-cell-detailed.tex
- **Backpropagation through time** (Recurrent networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/rnn_backprop.tex. Code: https://www.labcanvas.com/tikz-library/code/backpropagation-through-time.tex
- **RNN encoder–decoder** (Recurrent networks): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/rnn_encoder_decoder_cho.tex. Code: https://www.labcanvas.com/tikz-library/code/rnn-encoder-decoder.tex

## Attention & transformers

- **Self-attention** (Attention & transformers): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Self-attention/self-attention.tex. Code: https://www.labcanvas.com/tikz-library/code/self-attention.tex
- **Attention over encoder states** (Attention & transformers): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/attention.tex. Code: https://www.labcanvas.com/tikz-library/code/attention-over-encoder-states.tex
- **Scaled dot-product attention** (Attention & transformers): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/dot_product_attention.tex. Code: https://www.labcanvas.com/tikz-library/code/scaled-dot-product-attention.tex
- **Transformer (encoder–decoder)** (Attention & transformers): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/transformer.tex. Code: https://www.labcanvas.com/tikz-library/code/transformer-encoder-decoder.tex
- **Encoder-only transformer** (Attention & transformers): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/encoder_only.tex. Code: https://www.labcanvas.com/tikz-library/code/encoder-only-transformer.tex
- **LoRA fine-tuning** (Attention & transformers): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/examples/lora/figure.tex. Code: https://www.labcanvas.com/tikz-library/code/lora-fine-tuning.tex
- **FlashAttention** (Attention & transformers): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/examples/flash-attention/figure.tex. Code: https://www.labcanvas.com/tikz-library/code/flashattention.tex

## Generative models

- **MADE: masked autoencoder** (Generative models): MIT licence, © Janosh Riebesell and contributors. Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/made/made.tex. Code: https://www.labcanvas.com/tikz-library/code/made-masked-autoencoder.tex
- **CycleGAN** (Generative models): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/CycleGAN/cyclegan.tex. Code: https://www.labcanvas.com/tikz-library/code/cyclegan.tex
- **Generative adversarial network** (Generative models): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Generative%20adversarial%20network/generative_adversarial_network.tex. Code: https://www.labcanvas.com/tikz-library/code/generative-adversarial-network.tex
- **Variational denoising autoencoder** (Generative models): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Variational%20denoising%20autoencoder/variational_denoising_autoencoder.tex. Code: https://www.labcanvas.com/tikz-library/code/variational-denoising-autoencoder.tex
- **GAN overview** (Generative models): CC0 1.0, OpenTikZ contributors. Source: https://github.com/opentikz/opentikz/blob/359befbf8e8af7ce08e7e387b2c2a198e0ca735d/examples/gan/figure.tex. Code: https://www.labcanvas.com/tikz-library/code/gan-overview.tex

## Graph learning

- **Deep Graph Infomax** (Graph learning): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Deep%20Graph%20Infomax/deep_graph_infomax.tex. Code: https://www.labcanvas.com/tikz-library/code/deep-graph-infomax.tex
- **Graph attention (GAT) layer** (Graph learning): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/GAT%20layer/gat_layer.tex. Code: https://www.labcanvas.com/tikz-library/code/graph-attention-gat-layer.tex
- **Graph convolution** (Graph learning): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Graph%20convolution/graph_convolution.tex. Code: https://www.labcanvas.com/tikz-library/code/graph-convolution.tex
- **Message passing neural network** (Graph learning): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Message%20passing%20neural%20network/message_passing_neural_network.tex. Code: https://www.labcanvas.com/tikz-library/code/message-passing-neural-network.tex

## Probabilistic models

- **Regular vs Bayesian neural network** (Probabilistic models): MIT licence, © Janosh Riebesell and contributors. Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/regular-vs-bayes-nn/regular-vs-bayes-nn.tex. Code: https://www.labcanvas.com/tikz-library/code/regular-vs-bayesian-neural-network.tex
- **Restricted Boltzmann machine** (Probabilistic models): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/restricted-boltzmann-machine/restricted-botzmann-machine.tex. Code: https://www.labcanvas.com/tikz-library/code/restricted-boltzmann-machine.tex
- **Markov random field for segmentation** (Probabilistic models): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/graph-mrf-image-segmentation/graph-mrf-image-segmentation.tex. Code: https://www.labcanvas.com/tikz-library/code/markov-random-field-for-segmentation.tex
- **Hidden Markov model** (Probabilistic models): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/hidden-markov-model-abc/hidden-markov-model-abc.tex. Code: https://www.labcanvas.com/tikz-library/code/hidden-markov-model.tex
- **Bayesian graphical model (plate notation)** (Probabilistic models): MIT licence, © Xinyu Chen. Source: https://github.com/xinychen/awesome-latex-drawing/blob/a11dbbb3796fb279790509fb87e0083f8d11fc96/BayesNet/BATF.tex. Code: https://www.labcanvas.com/tikz-library/code/bayesian-graphical-model-plate-notation.tex

## Learning & training

- **Random forest** (Learning & training): MIT licence, © Janosh Riebesell and contributors. Source: https://github.com/janosh/diagrams/blob/7a79b3114e201fad9b6785e936eab859d1bc8c12/assets/random-forest/random-forest.tex. Code: https://www.labcanvas.com/tikz-library/code/random-forest.tex
- **Dropout** (Learning & training): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Dropout/dropout.tex. Code: https://www.labcanvas.com/tikz-library/code/dropout.tex
- **Reinforcement learning: greedy policy** (Learning & training): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Reinforcement%20learning%20greedy%20policy/reinforcement_learning_greedy_policy.tex. Code: https://www.labcanvas.com/tikz-library/code/reinforcement-learning-greedy-policy.tex
- **Semi-supervised learning** (Learning & training): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Semi-supervised%20learning/semi-supervised_learning.tex. Code: https://www.labcanvas.com/tikz-library/code/semi-supervised-learning.tex
- **Supervised learning setup** (Learning & training): MIT licence, © Petar Veličković. Source: https://github.com/PetarV-/TikZ/blob/86aee049f5355d77c598b936399e42caf8941e60/Supervised%20learning%20setup/supervised_learning_setup.tex. Code: https://www.labcanvas.com/tikz-library/code/supervised-learning-setup.tex
- **Overfitting: training vs validation error** (Learning & training): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/2d-epochs-overfitting/2d-epochs-overfitting.tex. Code: https://www.labcanvas.com/tikz-library/code/overfitting-training-vs-validation-error.tex
- **Bias–variance trade-off** (Learning & training): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/bias-variance/bias-variance.tex. Code: https://www.labcanvas.com/tikz-library/code/bias-variance-trade-off.tex
- **Learning curve** (Learning & training): MIT licence, © Martin Thoma. Source: https://github.com/MartinThoma/LaTeX-examples/blob/f9236c5fe5d47f19822fcb11097df27355562314/tikz/learn-curve-ml/learn-curve-ml.tex. Code: https://www.labcanvas.com/tikz-library/code/learning-curve.tex
- **Backpropagation through a node** (Learning & training): MIT licence, © Fraser Love. Source: https://github.com/fraserlove/nntikz/blob/3dc29cfda3bd18db2d1e73830f95b4d0985e050f/tikz/backprop/backprop.tex. Code: https://www.labcanvas.com/tikz-library/code/backpropagation-through-a-node.tex

## Using these figures

Every figure keeps its own licence: MIT or CC0 1.0, both of which allow use, change and sharing, commercial use included. The MIT licence asks that its copyright and permission notice go with copies of the code, so each figure’s code starts with its source, author and licence; keep those lines when you reuse it. The full licence texts are on the [sources and licences page](https://www.labcanvas.com/tikz-library/credits.html).

“Open in the TikZ editor” loads the figure’s complete document into the free TikZ editor, where it is typeset with TeX Live 2026 and you can change it and download a PNG. To compile it on your own computer, save the code as a.tex file and run pdfLaTeX (or the engine the tile names) on it; LabCanvas changed the files only where needed to make each one compile on its own, as its first lines say.

Licence texts: https://www.labcanvas.com/tikz-library/credits.html
