N Neurarch Architectures Models Checks Data Docs Open the app

Architectures / Recommendation

🕒 SLi-Rec

Yu et al. 2019 — Short and Long-term Interest Recommender. Time-LSTM + ASVD attention fused via gate

From Yu et al. (2019). Adaptive User Modeling with Long and Short-Term Preferences for Personalized Recommendation. IJCAI 2019. This page is the graph, not the PDF: open it, edit it, verify it, export it.

Layers
21
Parameters
64.05M
Input
50
Output
1
Verifier
1 advisory

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

Open SLi-Rec on the canvas Free, no account needed

When to pick it

Pick when both short-session intent and long-term preferences matter and you want each modelled separately, then fused via a learned gate.

Structure

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

LayerTypeParametersOutput shape
1User History (T items)Inputshape=[50]50
2Item EmbedEmbeddingvocabSize=100000050 × 32
3Time-LSTM (short)LSTMinFeatures=32, hiddenSize=64, numLayers=164
4ASVD Attn (long)Self-AttentionnumHeads=450 × 32
5to_channelsPermute32 × 50
6Pool LongGlobalAvgPool1D32
7Long ProjLinearoutFeatures=64, inFeatures=3264
8Target ItemInputshape=[1]1
9Target EmbedEmbeddingvocabSize=10000001 × 32
10FlattenFlatten32
11Target ProjLinearoutFeatures=64, inFeatures=3264
12Concat [s; l; t]Concatenate192
13Fusion Gate σ(W·[s;l;t])LinearoutFeatures=64, inFeatures=19264
14Gate σSigmoid64
15α·short + (1−α)·longAdd64
16Concat [user, target]Concatenate128
17MLP 1LinearoutFeatures=64, inFeatures=12864
18PReLUPReLU64
19Score HeadLinearoutFeatures=1, inFeatures=641
20SigmoidSigmoid1
21P(click)Output1

What the verifier says

The same 43 single-graph 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
warn1 attention layer(s) present but no positional encoding found. Attention is permutation-invariant, without position information the model cannot distinguish token order. Fix: Add a PositionalEncoding (sinusoidal) or RoPE layer before the first attention layer. (ASVD Attn (long))
attention-no-pe
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). (Gate σ)
vanishing-gradient
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
info18 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. (Fusion Gate σ(W·[s;l;t]))
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 SLi_Rec(nn.Module):
    def __init__(self):
        super().__init__()

        self.embedding_1 = nn.Embedding(1000000, 32)
        self.lstm_1 = nn.LSTM(32, 64, num_layers=1, batch_first=True)
        self.selfAttention_1 = nn.MultiheadAttention(embed_dim=32, num_heads=4, batch_first=True)
        self.linear_1 = nn.Linear(32, 64)
        self.embedding_2 = nn.Embedding(1000000, 32)
        self.linear_2 = nn.Linear(32, 64)
        self.linear_3 = nn.Linear(192, 64)
        self.linear_4 = nn.Linear(128, 64)
        self.prelu_1 = nn.PReLU(num_parameters=1)
        self.linear_5 = nn.Linear(64, 1)

    def forward(self, src, tgt=None):
        # User History (T items) shape: [50]
        # Target Item shape: [1]
        embedding_st_emb = self.embedding_1(src)
        lstm_lstm = self.lstm_1(embedding_st_emb)[0][:, -1, :]
        self_attention_g_attn = self.selfAttention_1(embedding_st_emb, embedding_st_emb, embedding_st_emb)[0]
        permute_g_swap = self_attention_g_attn.permute(0, 2, 1)
        global_avg_pool1d_g_pool = permute_g_swap.mean(dim=-1)
        linear_ong_fc = self.linear_1(global_avg_pool1d_g_pool)
        embedding_gt_emb = self.embedding_2(tgt)
        flatten_t_flat = torch.flatten(embedding_gt_emb, 1)
        linear_tgt_fc = self.linear_2(flatten_t_flat)
        concatenate_concat = torch.cat([lstm_lstm, linear_ong_fc, linear_tgt_fc], dim=-1)
        linear_gate = self.linear_3(concatenate_concat)
        sigmoid_te_sig = torch.sigmoid(linear_gate)
        add_fused = sigmoid_te_sig + lstm_lstm + linear_ong_fc
        concatenate__final = torch.cat([add_fused, linear_tgt_fc], dim=-1)
        linear_fc1 = self.linear_4(concatenate__final)
        prelu_act1 = self.prelu_1(linear_fc1)
        linear_fc2 = self.linear_5(prelu_act1)
        sigmoid_sig = torch.sigmoid(linear_fc2)
        # Output

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