How to build BLSTM applying NDL
I want to build a bidirectional-LSTM (BLSTM) with network definition language (NDL). There is an example shows how to build LSTM, but not BLSTM. Anyone can help? It is appreciated if an example of build LSTM using NDL can be shared.
Best, Huaiping
You can use FutureValue node (replace PastValue by FutureValue in the NDL). It will reverse the sequence automatically.
Here is an example:
layer 1
LSTMForwardOutput1 = LSTMPComponentForward(baseFeatDim, hiddenDim, cellDim, featNorm);
LSTMBackwardOutput1 = LSTMPComponentBackward(baseFeatDim, hiddenDim, cellDim, featNorm);
LSTMoutput1 = RowStack(LSTMForwardOutput1, LSTMBackwardOutput1)
LSTMPComponentBackward(inputDim, outputDim, cellDim, inputx)
{
Wxo = Parameter(cellDim, inputDim, init=uniform, initValueScale=1);
Wxi = Parameter(cellDim, inputDim, init=uniform, initValueScale=1);
Wxf = Parameter(cellDim, inputDim, init=uniform, initValueScale=1);
Wxc = Parameter(cellDim, inputDim, init=uniform, initValueScale=1);
bo = Parameter(cellDim, init=fixedValue, value=0.0);
bc = Parameter(cellDim, init=fixedValue, value=0.0);
bi = Parameter(cellDim, init=fixedValue, value=0.0);
bf = Parameter(cellDim, init=fixedValue, value=0.0);
Whi = Parameter(cellDim, outputDim, init=uniform, initValueScale=1);
Wci = Parameter(cellDim, init=uniform, initValueScale=1);
Whf = Parameter(cellDim, outputDim, init=uniform, initValueScale=1);
Wcf = Parameter(cellDim, init=uniform, initValueScale=1);
Who = Parameter(cellDim, outputDim, init=uniform, initValueScale=1);
Wco = Parameter(cellDim, init=uniform, initValueScale=1);
Whc = Parameter(cellDim, outputDim, init=uniform, initValueScale=1);
dh = FutureValue(outputDim, output, timeStep=1);
dc = FutureValue(cellDim, ct, timeStep=1);
Wxix = Times(Wxi, inputx);
Whidh = Times(Whi, dh);
Wcidc = DiagTimes(Wci, dc);
it = Sigmoid (Plus ( Plus (Plus (Wxix, bi), Whidh), Wcidc));
Wxcx = Times(Wxc, inputx);
Whcdh = Times(Whc, dh);
bit = ElementTimes(it, Tanh( Plus(Wxcx, Plus(Whcdh, bc))));
Wxfx = Times(Wxf, inputx);
Whfdh = Times(Whf, dh);
Wcfdc = DiagTimes(Wcf, dc);
ft = Sigmoid( Plus (Plus (Plus(Wxfx, bf), Whfdh), Wcfdc));
bft = ElementTimes(ft, dc);
ct = Plus(bft, bit);
Wxox = Times(Wxo, inputx);
Whodh = Times(Who, dh);
Wcoct = DiagTimes(Wco, ct);
ot = Sigmoid( Plus( Plus( Plus(Wxox, bo), Whodh), Wcoct));
mt = ElementTimes(ot, Tanh(ct));
Wmr = Parameter(outputDim, cellDim, init=uniform, initValueScale=1);
output = Times(Wmr, mt);
}
Thank you very much! It really helps!
I have already built a BLSTM using the futurevalue node. But it cause an error, have you ever meet this error?
EXCEPTION occurred: The delay node tries to access future values that are out of bound, possibly because there is no sentence end marker in the MBLayout.
make sure truncated is set to false
I have change the set of truncated just now , the original error disappeared , but a new one occurred:
EXCEPTION occurred: The training criterion is not a number (NAN). Stop
Learning rate is too high because now gradients are computed for whole utterances (i.e., more samples).
Thanks alot ,I got it.
I assume this got answered by Dong ...
@yzhang87 Do you know how to build a BLSTM in caffe?