{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 교재페이지 (323-324) #####"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6-4) Batching input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-3-dcb1df22d9c7>:19: 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",
      "(3, 7, 6)\n",
      "array([[[0., 0., 0., 0., 1., 0.],\n",
      "        [0., 1., 0., 0., 0., 0.],\n",
      "        [0., 0., 1., 0., 0., 0.],\n",
      "        [0., 1., 0., 0., 0., 0.],\n",
      "        [0., 0., 0., 1., 0., 0.],\n",
      "        [0., 0., 0., 0., 1., 0.],\n",
      "        [0., 0., 0., 0., 0., 1.]],\n",
      "\n",
      "       [[0., 1., 0., 0., 0., 0.],\n",
      "        [0., 0., 1., 0., 0., 0.],\n",
      "        [0., 1., 0., 0., 0., 0.],\n",
      "        [0., 0., 0., 1., 0., 0.],\n",
      "        [0., 0., 0., 0., 1., 0.],\n",
      "        [0., 0., 0., 0., 0., 1.],\n",
      "        [0., 0., 0., 0., 1., 0.]],\n",
      "\n",
      "       [[0., 0., 1., 0., 0., 0.],\n",
      "        [0., 1., 0., 0., 0., 0.],\n",
      "        [0., 0., 0., 1., 0., 0.],\n",
      "        [0., 0., 0., 0., 1., 0.],\n",
      "        [0., 0., 0., 0., 0., 1.],\n",
      "        [0., 0., 0., 0., 1., 0.],\n",
      "        [0., 1., 0., 0., 0., 0.]]], dtype=float32)\n",
      "WARNING:tensorflow:From <ipython-input-3-dcb1df22d9c7>:25: 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.02311974, -0.04308142],\n",
      "        [-0.02541643,  0.027114  ],\n",
      "        [-0.09375904, -0.05893641],\n",
      "        [-0.13613647,  0.01660936],\n",
      "        [-0.15346731, -0.04835917],\n",
      "        [-0.06899304, -0.08774862],\n",
      "        [-0.15417273, -0.15292256]],\n",
      "\n",
      "       [[-0.04469378,  0.04414848],\n",
      "        [-0.10204326, -0.04654878],\n",
      "        [-0.14554398,  0.02132127],\n",
      "        [-0.15804555, -0.04582615],\n",
      "        [-0.07227936, -0.08623173],\n",
      "        [-0.15604107, -0.15211627],\n",
      "        [-0.06012322, -0.12490103]],\n",
      "\n",
      "       [[-0.08280133, -0.07912831],\n",
      "        [-0.12369254,  0.00868126],\n",
      "        [-0.14740838, -0.05283064],\n",
      "        [-0.06463746, -0.09057274],\n",
      "        [-0.1516731 , -0.15463135],\n",
      "        [-0.05728146, -0.1258729 ],\n",
      "        [-0.08345545, -0.01394349]]], dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "from tensorflow.contrib import rnn\n",
    "import pprint\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",
    "\n",
    "# One cell RNN input_dim (6) -> output_dim (2). sequence: 7\n",
    "hidden_size = 2\n",
    "sequence_length = 7\n",
    "batch = 3\n",
    "cell = tf.contrib.rnn.BasicLSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
    "x_data = np.array([[d,a,t,a,e,d,u],\n",
    "                  [a,t,a,e,d,u,d],\n",
    "                  [t,a,e,d,u,d,a]], dtype=np.float32)\n",
    "print(x_data.shape)\n",
    "pp.pprint(x_data)\n",
    "outputs, _states = tf.nn.dynamic_rnn(cell, x_data, dtype=tf.float32)\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
}
