stacked_denoising_autoencoder.py 文件源码

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

项目:sequence-based-recommendations 作者: rdevooght 项目源码 文件源码
def top_k_recommendations(self, sequence, user_id=None, k=10, exclude=None, **kwargs):
        ''' Recieves a sequence of (id, rating), and produces k recommendations (as a list of ids)
        '''

        # Compile network if needed
        if not hasattr(self, 'predict_function'):
            self._compile_predict_function()

        # Prepare RNN input
        X = np.zeros((1, self._input_size())) # input of the RNN
        X[0, :] = self._one_hot_encoding([i[0] for i in sequence])

        # Run RNN
        output = self.predict_function(X.astype(theano.config.floatX))[0]

        # Put low similarity to viewed items to exclude them from recommendations
        output[[i[0] for i in sequence]] = -np.inf
        output[exclude] = -np.inf

        # find top k according to output
        return list(np.argpartition(-output, range(k))[:k])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号