gensim.similarities.SparseMatrixSimilarity get segmentation-

gensim.similarities.SparseMatrixSimilarity get segmentation-fault

本文关键字:segmentation- get SparseMatrixSimilarity similarities gensim      更新时间:2023-10-16

我想将一个文档的相似性与其他文档相似。我使用Gensim。该程序可以正确运行,但是经过一些步骤后,它会以细分故障退出。

以下是我的代码:

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]

它可以正常运行,直到获得SIMS,但是无法获得SIMS,并且使用gdb获取以下信息:

程序接收到信号sigsegv,分段故障。 CSR_TOCSC中的0x00007FFD881D809(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/稀疏/sparsetools/csr.h:没有没有。

我得到了github的答案

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

相同