gensim.similarities.SparseMatrixSimilarity得到分段错误

时间:2018-02-07 10:16:11

标签: python c++ segmentation-fault gensim

我希望获得一个文档与其他文档的相似性。我用gensim。该程序可以正常运行,但经过一些步骤后,它会以Segmentation fault退出。

以下是我的代码:

from gensim import corpora, models, similarities
docs = [['Looking', 'for', 'the', 'meanings', 'of', 'words'],
        ['phrases'],
        ['and', 'expressions'],
        ['We', 'provide', 'hundreds', 'of', 'thousands', 'of', 'definitions'],
        ['synonyms'],
        ['antonyms'],
        ['and', 'pronunciations', 'for', 'English', 'and', 'other', 'languages'],
        ['derived', 'from', 'our', 'language', 'research', 'and', 'expert', 'analysis'],
        ['We', 'also', 'offer', 'a', 'unique', 'set', 'of', 'examples', 'of', 'real', 'usage'],
        ['as', 'well', 'as', 'guides', 'to:']]
dictionary = corpora.Dictionary(docs)
corpus = [dictionary.doc2bow(text) for text in docs]
nf=len(dictionary.dfs)
index = similarities.SparseMatrixSimilarity(corpus, num_features=nf)
phrases = [['This',
            'section',
            'gives',
            'guidelines',
            'on',
            'writing',
            'in',
            'everyday',
            'situations'],
           ['from',
            'applying',
            'for',
            'a',
            'job',
            'to',
            'composing',
            'letters',
            'of',
            'complaint',
            'or',
            'making',
            'an',
            'insurance',
            'claim'],
           ['There',
            'are',
            'plenty',
            'of',
            'sample',
            'documents',
            'to',
            'help',
            'you',
            'get',
            'it',
            'right',
            'every',
            'time'],
           ['create',
            'a',
            'good',
            'impression'],
           ['and',
            'increase',
            'the',
            'likelihood',
            'of',
            'achieving',
            'your',
            'desired',
            'outcome']]
phrase2word=[dictionary.doc2bow(text,allow_update=True) for text in phrases]
sims=index[phrase2word]

它可以正常运行直到获得SIM卡,但它无法获得SIM卡,使用gdb获取以下信息:

  

编程接收信号SIGSEGV,分段故障。   csr_tocsc中的0x00007fffd881d809(n_row = 5,n_col = 39,   Ap = 0x4a4eb10,Aj = 0x9fc6ec0,Ax = 0x1be4a00,Bp = 0xa15f6a0,Bi = 0x9f3ee80,   Bx = 0x9f85f60)在scipy / sparse / sparsetools / csr.h:411 411
  scipy / sparse / sparsetools / csr.h:没有那个文件或目录。

1 个答案:

答案 0 :(得分:0)

I have get the answer from github

主要原因是num_features应该与dictionary.dfs相同