Reputation: 2382
I've been recently trying to implement a multi-class classification LSTM architecture, based on this example: biLSTM example
After I changed
self.label = tf.placeholder(tf.int32, [None])
to
self.label = tf.placeholder(tf.int32, [None,self.n_class)
The model seems to train normally, yet I am having trouble with this step:
self.loss = tf.reduce_mean(
tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y_hat, labels=self.label))
# prediction
self.prediction = tf.argmax(tf.nn.softmax(y_hat), 1)
As, even though the model learns normally, the predictions does not seem to work for multiple variables. I was wondering how should one code the self.prediction object, so that it emits a vector of predictions for individual instances?
Thank you very much.
Upvotes: 0
Views: 198
Reputation: 10709
I was wondering how should one code the self.prediction object, so that it emits a vector of predictions for individual instances?
In general tf.nn.softmax
returns a vector of probabilities. You just can't see them because your are using tf.argmax
, which returns the index of the largest value. Therefore you will just get one number. Just remove tf.argmax and you should be fine.
Upvotes: 1