Skip to content

Commit dbbe397

Browse files
qoocrabkkweon
authored andcommitted
Update lab-12-0-rnn_basics.ipynb
1. tf.contrib.rnn.BasicRNNCell will be removed in a future version. so changed to tf.keras.layers.SimpleRNNCell. 2. tf.contrib.rnn.BasicLSTMCell will be removed in a future version. so changed to tf.nn.rnn_cell.LSTMCell.
1 parent edf393e commit dbbe397

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

lab-12-0-rnn_basics.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"with tf.variable_scope('one_cell') as scope:\n",
6464
" # One cell RNN input_dim (4) -> output_dim (2)\n",
6565
" hidden_size = 2\n",
66-
" cell = tf.contrib.rnn.BasicRNNCell(num_units=hidden_size)\n",
66+
" cell = tf.keras.layers.SimpleRNNCell(units=hidden_size)\n",
6767
" print(cell.output_size, cell.state_size)\n",
6868
"\n",
6969
" x_data = np.array([[h]], dtype=np.float32) # x_data = [[[1,0,0,0]]]\n",
@@ -110,7 +110,7 @@
110110
"with tf.variable_scope('two_sequances') as scope:\n",
111111
" # One cell RNN input_dim (4) -> output_dim (2). sequence: 5\n",
112112
" hidden_size = 2\n",
113-
" cell = tf.contrib.rnn.BasicRNNCell(num_units=hidden_size)\n",
113+
" cell = tf.keras.layers.SimpleRNNCell(units=hidden_size)\n",
114114
" x_data = np.array([[h, e, l, l, o]], dtype=np.float32)\n",
115115
" print(x_data.shape)\n",
116116
" pp.pprint(x_data)\n",
@@ -184,7 +184,7 @@
184184
" pp.pprint(x_data)\n",
185185
" \n",
186186
" hidden_size = 2\n",
187-
" cell = rnn.BasicLSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
187+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
188188
" outputs, _states = tf.nn.dynamic_rnn(\n",
189189
" cell, x_data, dtype=tf.float32)\n",
190190
" sess.run(tf.global_variables_initializer())\n",
@@ -249,7 +249,7 @@
249249
" pp.pprint(x_data)\n",
250250
" \n",
251251
" hidden_size = 2\n",
252-
" cell = rnn.BasicLSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
252+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
253253
" outputs, _states = tf.nn.dynamic_rnn(\n",
254254
" cell, x_data, sequence_length=[5,3,4], dtype=tf.float32)\n",
255255
" sess.run(tf.global_variables_initializer())\n",
@@ -314,7 +314,7 @@
314314
" \n",
315315
" # One cell RNN input_dim (4) -> output_dim (5). sequence: 5, batch: 3\n",
316316
" hidden_size=2\n",
317-
" cell = rnn.BasicLSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
317+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, state_is_tuple=True)\n",
318318
" initial_state = cell.zero_state(batch_size, tf.float32)\n",
319319
" outputs, _states = tf.nn.dynamic_rnn(cell, x_data,\n",
320320
" initial_state=initial_state, dtype=tf.float32)\n",
@@ -412,7 +412,7 @@
412412
"source": [
413413
"with tf.variable_scope('generated_data') as scope:\n",
414414
" # One cell RNN input_dim (3) -> output_dim (5). sequence: 5, batch: 3\n",
415-
" cell = rnn.BasicLSTMCell(num_units=5, state_is_tuple=True)\n",
415+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=5, state_is_tuple=True)\n",
416416
" initial_state = cell.zero_state(batch_size, tf.float32)\n",
417417
" outputs, _states = tf.nn.dynamic_rnn(cell, x_data,\n",
418418
" initial_state=initial_state, dtype=tf.float32)\n",
@@ -470,7 +470,7 @@
470470
"source": [
471471
"with tf.variable_scope('MultiRNNCell') as scope:\n",
472472
" # Make rnn\n",
473-
" cell = rnn.BasicLSTMCell(num_units=5, state_is_tuple=True)\n",
473+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=5, state_is_tuple=True)\n",
474474
" cell = rnn.MultiRNNCell([cell] * 3, state_is_tuple=True) # 3 layers\n",
475475
"\n",
476476
" # rnn in/out\n",
@@ -529,7 +529,7 @@
529529
],
530530
"source": [
531531
"with tf.variable_scope('dynamic_rnn') as scope:\n",
532-
" cell = rnn.BasicLSTMCell(num_units=5, state_is_tuple=True)\n",
532+
" cell = tf.nn.rnn_cell.LSTMCell(num_units=5, state_is_tuple=True)\n",
533533
" outputs, _states = tf.nn.dynamic_rnn(cell, x_data, dtype=tf.float32,\n",
534534
" sequence_length=[1, 3, 2])\n",
535535
" # lentgh 1 for batch 1, lentgh 2 for batch 2\n",
@@ -642,8 +642,8 @@
642642
"source": [
643643
"with tf.variable_scope('bi-directional') as scope:\n",
644644
" # bi-directional rnn\n",
645-
" cell_fw = rnn.BasicLSTMCell(num_units=5, state_is_tuple=True)\n",
646-
" cell_bw = rnn.BasicLSTMCell(num_units=5, state_is_tuple=True)\n",
645+
" cell_fw = tf.nn.rnn_cell.LSTMCell(num_units=5, state_is_tuple=True)\n",
646+
" cell_bw = tf.nn.rnn_cell.LSTMCell(num_units=5, state_is_tuple=True)\n",
647647
"\n",
648648
" outputs, states = tf.nn.bidirectional_dynamic_rnn(cell_fw, cell_bw, x_data,\n",
649649
" sequence_length=[2, 3, 1],\n",

0 commit comments

Comments
 (0)