{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# RNN & LSTM Tutorial for Sequence Models\n",
        "Xenors practice notebook. Run each cell and compare the output with the tutorial page.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Build sliding windows without leakage\n",
        "Create train/validation splits by time before fitting scalers.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "s=np.arange(10)\n",
        "X=np.array([s[i:i+3] for i in range(len(s)-3)])\n",
        "y=np.array([s[i+3] for i in range(len(s)-3)])\n",
        "print(X[:2]); print(y[:2])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\n[[0 1 2]\n [1 2 3]]\n[3 4]\n```\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Inspect LSTM output shapes\n",
        "Shape checks catch many sequence-model bugs early.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import torch, torch.nn as nn\n",
        "lstm=nn.LSTM(input_size=1,hidden_size=8,batch_first=True)\n",
        "out,(h,c)=lstm(torch.randn(4,12,1))\n",
        "print(out.shape,h.shape)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\ntorch.Size([4, 12, 8]) torch.Size([1, 4, 8])\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}