N Neurarch Architectures Models Checks Data Docs Open the app

Architectures / Recommendation

๐Ÿ’  RQ-VAE Semantic ID Tokenizer

The tokenizer that turns an item content embedding into a short tuple of discrete codes, giving items a coarse-to-fine hierarchy a decoder can generate.

From Rajput et al. (2023). Recommender Systems with Generative Retrieval. NeurIPS 2023. This page is the graph, not the PDF: open it, edit it, verify it, export it.

Layers
13
Parameters
1.25M
Input
768
Output
768
Verifier
Clean

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

Open RQ-VAE Semantic ID Tokenizer on the canvas Free, no account needed

When to pick it

Pick as the front half of any semantic-ID recommender. The number of levels and codes sets the id length the downstream decoder has to emit.

Structure

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

LayerTypeParametersOutput shape
1Item content embeddingInputshape=[768]768
2Encoder 768-512LinearoutFeatures=512, inFeatures=768512
3ReLUReLU512
4Encoder 512-256LinearoutFeatures=256, inFeatures=512256
5ReLUReLU256
6Encoder 256-128LinearoutFeatures=128, inFeatures=256128
7Residual VQ (4 levels x 256 codes)Residual VQ (RVQ)embedDim=128128
8Decoder 128-256LinearoutFeatures=256, inFeatures=128256
9ReLUReLU256
10Decoder 256-512LinearoutFeatures=512, inFeatures=256512
11ReLUReLU512
12Decoder 512-768LinearoutFeatures=768, inFeatures=512768
13reconstructed embeddingOutput768

What the verifier says

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

info11 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 ResidualVQ(nn.Module):
    """Residual vector quantization: each level quantizes what the level above
    could not represent, which is what gives a semantic ID its coarse-to-fine
    hierarchy."""

    def __init__(self, num_quantizers: int = 8, codebook_size: int = 1024, embed_dim: int = 256):
        super().__init__()
        self.codebooks = nn.ModuleList(
            [nn.Embedding(codebook_size, embed_dim) for _ in range(num_quantizers)])

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        residual, out = x, torch.zeros_like(x)
        for cb in self.codebooks:
            dist = (residual.unsqueeze(-2) - cb.weight).pow(2).sum(-1)
            q = cb(dist.argmin(-1))
            out = out + q
            residual = residual - q
        return x + (out - x).detach()  # straight-through


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

        self.linear_1 = nn.Linear(768, 512)
        self.linear_2 = nn.Linear(512, 256)
        self.linear_3 = nn.Linear(256, 128)
        self.residualVQ_1 = ResidualVQ(num_quantizers=4, codebook_size=256, embed_dim=128)
        self.linear_4 = nn.Linear(128, 256)
        self.linear_5 = nn.Linear(256, 512)
        self.linear_6 = nn.Linear(512, 768)

    def forward(self, x):
        # Item content embedding shape: [768]
        linear_e1 = self.linear_1(x)
        relu_a1 = F.relu(linear_e1)
        linear_e2 = self.linear_2(relu_a1)

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