def __init__(self, n_vocab, n_layers, n_units, typ="lstm"): super(RNNLM, self).__init__() with self.init_scope(): self.embed = DL.EmbedID(n_vocab, n_units) self.rnn = chainer.ChainList( *[L.StatelessLSTM(n_units, n_units) for _ in range(n_layers)]) if typ == "lstm" \ else chainer.ChainList(*[L.StatelessGRU(n_units, n_units) for _ in range(n_layers)]) self.lo = L.Linear(n_units, n_vocab) for param in self.params(): param.data[...] = np.random.uniform(-0.1, 0.1, param.data.shape) self.n_layers = n_layers self.n_units = n_units self.typ = typ
def __init__( self, eprojs, odim, dtype, dlayers, dunits, sos, eos, att, verbose=0, char_list=None, labeldist=None, lsm_weight=0.0, sampling_probability=0.0, ): super(Decoder, self).__init__() with self.init_scope(): self.embed = DL.EmbedID(odim, dunits) self.rnn0 = ( L.StatelessLSTM(dunits + eprojs, dunits) if dtype == "lstm" else L.StatelessGRU(dunits + eprojs, dunits) ) for l in six.moves.range(1, dlayers): setattr( self, "rnn%d" % l, L.StatelessLSTM(dunits, dunits) if dtype == "lstm" else L.StatelessGRU(dunits, dunits), ) self.output = L.Linear(dunits, odim) self.dtype = dtype self.loss = None self.att = att self.dlayers = dlayers self.dunits = dunits self.sos = sos self.eos = eos self.verbose = verbose self.char_list = char_list # for label smoothing self.labeldist = labeldist self.vlabeldist = None self.lsm_weight = lsm_weight self.sampling_probability = sampling_probability