N Neurarch Architectures Models Checks Data Docs Open the app

Architectures / Recommendation

๐Ÿ”Ž Search-based Interest Model (SIM)

Alibaba 2020 - a lifelong sequence (2000 events) is cut to the 50 most relevant before anything quadratic runs, then attended against the candidate.

From Pi et al. (2020). Search-based User Interest Modeling with Lifelong Sequential Behavior Data for Click-Through Rate Prediction. CIKM 2020. This page is the graph, not the PDF: open it, edit it, verify it, export it.

Layers
16
Parameters
128.06M
Input
2000
Output
1
Verifier
Clean

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

Open Search-based Interest Model (SIM) on the canvas Free, no account needed

When to pick it

Pick when the behaviour history is thousands of events long and full attention over it is unaffordable. The retrieval step is what makes the cost linear again.

Structure

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

LayerTypeParametersOutput shape
1Lifelong Seq (2000 events)Inputshape=[2000]2000
2Item EmbedEmbeddingvocabSize=10000002000 ร— 64
3Candidate ItemInputshape=[1]1
4Candidate EmbedEmbeddingvocabSize=10000001 ร— 64
5GSU: top-50 by relevanceLong-Sequence Retrieval (SIM/ETA GSU)embedDim=64, topK=5050 ร— 64
6ESU: multi-head target attentionTarget Attention (DIN)embedDim=6464
7User ProfileInputshape=[16]16
8User TowerLinearoutFeatures=32, inFeatures=1632
9[interest; user]Concatenate96
10MLP 200LinearoutFeatures=200, inFeatures=96200
11Dice (~PReLU)PReLU200
12MLP 80LinearoutFeatures=80, inFeatures=20080
13Dice (~PReLU)PReLU80
14CTR HeadLinearoutFeatures=1, inFeatures=801
15SigmoidSigmoid1
16pCTROutput1

What the verifier says

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

info"Sigmoid" feeds directly into Output. PyTorch's nn.CrossEntropyLoss already applies log-softmax internally, an explicit Softmax causes double-application and degrades training stability. Fix: Remove Softmax/Sigmoid for training. Restore it in a separate inference wrapper or ONNX export. (Sigmoid)
output-activation
infoSigmoid saturates to [0,1] / [-1,1], and its gradient approaches zero for large inputs. In networks deeper than 5 layers, this halts learning in early layers. Fix: Use ReLU, GELU, or SiLU for hidden layers. Keep Sigmoid only at binary classification outputs; Tanh in specific contexts (GAN generators, LSTM gates). (Sigmoid)
vanishing-gradient
info12 layers with no BatchNorm, LayerNorm, or GroupNorm. Without normalization, activations can explode or vanish across layers, causing slow or unstable training. Fix: Add BatchNorm after Conv2d (CV tasks), LayerNorm after attention/FFN (NLP/LLM), or GroupNorm for small batch sizes.
deep-no-norm
infoPyTorch initializes Linear/Conv with Kaiming (He) init, which is derived for ReLU-family activations. Feeding a saturating activation (sigmoid/tanh) from a He-initialized layer starts training in the saturated tails, shrinking early gradients. Fix: Initialize these layers with Xavier instead: nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain("sigmoid"|"tanh")), or switch the activation to a ReLU-family one. (CTR Head)
init-activation-mismatch

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 TargetAttention(nn.Module):
    """DIN's local activation unit. The CANDIDATE is the query over the
    behaviour sequence, so the sequence axis is consumed and one interest
    vector comes out per candidate."""

    def __init__(self, embed_dim: int, hidden_dim: int = 36):
        super().__init__()
        self.mlp = nn.Sequential(
            nn.Linear(4 * embed_dim, hidden_dim),
            nn.PReLU(),
            nn.Linear(hidden_dim, 1),
        )

    def forward(self, query: torch.Tensor, keys: torch.Tensor) -> torch.Tensor:
        if query.dim() == keys.dim() - 1:
            query = query.unsqueeze(-2)
        q = query[..., :1, :].expand_as(keys)
        feats = torch.cat([q, keys, q - keys, q * keys], dim=-1)
        w = self.mlp(feats).softmax(dim=-2)
        return (w * keys).sum(dim=-2)


class BehaviorRetrieval(nn.Module):
    """SIM / ETA general search unit: cut a lifelong behaviour sequence to its
    top-k most relevant events BEFORE anything quadratic runs. Hard mode is a
    category lookup and learns nothing."""

    def __init__(self, top_k: int = 50, embed_dim: int = 64, mode: str = "soft"):
        super().__init__()
        self.top_k = top_k
        self.mode = mode
        self.proj = None if mode == "hard" else nn.Linear(embed_dim, embed_dim, bias=False)

    def forward(self, seq: torch.Tensor, target=None) -> torch.Tensor:
        k = min(self.top_k, seq.size(-2))
        h = seq if self.proj is None else self.proj(seq)
        if target is None:

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 Recommendation

๐Ÿ—ผ Two-Tower
User+Item dual encoder for retrieval โ€” embeddings โ†’ MLP per side โ†’ dot product score
15 layers ยท 70.44M
๐Ÿ“ Wide & Deep
Memorization
13 layers ยท 3.65M
๐Ÿ›’ DLRM
Meta's Deep Learning Recommendation Model โ€” bottom MLP for dense, embedding for sparse, feature interaction, top MLP
14 layers ยท 64.35M
๐Ÿค NeuMF (Fused GMF + MLP)
He et al
16 layers ยท 105.61M