TypeError: 'NoneType' object is not subscriptable` Node2Vec
timilsinamohan opened this issue · 2 comments
Hi,
Thanks for this great module. I have a large sparse csr graph of 10GB and I wanted to learn the node embedding using Node2Vec. However, I am keep getting this error:
TypeError: 'NoneType' object is not subscriptable
To reproduce this error in my machine here is my toy script:
from scipy.sparse import csr_matrix
import numpy as np
import nodevectors
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 1, 1, 1, 1, 1])
G = csr_matrix((data, (row, col)), shape=(3, 3))
n2v_model = nodevectors.Node2Vec()
n2v_model.fit(G)
Isn't it true that Node2Vec() module directly works with csr_matrix? I even tried the converting CSR matrix to CSRGraphs but stll get the same error. Any help would be great?
import csrgraph as cg
G = cg.csrgraph(G)
n2v_model = nodevectors.Node2Vec()
n2v_model.fit(G)
TypeError: 'NoneType' object is not subscriptable
Seems to be a bug in node names for some types of csr matrix input.
For now you could manually add node names:
import csrgraph as cg
from scipy.sparse import csr_matrix
import numpy as np
import nodevectors
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 1, 1, 1, 1, 1])
G = csr_matrix((data, (row, col)), shape=(3, 3))
# Note nodenames parameter manually added
G = cg.csrgraph(G, nodenames=[0,1,2])
n2v_model = nodevectors.Node2Vec()
n2v_model.fit(G)
Should work.
I'll find a fix and push it to the csrgraph library as soon as I can.z
Actually, nevermind, this was already fixed in the latest version of csrgraph
.
Please just update csrgraph
to version 0.1.27 and your example should just work right away.
I'll close it for now, feel free to open another issue if you have one!