во время вызова seq2seq_model для получения прогноза поезда и теста я получаю эту ошибку? - PullRequest
0 голосов
/ 24 апреля 2020
'''
training_predictions, test_predictions = seq2seq_model(tf.reverse(inputs, [-1]),
                                                       targets,
                                                       keep_prob,
                                                       batch_size,
                                                       sequence_length,
                                                       len(answerword2int),
                                                       len(questionword2int),
                                                       encoding_embedding_size,
                                                       decoding_embedding_size,
                                                       rnn_size,
                                                       num_layers,
                                                       questionword2int)
Traceback (most recent call last):

  File "<ipython-input-28-b2be08c330e7>", line 12, in <module>
    questionword2int)

  File "<ipython-input-22-c4f5411a2dc7>", line 26, in seq2seq_model
    batch_size)

  File "<ipython-input-21-472a41dad669>", line 34, in decoder_rnn
    batch_size)

TypeError: decode_test_set() missing 1 required positional argument: 'batch_size'
'''

'''
Its the following code
#decoding the test/validation set
def decode_test_set(encoder_state, decoder_cell, decoder_embeddings_matrix, sos_id, eos_id, maximum_length, num_words,

sequence_length, decoding_scope, output_function, keep_prob, batch_size): внимания_states = tf.zeros ([batch_size, 1, decoder_cell.output_size]) prepare_attention (Внимание_статы, Внимание_Опция = «Бахданау», num_units = Decoder_cell.output_size) , name = "attn_dec_inf") test_prediction, _, _ = tf.contrib.seq2seq.dynamic_rnn_decoder (decoder_cell, test_decoder_function, scope = decoding_scope)

    return test_prediction


#creating the decoder rnn
def decoder_rnn(decoder_embedded_input, decoder_embeddings_matrix, encoder_state, num_words, sequence_length, rnn_size, num_layers,

word2int, keep_prob, переменная_обозначения: пакетная копия: "decoding") как decoding_scope: lstm = tf.contrib.rnn.BasicLSTMCell (rnn_size) lstm_dropout = tf.contrib.rnn.DropoutWrapper (lstm, в put_keep_prob = keep_prob) decoder_cell = tf.contrib.rnn.MultiRNNCell ([lstm_dropout] * num_layers) weights = tf.truncated_normal_initializer (stddev = 0.1) biases = tf.zeros_initunctionf. x, num_words, None, scope = decoding_scope, weights_initializer = weights, biases_initializer = biases)

        training_predictions = decode_training_set(encoder_state,
                                                   decoder_cell,
                                                   decoder_embedded_input,
                                                   sequence_length,
                                                   decoding_scope,
                                                   output_function,
                                                   keep_prob,
                                                   batch_size)
        decoding_scope.reuse_variables()
        test_prediction = decode_test_set(encoder_state,
                                          decoder_cell,
                                          decoder_embeddings_matrix,
                                          word2int['<SOS>'],
                                          word2int['<EOS>'],
                                          sequence_length - 1,
                                          num_words,
                                          decoding_scope,
                                          output_function,
                                          keep_prob,
                                          batch_size)
    return training_predictions, test_prediction

#building the seq2seq model

def seq2seq_model(inputs, targets, keep_prob, batch_size, sequence_length, answers_num_words, questions_num_words,

encoder_embedding_size, decoder_embedding_size, rnn_size, num_layers, questionwords2int): input_tribute_emb_conf. answers_num_words + 1, encoder_embedding_size, initializer = tf.random_uniform_initializer (0,1)) encoder_state = encoder_rnn (encoder_embedded_input, rnn_size, num_layers, keep_prob, sequence_length) предварительно обработанный_целевой_объект_объявления random_uniform ([questions_num_words + 1, decoder_embedding_size], 0, 1)) = decoder_embedded_input tf.nn.embedding_lookup (decoder_embeddings_matrix, preprocessed_targets) training_predictions, test_predictions = decoder_rnn (decoder_embedded_input, decoder_embeddings_matrix, encoder_state, questions_num_words, sequence_length, rnn_size, num_layers, questionword2int, keep_prob , batch_size)

    return training_predictions, test_predictions


#training the seq2seq modal
#setting up the hyperparameter

epochs = 100
batch_size = 64
rnn_size = 512
num_layers = 3
encoding_embedding_size = 512
decoding_embedding_size = 512
learning_rate = 0.01
learning_rate_decay = 0.9
min_learning_rate = 0.0001
keep_probability = 0.5

#defining a session

tf.reset_default_graph()
session = tf.InteractiveSession()

#loading the modal input

inputs, targets, lr, keep_prob = modal_input()

#setting the sequence length

sequence_length = tf.placeholder_with_default(25, None, name = 'sequence_length')

#getting the shape of input tensor

input_shape = tf.shape(inputs)

#getting the training and test predivtions
training_predictions, test_predictions = seq2seq_model(tf.reverse(inputs, [-1]),
                                                       targets,
                                                       keep_prob,
                                                       batch_size,
                                                       sequence_length,
                                                       len(answerword2int),
                                                       len(questionword2int),
                                                       encoding_embedding_size,
                                                       decoding_embedding_size,
                                                       rnn_size,
                                                       num_layers,
                                                       questionword2int)
'''

1 Ответ

0 голосов
/ 24 апреля 2020

Пожалуйста, перечитайте вашу ошибку МЕДЛЕННО на этот раз. Вы увидите, что в вашей функции decode_test_set() определено 12 аргументов. Однако, вызывая его во время прогнозирования, вы предоставляете ему только 11 значений и пропускаете последнее, равное batch_size.

Кроме того, просто для будущих вопросов, пожалуйста, отформатируйте ваш вопрос так, чтобы его было легко прочитать, и сообщество могло бы помочь вам лучше.

...