Is the LSTM example out ?
Hi all, I wonder if the lstm example is out? also is there C++ code examples? I've realized that most examples are in python : )
Please check https://github.com/dmlc/mxnet/tree/master/example/rnn
seems that it only supports fixed seq_len ? And the compute graph has to ben pre-compiled with fixed sequence length. Is there a suggested solution for variable length model ?
One way to deal with that is unroll to maximum length you want to deal with, do padding on left over so batching is still enabled.
We can probably enable a condition on the internal nodes to stop execution until the maximum length of current batch
Another way is simply compile a executor for one time-step, and use the imperative API to do the unrolling, this might actually be the easier way, and can be achieved in current API
but in that case, does backprop through time still works ? When we proceed, the gradient will overwrite the gradient for previous step, right?
More specific about previous comment. The problem is when to stop so not waste computation on things that are not needed. What can be done is compile a executor for every time step, say t0, t1, t2, t3.
And use imperative API to chain them up, so the control of stop goes into python side.
We still need a different executor for each time stamp, but use python side to decide when to stop.
does that mean we need to compile an executor every time? instead of current solution which compiles once
No, compile executor for each time-stamp say t0, t1, t2, and you can reuse t0, t1, t2 next time, but if you need t3, then compile a new one.
@Kublai-Jing Interested in contribute a improved version?
yeah~ need some time to understand the whole mxnet though...
Hope the explanation makes sense to you. There are documents explaining things, but be sure to ask if we miss something, or even better contribute to the things so others can benefit from the answer.
This approach can also be generalized a bit, for example, unroll an executor every T step where T is a small number that we might not care about. And use imperative way to chain things up
yes. I might wanna contribute some examples I thought useful for newbie like me. I think that will make people understand whole programming model more quickly
That is awesome
Will MXNet support something like the scan operator in Theano in the future? It would be really great to have one so that coding RNN will get much easier.
@tqchen I assume what you mean is to compile a list of LSTM cell : LSTM[i] = LSTM for t_i ,
for t in xrange(T):
LSTM[t] = lstm(...)
executor[t] = LSTM[t].bind(...)
for t in xrange(len(x_i)):
input = x_i[t]
LSTM[t].forward()
for t in reverse(xrange(len(x_i)):
LSTM[t].backward(...)
update
something like this. instead of having one unrolled LSTM with fixed sequence length. This should be more flexible and allow more control from the python side.
Aside from efficiency, if we use minibatch, what happens if some data already reaches its end of sequence ? If we pad zeros to those data, I believe they will still contribute to the gradient signals, which seems wrong.
Yes,that was what I mean. The padding trick should be ok. As there is already a EOF tag introduced, and we can simply pad future labels to be EOF, and input to be EOF. The encoder/decoder will catch that EOF follows EOF, and thus no need to depend on previous result, and basically less gradient will be propagated back. This is not perfect solution, but should work
yeah ! we still get wrong gradient, but let the network learns to fix that...lol
I'm not sure what would be the standard way of dealing with LSTM. But it seems if along with the labels, we provide a stream of is_end_of_seq masks. And multiply 1-is_end_of_seq (maybe with an index shift) with the prev_hidden_states. Then it will allow variable-length sequences and automatically reset state propagation over time at the end of the sequence. A minor issue is if the underlying sequence is longer than the un-rolled seq length of the architecture, back-propagate-over-time will get truncated. But I think this won't be a too big issue if we un-roll for a large enough sequence size.