8

Is there a machine learning algorithm that maps a single input to an output list of variable length? If so, are there any implementations of the algorithm for public use? If not, what do you recommend as a workaround?

In my case, the input is a single scalar and the output is a list of scalars with variable length. For example, suppose I wanted to output a list of ones given the length of the list as input. Then <input, output> could be <1, [1]>, <2, [1, 1]>, etc. A small tweak would be providing the square root of the length in which case <2, [1, 1, 1, 1]> would be an answer. Note: the input need not be tied directly to the output.


For a more complex example, suppose I want to learn the look-and-say sequence. Valid <input, output> pairs would be: <1, [1]>, <2, [1, 1]>, <3, [2, 1]>, <4, [1, 2, 1, 1]>, <5, [1, 1, 1, 2, 2, 1]>, etc. My problem is also similar in that I can generate more examples; I am not restricted to a finite set of examples.
ricksmt
  • 183
  • 1
  • 5

2 Answers2

3

I would try to set a multilabel classification algorithm and make the output standard by adding zeros. So if your data is like this: <1, 1>, <2, [1, 1]>, <3, [2, 1]>, <4, [1, 2, 1, 1]>, <5, [1, 1, 1, 2, 2, 1]>. The maximum number of output is 6. So you could transform your data into something like: <1, [1,0,0,0,0,0]>, <2, [1, 1,0,0,0,0]>, <3, [2, 1,0,0,0,0]>, <4, [1, 2, 1, 1,0,0]>, <5, [1, 1, 1, 2, 2, 1]>

Another option that occurs to me is to add the limit dynamically. Let say you have your training and test set. You can search for the biggest length and create an algorithm that adds the zeros to both datasets. Then let's say a new data you want to predict has a bigger length, then you'll need to recompute all training and test with for this new prediction. You can even check how extending the limit affects your model.

hoaphumanoid
  • 911
  • 8
  • 19
1

So a couple of ways that can be conceived:

  1. @Miguel Gonzalez-Fierro's answer of 0-padding. probably the easiest to implement and makes sense.
  2. If padding is not sensible for your problem, if your output is a time series, you could learn a neural translation model of sorts and have a STOP/END token in your output.
  3. Have a generator based model (like an alteration on a VAE) and then generate a whole bunch of possible inputs, and you can take any # of draws that suffice some criterion (like a mode with little shift having some calculated conditional information).

There are probably others, but I can't think of them right now.

Stephen Rauch
  • 1,831
  • 11
  • 23
  • 34
mshlis
  • 83
  • 8