| name | draw-neural-networks-typst |
| description | Empower the agent to generate high-quality Neural Network architecture diagrams in Typst using the neural-netz package. |
Skill: Drawing Neural Networks with Typst (neural-netz)
🎯 Objective
Empower the agent to generate high-quality Neural Network architecture diagrams in Typst using the neural-netz package.
📦 Setup and Import
Whenever the user requests drawing or visualizing a neural network in Typst, always start by importing the main function from the neural-netz package:
#import "@preview/neural-netz:0.3.0": draw-network
🛠️ Basic Usage (draw-network)
The core function is draw-network. It accepts the following parameters:
#draw-network(
layers, // (Array) Required. List of dictionaries defining the layers
connections: (), // (Array) Optional. List of non-linear connections (skip connections)
palette: "warm", // (String) Optional. Color palette: "warm" (default) or "cold"
show-legend: false, // (Boolean) Optional. If true, displays the chart legend
legend-title: "Layers", // (String) Optional. Title for the legend
scale: 100%, // (Relative) Optional. Overall scale of the drawing (e.g., 50% to fit the page)
stroke-thickness: 1, // (Float) Optional. Line thickness
depth-multiplier: 0.3, // (Float) Optional. Multiplier for 3D visual depth
show-relu: false // (Boolean) Optional. If true, draws a darker color on convolutions to indicate ReLU
)
🧱 Defining Layers (layers)
The main parameter of draw-network is an array of dictionaries. The order in the array defines the sequential order (from left to right), and they are connected automatically by default.
Predefined Layer Types (type)
"input": Input layer (can take the key image: "path.jpg" or image: none).
"conv": Convolution.
"pool": Pooling. By default, it sticks to the previous layer.
"convres": Residual Convolution.
"fc": Fully Connected (Usually 2D, set depth: 0).
"custom": Fully customizable layer (using fill, bandfill, opacity).
Main Layer Attributes
type: The type of the layer (described above).
offset: Space/distance from the previous layer (e.g., offset: 2).
widths: Array of widths for layer subdivisions (e.g., (1, 1) or (1, 2)).
height and depth: Height and depth (e.g., height: 6, depth: 8). For pure 2D, set depth: 0.
channels: Array with labels for the channels that appear on the axes (e.g., (32, 64, 128) or ("10",)).
label: Name/Text displayed below the block.
connection-label: Name displayed on the arrow connecting to the NEXT layer.
name: Unique identifier used to create manual connections (e.g., name: "conv1").
show-connection: (Boolean) Whether the automatic arrow/connection after this layer should be drawn.
🔗 Manual Connections (connections)
Used for skip-connections (like in ResNets or U-Nets).
Each connection is a dictionary in the connections array:
from: Name of the origin layer (defined in the name attribute of the layer).
to: Name of the destination layer.
type: Usually "skip".
mode: Connection style. Options: "depth", "flat", or "air".
label: Text label over the connection.
pos: Vertical/horizontal offset of the connection arc (e.g., pos: 5).
touch-layer: (Boolean) If true and mode: "air", the arrow touches the layer instead of ending with a loose arrowhead.
📝 Complete Practical Example
Use this example as a baseline to understand the assembly:
#import "@preview/neural-netz:0.3.0": draw-network
#draw-network((
// Input
(type: "input", label: "Image", name: "in", show-connection: true),
// Convolutional Block
(type: "conv", widths: (1.5, 1.5), height: 4, depth: 4, label: "Conv1", name: "c1", offset: 2),
(type: "pool", channels: ("64",), height: 2, depth: 2, connection-label: "Max Pool"),
// Block that does not propagate arrow automatically
(type: "convres", channels: (128, 256), height: 5, depth: 5, label: "ResBlock", name: "c2", offset: 3, show-connection: false),
// Linear / Fully Connected 2D Layer (depth: 0)
(type: "fc", channels: ("10",), height: 6, depth: 0, label: "Linear", name: "out", offset: 2)
),
// Extra connections (skip connections)
connections: (
(from: "in", to: "c2", type: "skip", mode: "air", label: "Skip Connection", pos: 6, touch-layer: true),
),
// Global customizations
palette: "warm",
show-legend: true,
legend-title: "Architecture",
show-relu: true
)
🧠 Behavioral Instructions for the Agent
- When receiving instructions about architecture design (e.g., "Create a VGG16" or "Make a CNN with a 28x28 input and a 10 output"), map the requested layers using a coherent visual structure (increasing/decreasing
height/depth proportions according to Spatial Resolution or Channels).
- If the resulting image is too wide, suggest or apply the use of the
scale parameter (e.g., scale: 75%).
- Support custom colors only if explicitly requested (via
type: "custom" with fill: rgb("#...")), otherwise, encourage the use of native palettes (warm or cold).
- You MUST use
depth: 0 for purely Dense/Fully Connected layers to highlight the difference between 3D tensors and 1D vectors.