Answers.Body: <p>You can try <a href="https://www.geeksforgeeks.org/cnn-introduction-to-padding/" rel="nofollow noreferrer">padding</a>, which compensates the dimension with numbers (e.g., <code>zero</code>). This practice is very common in deep learning to have a desire embedding.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-31T22:40:10.937Z
Answers.Text: To improve this answer add some explanatory text about what padding is. Links can break or become invalid so it's best to include enough information to make the answer self-contained and durable
Answers.UserDisplayName: respectful
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-26T15:48:45.193Z
Answers.LastActivityDate: 2023-01-26T15:48:45.193Z
Answers.UserDisplayName: Long
Answers.Body: <p>In my view, the strange part seems to be the flattening of the useable_items matrix. At the very least, it is confusing for the reader of the article. If we want an output vector pi where the values actually correspond to each of the 55 input items, the information of which input belongs to which output should be kept.</p>
  <p>So either:</p>
  <ul>
  <li>It should be reshaped back to <em>(55 x k)</em> after the <code>MLP</code>. <br><em>That would make every value for every item depend on each other in the <code>MLP</code><br>Also, this approach makes it hard to keep track of the input/output relationship</em></li>
  <li>Or the matrix should be passed through the <code>MLP</code> as is, only using the features of the last dimension. <br><em>This effortlessly gives you a (55 x k) matrix where you could matmul away to get the desired output<br>And easily keep the input/output relationship<br>..and keep the number of <code>MLP</code> parameters way down.</em></li>
  </ul>
  <p>In either case you should probably choose an output dimension in the <code>MLP</code> to either directly get (or reshape to) <em>(55 x 1024)</em> as output dimension and treat the matmul as a dot product over the last dimensions to get your <em>(55 x 1)</em> vector.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-20T09:03:23.890Z
Answers.Text: ...and I just realized this question was from February 2023, not 2024. So, hopes up someone may still find it useful.
Answers.UserDisplayName: Victor Björkgren
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-20T09:00:49.573Z
Answers.LastActivityDate: 2024-03-20T09:05:30.487Z
Answers.LastEditDate: 2024-03-20T09:05:30.487Z
Answers.UserDisplayName: Victor Björkgren
Body: <p>I'm replicating a particular network architecture which is very sparse with its details.
  One part of said architecture is shown in the image, where <code>h</code> is a 1x1024 or 1024x1 output from a transformer and needs to be combined with the output of an <code>MLP</code> to produce a 1x55 or 55x1 vector, with the order of the dimensions not mattering. As such the matrix multiplication step should involve either multiplying (55 x k) and (k x 1), or (1 x k) and (k x 55) matrices. The input to the <code>MLP</code> is a (55 x 32) matrix flattened to a (1760 x 1) vector. For context, this input encodes item information from a game about 55 items. h contains information about the current game state and we want to produce a policy <code>pi</code> for selecting an item.</p>
  <p>The constraints of the matrix multiplication mean that I need to perform some kind of dimensionality increase or reduction on either the elements of <code>h</code> or the output of the <code>MLP</code>. However, I'm not really sure what would be best in this case as I don't have much experience with building neural networks in general. Any advice would be appreciated.</p>
  <p><a href="https://i.sstatic.net/yxJQ3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yxJQ3.png" alt="enter image description here" /></a></p>
  
Tags: <neural-networks>
Title: Combining neural network outputs via matrix multiplication
UserDisplayName: Telf
ThreadText: # Combining neural network outputs via matrix multiplication
  
  (Asked by: username_0 on 2023-01-26)
  
  I'm replicating a particular network architecture which is very sparse with its details.
  One part of said architecture is shown in the image, where `h` is a 1x1024 or 1024x1 output from a transformer and needs to be combined with the output of an `MLP` to produce a 1x55 or 55x1 vector, with the order of the dimensions not mattering. As such the matrix multiplication step should involve either multiplying (55 x k) and (k x 1), or (1 x k) and (k x 55) matrices. The input to the `MLP` is a (55 x 32) matrix flattened to a (1760 x 1) vector. For context, this input encodes item information from a game about 55 items. h contains information about the current game state and we want to produce a policy `pi` for selecting an item.
  
  The constraints of the matrix multiplication mean that I need to perform some kind of dimensionality increase or reduction on either the elements of `h` or the output of the `MLP`. However, I'm not really sure what would be best in this case as I don't have much experience with building neural networks in general. Any advice would be appreciated.
  
  [![enter image description here](https://i.sstatic.net/yxJQ3.png)](https://i.sstatic.net/yxJQ3.png)
  
  **Tags:** neural-networks
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-01-26. Score: 0
  
  You can try [padding](https://www.geeksforgeeks.org/cnn-introduction-to-padding/), which compensates the dimension with numbers (e.g., `zero`). This practice is very common in deep learning to have a desire embedding.
  
  > **Comments:**
  > **username_2**: To improve this answer add some explanatory text about what padding is. Links can break or become invalid so it's best to include enough information to make the answer self-contained and durable  
  
  ---
  
  ### Answer by username_3 on 2024-03-20. Score: 0
  
  In my view, the strange part seems to be the flattening of the useable\_items matrix. At the very least, it is confusing for the reader of the article. If we want an output vector pi where the values actually correspond to each of the 55 input items, the information of which input belongs to which output should be kept.
  
  So either:
  
  * It should be reshaped back to *(55 x k)* after the `MLP`.   
    *That would make every value for every item depend on each other in the `MLP`  
    Also, this approach makes it hard to keep track of the input/output relationship*
  * Or the matrix should be passed through the `MLP` as is, only using the features of the last dimension.   
    *This effortlessly gives you a (55 x k) matrix where you could matmul away to get the desired output  
    And easily keep the input/output relationship  
    ..and keep the number of `MLP` parameters way down.*
  
  In either case you should probably choose an output dimension in the `MLP` to either directly get (or reshape to) *(55 x 1024)* as output dimension and treat the matmul as a dot product over the last dimensions to get your *(55 x 1)* vector.
  
  > **Comments:**
  > **username_3**: ...and I just realized this question was from February 2023, not 2024. So, hopes up someone may still find it useful.  
  
  ---
  
  