问题
I am trying to classify sentiment on movie review and predict the genres of that movie based on the review itself. Now Sentiment is a Binary Classification problem where as Genres can be Multi-Label Classification problem.
Another example to clarify the problem is classifying Sentiment of a sentence and also predicting whether the tone of the sentence is happy, sarcastic, sad, pitiful, angry or fearful.
More to that is, I want to perform this classification using Tensorflow CNN. My problem is in structuring the y_label and training the data such that the output helps me retrieve Sentiment as well as the genres. Eg Data Y Label: [[0,1],[0,1,0,1,0]] for sentiment as Negative and mood as sarcastic and angry
How do you suggest I tackle this?
回答1:
Basically at the final layer of the CNN as you've resized the CNN output to a form of 1x1xN, add two Feed-Forward Neural Networks. So if you have a simple classification problem you feed the output of the CNN into a Feed-Forward Neural Network, now in this case you'll have two of these networks. So in order to accomplish this basically you'll have the following:
- CNN output ---feed---> Classifier#1
- CNN output ---feed---> Classifier#2
Thus you'll have to separate classifications BUT you'll still have to backpropagate them so it will look something like this:
loss1 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction1, labels_1))
loss2 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(prediction2, labels_2))
loss = loss1 + loss2
So you'll "minimize" the loss
with an optimizer.
回答2:
You can treat this as a multi-label
problem, and append the sentiment
and the tone
labels together.
Now since the network has to predict multiple outputs (2 in this case) you need to use an activation function like sigmoid
and not softmax
. And your prediction can be made using tf.round(logits)
.
来源:https://stackoverflow.com/questions/45004514/how-to-classify-both-sentiment-and-genres-from-movie-reviews-using-cnn-tensorflo