title: Keras : Cannot feed value of shape (64, 1) for Tensor which has shape '(?,)'
body: <p>I am trying to create a siamese network using Keras(tf as backend), for finding duplicate questions. But I am facing a problem of shape mismatch in output layer, showing the output shape as (64, 1), even though the output is of shape (64,).</p>
  
  <p>This is how my model looks :</p>
  
  <pre><code>inp_layer_1 = Input((maxlen,))
  embed_1 = Embedding(n_feat_1+1, embed_size, input_length=maxlen)(inp_layer_1)
  bi_layer_1 = Bidirectional(LSTM(128, return_sequences=True, dropout=0.2, recurrent_dropout=0.2))(embed_1)
  avg_pool_1 = GlobalAveragePooling1D()(bi_layer_1)
  drop_1 = Dropout(0.2)(avg_pool_1)
  dense_1 = Dense(256, activation='relu')(drop_1)
  out_1 = Lambda(lambda x: K.l2_normalize(x, axis=1))(dense_1)
  
  inp_layer_2 = Input((maxlen,))
  embed_2 = Embedding(n_feat_2+1, embed_size, input_length=maxlen)(inp_layer_2)
  bi_layer_2 = Bidirectional(LSTM(128, return_sequences=True, dropout=0.2, recurrent_dropout=0.2))(embed_2)
  avg_pool_2 = GlobalAveragePooling1D()(bi_layer_2)
  drop_2 = Dropout(0.2)(avg_pool_2)
  dense_2 = Dense(256, activation='relu')(drop_2)
  out_2 = Lambda(lambda x: K.l2_normalize(x, axis=1))(dense_2)
  
  lambda_merge = Lambda(eucl_dist)([out_1, out_2])
  final_model = Model(inputs=[inp_layer_1, inp_layer_2], outputs=lambda_merge)
  </code></pre>
  
  <p>So, basically I am trying to find the euclidean distance between outputs from two models, representing two questions. Also, <strong>maxlen=100</strong>, <strong>n_feat_1</strong> and <strong>n_feat_2</strong> are number of features(tokens) for all questions1 and questions2 respectively.</p>
  
  <p>Here's how I am creating batches of samples:</p>
  
  <pre><code>def _get_train_batch(batch_size=64):
  
      X = []
  
      idx = np.random.choice(404290, batch_size)
      X.append(ques1_train[idx])
      X.append(ques2_train[idx])
      X = np.asarray(X)
  
      y = train_df.iloc[idx, 5].values
      return [X[0, :, :], X[1, :, :]], y
  </code></pre>
  
  <p>In above code, <strong>ques1_train</strong> is an array of shape (404290, maxlen=100) consisting of token sequences from vocab of question1 from training set. Similar is the case for <strong>ques2_train</strong>. <strong>train_df</strong> is the training dataframe of shape (404290, 6), from which I am taking out result (1 or 0), for whether two questions are same(1) or not(0). </p>
  
  <p>Here's my training code:</p>
  
  <pre><code>loss = []
  for ep in range(1):
      for it in range(404290 // 64):
          X, y = _get_train_batch()
          print (y.shape)
          loss.append(final_model.train_on_batch(X, y))
  </code></pre>
  
  <p>And here's the error I am getting(image):
  <a href="https://i.stack.imgur.com/vpF6C.png" rel="nofollow noreferrer">valuerror</a></p>
  
  <p>As you can see shape printed in first line is shape of my output, which is (64,). Funny thing is, I created a siamese network for image classification, using almost similar code, and it worked.</p>
  
  <p>I'll be grateful for some insight.</p>
  
  <p>Thanks
  Ankit Paliwal</p>