error LNK1104: cannot open word2vec_inner.pyd' 5C

windons实现Yang Liu的Topical Word Embeddings时,运行错误
TWE\test.py:

import gensim
sentence_word = gensim.models.word2vec.LineSentence("tmp/word.file")

TWE\gensim\models\word2vec.py:

try:
    raise ImportError  # ignore for now
    from gensim_addons.models.word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_topic
except ImportError:
    try:
        # try to compile and use the faster cython version
        import pyximport
        print 'import pyximport'
        models_dir = os.path.dirname(__file__) or os.getcwd()
        print 'models_dir'
        pyximport.install(setup_args={"include_dirs": [models_dir, get_include()]})
        print 'pyximport'   # is the follow code's problem
        from word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_topic
        print 'from word2vec'
    except:
        print 'except2'
        # failed... fall back to plain numpy (20-80x slower training than the above)
        FAST_VERSION = -1

        def train_sentence_sg(model, sentence, alpha, work=None):
                                                          ...
                def train_sentence_cbow(model, sentence, alpha, work=None, neu1=None):
                                                           ...
class Word2Vec(utils.SaveLoad):
    def __init__(self, sentences=None, size=100, alpha=0.025, window=5, min_count=5,sample=0, seed=1, workers=1, min_alpha=0.0001, sg=1, hs=1, negative=0, cbow_mean=0):
                                                          ...
    def train(self, sentences, total_words=None, word_count=0, chunksize=100):
                if FAST_VERSION < 0:
                        import warnings
            warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
            logger.info("training model with %i workers on %i vocabulary and %i features, "
             "using 'skipgram'=%s 'hierarchical softmax'=%s 'subsample'=%s and 'negative sampling'=%s" %
              (self.workers, len(self.vocab), self.layer1_size, self.sg, self.hs, self.sample, self.negative))
                                                                   ...
        def worker_train():
                        if self.sg:
                job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
            else:
                job_words = sum(train_sentence_cbow(self, sentence, alpha, work, neu1) for sentence in job)
                                                                          ...

运行train.py,出现以下错误:

E:\Python27\python.exe D:/pycharm/TWE/TWE1/train.py wordmap.txt model-final.tassign 100
import pyximport
models_dir
pyximport
word2vec_inner.c
e:\python27\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
C:\Users\hp\.pyxbld\temp.win32-2.7\Release\pyrex\gensim\models\word2vec_inner.c(15079) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
C:\Users\hp\.pyxbld\temp.win32-2.7\Release\pyrex\gensim\models\word2vec_inner.c(15085) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
LINK : fatal error LNK1104: cannot open file 'C:\Users\hp\.pyxbld\lib.win32-2.7\gensim\models\word2vec_inner.pyd'
except2
Training the word vector...
D:\pycharm\TWE\TWE1\gensim\models\word2vec.py:410: UserWarning: Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`
warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
PROGRESS: at 100.00% words, alpha 0.02500, 2556 words/s
Training the topic vector...
D:\pycharm\TWE\TWE1\gensim\models\word2vec.py:882: UserWarning: Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`
warnings.warn("Cython compilation failed, training will be slow. Do you have Cython installed? `pip install cython`")
Exception in thread Thread-23:
Traceback (most recent call last):
File "E:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "E:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
File "D:\pycharm\TWE\TWE1\gensim\models\word2vec.py", line 909, in worker_train
job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
File "D:\pycharm\TWE\TWE1\gensim\models\word2vec.py", line 909, in <genexpr>
job_words = sum(train_sentence_topic(self, sentence, alpha, work) for sentence in job)
NameError: global name 'train_sentence_topic' is not defined

Saving the topic vectors...
Saving the word vectors...

Process finished with exit code 0

我已经安装了Microsoft Visual C++ Compiler for Python 2.7和cython,而且我也用一个小的程序测试了cython是正确编译和安装了的,但是还是出现问题。按照这个博客上的测试了cython,然后按照一个博客运行的TWE程序。看了好久,总结了应该是在word2vec.py最开始导入不了train_sentence_sg, train_sentence_cbow, FAST_VERSION, train_sentence_to。但是为什么导入不了,总觉得不应该,我成功编译了pyx文件的,cython也是正确安装了的。到底是什么问题,有大神遇到过这个问题的吗?求大神帮忙,谢谢!急急急,在线等

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!