我正在使用 Word2vec 和 gensim 进行项目,
model = gensim.models.Word2Vec(
documents = 'userDataFile.txt',
size=150,
window=10,
min_count=2,
workers=10)
model = gensim.model.Word2Vec.load("word2vec.model")
model.train(documents, total_examples=len(documents), epochs=10)
model.save("word2vec.model")
这是我目前拥有的部分代码,我在下面收到此错误
Traceback (most recent call last): File "C:\Users\User\Desktop\InstaSubProject\templates\HashtagData.py", line 37, in <module> workers=10) TypeError: __init__() got an unexpected keyword argument 'documents'
UserDataFile.txt
是我存储从网络抓取中获得的输出结果数据的文件。
我不太确定这里需要修复什么。
提前谢谢您!
今年是 2021 年,如果您出于与我相同的原因来到这里,那是因为您在
size
参数上遇到了相同的错误。
您需要使用
vector_size
来代替。
使用矢量大小代替大小强文本
# creating a word to vector model
model_w2v = gensim.models.Word2Vec(
tokenize_data,
vector_size=200)
__init__()
是Word2Vec的类构造函数,当您使用gensim.models.Word2Vec()
实例化该类时,参数documents
可能实际上并不是必需的
试试这个:
model = gensim.models.Word2Vec(
size=150,
window=10,
min_count=2,
workers=10)
看起来该模型在初始化时没有采用关键字参数
documents
。我认为你可以尝试其中任何一个来代替你的 documents=
声明:
corpus_file = 'userDataFile.txt'
或
sentences = # your iterable of sentences here
取决于您正在使用的内容的格式
您可以尝试查看从 v3 到 v4 的新更新: 链接
model = Word2Vec(size=100, …) # bad
model = Word2Vec(vector_size=100, …) # good