Как исправить код выхода при использовании Sparse_dot_top_n? - PullRequest
0 голосов
/ 03 июня 2019

Я пытаюсь сопоставить 2 набора данных.Для этого я использую функцию sparse_dot_top_n из ing (https://github.com/ing-bank/sparse_dot_topn).. Когда я пытаюсь ее использовать, я получаю код выхода. Ребята, вы хоть представляете, почему?

from scipy.sparse import csr_matrix
import sparse_dot_topn.sparse_dot_topn as ct
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer

a = {'id': [1, 2, 3], 'exp': ['aa ble', 'bb qertt', 'cc qpoer']}
b = {'id': [10, 11, 12, 13], 'exp': ['aa nmr qemr', 'bcb gerrr', 'ccc qrtggd', 'acb glr']}

df1 = pd.DataFrame(data=a)
df2 = pd.DataFrame(data=b) 

vectorizer = tfidfVectorizer()
vec1 = vectorizer.fit_transform(df1.exp)
vec2 = vectorizer.fit_transform(df2.exp)

def awesome_cossim_top(A, B, ntop, lower_bound=0):
    # force A and B as a CSR matrix.
    # If they have already been CSR, there is no overhead
    A = A.tocsr()
    B = B.tocsr()
    M, _ = A.shape
    _, N = B.shape

    idx_dtype = np.int32

    nnz_max = M * ntop

    indptr = np.zeros(M + 1, dtype=idx_dtype)
    indices = np.zeros(nnz_max, dtype=idx_dtype)
    data = np.zeros(nnz_max, dtype=A.dtype)

    ct.sparse_dot_topn(
        M, N, np.asarray(A.indptr, dtype=idx_dtype),
        np.asarray(A.indices, dtype=idx_dtype),
        A.data,
        np.asarray(B.indptr, dtype=idx_dtype),
        np.asarray(B.indices, dtype=idx_dtype),
        B.data,
        ntop,
        lower_bound,
        indptr, indices, data)

    return csr_matrix((data, indices, indptr), shape=(M, N))

matches = awesome_cossim_top(vec1, vec2, 2, 0.4)

Я получаю это Process finished with exit code -1073741819 (0xC0000005)

...