def most_similar(self, *args, **kwargs):
positive = cherrypy.request.params.get('positive[]', [])
if isinstance(positive, basestring):
positive = [positive]
negative = cherrypy.request.params.get('negative[]', [])
if isinstance(negative, basestring):
negative = [negative]
try:
result = self.model.most_similar(
positive=[gensim.utils.to_utf8(word).strip() for word in positive if word],
negative=[gensim.utils.to_utf8(word).strip() for word in negative if word],
topn=5)
except:
result = []
logger.info("similars for %s vs. %s: %s" % (positive, negative, result))
return {'similars': result}
w2v_server.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录