ValueError: Variable rnnlm/multi_rnn_cell/cell_0/basic_lstm_cell/kernel already exists, disallowed.

在使用语言模型训练完成之后,在生成的时候,需要使用while循环多次调用生成多句。

报错:ValueError: Variable rnnlm/multi_rnn_cell/cell_0/basic_lstm_cell/kernel already exists, disallowed.

解决方法:在构建图的代码块上加上with tf.Graph().as_default():

with tf.Graph().as_default():
    input_data = tf.placeholder(tf.int32, [batch_size, None])  
    output_targets = tf.placeholder(tf.int32, [batch_size, None])  
    _, last_state, probs, cell, initial_state = neural_network(input_data)

 

你可能感兴趣的:(python,tensorflow)