title: Multi-label classification with Theano and Lasagne?
body: <p>I am trying to make the <code>mnist.py</code> tutorial into multi-label classification using CNN. I am very new on this field and my goal is to understand the architecture, the input-output data format in order to be more familiar and run my own multi-label classification problems.</p>
  
  <p>From what I have read until now the modifications I have done are:</p>
  
  <ol>
  <li><p>Change the training and test labels to 2d numpy arrays where the first dimension (rows) corresponds to instances and the second dimension (columns) to the specific label(s) corresponding to each instance. For mnist example if I want to convert it to a 10 multi-label classification the y_train &amp; y_test should be like</p>
  
  <p><code>y = np.array([[0, 1, 1, 0, 1, 0, 0, 0, 0, 0],
  [0, 1, 1, 0, 1, 0, 0, 0, 1, 1],....[1, 1, 1, 0, 1, 0, 0, 0, 0, 1]]);</code></p></li>
  <li><p>On the network code we change the non-linearity in the final layer from a softmax to a sigmoid. </p>
  
  <p><code>network = lasagne.layers.DenseLayer(
           lasagne.layers.dropout(network, p=.5),
           num_units=10,
           nonlinearity=lasagne.nonlinearities.sigmoid)</code></p>
  
  <p>The <code>num_units</code> remain 10 right? Again it is a 10-class classification problem or not?</p></li>
  <li><p>On theano variables we change the <code>target_var = T.imatrix('targets')</code> from <code>T.ivector</code>. Then according to <a href="https://stackoverflow.com/questions/35356608/input-dimension-mismatch-binary-crossentropy-lasagne-and-theano" title="this post">this post</a> I change the loss functions from categorical cross-entropy to binary cross-entropy</p>
  
  <p><code>loss = lasagne.objectives.binary_crossentropy(prediction, target_var)</code></p>
  
  <p><code>test_loss = lasagne.objectives.binary_crossentropy(test_prediction, target_var)</code> </p></li>
  <li><p>I also change the test_acc variable because I was getting error with mismatch input size. From the previous post this solution seems to work</p>
  
  <p><code>binaryPrediction = test_prediction &gt; .5
  test_acc = T.mean(T.eq(binaryPrediction, target_var))</code></p></li>
  </ol>
  
  <p>Well, the I get no errors now but I am not pretty sure that the code is correct. When you are doing muli-label classifaction you have to define other metrics than the typical accuracy, right? Any suggestions??</p>