ValueError: Variable bidirectional_rnn/fw/gru_cell/w_ru already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
我尝试如下定义自己的name_scope
中的每个元素,但无济于事:
def enc(message, weights, biases):
message = tf.unstack(message, timesteps_enc, 1)
fw_cell = rnn.GRUBlockCell(num_hidden_enc)
bw_cell = rnn.GRUBlockCell(num_hidden_enc)
with tf.name_scope("encoder"):
outputs, _, _ = rnn.static_bidirectional_rnn(fw_cell, bw_cell, message, dtype=tf.float32)
return tf.matmul(outputs[-1], weights) + biases
def dec(codeword, weights, biases):
codeword = tf.expand_dims(codeword, axis=2)
codeword = tf.unstack(codeword, timesteps_dec, 1)
fw_cell = rnn.GRUBlockCell(num_hidden_dec)
bw_cell = rnn.GRUBlockCell(num_hidden_dec)
with tf.name_scope("decoder"):
outputs, _, _ = rnn.static_bidirectional_rnn(fw_cell, bw_cell, codeword, dtype=tf.float32)
return tf.matmul(outputs[-1], weights) + biases
有人可以暗示我在做什么错吗?
答案 0 :(得分:1)
只需将其作为答案:
只需尝试将name_scope
换成variable_scope
。我不确定它是否仍然有效,但是对于旧版本的TF,不鼓励使用name_scope
。从变量名bidirectional_rnn/fw/gru_cell/w_ru
中,您可以看到未应用范围。
答案 1 :(得分:1)
一件事是,您无法在同一范围内创建具有相同名称的变量,因此将name_scope
更改为variable_scope
会解决问题。
另一件事是,由于解码器RNN不能双向,所以这样的模型不能用作编码器-解码器模型。您确实在训练时就拥有了整个目标序列,但是在推理时,您从左到右生成了目标。这意味着您仅具有前向RNN的左侧上下文,而没有向后RNN的右侧上下文。