# Simple RNN

> Simple Recurrent Neural Network for sequence processing

Pick as a teaching reference. Real workloads should reach for LSTM/GRU or transformer — vanilla RNN suffers from vanishing gradients on anything beyond ~50 steps.

- Category: NLP
- Layers: 4
- Parameters: 1.10M
- Input shape (batchless): 128 × 300
- Output shape: 128 × 10
- Verifier verdict: pass
- Graph JSON: https://neurarch.com/templates/simple-rnn/model.json
- Open on the canvas: https://neurarch.com/?template=simple-rnn

## Structure

| # | Layer | Type | Parameters | Output shape |
| --- | --- | --- | --- | --- |
| 1 | Input | Input | shape=[128, 300] | 128 × 300 |
| 2 | LSTM | LSTM | hiddenSize=256, numLayers=2 | 128 × 256 |
| 3 | Linear | Linear | outFeatures=10 | 128 × 10 |
| 4 | Output | Output |  | 128 × 10 |

## Verifier findings

No finding. Shapes propagate end to end and no advisory rule fires.

## Exported PyTorch

```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)

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

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

        self.lstm_1 = nn.LSTM(300, 256, num_layers=2, batch_first=True)
        self.linear_1 = nn.Linear(256, 10)

    def forward(self, x):
        # Input shape: [128,300]
        lstm_lstm_1 = self.lstm_1(x)[0]
        linear_near_1 = self.linear_1(lstm_lstm_1)
        # Output
        return linear_near_1


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

    x = torch.randn(1, 128, 300)  # (batch, channels, length)
    with torch.no_grad():
        output = model(x)

    print(f'Input  shape : {tuple(x.shape)}')
    print(f'Output shape : {tuple(output.shape)}')
    total = sum(p.numel() for p in model.parameters())
    trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
    print(f'Parameters   : {total:,} total, {trainable:,} trainable')
```

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