def decoder(layer_number=1, hidden_number=500, output_number=100, Dropout_rate=0.2, cell='gru'): cell_type = cell Muilti_cell = RNN.SequentialRNNCell() for i in range(layer_number): if cell_type == 'gru' or cell_type == 'GRU': Muilti_cell.add( RNN.GRUCell(num_hidden=hidden_number, num_output=output_number, prefix="gru_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i, cell_type)) elif cell_type == 'lstm' or cell_type == 'LSTM': Muilti_cell.add( RNN.LSTMCell(num_hidden=hidden_number, num_output=output_number, prefix="lstm_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i, cell_type)) else: Muilti_cell.add( RNN.RNNCell(num_hidden=hidden_number, num_output=output_number, prefix="rnn_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i, cell_type)) if Dropout_rate > 0 and (layer_number - 1) > i: Muilti_cell.add( RNN.DropoutCell(Dropout_rate, prefix="dropout_decoder_{}".format(i))) print("stack {}-'{}'- decoder dropout cell".format(i, cell_type)) return Muilti_cell
def decoder(layer_number=1 , hidden_number=500 , output_number = 100 , Dropout_rate=0.2 , Zoneout_rate=0.0 , Residual=True , cell='gru'): print("<<<decoder structure>>>") cell_type = cell Muilti_cell = RNN.SequentialRNNCell() for i in range(layer_number): if cell_type == 'gru' or cell_type == 'GRU' or cell_type == 'Gru' : if Residual == True and Zoneout_rate > 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.GRUCell(num_hidden=hidden_number, num_output= output_number ,prefix="gru_decoder_{}".format(i))) print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(Residual_cell,zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) elif Residual == True and Zoneout_rate == 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.GRUCell(num_hidden=hidden_number, num_output= output_number ,prefix="gru_decoder_{}".format(i))) Muilti_cell.add(Residual_cell) elif Residual == False and Zoneout_rate > 0: print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(RNN.GRUCell(num_hidden=hidden_number, num_output= output_number ,prefix="gru_decoder_{}".format(i)),zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) else: Muilti_cell.add(RNN.GRUCell(num_hidden=hidden_number, num_output= output_number ,prefix="gru_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i,cell_type)) elif cell_type == 'lstm' or cell_type == 'LSTM' or cell_type == 'Lstm': if Residual == True and Zoneout_rate > 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.LSTMCell(num_hidden=hidden_number, num_output=output_number, prefix="lstm_decoder_{}".format(i))) print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(Residual_cell,zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) elif Residual == True and Zoneout_rate == 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.LSTMCell(num_hidden=hidden_number, num_output=output_number, prefix="lstm_decoder_{}".format(i))) Muilti_cell.add(Residual_cell) elif Residual == False and Zoneout_rate > 0: print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(RNN.LSTMCell(num_hidden=hidden_number, num_output=output_number, prefix="lstm_decoder_{}".format(i)),zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) else: Muilti_cell.add(RNN.LSTMCell(num_hidden=hidden_number, num_output=output_number, prefix="lstm_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i,cell_type)) else: if Residual == True and Zoneout_rate > 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.RNNCell(num_hidden=hidden_number, num_output=output_number, activation='relu' , prefix="rnn_decoder_{}".format(i))) print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(Residual_cell,zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) elif Residual == True and Zoneout_rate == 0: print("residualcell applied_{}".format(i)) Residual_cell=RNN.ResidualCell(RNN.RNNCell(num_hidden=hidden_number, num_output=output_number, activation='relu', prefix="rnn_decoder_{}".format(i))) Muilti_cell.add(Residual_cell) elif Residual == False and Zoneout_rate > 0: print("zoneoutcell applied-{}".format(i)) Zoneout_cell=RNN.ZoneoutCell(RNN.RNNCell(num_hidden=hidden_number, num_output=output_number, activation='relu' , prefix="rnn_decoder_{}".format(i)),zoneout_outputs=Zoneout_rate , zoneout_states=Zoneout_rate) Muilti_cell.add(Zoneout_cell) else: Muilti_cell.add(RNN.RNNCell(num_hidden=hidden_number , num_output=output_number , activation='relu' , prefix="rnn_decoder_{}".format(i))) print("stack {}-'{}'- decoder cell".format(i,cell_type)) if Dropout_rate > 0 and (layer_number-1) > i: Muilti_cell.add(RNN.DropoutCell(Dropout_rate, prefix="dropout_decoder_{}".format(i))) print("stack {}-'{}'- decoder dropout cell".format(i,cell_type)) print("\n") return Muilti_cell