Predicting Next Word of LSTM Model from Tensorflow Example

不羁岁月 提交于 2019-12-22 12:54:09

问题


My buddy and I are trying to utilize the trained model from the LSTM tensorflow example here. We've been able to train our model, save the model, and then import the model. We've just used tensorflow's Supervisor. It was in the tutorial, but you can read more about it here.

It's weird because there's not a whole lot of clear documentation for this. I understand that tensorflow is an API that's going through a lot of changes and adaptations right now, but it's hard to find clear answers. For example, we want to use tf.train.Saver(), but we aren't sure if there is anything comparable to tf.train.Supervisor()'s managed_session.

More to the point, however, we just want to use our model. We want to be able to map a string using tensorflow.models.rnn.ptb.reader. We're not sure how to do this. We pass in a string, and we want to do a simple prediction in terms of like predicting the next word in a string. So, something similar to this:

import tensorflow as tf
sess = tf.Session()
new_saver = tf.train.import_meta_graph('ptbmodel.meta')
new_saver.restore(sess, tf.train.latest_checkpoint('./')) # latest checkpoint
all_vars = tf.global_variables()
# just want to make sure all our variables are there!
for v in all_vars:
    v_ = sess.run(v)
    print("This is {} with value: {}".format(v.name, v_))


sent = raw_input("Enter a string where you want to predict the next word: ")
split_sent = sent.split()
# THEN map these words into our LSTM model and pull off the most likely word that 
# is coming next

But again, my buddy and I are pretty new to this, so we're not sure about where to go. I know this is probably too broad of a question for stack, but we've been pouring over the documentation and haven't been able to make much progress. ANY help would be appreciated so much!

We've already found these other Stack links. Check them out here and here.

We are not sure how to associate the logits probability list with any meaningful words.

来源:https://stackoverflow.com/questions/42333101/predicting-next-word-of-lstm-model-from-tensorflow-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!