1

我正在尝试使用带有 Beam Search 和 Attention 的 Tensorflow 编写 seq2seq 示例。到目前为止,我还没有找到具体的例子来解释使用当前 tf 版本的解码和/或注意力。

之前的版本都存在波束搜索解码器的问题,它会告诉您执行 batch_tile。

我有一个简单解码器示例的工作示例,暂时还可以,但我想使用 Beam Search

 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], [].

如果有人能帮我解决这个错误,我会很高兴。如果我设置

4

0 回答 0