Tensorflow-预测序列:X和Y是什么? [英] Tensorflow - predicting sequences: what is X and Y?

查看:213
本文介绍了Tensorflow-预测序列:X和Y是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个张量,需要考虑到前5个元素,并使用张量流LSTM/RNN预测序列中的下一个元素.我应该给X和Y喂什么?

I have a tensor that needs to predict the next element in a sequence with a tensorflow LSTM/RNN, while taking into account the previous 5 elements. What should I feed into X and Y?

从1 2 3 4 5开始,我想预测6

From 1 2 3 4 5, I want to predict 6

假设我的输入序列X为:

Suppose my input sequence X is:

X = 1 2 3 4 5 
    6 7 8 9 10 
    11 12 13 14 15
    ...

我的Y会是:

Y = 2 3 4 5 6 
    7 8 9 10 11 
    12 13 14 15 16
    ... ?

还是我应该喂它:

X = 1 2 3 4 5 
    2 3 4 5 6
    3 4 5 6 7 
    ....

我的Y会是:

Y = 6
    7 
    8 
    ... ?

还是TensorFlow会自动执行此操作?

Or does TensorFlow do this automatically?

我现在正在使用第一种方法,该方法受一个教程的启发,并且具有:

I am using the first approach now, inspired by a tutorial, with:

    x = tf.placeholder(tf.int32, [None, num_steps], name='input_placeholder')
    y = tf.placeholder(tf.int32, [None, num_steps], name='labels_placeholder')

    rnn_outputs = tf.reshape(rnn_outputs, [-1, state_size])
    y_reshaped = tf.reshape(y, [-1])
    logits = tf.matmul(rnn_outputs, W) + b
    predictions = tf.nn.softmax(logits)
    total_loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=y_reshaped))

如果我要求预测(在实际代码中,时间步长为16,类数为14313,对不起):

If I ask for a prediction (in the actual code the time steps is 16 and number of classes is 14313, sorry for that):

        prevSlice = np.array([[1, 2 , 3 , 4, 5, 6 ,7, 8, 9 ,10, 11, 12, 13, 14, 15, 16]], dtype=np.string_)
        feed_dict={g['x']: prevSlice}
        preds, state = sess.run([g['preds'],g['final_state']], feed_dict)

我对15个预测的预测过多.还是我应该如何解释这些?我不需要接下来的16个切片的预测,只需接下来的1个切片.

I get 15 predictions too many. Or how should I interpret these? I don't need predictions for the next 16 slices, just for the 1 next.

推荐答案

由于LSTM执行sequence to sequence预测,这并不意味着您将得到一个长度为batch_size的序列作为输出您的预测变量,而不是单个时间步长.

Since an LSTM performs a sequence to sequence prediction, would this not mean that you're being given a sequence of batch_size length as the output of your predictor instead of a single timestep.

因此,简而言之,您将获得与预测大小相同的序列.

So in short you would be getting a sequence of the same size as a prediction.

def predict_point_by_point(model, data):
    #Predict each timestep given the last sequence of true data, in effect only predicting 1 step ahead each time
    predicted = model.predict(data)
    predicted = np.reshape(predicted, (predicted.size,))
    return predicted

您可以沿这些方向做一些事情,并为每个len(timestep)添加一个移动窗口 您将模型添加到模型中,并添加了一个时间步,因此您一次也输出了一个.

you could do something along those lines, and add a moving window for each len(timestep) that you feed onto your model accounting for that one timestep added so you output one at a time aswell.

这篇关于Tensorflow-预测序列:X和Y是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆