You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in your LSTM code for sentiment analysis, it goes like: lstmCell = tf.contrib.rnn.BasicLSTMCell(lstmUnits) lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=0.25) value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32) weight = tf.Variable(tf.truncated_normal([lstmUnits, numClasses])) bias = tf.Variable(tf.constant(0.1, shape=[numClasses])) value = tf.transpose(value, [1, 0, 2]) last = tf.gather(value, int(value.get_shape()[0]) - 1) prediction = (tf.matmul(last, weight) + bias)
why not use the second value from function dynamic_rnn() ?
the second value is the final_state of LSTM cell, that is a tuple of (h, Ct).
The h is the output of the last cell, so you can just code like this value, (c, h) = tf.nn.dynamic_rnn(lstmcell, data, dtype=tf.float32)
When get the h, we can directly apply the multiplication to it.
so, there is no need to use this: value = tf.transpose(value, [1, 0, 2]) last = tf.gather(value, int(value.get_shape()[0]) - 1)
so, this is just some advices, in fact your tutorials are really good, Greet appreciates!
The text was updated successfully, but these errors were encountered:
in your LSTM code for sentiment analysis, it goes like:
lstmCell = tf.contrib.rnn.BasicLSTMCell(lstmUnits) lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=0.25) value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float32) weight = tf.Variable(tf.truncated_normal([lstmUnits, numClasses])) bias = tf.Variable(tf.constant(0.1, shape=[numClasses])) value = tf.transpose(value, [1, 0, 2]) last = tf.gather(value, int(value.get_shape()[0]) - 1) prediction = (tf.matmul(last, weight) + bias)
why not use the second value from function dynamic_rnn() ?
the second value is the final_state of LSTM cell, that is a tuple of (h, Ct).
The h is the output of the last cell, so you can just code like this
value, (c, h) = tf.nn.dynamic_rnn(lstmcell, data, dtype=tf.float32)
When get the h, we can directly apply the multiplication to it.
so, there is no need to use this:
value = tf.transpose(value, [1, 0, 2]) last = tf.gather(value, int(value.get_shape()[0]) - 1)
so, this is just some advices, in fact your tutorials are really good, Greet appreciates!
The text was updated successfully, but these errors were encountered: