{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c1333286", "metadata": {}, "outputs": [], "source": [ "import torch\n", "from torch import nn" ] }, { "cell_type": "code", "execution_count": 2, "id": "4bd8e564", "metadata": {}, "outputs": [], "source": [ "batch_size = 4\n", "input_size = 5\n", "hidden_size = 8\n", "seq_length = 31\n", "rnn = nn.LSTM(input_size=input_size, hidden_size=hidden_size, batch_first=True)" ] }, { "cell_type": "code", "execution_count": 3, "id": "e4c9ff01", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([4, 31, 5])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "input_tensor = torch.randn(batch_size, seq_length, input_size)\n", "input_tensor.shape" ] }, { "cell_type": "code", "execution_count": 4, "id": "d3ad7340", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(torch.Size([4, 31, 8]), torch.Size([1, 4, 8]), torch.Size([1, 4, 8]))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output_tensor, (hidden_state, cell_state) = rnn(input_tensor)\n", "output_tensor.shape, hidden_state.shape, cell_state.shape" ] }, { "cell_type": "code", "execution_count": null, "id": "7bd296a8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.11" } }, "nbformat": 4, "nbformat_minor": 5 }