我正在尝试使用带有波束搜索和注意力的Tensorflow来编码seq2seq示例。到目前为止,我还没有找到具体的示例来说明使用当前tf版本进行的解码和/或注意。
以前的版本中的波束搜索解码器都有一个问题,它将告诉您执行batch_tile。
我有一个简单的解码器示例的工作示例,暂时还可以,但我想使用波束搜索
inference_decoder = tf.contrib.seq2seq.BeamSearchDecoder(cell = dec_cell,
embedding = embedings,
start_tokens = starting_id_vec,
end_token = word_to_id['<EOS>'],
initial_state = enc_states,#dec_cell.zero_state(config.BATCH_SIZE * config.BEAM_SIZE,tf.float32).clone(cell_state=enc_states),
beam_width = config.BEAM_SIZE,
output_layer = output_layer
)
我收到此错误
ValueError: Cannot reshape a tensor with 32768 elements to shape [64,10,512] (327680 elements) for 'decoder_1/Reshape' (op: 'Reshape') with input shapes: [64,512], [3] and with input tensors computed as partial shapes: input[1] = [64,10,512].
我相信,beam_width增加了额外的维数,因为在没有使用BasicDecoder的BeamSearch的情况下,该代码可以更改张量的等级。如果我将beam_size设置为= 1(有趣的缘故),则会引发此错误
ValueError: Shape must be rank 3 but is rank 2 for 'decoder/decoder/while/BasicDecoderStep/decoder/Attention_Wrapper/concat_3' (op: 'ConcatV2') with input shapes: [64,?,512], [64,512], [].
如果有人可以帮助我解决此错误,我将非常高兴。 如果设置