{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 6.2 循环神经网络" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.4.1\n" ] } ], "source": [ "import torch\n", "\n", "print(torch.__version__)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tensor([[ 5.2633, -3.2288, 0.6037, -1.3321],\n", " [ 9.4012, -6.7830, 1.0630, -0.1809],\n", " [ 7.0355, -2.2361, 0.7469, -3.4667]])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X, W_xh = torch.randn(3, 1), torch.randn(1, 4)\n", "H, W_hh = torch.randn(3, 4), torch.randn(4, 4)\n", "torch.matmul(X, W_xh) + torch.matmul(H, W_hh)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tensor([[ 5.2633, -3.2288, 0.6037, -1.3321],\n", " [ 9.4012, -6.7830, 1.0630, -0.1809],\n", " [ 7.0355, -2.2361, 0.7469, -3.4667]])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "torch.matmul(torch.cat((X, H), dim=1), torch.cat((W_xh, W_hh), dim=0))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "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.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }