Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Tensorflow LSTM tutorial prediction

MetaInstigator:

I'm trying to set up the tensorflow seq2seq tutorial. I could get it to run, but I can't figure out how to make predictions. For example, I wrote the following program to train a basic model like like it was demonstrated in the file translate.py:


# Init model and data:
data_set = ([([1, 1], [2, 2]), ([3, 3], [4]), ([3], [4])],
[([1, 1, 1, 1, 1], [2, 2, 2, 2, 2]), ([3, 3, 3], [4, 4])])
model = seq2seq_model.Seq2SeqModel(10, 10, [(3, 3), (6, 6)], 32, 2,
5.0, 32, 0.3, 0.99, num_samples=8)

# Train:

sess = tf.Session()
sess.run(tf.global_variables_initializer())

for epoch in xrange(100):
bucket_id = random.choice([0, 1])
encoder_inputs, decoder_inputs, target_weights = model.get_batch(
data_set, bucket_id)
model.step(sess, encoder_inputs, decoder_inputs, target_weights,
bucket_id, False)
print ("Ecoch: %d" % epoch)

# Predict on inputs

inputs = [[3,3,3],
[1,1]]

for input in inputs:
# Find right bucket for input:
bucket_id = 1
for i, bucket in enumerate(_buckets):
if bucket[0] >= len(input):
bucket_id = i
break

# make prediction on input:
encoder_inputs, decoder_inputs, target_weights = model.get_batch(
{bucket_id: [(input, [])]}, bucket_id)

_, _, outputs = model.step(sess, encoder_inputs, decoder_inputs,
target_weights, bucket_id, True)

# print prediction
for output in outputs:
print (np.argmax(output, axis=1)) # Take logit with maximum index

Now, according to the seq2seq tutorial, the logits are logit vectors of dimension V, so they should each be a distribution over possible outputs, and since there are 10 possible outputs, the buckets should be [4,0,0] and [2,0,0]. But instead, the logits are each a distribution over the batch_size of th emodel. So I am getting the following cryptic output:


[30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30]
[30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30]
[30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30]
[4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4]
[25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25
25 25 25 25 25 25 25]
[13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13
13 13 13 13 13 13 13]

From which the correct labels, namely 2 and 4, are not recoverable. So what do the logits represent? How can the correct labels be recovered from them?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Tensorflow LSTM tutorial prediction

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×