adeshpande3 / LSTM-Sentiment-Analysis

Sentiment Analysis with LSTMs in Tensorflow
MIT License
984 stars 431 forks source link

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

Open maheshkumarrp opened 7 years ago

maheshkumarrp commented 7 years ago

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

adeshpande3 commented 7 years ago

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.

maheshkumarrp commented 7 years ago

Thanks :)

sabriwi commented 7 years ago

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.

bradleyfowler123 commented 7 years ago

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)

chenwydj commented 7 years ago

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.

alemap commented 7 years ago

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