Answers.Body: <p>If I understood things correctly: You have a task which you need to estimate two values, gender and age. Your question revolves about the difference between networks which share layers for both inputs, whether the shared layers should be followed independent linear layers.</p>
  <p>Firstly, using shared layers in the networks of two related tasks may be useful to create more general latent representations in the network hidden layers. It also can speed up training, the shared layer will learn useful features more quickly than if there were two separate networks for each task.
  Some examples which demonstrate the potential benefit of shared networks can be found in the papers for two RL algorithms, A3C and PPG (PPG adds some extra tricks to the shared layers it):<br />
  <a href="http://proceedings.mlr.press/v48/mniha16.html" rel="nofollow noreferrer">http://proceedings.mlr.press/v48/mniha16.html</a><br />
  <a href="https://arxiv.org/abs/2009.04416v1" rel="nofollow noreferrer">https://arxiv.org/abs/2009.04416v1</a></p>
  <p>Whether the shared layers should be followed by many separate linear layers or a single one, at least for me, isn't something easy to deduce. Intuitively, having a single linear mapping after the shared layers will help prevent over-fitting because the shared layers induce more general features in those layers. While having many separate layers may be useful if there is some complex non linear mapping between the final output and the latent features from the shared layers.</p>
  <p>I think the best way to find out is just to experiment with it and see which gives the best results.</p>
  <p>A little bit anecdotal, but, an example from my experience:<br />
  Shared layers are commonly used in RL for actor critic algorithms. A network takes an image as input and outputs an action and a value (the output for the actor and the critic, receptively). Generally a single linear mapping from the shared layers works just fine, even better than more complex networks.</p>
  <p>=========== Edit<br />
  In pseudo-code, this is the networks that came to my mind:</p>
  <pre><code># Network 1  
   shared_layer = Linear(input_dim, latent_dim)  
   output_layer = Linear(latent_dim, m + n)  
  
  # Network 2  
   shared_layer = Linear(input_dim, latent_dim)  
   output1_layer = Linear(latent_dim, m)  
   output2_layer = Linear(latent_dim, n)  
  </code></pre>
  <p>And, in the question you mention about using BCE with Network 1 and changing to CE for one of the outputs of the  Network 2.<br />
  The networks themselves are equal to one another. One implementation might be more practical than the other, but they are the same. Depending on the framework you use, you can use either BCE or CE loss in Network 1 and 2. In Network 1 this would mean taking the output  of the last layer and slicing the outputs for age and gender into two variables and applying a loss function in each of them.</p>
  <p>That said, I would expect to see a difference between using CE or BCE for age classification. When training with BCE it's possible that one estimator turn to be more 'optimist' or 'pessimist' and gives overall high/low probabilities (this will depend on factors such as whether there is class unbalance, if those are taken into account in the training procedure, etc...). And, that will mean that when you take the maximum probability of the age outputs there will be some bias.<br />
  CE seems to me to be a more appropriate choice for age classification. Using CE will not prevent bias if there is class unbalance in your data, but with it is more straightforward to handle these issues.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T07:19:28.840Z
Answers.Text: Thank you, my question more more about the difference between shared layers and a 2 separate (as in the case with A2/a3c and one shared layers with a final sense layer of number of outputs (not multi head) and each label being treated as binary, so two neurons would fire in the last layer, one for organ and one for gender. Intuitively I am struggling to see the true difference between the two..  especially if layers are shared upstream which is definitely the case for me. I do have an architecture of shared layers for the reasons you mentioned.
Answers.UserDisplayName: user9317212
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T13:12:10.473Z
Answers.Text: @user9317212 Made an edit to the answer!
Answers.UserDisplayName: João Schapke
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T15:07:50.903Z
Answers.Text: thanks! for network1 why would you need to apply two losses when the bce loss handles each class as a binary? and therefore can assign to each sample both an organ and an age classification?
Answers.UserDisplayName: user9317212
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T15:58:13.583Z
Answers.Text: You can apply BCE loss for the task. If you have the exact age of your samples you may also treat the problem as a regression problem, and postprocess the estimated value if needed. All these alternatives should work. Which option is better? BCE loss may be a worse alternative to CE for the reason given in the answer (also, a regression loss can be an even better alternative because it provided a richer feedback). Practically speaking, it is difficult to say whether there will be a significant difference in performance. You may test it to find out!
Answers.UserDisplayName: João Schapke
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T16:06:10.653Z
Answers.Text: Thank you! Will try all methods (it is strictly a classification though and I don't need to do a regression for the purposes of this) in also using interpretation tools to find out why the classification decisions are as they are.
Answers.UserDisplayName: user9317212
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-06T02:33:30.493Z
Answers.LastActivityDate: 2021-06-06T13:11:46.043Z
Answers.LastEditDate: 2021-06-06T13:11:46.043Z
Answers.UserDisplayName: João Schapke
Body: <p>I haven't been able to find a good discussion specifically comparing the two (only one describing a classification and regression problem). I am training a classifier to learn both age and gender based on genomic data. Every sample has a known age and known gender (20 classes in total).</p>
  <p>Currently, I am using a single neural network with a sigmoid activation in the last layer with a binary_crossentropy loss. This works fine. However, I also see people using multi-head neural networks where, for example, a set of shared layers would split in to two either additional dense layers or in to two final layers for classification – each with an independent loss (in my case likely a categorical_ce).</p>
  <p>What I am unsure of, though, are the advantages and disadvantages between the two (maybe advantages and disadvantages are not the right words to use – actual differences between the two might be more appropriate and when one might use one of those over the other)?</p>
  <p>I want to be able to calculate the usual metrics – TP, FP, etc. after training – presumably it would be easier with two heads at the end of the network, as you can work with two independent sets of predictions to calculate these?</p>
  
Tags: <binary-classification><multi-label-classification><binary-crossentropy>
Title: What are pros and cons of using a multi-head neural network versus a single neural network for multi-label classification?
UserDisplayName: user9317212
ThreadText: # What are pros and cons of using a multi-head neural network versus a single neural network for multi-label classification?
  
  (Asked by: username_0 on 2021-06-02)
  
  I haven't been able to find a good discussion specifically comparing the two (only one describing a classification and regression problem). I am training a classifier to learn both age and gender based on genomic data. Every sample has a known age and known gender (20 classes in total).
  
  Currently, I am using a single neural network with a sigmoid activation in the last layer with a binary\_crossentropy loss. This works fine. However, I also see people using multi-head neural networks where, for example, a set of shared layers would split in to two either additional dense layers or in to two final layers for classification – each with an independent loss (in my case likely a categorical\_ce).
  
  What I am unsure of, though, are the advantages and disadvantages between the two (maybe advantages and disadvantages are not the right words to use – actual differences between the two might be more appropriate and when one might use one of those over the other)?
  
  I want to be able to calculate the usual metrics – TP, FP, etc. after training – presumably it would be easier with two heads at the end of the network, as you can work with two independent sets of predictions to calculate these?
  
  **Tags:** binary-classification, multi-label-classification, binary-crossentropy
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-06. Score: 2 | Accepted answer
  
  If I understood things correctly: You have a task which you need to estimate two values, gender and age. Your question revolves about the difference between networks which share layers for both inputs, whether the shared layers should be followed independent linear layers.
  
  Firstly, using shared layers in the networks of two related tasks may be useful to create more general latent representations in the network hidden layers. It also can speed up training, the shared layer will learn useful features more quickly than if there were two separate networks for each task.
  Some examples which demonstrate the potential benefit of shared networks can be found in the papers for two RL algorithms, A3C and PPG (PPG adds some extra tricks to the shared layers it):  
  <http://proceedings.mlr.press/v48/mniha16.html>  
  <https://arxiv.org/abs/2009.04416v1>
  
  Whether the shared layers should be followed by many separate linear layers or a single one, at least for me, isn't something easy to deduce. Intuitively, having a single linear mapping after the shared layers will help prevent over-fitting because the shared layers induce more general features in those layers. While having many separate layers may be useful if there is some complex non linear mapping between the final output and the latent features from the shared layers.
  
  I think the best way to find out is just to experiment with it and see which gives the best results.
  
  A little bit anecdotal, but, an example from my experience:  
  Shared layers are commonly used in RL for actor critic algorithms. A network takes an image as input and outputs an action and a value (the output for the actor and the critic, receptively). Generally a single linear mapping from the shared layers works just fine, even better than more complex networks.
  
  =========== Edit  
  In pseudo-code, this is the networks that came to my mind:
  
  ```
  # Network 1  
   shared_layer = Linear(input_dim, latent_dim)  
   output_layer = Linear(latent_dim, m + n)  
  
  # Network 2  
   shared_layer = Linear(input_dim, latent_dim)  
   output1_layer = Linear(latent_dim, m)  
   output2_layer = Linear(latent_dim, n)  
  
  ```
  
  And, in the question you mention about using BCE with Network 1 and changing to CE for one of the outputs of the Network 2.  
  The networks themselves are equal to one another. One implementation might be more practical than the other, but they are the same. Depending on the framework you use, you can use either BCE or CE loss in Network 1 and 2. In Network 1 this would mean taking the output of the last layer and slicing the outputs for age and gender into two variables and applying a loss function in each of them.
  
  That said, I would expect to see a difference between using CE or BCE for age classification. When training with BCE it's possible that one estimator turn to be more 'optimist' or 'pessimist' and gives overall high/low probabilities (this will depend on factors such as whether there is class unbalance, if those are taken into account in the training procedure, etc...). And, that will mean that when you take the maximum probability of the age outputs there will be some bias.  
  CE seems to me to be a more appropriate choice for age classification. Using CE will not prevent bias if there is class unbalance in your data, but with it is more straightforward to handle these issues.
  
  > **Comments:**
  > **username_0**: Thank you, my question more more about the difference between shared layers and a 2 separate (as in the case with A2/a3c and one shared layers with a final sense layer of number of outputs (not multi head) and each label being treated as binary, so two neurons would fire in the last layer, one for organ and one for gender. Intuitively I am struggling to see the true difference between the two..  especially if layers are shared upstream which is definitely the case for me. I do have an architecture of shared layers for the reasons you mentioned.  
  > **username_1**: @username_0 Made an edit to the answer!  
  > **username_0**: thanks! for network1 why would you need to apply two losses when the bce loss handles each class as a binary? and therefore can assign to each sample both an organ and an age classification?  
  > **username_1**: You can apply BCE loss for the task. If you have the exact age of your samples you may also treat the problem as a regression problem, and postprocess the estimated value if needed. All these alternatives should work. Which option is better? BCE loss may be a worse alternative to CE for the reason given in the answer (also, a regression loss can be an even better alternative because it provided a richer feedback). Practically speaking, it is difficult to say whether there will be a significant difference in performance. You may test it to find out!  
  > **username_0**: Thank you! Will try all methods (it is strictly a classification though and I don't need to do a regression for the purposes of this) in also using interpretation tools to find out why the classification decisions are as they are.  
  
  ---
  
  