title: How do I determine the binary class predicted by a convolutional neural network on Keras?
body: <p>I'm building a CNN to perform sentiment analysis on Keras.
  Everything is working perfectly, the model is trained and ready to be launched to production.</p>
  
  <p>However, when I try to predict on new unlabelled data by using the method <code>model.predict()</code> it only outputs the associated probability. I tried to use the method <code>np.argmax()</code> but it <strong>always</strong> outputs 0 even when it should be 1 (on test set, my model achieved 80% of accuracy). </p>
  
  <p>Here is my code to pre-process the data:</p>
  
  <pre><code># Pre-processing data
  x = df[df.Sentiment != 3].Headlines
  y = df[df.Sentiment != 3].Sentiment
  
  # Splitting training, validation, testing dataset
  x_train, x_validation_and_test, y_train, y_validation_and_test = train_test_split(x, y, test_size=.3,
                                                                                        random_state=SEED)
  x_validation, x_test, y_validation, y_test = train_test_split(x_validation_and_test, y_validation_and_test,
                                                                    test_size=.5, random_state=SEED)
  
  tokenizer = Tokenizer(num_words=NUM_WORDS)
  tokenizer.fit_on_texts(x_train)
  
  sequences = tokenizer.texts_to_sequences(x_train)
  x_train_seq = pad_sequences(sequences, maxlen=MAXLEN)
  
  sequences_val = tokenizer.texts_to_sequences(x_validation)
  x_val_seq = pad_sequences(sequences_val, maxlen=MAXLEN)
  
  sequences_test = tokenizer.texts_to_sequences(x_test)
  x_test_seq = pad_sequences(sequences_test, maxlen=MAXLEN)
  </code></pre>
  
  <p>And here is my model:</p>
  
  <pre><code>MAXLEN = 25
  NUM_WORDS = 5000
  VECTOR_DIMENSION = 100
  
  tweet_input = Input(shape=(MAXLEN,), dtype='int32')
  
  tweet_encoder = Embedding(NUM_WORDS, VECTOR_DIMENSION, input_length=MAXLEN)(tweet_input)
  
  # Combinating n-gram to optimize results
  bigram_branch = Conv1D(filters=100, kernel_size=2, padding='valid', activation="relu", strides=1)(tweet_encoder)
  bigram_branch = GlobalMaxPooling1D()(bigram_branch)
  trigram_branch = Conv1D(filters=100, kernel_size=3, padding='valid', activation="relu", strides=1)(tweet_encoder)
  trigram_branch = GlobalMaxPooling1D()(trigram_branch)
  fourgram_branch = Conv1D(filters=100, kernel_size=4, padding='valid', activation="relu", strides=1)(tweet_encoder)
  fourgram_branch = GlobalMaxPooling1D()(fourgram_branch)
  merged = concatenate([bigram_branch, trigram_branch, fourgram_branch], axis=1)
  
  merged = Dense(256, activation="relu")(merged)
  merged = Dropout(0.25)(merged)
  output = Dense(1, activation="sigmoid")(merged)
  
  optimizer = optimizers.adam(0.01)
  
  model = Model(inputs=[tweet_input], outputs=[output])
  model.compile(loss="binary_crossentropy", optimizer=optimizer, metrics=['accuracy'])
  model.summary()
  
  # Training the model
  history = model.fit(x_train_seq, y_train, batch_size=32, epochs=5, validation_data=(x_val_seq, y_validation))
  </code></pre>
  
  <p>I also tried to change the number of activations on the final Dense layer from 1 to 2, but I get an error: </p>
  
  <pre><code>Error when checking target: expected dense_12 to have shape (2,) but got array with shape (1,)
  </code></pre>