def get_backward_states(self, h0, states_tp1, dropout_ratio, train): if dropout_ratio < 0.01: train=False #backward direction h1_b, c1_b = self.h0_to_h1_b(h0, states_tp1['h1'], states_tp1['c1']) h2_b, c2_b = self.h1_to_h2_b(nF.dropout(h1_b, ratio=dropout_ratio, train=train), states_tp1['h2'], states_tp1['c2']) return {'c1': c1_b, 'h1': h1_b, 'c2': c2_b, 'h2': h2_b}
def get_forward_states(self, h0, states_tm1, dropout_ratio, train): if dropout_ratio < 0.01: train=False #forward direction h1_f, c1_f = self.h0_to_h1_f(h0, states_tm1['h1'], states_tm1['c1']) h2_f, c2_f = self.h1_to_h2_f(nF.dropout(h1_f, ratio=dropout_ratio, train=train), states_tm1['h2'], states_tm1['c2']) return {'c1': c1_f, 'h1': h1_f, 'c2': c2_f, 'h2': h2_f}
def get_backward_states(self, h0, states_tp1, dropout_ratio, train): if dropout_ratio < 0.01: train = False # backward direction h1_b, c1_b = self.h0_to_h1_b(h0, states_tp1["h1"], states_tp1["c1"]) h2_b, c2_b = self.h1_to_h2_b( nF.dropout(h1_b, ratio=dropout_ratio, train=train), states_tp1["h2"], states_tp1["c2"] ) return {"c1": c1_b, "h1": h1_b, "c2": c2_b, "h2": h2_b}
def get_forward_states(self, h0, states_tm1, dropout_ratio, train): if dropout_ratio < 0.01: train = False # forward direction h1_f, c1_f = self.h0_to_h1_f(h0, states_tm1["h1"], states_tm1["c1"]) h2_f, c2_f = self.h1_to_h2_f( nF.dropout(h1_f, ratio=dropout_ratio, train=train), states_tm1["h2"], states_tm1["c2"] ) return {"c1": c1_f, "h1": h1_f, "c2": c2_f, "h2": h2_f}