|
63 | 63 | "with tf.variable_scope('one_cell') as scope:\n", |
64 | 64 | " # One cell RNN input_dim (4) -> output_dim (2)\n", |
65 | 65 | " 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", |
67 | 67 | " print(cell.output_size, cell.state_size)\n", |
68 | 68 | "\n", |
69 | 69 | " x_data = np.array([[h]], dtype=np.float32) # x_data = [[[1,0,0,0]]]\n", |
|
110 | 110 | "with tf.variable_scope('two_sequances') as scope:\n", |
111 | 111 | " # One cell RNN input_dim (4) -> output_dim (2). sequence: 5\n", |
112 | 112 | " 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", |
114 | 114 | " x_data = np.array([[h, e, l, l, o]], dtype=np.float32)\n", |
115 | 115 | " print(x_data.shape)\n", |
116 | 116 | " pp.pprint(x_data)\n", |
|
184 | 184 | " pp.pprint(x_data)\n", |
185 | 185 | " \n", |
186 | 186 | " 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", |
188 | 188 | " outputs, _states = tf.nn.dynamic_rnn(\n", |
189 | 189 | " cell, x_data, dtype=tf.float32)\n", |
190 | 190 | " sess.run(tf.global_variables_initializer())\n", |
|
249 | 249 | " pp.pprint(x_data)\n", |
250 | 250 | " \n", |
251 | 251 | " 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", |
253 | 253 | " outputs, _states = tf.nn.dynamic_rnn(\n", |
254 | 254 | " cell, x_data, sequence_length=[5,3,4], dtype=tf.float32)\n", |
255 | 255 | " sess.run(tf.global_variables_initializer())\n", |
|
314 | 314 | " \n", |
315 | 315 | " # One cell RNN input_dim (4) -> output_dim (5). sequence: 5, batch: 3\n", |
316 | 316 | " 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", |
318 | 318 | " initial_state = cell.zero_state(batch_size, tf.float32)\n", |
319 | 319 | " outputs, _states = tf.nn.dynamic_rnn(cell, x_data,\n", |
320 | 320 | " initial_state=initial_state, dtype=tf.float32)\n", |
|
412 | 412 | "source": [ |
413 | 413 | "with tf.variable_scope('generated_data') as scope:\n", |
414 | 414 | " # 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", |
416 | 416 | " initial_state = cell.zero_state(batch_size, tf.float32)\n", |
417 | 417 | " outputs, _states = tf.nn.dynamic_rnn(cell, x_data,\n", |
418 | 418 | " initial_state=initial_state, dtype=tf.float32)\n", |
|
470 | 470 | "source": [ |
471 | 471 | "with tf.variable_scope('MultiRNNCell') as scope:\n", |
472 | 472 | " # 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", |
474 | 474 | " cell = rnn.MultiRNNCell([cell] * 3, state_is_tuple=True) # 3 layers\n", |
475 | 475 | "\n", |
476 | 476 | " # rnn in/out\n", |
|
529 | 529 | ], |
530 | 530 | "source": [ |
531 | 531 | "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", |
533 | 533 | " outputs, _states = tf.nn.dynamic_rnn(cell, x_data, dtype=tf.float32,\n", |
534 | 534 | " sequence_length=[1, 3, 2])\n", |
535 | 535 | " # lentgh 1 for batch 1, lentgh 2 for batch 2\n", |
|
642 | 642 | "source": [ |
643 | 643 | "with tf.variable_scope('bi-directional') as scope:\n", |
644 | 644 | " # 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", |
647 | 647 | "\n", |
648 | 648 | " outputs, states = tf.nn.bidirectional_dynamic_rnn(cell_fw, cell_bw, x_data,\n", |
649 | 649 | " sequence_length=[2, 3, 1],\n", |
|
0 commit comments