Answers.Body: <p>A recurrent neural network (RNN, specifically either an LSTM or GRU)  will work well for variable length sequences like you’ve described. Assuming the order of the sequence is meaningful (I.e. you can’t just break up the sequence into individual inputs and associated target value) an RNN model will learn how the sequence of inputs maps to the sequence of outputs.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-11T20:11:39.827Z
Answers.Text: If the sequence is not meaningful, then the OP could take advantage of that symmetry and sort the items using a consistent rule, which may make the learning task easier.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-11T18:35:51.917Z
Answers.LastActivityDate: 2021-07-11T18:35:51.917Z
Answers.UserDisplayName: Jo Olley
Answers.Body: <p>Look for <a href="https://www.tensorflow.org/guide/keras/masking_and_padding" rel="nofollow noreferrer">padding</a>.</p>
  <p>There are even versions of it: pre-padding, post-padding.
  <a href="https://stackoverflow.com/questions/46298793/how-does-choosing-between-pre-and-post-zero-padding-of-sequences-impact-results">https://stackoverflow.com/questions/46298793/how-does-choosing-between-pre-and-post-zero-padding-of-sequences-impact-results</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-12T14:30:19.417Z
Answers.LastActivityDate: 2021-07-12T14:30:19.417Z
Answers.UserDisplayName: meliksahturker
Body: <p>I am trying to build a neural network that has an input of <span class="math-container">$n$</span> pairs of integer values (where <span class="math-container">$n$</span> is random) and a corresponding output of a binary array with length <span class="math-container">$n$</span>.</p>
  <p>The input will be a set of integer value coordinates <span class="math-container">$[(x_{1}, y_{1}), (x_{2}, y_{2}), (x_{3}, y_{3}), \dots, (x_{50}, y_{50}), \dots]$</span>, where each instance can be of various lengths, like <span class="math-container">$[(x_{1}, y_{1}), (x_{2}, y_{2}), (x_{3}, y_{3}), \dots, (x_{52}, y_{52})]$</span> or <span class="math-container">$[(x_{1}, y_{1}), (x_{2}, y_{2}), (x_{3}, y_{3}), \dots, (x_{101}, y_{101})]$</span>, etc.</p>
  <p>The output is a set of binary arrays with each instance having the same length as the corresponding input.</p>
  <p><a href="https://i.sstatic.net/Ufw4S.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ufw4S.png" alt="enter image description here" /></a></p>
  <p>May I know if anyone has any recommendations on what neural network would fit this use case?</p>
  
Tags: <neural-networks><machine-learning><deep-learning><recurrent-neural-networks><pretrained-models>
Title: How to design a neural network with arbitrary input and output length?
UserDisplayName: Kian
ThreadText: # How to design a neural network with arbitrary input and output length?
  
  (Asked by: username_0 on 2021-07-01)
  
  I am trying to build a neural network that has an input of $n$ pairs of integer values (where $n$ is random) and a corresponding output of a binary array with length $n$.
  
  The input will be a set of integer value coordinates $[(x\_{1}, y\_{1}), (x\_{2}, y\_{2}), (x\_{3}, y\_{3}), \dots, (x\_{50}, y\_{50}), \dots]$, where each instance can be of various lengths, like $[(x\_{1}, y\_{1}), (x\_{2}, y\_{2}), (x\_{3}, y\_{3}), \dots, (x\_{52}, y\_{52})]$ or $[(x\_{1}, y\_{1}), (x\_{2}, y\_{2}), (x\_{3}, y\_{3}), \dots, (x\_{101}, y\_{101})]$, etc.
  
  The output is a set of binary arrays with each instance having the same length as the corresponding input.
  
  [![enter image description here](https://i.sstatic.net/Ufw4S.png)](https://i.sstatic.net/Ufw4S.png)
  
  May I know if anyone has any recommendations on what neural network would fit this use case?
  
  **Tags:** neural-networks, machine-learning, deep-learning, recurrent-neural-networks, pretrained-models
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-07-11. Score: 1
  
  A recurrent neural network (RNN, specifically either an LSTM or GRU) will work well for variable length sequences like you’ve described. Assuming the order of the sequence is meaningful (I.e. you can’t just break up the sequence into individual inputs and associated target value) an RNN model will learn how the sequence of inputs maps to the sequence of outputs.
  
  > **Comments:**
  > **username_2**: If the sequence is not meaningful, then the OP could take advantage of that symmetry and sort the items using a consistent rule, which may make the learning task easier.  
  
  ---
  
  ### Answer by username_3 on 2021-07-12. Score: 0
  
  Look for [padding](https://www.tensorflow.org/guide/keras/masking_and_padding).
  
  There are even versions of it: pre-padding, post-padding.
  <https://stackoverflow.com/questions/46298793/how-does-choosing-between-pre-and-post-zero-padding-of-sequences-impact-results>
  
  
  ---
  
  