Writing RNNs in Tensorflow
n-s-f.github.io
n-s-f.github.io
We are looking to replace our Arima models with RNNs and the results so far has been far from satisfactory.
The usecase is: based on sale quantity in past year, predict the sale quantity tomorrow.
Regression does not consider weekdays or weekends or similar bumps and we thought RNN w/LSTM would be well suited for this problem
Also I believe that RNNs are useful mainly for highly non-linear problems. Non-linearities in a problem such as sales forecasting are best handled through interaction terms or by including non-linear transformations (e.g. logarithm) of existing features into your model.
So you are saying that RNN won't be suited for non-linear sales forecasting?
If you are convinced that there are complex non-linearities that an ARIMA model cannot describe, then I would try to use RNNs to find a pattern in your ARIMA models' residuals and try to augment your ARIMA model with an RNN.
Knowing nothing about his sales process and features, I would assume there are many complex non-linearities (to be possibly leveraged for better predictions). I find this statement bizarre.
But if you can give me an example of a non-linearity in sales forecasting that cannot be fit by a linear model but can by an RNN I'd honestly be really interested in that.
ARIMA models cannot take into consideration special scenarios or even multivariate features (Like location and time). It's good for simple forecasting but when you need more "human like" predictions we are betting on neural networks.
For example we would instinctively know that sales of turkey goes up on Thanksgiving. ARIMA model cannot factor this but RNN/LSTM should be able to (Theoretically speaking).
https://en.wikipedia.org/wiki/Dummy_variable_(statistics) https://en.wikipedia.org/wiki/Interaction_(statistics)
For even more customized RNNs such as attention mechanism, beam search as in Seq2Seq, you'll need to skip the tf.dynamic_rnn abstraction and use a symbolic loop directly: tf.while_loop
scan implements strict semantics so it will always execute the same number of timesteps no matter what the accumulator is (nan).
while_loop implements dynamic execution (quit once cond is not met) and at the same time allows parallel execution when some ops are not dependent on accumulator.
If you read the code for `dynamic_rnn` and contrib.legacy Seq2seq model you'll find while_loop. I have yet to see tensorflow library code using tf.scan anywhere!
Also, internally, scan is defined using while_loop. In my code, I find scan lacking in RNN and always have to fall back to while_loop.
Here is video of a talk by the RNN/Seq2Seq author himself:
The difference from using tf.while_loop directly is that tf.scan handles the logistics of an accumulator to keep track of hidden states, so you don't have to implement that piece yourself.
As you say, tf.scan uses tf.while_loop internally; it's not particularly different from something you might build using tf.while_loop yourself.
I agree that you have to use a tf.while_loop in those cases. But then tf.scan isn't an option, so I don't understand what you mean by 'quit early' or 'saves time'.
When tf.scan is possible, i.e. when you have an input sequence you want to scan over, it is a perfectly good option.