LSTM-Sentiment-Analysis icon indicating copy to clipboard operation
LSTM-Sentiment-Analysis copied to clipboard

Using Pre-Trained LSTM.ipynb gives always Negative Sentiment for any text

Open maheshkumarrp opened this issue 7 years ago • 6 comments

error Using the code on Windows 10 with Python v3.5.4 & TensorFlow v1.1 But it always gives Sentiment as Negative respective of the text.

Actually, for text like "That movie was the best one I have ever seen" & "I am very happy today" the sentiment should be positive right? But the code gives negative sentiment as the output

maheshkumarrp avatar Aug 27 '17 11:08 maheshkumarrp

So, I think this is just an issue with the pretrained model. I believe it has overfit to the training dataset, and thus has trouble with some of the new input phrases. You can try training your own model (maybe with different hyperparameters) and seeing if you get better performance. I'll also look into seeing if I can upload a more accurate pretrained model.

adeshpande3 avatar Aug 27 '17 18:08 adeshpande3

Thanks :)

maheshkumarrp avatar Aug 28 '17 04:08 maheshkumarrp

Hi, I had a similar problem, but for me the reason was that I had mistakenly loaded an untrained network because I had some issues with restoring the provided saved model on tf 1.3.

sabriwi avatar Aug 30 '17 15:08 sabriwi

As adeshpande3 has already pointed out, the model has most definitely overfitted to the training data so I would recommend re-training from scratch. However, the output_keep_prob parameter in the following line should be set to unity for evaluation. lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=1) Dropout is used to help to reduce overfitting during training, by forcing the network to find robust, lower dimensionality solutions by only updating a random proportion of the weights for a cell. For evaluation, the best prediction is achieved by using the entirety of the network.

Finally, I recommend adding a softmax layer at the end of the network and evaluating this instead of prediction. This will make the final layer will be much more interpretable, where predictedSentiment[0] now represents the probability of a positive review, and predictedSentiment[1] represents the probability of a negative review. softmax = tf.nn.softmax(prediction)

bradleyfowler123 avatar Sep 11 '17 20:09 bradleyfowler123

I don't think it is because of the over-fitting. I found one line missing in the Pre-Trained LSTM.ipynb when loading the wordsList: wordsList = [word.decode('UTF-8') for word in wordsList] #Encode words as UTF-8 it works after adding this encoding line.

chenwydj avatar Oct 03 '17 23:10 chenwydj

chenwydj I have tried to add the line but the result is always 'negative' also for positive text

alemap avatar Oct 06 '17 07:10 alemap