SDAE.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:HyPRec 作者: mostafa-mahmoud 项目源码 文件源码
def get_cnn(self):
        """
        Build a keras' convolutional neural network model.

        :returns: A tuple of 2 models, for encoding and encoding+decoding model.
        :rtype: tuple(Model)
        """
        n_vocab = self.abstracts_preprocessor.get_num_vocab()
        n1 = 64
        input_layer = Input(shape=(n_vocab,))
        model = Reshape((1, n_vocab,))(input_layer)
        model = Convolution1D(n1, 3, border_mode='same', activation='sigmoid', W_regularizer=l2(.01))(model)
        model = Reshape((n1,))(model)
        model = Dense(n1, activation='sigmoid', W_regularizer=l2(.01))(model)
        model = Reshape((1, n1))(model)
        model = Convolution1D(self.n_factors, 3, border_mode='same',
                              activation='softmax', W_regularizer=l2(.01))(model)
        encoding = Reshape((self.n_factors,), name='encoding')(model)

        model = Reshape((1, self.n_factors))(encoding)
        model = Convolution1D(n1, 3, border_mode='same', activation='sigmoid', W_regularizer=l2(.01))(model)
        model = Reshape((n1,))(model)
        model = Dense(n1, activation='relu', W_regularizer=l2(.01))(model)
        model = Reshape((1, n1))(model)
        model = Convolution1D(n_vocab, 3, border_mode='same', W_regularizer=l2(.01))(model)
        decoding = Reshape((n_vocab,))(model)

        model = concatenate([encoding, decoding])
        self.model = Model(inputs=input_layer, outputs=model)
        self.model.compile(loss='mean_squared_error', optimizer='sgd')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号