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])
stacked_denoising_autoencoder.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录