【发布时间】:2017-11-18 22:13:04
【问题描述】:
我正在尝试构建一个多元时间序列预测模型。我按照以下教程进行温度预测。 http://nbviewer.jupyter.org/github/addfor/tutorials/blob/master/machine_learning/ml16v04_forecasting_with_LSTM.ipynb
我想使用以下代码将他的模型扩展到多层 LSTM 模型:
cell = tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True)
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers,state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
但我有一个错误提示:
ValueError: 维度必须相等,但对于 256 和 142 'rnn/while/rnn/multi_rnn_cell/cell_0/cell_0/lstm_cell/MatMul_1'(操作: 'MatMul') 输入形状:[?,256], [142,512]。
当我尝试这个时:
cell = []
for i in range(num_layers):
cell.append(tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True))
cell = tf.contrib.rnn.MultiRNNCell(cell,state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
我没有这样的错误,但预测真的很糟糕。
我定义hidden=128。
features = tf.reshape(features, [-1, n_steps, n_input]) 的形状为 (?,1,14),用于单层外壳。
我的数据看起来像这样x.shape=(594,14), y.shape=(591,1)
我很困惑如何在 tensorflow 中堆叠 LSTM 单元。我的张量流版本是 0.14。
【问题讨论】:
标签: tensorflow lstm multi-layer