def __init__(self, vocab_size, embed_size, hidden_size, out_size): super(GRU_SentenceClassifier, self).__init__(xe=L.EmbedID(vocab_size, embed_size), eh=L.GRU(embed_size, hidden_size), eh2=L.GRU(hidden_size, hidden_size), hh=L.Linear(hidden_size, hidden_size), hy=L.Linear(hidden_size, out_size))
def __init__(self, src_vocab, args, src_w2v): super(biGRU_encoder, self).__init__() with self.init_scope(): self.word2embed = chainLinks.EmbedID(src_vocab.size, args.edim, ignore_label=-1) self.embed2hiddenf = chainLinks.GRU(args.edim, args.nhid) self.embed2hiddenb = chainLinks.GRU(args.edim, args.nhid) #embedding weight is intialized by w2v. if src_w2v is not None: for i in range(src_vocab.size): word = src_vocab.id2word[i] if word in src_w2v: self.word2embed.W.data[i] = src_w2v[word] self.vocab_size = src_vocab.size self.embedding_size = args.edim self.hidden_size = args.nhid if args.useDropout: self.use_dropout = args.useDropout self.dropoutr = args.dlr else: self.use_dropout = None self.dropoutr = 0 util.trace('{}'.format(chainer.global_config.__dict__))
def __init__(self, in_size, n_units, out_size, train=True): super(BiGRU, self).__init__() with self.init_scope(): self.embed = L.EmbedID(in_size, n_units) self.hf = L.GRU(n_units, n_units) self.hb = L.GRU(n_units, n_units) self.l3 = L.Linear(n_units * 2, out_size) for param in self.params(): param.data[...] = np.random.uniform(-0.1, 0.1, param.data.shape)
def __init__(self, in_size, out_size): log.info("Creating GRUCell(%i, %i)" % (in_size, out_size)) super(GRUCell, self).__init__(gru=L.GRU(out_size, in_size), ) self.add_param("initial_state", (1, out_size)) self.initial_state.data[...] = self.xp.random.randn(out_size) self.out_size = out_size self.in_size = in_size
def __init__(self, vocab_size=10, word_size=10, hidden_state=10, class_num=10, dtype=np.float32, maxLength=10, layer_num=1): super(Decoder, self).__init__() with self.init_scope(): self.word_size = word_size self.beginToken = 0 self.endToken = 1 self.dtype = dtype self.maxLength = maxLength W = initializers.HeNormal(1 / np.sqrt(2), self.dtype) self.embed = L.EmbedID(vocab_size, word_size) self.embed_proj = L.Linear(word_size, hidden_state, initialW=W) self.out = L.Linear(in_size=hidden_state, out_size=class_num, initialW=W) self.attention = GlobalAttention(hidden_size=hidden_state) self.layer_num = layer_num for layer_id in range(self.layer_num): setattr(self, "rnn_cell_" + str(layer_id), L.GRU(in_size=hidden_state, out_size=hidden_state))
def __init__(self, hidden_dim, out_dim, n_layers, n_atom_types=MAX_ATOMIC_NUM, concat_hidden=False, weight_tying=True): super(GGNN, self).__init__() n_readout_layer = 1 if concat_hidden else n_layers n_message_layer = 1 if weight_tying else n_layers with self.init_scope(): # Update self.embed = EmbedAtomID(out_size=hidden_dim, in_size=n_atom_types) self.message_layers = chainer.ChainList(*[ GraphLinear(hidden_dim, self.NUM_EDGE_TYPE * hidden_dim) for _ in range(n_message_layer) ]) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) # Readout self.i_layers = chainer.ChainList(*[ GraphLinear(2 * hidden_dim, out_dim) for _ in range(n_readout_layer) ]) self.j_layers = chainer.ChainList(*[ GraphLinear(hidden_dim, out_dim) for _ in range(n_readout_layer) ]) self.out_dim = out_dim self.hidden_dim = hidden_dim self.n_layers = n_layers self.concat_hidden = concat_hidden self.weight_tying = weight_tying
def __init__(self, hidden_dim=16, num_edge_type=4): super(GGNNUpdate, self).__init__() with self.init_scope(): self.graph_linear = GraphLinear(hidden_dim, num_edge_type * hidden_dim) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) self.num_edge_type = num_edge_type
def __init__(self, hidden_dim=16, nn=None): super(MPNNUpdate, self).__init__() with self.init_scope(): self.message_layer = EdgeNet(out_channels=hidden_dim, nn=nn) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) self.hidden_dim = hidden_dim self.nn = nn
def __init__(self, n_units, n_out, layers=2, dropout=0): super(GRU, self).__init__() self.layers = layers self.dropout = dropout with self.init_scope(): for l in range(layers): setattr(self, "layer_{}".format(l), L.GRU(None, n_units)) self.out = L.Linear(None, n_out)
def __init__(self, hidden_dim=16, nn=None): # type: (int, Optional[chainer.Link]) -> None super(MPNNUpdate, self).__init__() with self.init_scope(): self.message_layer = EdgeNet(out_channels=hidden_dim, nn=nn) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) self.hidden_dim = hidden_dim self.nn = nn
def __init__(self, vocab_size, in_size, hidden_size, out_size): super(Char_Rnn, self).__init__(xh=L.EmbedID(vocab_size, in_size, ignore_label=-1), bn1=L.BatchNormalization(hidden_size), hh=L.GRU(in_size, hidden_size), hy=L.Linear(hidden_size, out_size), bn2=L.BatchNormalization(out_size))
def __init__(self, n_out=1): super(NPGRUPopulation, self).__init__() self.n_out = n_out with self.init_scope(): self.l1 = L.GRU(None, n_out)
def __init__( self, out_dim, hidden_dim=16, n_layers=4, n_atom_types=MAX_ATOMIC_NUM, concat_hidden=False, dropout_rate=0.0, batch_normalization=False, weight_tying=True, update_tying=True, self_loop=False, ): super(GGNN, self).__init__() n_readout_layer = n_layers if concat_hidden else 1 n_message_layer = 1 if weight_tying else n_layers n_update_layer = 1 if update_tying else n_layers self.n_readout_layer = n_readout_layer self.n_message_layer = n_message_layer self.out_dim = out_dim self.hidden_dim = hidden_dim self.n_layers = n_layers self.concat_hidden = concat_hidden self.dropout_rate = dropout_rate self.batch_normalization = batch_normalization self.weight_tying = weight_tying self.update_tying = update_tying self.self_loop = self_loop with self.init_scope(): # Update self.embed = EmbedAtomID(out_size=hidden_dim, in_size=n_atom_types) self.message_layers = chainer.ChainList(*[ GraphLinear(hidden_dim, self.NUM_EDGE_TYPE * hidden_dim) for _ in range(n_message_layer) ]) self.update_layers_0 = chainer.ChainList(*[ links.Linear(2 * hidden_dim, 2 * hidden_dim) for _ in range(n_update_layer) ]) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) if self_loop: self.self_loop_layer = GraphLinear(hidden_dim, hidden_dim) # Readout self.i_layers = chainer.ChainList(*[ GraphLinear(2 * hidden_dim, out_dim) for _ in range(n_readout_layer) ]) self.j_layers = chainer.ChainList(*[ GraphLinear(hidden_dim, out_dim) for _ in range(n_readout_layer) ])
def __init__(self, size_vocab, size_embed, size_hidden): ''' : arg size_vocab : 使われる単語の語彙数 : arg size_embed : 単語をベクトル表現した時のサイズ : arg size_hidden : 隠れ層のサイズ : arg size_batch : バッチのサイズ ''' super(Seq2SeqVAE, self).__init__() self.size_vocab = size_vocab with self.init_scope(): # encoder self.enc_embed = L.EmbedID(size_vocab, size_embed, ignore_label=-1) self.enc_rnn = L.GRU(size_embed, size_hidden) self.h_mu = L.Linear(size_hidden, size_hidden) self.h_ln = L.Linear(size_hidden, size_hidden) # decoder self.dec_embed = L.EmbedID(size_vocab, size_embed, ignore_label=-1) self.dec_rnn = L.GRU(size_embed, size_hidden) self.dec_out = L.Linear(size_hidden, size_vocab)
def __init__(self, input_size, output_size, hidden_size=32): self.input_size = input_size self.output_size = output_size self.hidden_size = hidden_size self.v = Variable(np.zeros((1, input_size), dtype=np.float32)) self.h = Variable(np.zeros((1, hidden_size), dtype=np.float32)) self.p = Variable(np.zeros((1, output_size), dtype=np.float32)) super(RNN, self).__init__( # Use LSTM or GRU in the RNN # l0=L.LSTM(input_size, hidden_size), l0=L.GRU(input_size, hidden_size), l1=L.Linear(hidden_size, output_size) )
def __init__(self, in_channels=None, hidden_channels=16, out_channels=None, n_edge_types=4, **kwargs): if out_channels is None: out_channels = hidden_channels super(GGNNUpdate, self).__init__() if in_channels is None: gru_in_channels = None else: gru_in_channels = in_channels + hidden_channels with self.init_scope(): self.graph_linear = GraphLinear( in_channels, n_edge_types * hidden_channels) self.update_layer = links.GRU(gru_in_channels, out_channels) self.n_edge_types = n_edge_types self.in_channels = in_channels self.hidden_channels = hidden_channels self.out_channels = out_channels
def __init__(self, hidden_dim=16, n_layers=4, n_atom_types=MAX_ATOMIC_NUM, num_edge_type=4, weight_tying=True): super(GGNNUpdate, self).__init__() n_layer = 1 if weight_tying else n_layers with self.init_scope(): self.graph_linears = chainer.ChainList(*[ GraphLinear(hidden_dim, num_edge_type * hidden_dim) for _ in range(n_layer) ]) self.update_layer = links.GRU(2 * hidden_dim, hidden_dim) self.n_layers = n_layers self.num_edge_type = num_edge_type self.weight_tying = weight_tying
def __init__(self, in_channels=None, hidden_channels=16, out_channels=None, nn=None, **kwargs): if out_channels is None: out_channels = hidden_channels if in_channels is None: # Current `EdgeNet` hidden_channels must be same with input `h` dim. in_channels = out_channels super(MPNNUpdate, self).__init__() with self.init_scope(): self.message_layer = EdgeNet(out_channels=hidden_channels, nn=nn) self.update_layer = links.GRU(2 * hidden_channels, out_channels) self.in_channels = in_channels # currently it is not used... self.hidden_channels = hidden_channels self.out_channels = out_channels self.nn = nn
def __init__(self, params): self.__dict__.update(params) super(GRU_Baseline, self).__init__( embed=L.EmbedID(self.n_vocab + 3, self.word_dim), gru=L.GRU(n_units=self.n_units, n_inputs=self.word_dim), # l2v = L.Linear( # in_size = self.n_units, # out_size = self.n_vocab + 2 # ) # blackout = L.BlackOut( # in_size = self.n_units, # counts = self.vocab_counts, # sample_size = self.blackout_sample_size # ) # bottleneck = L.Linear( # in_size = self.n_units, # out_size = 128 # ), bh_softmax=L.BinaryHierarchicalSoftmax(in_size=self.n_units, tree=self.huffman_tree))
def __init__(self, src_vocab, tgt_vocab, args): super().__init__() with self.init_scope(): self.word2embed = chainLinks.EmbedID(src_vocab.size, args.nhid, ignore_label=-1) # W_1, U self.embed2hidden = chainLinks.GRU(args.nhid, args.nhid) # W_2 self.W_2 = chainLinks.Linear(args.nhid, tgt_vocab.size) self.vocab_size = src_vocab.size self.hidden_size = args.nhid if args.useDropout: self.use_dropout = args.useDropout self.dropoutr = args.dlr else: self.use_dropout = None self.dropoutr = 0 util.trace('{}'.format(chainer.global_config.__dict__))
def __init__(self, n_voc, emb_dim, hid_dim, seq_len, gpu_num): super(Generator, self).__init__() self.n_voc = n_voc self.hid_dim = hid_dim self.emb_dim = emb_dim self.seq_len = seq_len self.gpu_num = gpu_num self._gpu_id = None self.voc_size = xp.array([i for i in range(n_voc)]) w = I.Normal(1.) with self.init_scope(): self.embeddings = L.EmbedID(n_voc, emb_dim, initialW=w) self.gru = L.GRU(emb_dim, hid_dim, init=w, inner_init=w, bias_init=I.Zero()) self.gru2out = L.Linear(hid_dim, n_voc, initialW=w, initial_bias=I.Zero())
def __init__(self, hidden_dim, out_dim, n_atom_types, radius, concat_hidden=False, weight_tying=True): super(GGNN, self).__init__() num_layer = 1 if weight_tying else radius with self.init_scope(): self.embed = L.EmbedID(n_atom_types, hidden_dim) self.edge_layer = L.Linear(hidden_dim, self.NUM_EDGE_TYPE * hidden_dim) self.update_layer = L.GRU(2 * hidden_dim, hidden_dim) self.i_layers = chainer.ChainList( *[L.Linear(2 * hidden_dim, out_dim) for _ in range(num_layer)]) self.j_layers = chainer.ChainList( *[L.Linear(hidden_dim, out_dim) for _ in range(num_layer)]) self.out_dim = out_dim self.hidden_dim = hidden_dim self.radius = radius self.concat_hidden = concat_hidden self.weight_tying = weight_tying
def __init__(self, embed_size, hidden_size): super(Encoder, self).__init__( GRU = links.GRU(embed_size, hidden_size), )
def __init__(self, embed_size, hidden_size, num_layers): super(MultiLayerGRUEncoder, self).__init__() self.add_link(links.GRU(hidden_size,embed_size)) for i in num_layers: self.add_link(links.GRU(hidden_size,hidden_size)) self.num_layers = num_layers
def setUp(self): self.gru = links.GRU(10, 10)
def __init__(self, in_size, hidden_size, out_size): super(LSTM, self).__init__(xh=L.Linear(in_size, hidden_size), hh=L.GRU(hidden_size, hidden_size), hy=L.Linear(hidden_size, out_size))
def setUp(self): self.link = links.GRU(8) self.x = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32) self.h = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32) self.gy = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32)
def __init__(self, hidden_dim): super(GruRnn, self).__init__(gru=L.GRU(hidden_dim, hidden_dim), ) self.hidden_dim = hidden_dim
def __init__(self, hidden_dim=16, hidden_dim_super=16, n_layers=4, n_heads=8, dropout_ratio=0.5, concat_hidden=False, tying_flag=False, gpu=-1): super(GWM, self).__init__() num_layer = n_layers if tying_flag: num_layer = 1 with self.init_scope(): # # for Transmitter unit # self.F_super = chainer.ChainList( *[L.Linear(in_size=hidden_dim_super, out_size=hidden_dim_super) for _ in range(num_layer)] ) self.V_super = chainer.ChainList( *[L.Linear(hidden_dim * n_heads, hidden_dim * n_heads) for _ in range(num_layer)] ) self.W_super = chainer.ChainList( *[L.Linear(hidden_dim * n_heads, hidden_dim_super) for _ in range(num_layer)] ) self.B = chainer.ChainList( *[GraphLinear(n_heads * hidden_dim, n_heads * hidden_dim_super) for _ in range(num_layer)] ) # # for Warp Gate unit # self.gate_dim = hidden_dim self.H_local = chainer.ChainList( *[GraphLinear(in_size=hidden_dim, out_size=self.gate_dim) for _ in range(num_layer)] ) self.G_local = chainer.ChainList( *[GraphLinear(in_size=hidden_dim_super, out_size=self.gate_dim) for _ in range(num_layer)] ) self.gate_dim_super = hidden_dim_super self.H_super = chainer.ChainList( *[L.Linear(in_size=hidden_dim, out_size=self.gate_dim_super) for _ in range(num_layer)] ) self.G_super = chainer.ChainList( *[L.Linear(in_size=hidden_dim_super, out_size=self.gate_dim_super) for _ in range(num_layer)] ) # GRU's. not layer-wise (recurrent through layers) self.GRU_local = L.GRU(in_size=hidden_dim, out_size=hidden_dim) self.GRU_super = L.GRU(in_size=hidden_dim_super, out_size=hidden_dim_super) # end init_scope-with self.hidden_dim = hidden_dim self.hidden_dim_super = hidden_dim_super self.n_layers = n_layers self.n_heads = n_heads self.dropout_ratio = dropout_ratio self.concat_hidden = concat_hidden self.tying_flag = tying_flag
def __init__(self, hidden_dim=16, hidden_dim_super=16, n_layers=4, n_heads=8, dropout_ratio=-1, tying_flag=False, activation=functions.relu, wgu_activation=functions.sigmoid, gtu_activation=functions.tanh): super(GWM, self).__init__() n_use_layers = 1 if tying_flag else n_layers with self.init_scope(): self.update_super = chainer.ChainList(*[ links.Linear(in_size=hidden_dim_super, out_size=hidden_dim_super) for _ in range(n_use_layers) ]) # for Transmitter unit self.super_transmitter = chainer.ChainList(*[ SuperNodeTransmitterUnit(hidden_dim=hidden_dim, hidden_dim_super=hidden_dim_super, dropout_ratio=dropout_ratio) for _ in range(n_use_layers) ]) self.graph_transmitter = chainer.ChainList(*[ GraphTransmitterUnit(hidden_dim=hidden_dim, hidden_dim_super=hidden_dim_super, n_heads=n_heads, dropout_ratio=dropout_ratio, activation=gtu_activation) for _ in range(n_use_layers) ]) # for Warp Gate unit self.wgu_local = chainer.ChainList(*[ WarpGateUnit(output_type='graph', hidden_dim=hidden_dim, dropout_ratio=dropout_ratio, activation=wgu_activation) for _ in range(n_use_layers) ]) self.wgu_super = chainer.ChainList(*[ WarpGateUnit(output_type='super', hidden_dim=hidden_dim_super, dropout_ratio=dropout_ratio, activation=wgu_activation) for _ in range(n_use_layers) ]) # Weight tying: not layer-wise but recurrent through layers self.GRU_local = links.GRU(in_size=hidden_dim, out_size=hidden_dim) self.GRU_super = links.GRU(in_size=hidden_dim_super, out_size=hidden_dim_super) # end init_scope-with self.hidden_dim = hidden_dim self.hidden_dim_super = hidden_dim_super self.n_layers = n_layers self.n_heads = n_heads self.dropout_ratio = dropout_ratio self.tying_flag = tying_flag self.activation = activation self.wgu_activation = wgu_activation