1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| def _generate_params_for_lstm_cell(x_size, h_size, bias_size): x_w = tf.get_variable('x_weights', x_size) h_w = tf.get_variable('h_weights', h_size) b = tf.get_variable('bias', bias_size, initializer=tf.constant_initializer(0.0)) return x_w, h_w, b
with tf.variable_scope('lstm', initializer=lstm_init): with tf.variable_scope('inputs'): ix_w, ih_w, ib = _generate_params_for_lstm_cell( x_size=[hps.embedding_size, hps.num_lstm_nodes[0]], h_size=[hps.num_lstm_nodes[0], hps.num_lstm_nodes[0]], bias_size=[1, hps.num_lstm_nodes[0]] ) with tf.variable_scope('outputs'): ox_w, oh_w, ob = _generate_params_for_lstm_cell( x_size=[hps.embedding_size, hps.num_lstm_nodes[0]], h_size=[hps.num_lstm_nodes[0], hps.num_lstm_nodes[0]], bias_size=[1, hps.num_lstm_nodes[0]] ) with tf.variable_scope('forget'): fx_w, fh_w, fb = _generate_params_for_lstm_cell( x_size=[hps.embedding_size, hps.num_lstm_nodes[0]], h_size=[hps.num_lstm_nodes[0], hps.num_lstm_nodes[0]], bias_size=[1, hps.num_lstm_nodes[0]] ) with tf.variable_scope('memory'): cx_w, ch_w, cb = _generate_params_for_lstm_cell( x_size=[hps.embedding_size, hps.num_lstm_nodes[0]], h_size=[hps.num_lstm_nodes[0], hps.num_lstm_nodes[0]], bias_size=[1, hps.num_lstm_nodes[0]] ) state_C = tf.Variable( tf.zeros([batch_size, hps.num_lstm_nodes[0]]), trainable=False ) h = tf.Variable( tf.zeros([batch_size, hps.num_lstm_nodes[0]]), trainable=False )
|