def RNN_step(weights, gates):
def rnn_step_fwd(prevstate_inputs, drop=<NUM_LIT:0.0>):<EOL><INDENT>prevstate, inputs = prevstate_inputs<EOL>cell_tm1, hidden_tm1 = prevstate<EOL>acts, bp_acts = weights.begin_update((inputs, hidden_tm1), drop=drop)<EOL>(cells, hiddens), bp_gates = gates.begin_update((acts, cell_tm1), drop=drop)<EOL>def rnn_step_bwd(d_state_d_hiddens, sgd=None):<EOL><INDENT>(d_cells, d_hiddens), d_hiddens = d_state_d_hiddens<EOL>d_acts, d_cell_tm1 = bp_gates((d_cells, d_hiddens), sgd=sgd)<EOL>d_inputs, d_hidden_tm1 = bp_acts(d_acts, sgd=sgd)<EOL>return (d_cell_tm1, d_hidden_tm1), d_inputs<EOL><DEDENT>return ((cells, hiddens), hiddens), rnn_step_bwd<EOL><DEDENT>model = wrap(rnn_step_fwd, weights, gates)<EOL>model.nO = weights.nO<EOL>model.nI = weights.nI<EOL>model.weights = weights<EOL>model.gates = gates<EOL>return model<EOL>
Create a step model for an RNN, given weights and gates functions.