我有用于预测股票价格的简单 seq2seq 模型。我创建了一个 lstm 单元的编码器和解码器,它将预测接下来的 5 个时间步值。但它会引发错误:
ValueError: Dimensions must be equal, but are 517 and 562 for 'rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/MatMul_1' (op: 'MatMul') with input shapes: [10,517], [562,2048].
数据样本
t1 t2 t3 t4 t5 ...
19/10/2018 0.005 0.100 -0.021 0.030 -0.025
20/10/2018 0.023 0.020 0.020 0.130 0.125
21/10/2018 -0.205 0.140 -0.011 0.020 -0.305
代码
import tensorflow as tf
import numpy as np
seq_len = 1
n_inputs = 50
n_outputs = 5
n_layers = 3
n_neurons = 512
batch_size = 10
g = tf.Graph()
with g.as_default():
X = tf.placeholder(tf.float32,shape=(None,seq_len,n_inputs),name="X")
y = tf.placeholder(tf.float32,shape=(None,seq_len,n_outputs),name="y")
cells = tf.nn.rnn_cell.MultiRNNCell([ tf.nn.rnn_cell.LSTMCell(n_neurons) for _ in range(n_layers) ])
init_state = cells.zero_state(batch_size, tf.float32)
enc_outputs, enc_states = tf.nn.dynamic_rnn(cells, X,initial_state=init_state)
dec_outputs,dec_states = tf.nn.dynamic_rnn(cells, y, initial_state=enc_states)
loss = tf.reduce_mean(tf.square(dec_outputs - y))
train_op = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session(graph=g)
sess.run(init)
欢迎任何帮助。