-2
'''
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): attention_states = tf.zeros([batch_size, 1, decoder_cell.output_size]) attention_keys, attention_values, attention_score_function, attention_construct_function = tf.contrib.seq2seq.prepare_attention(attention_states, attention_option= 'bahdanau', num_units = decoder_cell.output_size) test_decoder_function = tf.contrib.seq2seq.attention_decoder_fn_inference(output_function, encoder_state[0], attention_keys, attention_values, attention_score_function, attention_construct_function, decoder_embeddings_matrix, sos_id, eos_id, maximum_length, num_words, 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, batch_size): with tf.variable_scope("decoding") as decoding_scope: lstm = tf.contrib.rnn.BasicLSTMCell(rnn_size) lstm_dropout = tf.contrib.rnn.DropoutWrapper(lstm, input_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_initializer() output_function = lambda x: tf.contrib.layers.fully_connected(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): encoder_embedded_input = tf.contrib.layers.embed_sequence(inputs, 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) preprocessed_targets = preprocess_targets(targets, questionwords2int, batch_size) decoder_embeddings_matrix = tf.Variable(tf.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 Answers1

1

Please re-read your error SLOWLY this time. You would see your function decode_test_set() definition has 12 arguments defined. However, while calling it during prediction you are providing only 11 values to it and missing the last one which is batch_size.

Also, just for future questions, please format your question properly so that it is easy to read and the community can help you better.

Rishabh Sahrawat
  • 2,437
  • 1
  • 15
  • 32
  • Yeah, now it's working. Thank you In the tutorial, they passed only 11. Next time I'll keep care of formating, Sorry for that – Aman Gupta Apr 24 '20 at 11:59