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

[BUG] type error when running node2vec_embed #800

Closed
diane-lee-01 opened this issue Jun 17, 2021 · 6 comments · Fixed by #789
Closed

[BUG] type error when running node2vec_embed #800

diane-lee-01 opened this issue Jun 17, 2021 · 6 comments · Fixed by #789
Labels
bug Something isn't working

Comments

@diane-lee-01
Copy link
Contributor

Expected Behavior

Generate a node2vec embedding of the input graph

Actual Behavior

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' occurs during the _preprocess_transition_probabilities() step in node2vec_embed. I'm not sure why, but unnormalized_probs is currently a list of all 'None's.

Example Code

g = nx.erdos_renyi_graph(10, 0.7, directed=False)
tensors, labels = node2vec_embed(g, dimensions=128, num_walks=10, window_size=2, iterations=3)

The parameters are from layouts\auto.py

Full Traceback

 File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\layouts\test_n2v.py", line 5, in <module>
    tensors, labels = node2vec_embed(g)
  File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\embed\n2v.py", line 116, in node2vec_embed
    node2vec_graph._preprocess_transition_probabilities()
  File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\embed\n2v.py", line 437, in _preprocess_transition_probabilities
    norm_const = sum(unnormalized_probs)
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Your Environment

  • Python version: 3.9

Additional Details

Same error occurs for directed graphs too.

@diane-lee-01 diane-lee-01 added the bug Something isn't working label Jun 17, 2021
@bdpedigo
Copy link
Collaborator

@nyecarr any ideas?

@nicaurvi nicaurvi linked a pull request Jun 21, 2021 that will close this issue
4 tasks
@nicaurvi
Copy link
Contributor

Yup, this n2v impl stumbled on unweighted graphs and doesn't really give a good error message. I have a PR that will default weights to 1 and raise a warning for unweighted graphs.

@nicaurvi
Copy link
Contributor

In the meantime, if you are still blocked, you can do something like:

for s, t in g.edges():
    g.add_edge(s, t, weight=1)  # re-add each edge with weight=1

@diane-lee-01
Copy link
Contributor Author

@Nyecarr Thanks so much, that worked!

I think Word2Vec might have changed the names of some of their arguments though, because I got this error as well:

  File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\layouts\test_n2v.py", line 7, in <module>
    tensors, labels = node2vec_embed(g,dimensions=128,num_walks=10,window_size=2,iterations=3)
  File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\embed\n2v.py", line 124, in node2vec_embed
    model = _learn_embeddings(
  File "C:\Users\d0156\OneDrive\Documents\GitHub\graspologic\graspologic\embed\n2v.py", line 205, in _learn_embeddings
    model = Word2Vec(
TypeError: __init__() got an unexpected keyword argument 'size'

And so I changed the arguments 'size' to 'vector_size' and 'iter' to 'epochs' (according to their new documentation) when I was running it. Super minor, but still wanted to let you know.

Again, thanks so much!

@bdpedigo
Copy link
Collaborator

i believe that was the reason for pinning gensim's version https://github.com/microsoft/graspologic/blob/5ed36484d32a6ed79db1b7ea087d93fc238df613/setup.cfg#L29

what version of gensim are you running @dlee0156?

@diane-lee-01
Copy link
Contributor Author

Ohhh I see, I just downloaded the most recent version which was 4.0.1. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants