Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object is not subscriptable` Node2Vec #27

Closed
timilsinamohan opened this issue Dec 21, 2020 · 2 comments
Closed

TypeError: 'NoneType' object is not subscriptable` Node2Vec #27

timilsinamohan opened this issue Dec 21, 2020 · 2 comments

Comments

@timilsinamohan
Copy link

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

@VHRanger
Copy link
Owner

VHRanger commented Dec 22, 2020

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

@VHRanger
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants