# LightGCN

> He et al. 2020 — user/item embeddings propagated through 3 light graph-conv layers, layer combination via mean (no transforms, no nonlinearities)

Pick for collaborative filtering with implicit feedback (clicks, plays). Strips graph-conv to its essentials — often beats heavier GCN variants on rec benchmarks.

- Category: Recommendation
- Layers: 14
- Parameters: 70.42M
- Input shape (batchless): 1
- Output shape: 64
- Verifier verdict: pass
- Graph JSON: https://neurarch.com/templates/lightgcn/model.json
- Open on the canvas: https://neurarch.com/?template=lightgcn

## Structure

| # | Layer | Type | Parameters | Output shape |
| --- | --- | --- | --- | --- |
| 1 | User ID | Input | shape=[1] | 1 |
| 2 | E_user(0) | Embedding | vocabSize=100000 | 1 × 64 |
| 3 | GraphConv(1) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 4 | GraphConv(2) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 5 | GraphConv(3) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 6 | Layer Combine (mean) | Mean |  | 64 |
| 7 | Item ID | Input | shape=[1] | 1 |
| 8 | E_item(0) | Embedding | vocabSize=1000000 | 1 × 64 |
| 9 | GraphConv(1) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 10 | GraphConv(2) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 11 | GraphConv(3) | GraphConv | outFeatures=64, inFeatures=64 | 1 × 64 |
| 12 | Layer Combine (mean) | Mean |  | 64 |
| 13 | Dot Score | MatMul |  | 64 |
| 14 | Score | Output |  | 64 |

## Verifier findings

- **info** `deep-no-norm`: 11 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.

## Exported PyTorch (first 46 lines)

```python
# 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)
#
# WARNING: 3 layer(s) below are not yet supported by the PyTorch
# exporter and pass their input through UNCHANGED in forward():
#   - Layer Combine (mean) (mean)
#   - Layer Combine (mean) (mean)
#   - Dot Score (matmul)

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

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

        self.embedding_1 = nn.Embedding(100000, 64)
        self.embedding_2 = nn.Embedding(1000000, 64)

    def forward(self, src, tgt=None):
        # User ID shape: [1]
        # Item ID shape: [1]
        embedding_ser_e0 = self.embedding_1(src)
        graph_conv_er_gc1 = self.graphConv_1(embedding_ser_e0, edge_index)  # pass edge_index from graph data
        graph_conv_er_gc2 = self.graphConv_2(graph_conv_er_gc1, edge_index)  # pass edge_index from graph data
        graph_conv_er_gc3 = self.graphConv_3(graph_conv_er_gc2, edge_index)  # pass edge_index from graph data
        # TODO: layer 'Layer Combine (mean)' (mean) is not yet supported by the exporter; passing through unchanged
        embedding_tem_e0 = self.embedding_2(tgt)
        graph_conv_em_gc1 = self.graphConv_4(embedding_tem_e0, edge_index)  # pass edge_index from graph data
        graph_conv_em_gc2 = self.graphConv_5(graph_conv_em_gc1, edge_index)  # pass edge_index from graph data
        graph_conv_em_gc3 = self.graphConv_6(graph_conv_em_gc2, edge_index)  # pass edge_index from graph data
        # TODO: layer 'Layer Combine (mean)' (mean) is not yet supported by the exporter; passing through unchanged
        # TODO: layer 'Dot Score' (matmul) is not yet supported by the exporter; passing through unchanged
        # Output
        return embedding_ser_e0


if __name__ == '__main__':
    model = LightGCN()
    model.eval()

    src = torch.randint(0, 1, (1))  # (batch, src_seq_len)
    tgt = torch.randint(0, 1, (1))  # (batch, tgt_seq_len)
```

## Machine access

- Every architecture: https://neurarch.com/a/index.json
- Verify a graph of your own: `POST https://www.neurarch.com/api/v1/check` (see https://neurarch.com/developer.html)
- MCP server, so an agent edits the graph with the checks in the loop: https://neurarch.com/docs/mcp.md
