### Compiling TikZ Diagrams to PDF (Bash) Source: https://context7.com/fraserlove/nntikz/llms.txt This Bash script demonstrates how to compile TikZ diagrams into PDF format using pdflatex. It includes commands for compiling a single diagram and for batch compilation of all diagrams within specified directories. An optional step for converting PDF to PNG using ImageMagick is also shown. The primary dependency is a LaTeX distribution with pdflatex. ```bash # Compile a single diagram pdflatex tikz/transformer.tex # Compile all diagrams for f in tikz/*.tex tikz/backprop/*.tex; do pdflatex -output-directory=pdf "$f" done # Convert PDF to PNG (requires ImageMagick) convert -density 300 pdf/transformer.pdf -quality 90 assets/transformer.png ``` -------------------------------- ### Create Single Neuron (Perceptron) Diagram in LaTeX Source: https://context7.com/fraserlove/nntikz/llms.txt Illustrates a single neuron, also known as a perceptron, demonstrating weighted inputs, summation, and activation. This TikZ diagram uses basic shapes and arrows to depict the flow of computation within a neuron, including mathematical notation for weights and the activation function. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc} \begin{document} \begin{tikzpicture}[ >=LaTeX, node/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, arrow/.style={-latex, thick} ] % Input nodes \foreach \x in {0,1,2} \node[node] (x\x) at (0,-\x*1.25) {$x_{\x}$}; \node[node] (xm) at (0,-4*1.25) {$x_{n}$}; \path (x2) -- (xm) node[pos=0.35, scale=2] {\vdots}; % Summation node \node[node] (z) at (2.5,-2.5) {$z$}; % Output node \node[node, right of=z, node distance=2.5cm] (yhat) {$\hat{y}$}; % Weighted connections \draw[arrow] (x0) -- (z) node[midway, fill=white, inner sep=1.5pt] {$w_0$}; \foreach \x in {1,...,2} \draw[arrow] (x\x) -- (z) node[midway, fill=white, inner sep=1.5pt] {$w_{\x}$}; \draw[arrow] (xm) -- (z) node[midway, fill=white, inner sep=1.5pt] {$w_{n}$}; % Activation function \draw[arrow] (z) -- (yhat) node[midway, fill=white, inner sep=1.5pt] {$\sigma(z)$}; % Equation \node[above of=z, node distance=1.2cm] {$z = \mathbf{w}^\top \mathbf{x}$}; \end{tikzpicture} \end{document} ``` -------------------------------- ### Create Neural Network Diagram in LaTeX Source: https://context7.com/fraserlove/nntikz/llms.txt Generates a fully connected feedforward neural network diagram with input, hidden, and output layers. It utilizes TikZ libraries for positioning, chains, shapes, and arrows, defining styles for nodes and connections. The diagram visually represents the flow of data and mathematical notation for layers. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc, backgrounds} \begin{document} \begin{tikzpicture}[ >=LaTeX, node/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, cell/.style={rectangle, rounded corners=2mm, minimum height=2.5em, minimum width=2.5em, draw, thick}, arrow/.style={-latex, thick} ] % Input layer \foreach \x in {1,...,2} \draw node at (0, -\x*1.25 - 0.625) [node] (first_\x) {$x_\x$}; \draw node at (0, -5*1.25 + 0.625) [node] (first_n) {$x_n$}; \path (first_2) -- (first_n) node[pos=0.38, scale=2] {\vdots}; % Hidden layer 1 \foreach \x in {1,...,3} \node at (2.5, -\x*1.25) [node] (second_\x){}; \draw node at (2.5, -5*1.25) [node] (second_m) {}; \path (second_3) -- (second_m) node[pos=0.38, scale=2] {\vdots}; % Connections: Input -> Hidden \foreach \i in {1,...,2} \foreach \j in {1,...,3} \draw [arrow] (first_\i) to (second_\j); % Layer labels \node[above=0.25cm of first_1] {$\mathbf{x}$}; \node[above=0.25cm of second_1] {$\mathbf{h}^{(1)}$}; \end{tikzpicture} \end{document} ``` -------------------------------- ### RNN Sequence Model Diagram using TikZ Source: https://context7.com/fraserlove/nntikz/llms.txt This TikZ code visualizes a basic recurrent neural network (RNN) processing a sequence. It presents both an unfolded chain of RNN cells, showing step-by-step processing, and a folded representation that encapsulates the recurrent nature. The diagram includes inputs, outputs, and hidden state propagation for each time step. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc} \begin{document} \begin{tikzpicture}[ >=LaTeX, cell/.style={rectangle, rounded corners=2mm, minimum height=2.5em, minimum width=2.5em, draw, thick}, cellc/.style={cell, on chain, join}, input/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, arrow/.style={-latex, very thick} ] % Unfolded RNN chain \begin{scope}[start chain=going right, nodes=cellc, arrow, local bounding box=chain] \path[shift={(-9em, 1em)}] node (h1) {$\mathbf{h}_1$} node[] (h2) {$\mathbf{h}_2$} node[xshift=2em] (hT) {$\mathbf{h}_{T}$}; \end{scope} % Inputs \foreach \X in {1, 2, T} { \draw[arrow, latex-] (h\X.south) -- ++ (0, -2em) node[below, input] (x\X) {$\mathbf{x}_\X$}; } % Outputs \foreach \X in {1, 2, T} { \draw[arrow] (h\X.north) -- ++ (0, 2em) node[above, input] (y\X) {$\hat{\mathbf{y}}_\X$}; } % Continuation dots \path (x2) -- (xT) node[midway, scale=2] {$\dots$}; % Equals sign \node[left=1em of chain, scale=2] (eq) {$=$}; % Folded RNN representation \node[cell, left=2em of eq] (AL) {$\mathbf{h}_t$}; \path (AL.west) ++ (-1em,2em) coordinate (aux); \draw[arrow, rounded corners] (AL.east) -| ++ (1em, 2em) -- (aux) |- (AL.west); \draw[white, line width=0.5em] (AL.north) -- ++ (0, 1.9em); \draw[arrow] (AL.north) -- ++ (0, 2em) node[above,input] {$\hat{\mathbf{y}}_t$}; \draw[arrow, latex-] (AL.south) -- ++ (0, -2em) node[below,input] {$\mathbf{x}_t$}; \end{tikzpicture} \end{document} ``` -------------------------------- ### Dropout Regularization Diagram (LaTeX) Source: https://context7.com/fraserlove/nntikz/llms.txt This LaTeX code snippet generates a visual representation of dropout regularization in a neural network. It uses TikZ to illustrate randomly dropped units and connections during training, highlighting the regularization effect. Dependencies include the TikZ package and its libraries. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc} \begin{document} \begin{tikzpicture}[ >=LaTeX, node/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, cell/.style={rectangle, rounded corners=2mm, minimum height=2.5em, minimum width=2.5em, draw, thick}, arrow/.style={-latex, thick}, dropout/.style={node, dashed} ] % Input layer (x1 dropped) \draw node at (0, -2*1.25 - 0.625) [node] (first_2) {$x_2$}; \draw node at (0, -1*1.25 - 0.625) [dropout] (first_1) {$x_1$}; \draw node at (0, -5*1.25 + 0.625) [node] (first_n) {$x_n$}; \path (first_2) -- (first_n) node[pos=0.38, scale=2] {\vdots}; % Hidden layer (some units dropped) \foreach \x in {1,3} \node at (2.5, -\x*1.25) [node] (second_\x){}; \draw node at (2.5, -2*1.25) [dropout] (second_2) {}; \draw node at (2.5, -5*1.25) [dropout] (second_m) {}; \path (second_3) -- (second_m) node[pos=0.38, scale=2] {\vdots}; % Connections from active units only \foreach \i in {2} \foreach \j in {1,3} \draw [arrow] (first_\i) to (second_\j); \foreach \i in {1,3} \draw [arrow] (first_n) to (second_\i); % Layer labels \node[above=0.25cm of first_1] {$\mathbf{x}$}; \node[above=0.25cm of second_1] {$\mathbf{h}^{(1)}$}; % Bounding boxes \node[cell, dashed, fit=(first_1) (first_n)] {}; \node[cell, dashed, fit=(second_1) (second_m)] {}; \end{tikzpicture} \end{document} ``` -------------------------------- ### GRU Cell Diagram using TikZ Source: https://context7.com/fraserlove/nntikz/llms.txt This TikZ code generates a diagram illustrating the Gated Recurrent Unit (GRU) cell. It visualizes the reset and update gates, as well as the flow of hidden states and inputs. The diagram uses various shapes and styles to represent different components like sigmoid and tanh functions, multiplication and addition operations, and input/output nodes. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc} \begin{document} \begin{tikzpicture}[ >=LaTeX, cell/.style={rectangle, rounded corners=5mm, draw, very thick, minimum height=4cm, minimum width=6cm}, input/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, func/.style={rectangle, draw, inner sep=2pt, minimum height=0.4cm}, op/.style={circle, draw, inner sep=-0.5pt, minimum height=0.4cm}, pointwise/.style={fill=gray!50}, arrow/.style={-latex, very thick}, arrowc1/.style={arrow, rounded corners=.25cm}, arrowc2/.style={arrow, rounded corners=.5cm} ] % GRU cell boundary \node [cell] at (0,0){}; % Gates \node [func] (sigr) at (-0.75,-0.75) {$\sigma$}; \node [func] (sigz) at (0,-0.75) {$\sigma$}; \node [func] (tanh) at (2,-0.75) {$\tanh$}; \node [func, pointwise] (minus) at (0,0.5) {$1-$}; % Operations \node [op, pointwise] (mulr) at (-1.5,0) {$\times$}; \node [op, pointwise] (mulz) at (0,1.5) {$\times$}; \node [op, pointwise] (add) at (2,1.5) {$+$}; \node [op, pointwise] (mulh) at (2,0) {$\times$}; % States and I/O \node (ht-1) at (-4,1.5) {$\mathbf{h}_{t-1}$}; \node[input] (x) at (-2.5,-3) {$\mathbf{x}_{t}$}; \node (ht) at (4,1.5) {$\mathbf{h}_{t}$}; \node[input] (y) at (2.5,3) {$\hat{\mathbf{y}}_{t}$}; % Hidden state flow \draw [arrowc1] (ht-1) -- (mulz) -- (add) -- (ht); % Gate labels \draw [arrowc1] (sigr) |- node[midway, shift={(-2pt,4pt)}] {$\mathbf{r}_t$} (mulr.east); \draw [arrowc2] (sigz) -- node[midway, left] {$\mathbf{z}_t$} (minus); \draw [arrowc2] (tanh) -- node[midway, shift={(12pt,1.5pt)}] {$\tilde{\mathbf{h}}_t$} (mulh); \end{tikzpicture} \end{document} ``` -------------------------------- ### Transformer Encoder-Decoder Architecture Diagram (LaTeX) Source: https://context7.com/fraserlove/nntikz/llms.txt A TikZ diagram representing the complete Transformer encoder-decoder architecture as described in 'Attention Is All You Need'. It includes positional encoding, multi-head attention, feed-forward layers, layer normalization, and connections. This diagram is generated using LaTeX and TikZ. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc, backgrounds} \begin{document} \begin{tikzpicture}[ >=LaTeX, very thick, arrow/.style={-latex, very thick, rounded corners=0.2cm}, block/.style={rectangle, fill=gray!10, rounded corners=3mm, draw, very thick}, layer/.style={rectangle, fill=white!10, rounded corners=1mm, inner xsep=0em, inner ysep=0.25em, minimum height=1.4em, align=center, text width=2.5cm, draw, very thick}, input/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick} ] % Input embeddings \node[input] (iemb) at (1.25,-0.45) {$\mathbf{x}$}; \node[input] (oemb) at (5.25,-0.45) {$\mathbf{y}$}; % Positional encoding sums \node[circle, draw, minimum size=0.25em, inner sep=0pt, above=1em of iemb] (sum1) {$\mathbf{+}$}; \node[circle, draw, minimum size=0.25em, inner sep=0pt, above=1em of oemb] (sum2) {$\mathbf{+}$}; % Encoder layers \node[layer] (add1) at (1.25,3.43) {Add & Norm}; \node[layer] (attn1) at (1.25,2.58) {Multi-Head \vspace{-0.05cm} \linebreak Attention}; \node[layer] (add4) at (1.25,5.98) {Add & Norm}; \node[layer] (ff1) at (1.25,5.13) {Feed \vspace{-0.05cm} \linebreak Forward}; % Decoder layers \node[layer] (add3) at (5.25,3.83) {Add & Norm}; \node[layer] (attn3) at (5.25,2.78) {Masked \vspace{-0.05cm} \linebreak Multi-Head \vspace{-0.05cm} \linebreak Attention}; % Output classifier \node[layer, above=8em of add3] (linear) {Linear}; \node[layer, above=1em of linear] (softmax) {Softmax}; \node[input, above=1em of softmax] (probs) {$\hat{\mathbf{y}}$}; % Connections \draw[arrow] (iemb) -- (sum1); \draw[arrow] (sum1) -- (attn1); \draw[] (attn1) -- (add1); \draw[arrow] (add1) -- (ff1); \draw[] (ff1) -- (add4); \draw[arrow] (linear) -- (softmax); \draw[arrow] (softmax) -- (probs); % N times labels \node[anchor=east] at (0,4) {$N\times$}; \end{tikzpicture} \end{document} ``` -------------------------------- ### LSTM Cell Internal Operations Diagram (LaTeX) Source: https://context7.com/fraserlove/nntikz/llms.txt A TikZ diagram illustrating the internal operations of a Long Short-Term Memory (LSTM) cell. It visualizes the forget gate, input gate, output gate, cell state, and hidden state, including sigmoid and tanh activations and pointwise operations. This diagram is generated using LaTeX and TikZ. ```latex \documentclass{standalone} \usepackage{tikz} \usetikzlibrary{positioning, chains, shapes.geometric, fit, shapes, arrows.meta, calc} \begin{document} \begin{tikzpicture}[ >=LaTeX, cell/.style={rectangle, rounded corners=5mm, draw, very thick, minimum height=4cm, minimum width=6cm}, input/.style={circle, minimum width=2.25em, draw, fill=gray!10, thick}, func/.style={rectangle, draw, inner sep=2pt, minimum height=0.4cm}, op/.style={circle, draw, inner sep=-0.5pt, minimum height=0.4cm}, pointwise/.style={fill=gray!50}, arrow/.style={-latex, very thick}, arrowc1/.style={arrow, rounded corners=.25cm}, arrowc2/.style={arrow, rounded corners=.5cm} ] % LSTM cell boundary \node [cell] at (0,0){}; % Gates \node [func] (sigf) at (-2,-0.75) {$\sigma$}; \node [func] (sigi) at (-1.4,-0.75) {$\sigma$}; \node [func] (tanhi) at (-0.5,-0.75) {$\tanh$}; \node [func] (sigo) at (0.5,-0.75) {$\sigma$}; \node [func, pointwise] (tanho) at (1.5,0.75) {$\tanh$}; % Operations \node [op, pointwise] (mulf) at (-2,1.5) {$\times$}; \node [op, pointwise] (add) at (-0.5,1.5) {+}; \node [op, pointwise] (muli) at (-0.5,0) {$\times$}; \node [op, pointwise] (mulo) at (1.5,0) {$\times$}; % States and I/O \node[input] (x) at (-2.5,-3) {$\mathbf{x}_{t}$}; \node (ct-1) at (-4,1.5) {$\mathbf{c}_{t-1}$}; \node (ht-1) at (-4,-1.5) {$\mathbf{h}_{t-1}$}; \node (ct) at (4,1.5) {$\mathbf{c}_{t}$}; \node (ht) at (4,-1.5) {$\mathbf{h}_{t}$}; \node[input] (y) at (2.5,3) {$\hat{\mathbf{y}}_{t}$}; % Cell state flow \draw [arrow] (ct-1) -- (mulf) -- (add) -- (ct); % Gate labels \draw [arrow] (sigf) -- node[midway, left] {$\mathbf{f}_t$} (mulf); \draw [arrowc2] (sigi) |- node[midway, xshift=-1.5, yshift=1.5] {$\mathbf{i}_t$} (muli); \draw [arrowc2] (sigo) |- node[midway, xshift=-1.5, yshift=1.5] {$\mathbf{o}_t$} (mulo); \end{tikzpicture} \end{document} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.