{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 교재 페이지 (321-322) #####"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6-2) one node : 5 (input-dim) in 2 (hidden_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-1-53bce69330d5>:17: BasicLSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.\n",
      "2 LSTMStateTuple(c=2, h=2)\n",
      "array([[[0., 0., 0., 0., 1., 0.]]], dtype=float32)\n",
      "WARNING:tensorflow:From <ipython-input-1-53bce69330d5>:22: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use `keras.layers.RNN(cell)`, which is equivalent to this API\n",
      "WARNING:tensorflow:From C:\\Users\\jsdata00010\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\tensor_array_ops.py:162: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "array([[[0.06355406, 0.07222702]]], dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "from tensorflow.contrib import rnn\n",
    "import pprint\n",
    "tf.random.set_random_seed(777)\n",
    "pp = pprint.PrettyPrinter(indent=4)\n",
    "sess = tf.InteractiveSession()\n",
    "# One hot encoding for each char in 'matchup'\n",
    "d = [1, 0, 0, 0, 0, 0]\n",
    "a = [0, 1, 0, 0, 0, 0]\n",
    "t = [0, 0, 1, 0, 0, 0]\n",
    "e = [0, 0, 0, 1, 0, 0]\n",
    "d = [0, 0, 0, 0, 1, 0]\n",
    "u = [0, 0, 0, 0, 0, 1]\n",
    "# One cell RNN input_dim (5) -> output_dim (2)\n",
    "hidden_size = 2\n",
    "cell = tf.contrib.rnn.BasicLSTMCell(num_units=hidden_size)\n",
    "print(cell.output_size, cell.state_size)\n",
    "\n",
    "x_data = np.array([[d]], dtype=np.float32) # x_data = [[[1,0,0,0,0,0,0]]]\n",
    "pp.pprint(x_data)\n",
    "outputs, _states = tf.nn.dynamic_rnn(cell, x_data, dtype=tf.float32)\n",
    "\n",
    "sess.run(tf.global_variables_initializer())\n",
    "pp.pprint(outputs.eval())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
