喧豗
2021-06-24 15:16
采纳率: 0%
浏览 45

关于Word2vec保存模型时出错

Windows10 python3.8

编程小白,自学自然语言处理的Word2vec模块

想试着训练一个词向量模型

最后保存的时候,这两句

model.save(outp1)
model.wv.save_word2vec_format(outp2, binary=False)

显示invalid syntax

试过gensim各种版本都不行

 

这是全部代码

不知道有没有大佬能给予帮助

#词向量训练
import logging
import os
import sys
import multiprocessing

from gensim.models import word2vec
from gensim.models.word2vec import LineSentence

if __name__ == '__main__':
    program = os.path.basename(sys.argv[0])
    logger = logging.getLogger(program)

    logging.basicConfig(format='%(asctime)s: %(levelname)s: %(message)s')
    logging.root.setLevel(level=logging.INFO)
    logger.info("running %s" % ' '.join(sys.argv))

    # check and process input arguments
    if len(sys.argv) < 4:
        print(globals()['__doc__'] , locals())
        sys.exit(1)
    inp, outp1, outp2 = sys.argv[1:4]

    model = Word2Vec(LineSentence(inp), vector_size=400, window=5, min_count=5,
                     workers=multiprocessing.cpu_count(),#iter=100)

    #trim unneeded model memory = use(much) less RAM
    model.init_sims(replace=True)
    model.save(outp1)
    model.wv.save_word2vec_format(outp2, binary=False)
    print('训练结束')

1条回答 默认 最新

相关推荐 更多相似问题