N Neurarch Architectures Checks Docs Open the app

Architectures / Time-series

๐Ÿ“ˆ PatchTST

Channel-independent patching + Transformer for multivariate time-series (Nie 2023)

Layers
19
Parameters
395.4K
Input
1 ร— 22 ร— 1000
Output
4
Verifier
Clean

Every number on this page is computed from the graph by the same functions the app runs, not written by hand.

Open PatchTST on the canvas Free, no account needed

When to pick it

Pick for multivariate time-series with long windows where channels can be treated independently. Same backbone serves classification and forecasting.

Structure

19 layers. Output shapes are propagated from the input shape, batch dimension excluded.

LayerTypeParametersOutput shape
1ts_windowInputshape=[1, 22, 1000]1 ร— 22 ร— 1000
2patch_embedPatch Embedstride=8, embedDim=128, patchSize=1662 ร— 128
3pos_embedPositional EncodingembedDim=128, maxLen=25662 ร— 128
4normLayerNormnormalizedShape=12862 ร— 128
5self_attnMulti-Head AttentionembedDim=128, numHeads=1662 ร— 128
6residualAdd62 ร— 128
7normLayerNormnormalizedShape=12862 ร— 128
8denseFeed ForwardembedDim=128, ffDim=25662 ร— 128
9residualAdd62 ร— 128
10normLayerNormnormalizedShape=12862 ร— 128
11self_attnMulti-Head AttentionembedDim=128, numHeads=1662 ร— 128
12residualAdd62 ร— 128
13normLayerNormnormalizedShape=12862 ร— 128
14denseFeed ForwardembedDim=128, ffDim=25662 ร— 128
15residualAdd62 ร— 128
16normLayerNormnormalizedShape=12862 ร— 128
17flattenFlatten7936
18classifierLinearoutFeatures=44
19logitsOutput4

What the verifier says

The same 41 structural checks that run on every edit in the app, on this graph.

No finding. Shapes propagate end to end, every divisibility condition holds, and no advisory rule fires. See the checks.

The PyTorch it exports

Generated from the graph above. First 46 lines; the app exports the whole file, plus the training loop, the data contract and a deploy bundle.

# Architecture designed with Neurarch: https://neurarch.com
# PyTorch: compatible with Python 3.8+ and torch>=1.12
# Colab: pip install torch torchvision  (usually pre-installed)

import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Tuple

class PatchTST(nn.Module):
    def __init__(self):
        super().__init__()

        self.patchEmbed_1 = nn.Conv2d(3, 128, kernel_size=16, stride=16)  # Patch embedding (ViT-style)
        self.layerNorm_1 = nn.LayerNorm(128)
        self.multiHeadAttention_1 = nn.MultiheadAttention(embed_dim=128, num_heads=16, batch_first=True)
        self.layerNorm_2 = nn.LayerNorm(128)
        self.feedForward_1 = nn.Sequential(
            nn.Linear(128, 256),
            nn.ReLU(),
            nn.Linear(256, 128)
        )
        self.layerNorm_3 = nn.LayerNorm(128)
        self.multiHeadAttention_2 = nn.MultiheadAttention(embed_dim=128, num_heads=16, batch_first=True)
        self.layerNorm_4 = nn.LayerNorm(128)
        self.feedForward_2 = nn.Sequential(
            nn.Linear(128, 256),
            nn.ReLU(),
            nn.Linear(256, 128)
        )
        self.layerNorm_5 = nn.LayerNorm(128)
        self.linear_1 = nn.Linear(7936, 4)

    def forward(self, x):
        # ts_window shape: [1,22,1000]
        patch_embed__embed = self.patchEmbed_1(x).flatten(2).transpose(1, 2)  # [B, num_patches, embed_dim]
        # positionalEncoding: add positional encoding externally (e.g. sinusoidal or learned PE)
        layer_norm_attn_1 = self.layerNorm_1(patch_embed__embed)
        multi_head_attention_mha_1 = self.multiHeadAttention_1(layer_norm_attn_1, layer_norm_attn_1, layer_norm_attn_1)[0]
        add_attn_1 = multi_head_attention_mha_1 + patch_embed__embed
        layer_norm__ffn_1 = self.layerNorm_2(add_attn_1)
        feed_forward_ffn_1 = self.feedForward_1(layer_norm__ffn_1)
        add__ffn_1 = feed_forward_ffn_1 + add_attn_1
        layer_norm_attn_2 = self.layerNorm_3(add__ffn_1)
        multi_head_attention_mha_2 = self.multiHeadAttention_2(layer_norm_attn_2, layer_norm_attn_2, layer_norm_attn_2)[0]
        add_attn_2 = multi_head_attention_mha_2 + add__ffn_1

For agents

This architecture is machine-readable end to end. An agent can list the set, fetch this graph, edit it, and have the edit verified before any GPU time is spent.

Also in Time-series

๐Ÿ“ˆ 1D CNN + LSTM
Conv1D + LSTM baseline for ECG/PPG/IMU and other long-form physio signals
14 layers ยท 311.7K