python - TensorFlow sentiment analysis: use own data -


i've been using following code tflearn examples:

""" simple example using lstm recurrent neural network classify imdb sentiment dataset. references:     - long short term memory, sepp hochreiter & jurgen schmidhuber, neural     computation 9(8): 1735-1780, 1997.     - andrew l. maas, raymond e. daly, peter t. pham, dan huang, andrew y. ng,     , christopher potts. (2011). learning word vectors sentiment     analysis. 49th annual meeting of association computational     linguistics (acl 2011). links:     - http://deeplearning.cs.cmu.edu/pdfs/hochreiter97_lstm.pdf     - http://ai.stanford.edu/~amaas/data/sentiment/ """ __future__ import division, print_function, absolute_import import os import tflearn tflearn.data_utils import to_categorical, pad_sequences tflearn.datasets import imdb  # imdb dataset loading train, test, _ = imdb.load_data(path='imdb.pkl', n_words=100,                                 valid_portion=0.1)  trainx, trainy = train testx, testy = test  # data preprocessing # sequence padding trainx = pad_sequences(trainx, maxlen=100, value=0.) testx = pad_sequences(testx, maxlen=100, value=0.) # converting labels binary vectors trainy = to_categorical(trainy, nb_classes=2) testy = to_categorical(testy, nb_classes=2)  # network building net = tflearn.input_data([none, 100]) net = tflearn.embedding(net, input_dim=10000, output_dim=128) net = tflearn.lstm(net, 128) net = tflearn.fully_connected(net, 2, activation='softmax') net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,                          loss='categorical_crossentropy')  # training model = tflearn.dnn(net, tensorboard_verbose=0) model.fit(trainx, trainy, validation_set=(testx, testy), show_metric=true,           batch_size=32) 

the model trains , manages 83% accuracy on test set. want apply trained model new unseen data.

for example, like: model.predict("i happy today") should return positive sentiment value.

i new tensorflow , python, since i've been using r sentiment analysis , looks using lstm model in tensorflow has higher accuracy i've used in past.

any appreciated.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -