title: Deep Neural Network : Probability issue
body: <p>I'm working on a keyword spotting with deep neural network (Multi-Layer Perceptron) and I'm facing a following issue. </p>
  
  <p>I have to detect a keyword in a speech signal. I use the library Tensorflow and I write my code based on this <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py" rel="nofollow">example</a>.</p>
  
  <pre><code>'''
  A Multilayer Perceptron implementation example using TensorFlow library.
  This example is using the MNIST database of handwritten digits
  (http://yann.lecun.com/exdb/mnist/)
  Author: Aymeric Damien
  Project: https://github.com/aymericdamien/TensorFlow-Examples/
  '''
  
  # Import MINST data
  from tensorflow.examples.tutorials.mnist import input_data
  mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
  
  import tensorflow as tf
  
  # Parameters
  learning_rate = 0.001
  training_epochs = 15
  batch_size = 100
  display_step = 1
  
  # Network Parameters
  n_hidden_1 = 256 # 1st layer number of features
  n_hidden_2 = 256 # 2nd layer number of features
  n_input = 784 # MNIST data input (img shape: 28*28)
  n_classes = 10 # MNIST total classes (0-9 digits)
  
  # tf Graph input
  x = tf.placeholder("float", [None, n_input])
  y = tf.placeholder("float", [None, n_classes])
  
  
  # Create model
  def multilayer_perceptron(x, weights, biases):
      # Hidden layer with RELU activation
      layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
      layer_1 = tf.nn.relu(layer_1)
      # Hidden layer with RELU activation
      layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])
      layer_2 = tf.nn.relu(layer_2)
      # Output layer with linear activation
      out_layer = tf.matmul(layer_2, weights['out']) + biases['out']
      return out_layer
  
  # Store layers weight &amp; bias
  weights = {
      'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1])),
      'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),
      'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes]))
  }
  biases = {
      'b1': tf.Variable(tf.random_normal([n_hidden_1])),
      'b2': tf.Variable(tf.random_normal([n_hidden_2])),
      'out': tf.Variable(tf.random_normal([n_classes]))
  }
  
  # Construct model
  pred = multilayer_perceptron(x, weights, biases)
  
  # Define loss and optimizer
  cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
  optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)
  
  # Initializing the variables
  init = tf.initialize_all_variables()
  
  # Launch the graph
  with tf.Session() as sess:
      sess.run(init)
  
      # Training cycle
      for epoch in range(training_epochs):
          avg_cost = 0.
          total_batch = int(mnist.train.num_examples/batch_size)
          # Loop over all batches
          for i in range(total_batch):
              batch_x, batch_y = mnist.train.next_batch(batch_size)
              # Run optimization op (backprop) and cost op (to get loss value)
              _, c = sess.run([optimizer, cost], feed_dict={x: batch_x,
                                                            y: batch_y})
              # Compute average loss
              avg_cost += c / total_batch
          # Display logs per epoch step
          if epoch % display_step == 0:
              print "Epoch:", '%04d' % (epoch+1), "cost=", \
                  "{:.9f}".format(avg_cost)
      print "Optimization Finished!"
  
      # Test model
      correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
      # Calculate accuracy
      accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
      print "Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels})
  </code></pre>
  
  <p>I trained my network using MFCC features with double delta. In inputs, I have 2300 inputs which correspond to the MFCC for around 600ms in order to add context. In outputs, I have 2 classes, <code>mykeyword</code> and an other class <code>filler</code>. </p>
  
  <p>I have a 3x128 MLP with ReLU activations and softmax output layer. I have also centered and whitened my data. </p>
  
  <p>My labels vector looks like : <code>[ 1 0 ]</code> for the keyword and <code>[ 0 1 ]</code> for the "filler". </p>
  
  <p>I would like to get a probability at the end which traduces the confidence score of detecting the keyword, thus I can use a threshold. However , after the softmax layer, I get only <code>0</code> or <code>1</code> for each examples of the testing data. I don't really understand why..</p>
  
  <p>Thank you</p>