本文介绍了Gensim示例,TypeError:str和int之间的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码时.这个Python 3.6,Jupyter中最新的Gensim库

When running the below code. this Python 3.6, latest Gensim library in Jupyter

for model in models:
       print(str(model))
       pprint(model.docvecs.most_similar(positive=["Machine learning"], topn=20))

[1]: https://github.com/RaRe-Technologies/gensim/blob/develop/docs/notebooks/doc2vec-wikipedia.ipynb

推荐答案

string= "machine learning".split()

doc_vector = model.infer_vector(string)
out= model.docvecs.most_similar([doc_vector])

由于使用的是较新的版本,因此我不确定100%,但是我认为问题与most_like函数期望在功能空间中映射的字符串而不是原始字符串有关.

I'm not sure 100% since I'm using a more recent release, but I think that the issue is connected to the fact that the most_similar function is expecting a string mapped in the feature space and not the raw string.

这篇关于Gensim示例,TypeError:str和int之间的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 17:52