title: How do I get the predicted labels from a model.predict function from Keras?
body: <p>I have built a LSTM model using Keras library to predict duplicate questions on the Quora official dataset. The test labels are 0 or 1. 1 indicates the question pair is duplicate. After building the model using <code>model.fit</code>, I test the model using <code>model.predict</code> on the test data. The output is an array of values(probabilities) like below:</p>
  
  <pre><code> [ 0.00514298]
   [ 0.15161049]
   [ 0.27588326]
   [ 0.00236167]
   [ 1.80067325]
   [ 0.01048524]
   [ 1.43425131]
   [ 1.99202418]
   [ 0.54853892]
   [ 0.02514757]
  </code></pre>
  
  <p>I am only showing the first 10 values in the array. I don't understand what do these values mean and how do I compare it against the test labels to calculate the test accuracy. I want the model to output the binary predicted values as 0 or 1 rather than the probabilities. Please refer the last section of my code below:</p>
  
  <pre><code>sequence_1_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
  embedded_sequences_1 = embedding_layer(sequence_1_input)
  x1 = lstm_layer(embedded_sequences_1)
  
  sequence_2_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
  embedded_sequences_2 = embedding_layer(sequence_2_input)
  y1 = lstm_layer(embedded_sequences_2)
  
  merged = concatenate([x1, y1])
  merged = Dropout(rate_drop_dense)(merged)
  merged = BatchNormalization()(merged)
  
  merged = Dense(num_dense, activation=act)(merged)
  merged = Dropout(rate_drop_dense)(merged)
  merged = BatchNormalization()(merged)
  
  preds = Dense(1, activation='sigmoid')(merged)
  
  
  ########################################
  ## train the model
  ########################################
  model = Model(inputs=[sequence_1_input, sequence_2_input], \
          outputs=preds)
  model.compile(loss='binary_crossentropy',
          optimizer='nadam',
          metrics=['acc'])
  
  
  
  hist = model.fit([data_1_train, data_2_train], labels_train, \
      validation_data=([data_1_val, data_2_val], labels_val, weight_val), \
      epochs=200, batch_size=2048, shuffle=True, \
      class_weight=class_weight, callbacks=[early_stopping, model_checkpoint])
  
  
  preds = model.predict([test_data_1, test_data_2], batch_size=8192, 
  verbose=1)
  preds += model.predict([test_data_2, test_data_1], batch_size=8192, 
  verbose=1)
  preds /= 2
  print(type(preds))
  print(preds[:20])
  print('preds.ravel')
  print(preds.ravel())
  </code></pre>