N Neurarch Architectures Models Checks Data Docs Open the app

Architectures / Recommendation

๐Ÿงญ Multi-Interest Network (MIND)

Alibaba 2019 - dynamic routing turns one behaviour sequence into K interest vectors, so a user is K points in item space rather than one.

From Li et al. (2019). Multi-Interest Network with Dynamic Routing for Recommendation at Tmall. CIKM 2019. This page is the graph, not the PDF: open it, edit it, verify it, export it.

Layers
12
Parameters
128.01M
Input
50
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 Multi-Interest Network (MIND) on the canvas Free, no account needed

When to pick it

Pick for candidate retrieval when users have several distinct intents and a single user vector averages them into nothing. Note every downstream layer gains a rank.

Structure

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

LayerTypeParametersOutput shape
1Behavior Seq (50 items)Inputshape=[50]50
2Item EmbedEmbeddingvocabSize=100000050 ร— 64
3Dynamic Routing (K=4)Multi-Interest Extractor (MIND/ComiRec)embedDim=644 ร— 64
4Interest ProjectionLinearoutFeatures=64, inFeatures=644 ร— 64
5Candidate ItemInputshape=[1]1
6Item Embed (shared vocab)EmbeddingvocabSize=10000001 ร— 64
7transposePermute64 ร— 1
8interest ยท itemMatMul4 ร— 1
9Label-aware max over KTopK1 ร— 1
10flattenFlatten1
11SigmoidSigmoid1
12scoreOutput1

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
info9 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

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 MultiInterest(nn.Module):
    """MIND behaviour-to-interest dynamic routing. One user becomes K vectors,
    not one, so every downstream layer sees a rank it has to agree with."""

    def __init__(self, embed_dim: int, num_interests: int = 4, num_iterations: int = 3):
        super().__init__()
        self.k = num_interests
        self.iters = max(1, num_iterations)
        self.bilinear = nn.Linear(embed_dim, embed_dim, bias=False)

    @staticmethod
    def _squash(x: torch.Tensor) -> torch.Tensor:
        n2 = x.pow(2).sum(-1, keepdim=True)
        return (n2 / (1.0 + n2)) * x / (n2.sqrt() + 1e-8)

    def forward(self, seq: torch.Tensor) -> torch.Tensor:
        u = self.bilinear(seq)
        b = seq.new_zeros(seq.size(0), self.k, seq.size(-2))
        v = self._squash(torch.bmm(b.softmax(dim=1), u))
        for _ in range(self.iters - 1):
            b = b + torch.bmm(v, u.transpose(1, 2))
            v = self._squash(torch.bmm(b.softmax(dim=1), u))
        return v


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

        self.embedding_1 = nn.Embedding(1000000, 64)
        self.multiInterest_1 = MultiInterest(embed_dim=64, num_interests=4, num_iterations=3)
        self.linear_1 = nn.Linear(64, 64)
        self.embedding_2 = nn.Embedding(1000000, 64)

    def forward(self, src, tgt=None):
        # Behavior Seq (50 items) shape: [50]
        # Candidate Item shape: [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 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