Search code examples
deep-learningneural-networklstm

LSTM prediction restriction


Is it possible to restrict the prediction of LSTM neural network to a finite set of values? For example if I have the following sequence 1,4,5,3,2,1,3,2, ... and I know that the next value will be in the set {1,2,3,4,5}, is it possible to feed that somehow to the network so it will always output one of these values?


Solution

  • While this is technically possible (you would have to write your own LSTM implementation or extend the existing one, however), it doesn't seem like a good approach towards this problem. If you find yourself in the situation where you're feeding data to the network that you don't want it to process, you should just preprocess your input to only hold relevant data.

    Show the network what you want it to see. If you want the network to output specific behavior in certain situations, you can encode that behavior by modifying the labels to reflect this behavior. Finally, note that your use case suggests that you should be working with categorical labels and softmax output, i.e. framing this as a classification instead of a regression problem.