def create_blstm(l_incoming, l_mask, hidden_units, cell_parameters, gate_parameters, name):
if cell_parameters is None:
cell_parameters = Gate()
if gate_parameters is None:
gate_parameters = Gate()
l_lstm = LSTMLayer(
l_incoming, hidden_units,
# We need to specify a separate input for masks
mask_input=l_mask,
# Here, we supply the gate parameters for each gate
ingate=gate_parameters, forgetgate=gate_parameters,
cell=cell_parameters, outgate=gate_parameters,
# We'll learn the initialization and use gradient clipping
learn_init=True, grad_clipping=5., name='f_{}'.format(name))
# The "backwards" layer is the same as the first,
# except that the backwards argument is set to True.
l_lstm_back = LSTMLayer(
l_incoming, hidden_units, ingate=gate_parameters,
mask_input=l_mask, forgetgate=gate_parameters,
cell=cell_parameters, outgate=gate_parameters,
learn_init=True, grad_clipping=5., backwards=True, name='b_{}'.format(name))
return l_lstm, l_lstm_back
评论列表
文章目录