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

unsupported operand type(s) for +: 'int' and 'str' #16

Open
tohich51 opened this issue May 22, 2019 · 5 comments
Open

unsupported operand type(s) for +: 'int' and 'str' #16

tohich51 opened this issue May 22, 2019 · 5 comments

Comments

@tohich51
Copy link

@tohich51 tohich51 commented May 22, 2019

I got this issue using struc2vec and node2vec methods
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
1 model_struc2vec = ge.Struc2Vec(G, 10, 80, workers=4, verbose=40, ) #init model
----> 2 model_struc2vec.train(window_size = 5, iter = 3)# train model
3 embeddings_struc2vec = model_struc3vec.get_embeddings()# get embedding vectors

/anaconda3/envs/python36/lib/python3.6/site-packages/ge-0.0.0-py3.6.egg/ge/models/struc2vec.py in train(self, embed_size, window_size, workers, iter)
114 print("Learning representation...")
115 model = Word2Vec(sentences, size=embed_size, window=window_size, min_count=0, hs=1, sg=1, workers=workers,
--> 116 iter=iter)
117 print("Learning representation done!")
118 self.w2v_model = model

/anaconda3/envs/python36/lib/python3.6/site-packages/gensim-3.6.0-py3.6-macosx-10.7-x86_64.egg/gensim/models/word2vec.py in init(self, sentences, corpus_file, size, alpha, window, min_count, max_vocab_size, sample, seed, workers, min_alpha, sg, hs, negative, ns_exponent, cbow_mean, hashfxn, iter, null_word, trim_rule, sorted_vocab, batch_words, compute_loss, callbacks, max_final_vocab)
765 callbacks=callbacks, batch_words=batch_words, trim_rule=trim_rule, sg=sg, alpha=alpha, window=window,
766 seed=seed, hs=hs, negative=negative, cbow_mean=cbow_mean, min_alpha=min_alpha, compute_loss=compute_loss,
--> 767 fast_version=FAST_VERSION)
768
769 def _do_train_epoch(self, corpus_file, thread_id, offset, cython_vocab, thread_private_mem, cur_epoch,

/anaconda3/envs/python36/lib/python3.6/site-packages/gensim-3.6.0-py3.6-macosx-10.7-x86_64.egg/gensim/models/base_any2vec.py in init(self, sentences, corpus_file, workers, vector_size, epochs, callbacks, batch_words, trim_rule, sg, alpha, window, seed, hs, negative, ns_exponent, cbow_mean, min_alpha, compute_loss, fast_version, **kwargs)
757 raise TypeError("You can't pass a generator as the sentences argument. Try an iterator.")
758
--> 759 self.build_vocab(sentences=sentences, corpus_file=corpus_file, trim_rule=trim_rule)
760 self.train(
761 sentences=sentences, corpus_file=corpus_file, total_examples=self.corpus_count,

/anaconda3/envs/python36/lib/python3.6/site-packages/gensim-3.6.0-py3.6-macosx-10.7-x86_64.egg/gensim/models/base_any2vec.py in build_vocab(self, sentences, corpus_file, update, progress_per, keep_raw_vocab, trim_rule, **kwargs)
941 trim_rule=trim_rule, **kwargs)
942 report_values['memory'] = self.estimate_memory(vocab_size=report_values['num_retained_words'])
--> 943 self.trainables.prepare_weights(self.hs, self.negative, self.wv, update=update, vocabulary=self.vocabulary)
944
945 def build_vocab_from_freq(self, word_freq, keep_raw_vocab=False, corpus_count=None, trim_rule=None, update=False):

/anaconda3/envs/python36/lib/python3.6/site-packages/gensim-3.6.0-py3.6-macosx-10.7-x86_64.egg/gensim/models/word2vec.py in prepare_weights(self, hs, negative, wv, update, vocabulary)
1820 # set initial input/projection and hidden weights
1821 if not update:
-> 1822 self.reset_weights(hs, negative, wv)
1823 else:
1824 self.update_weights(hs, negative, wv)

/anaconda3/envs/python36/lib/python3.6/site-packages/gensim-3.6.0-py3.6-macosx-10.7-x86_64.egg/gensim/models/word2vec.py in reset_weights(self, hs, negative, wv)
1837 for i in xrange(len(wv.vocab)):
1838 # construct deterministic seed from word AND seed argument
-> 1839 wv.vectors[i] = self.seeded_vector(wv.index2word[i] + str(self.seed), wv.vector_size)
1840 if hs:
1841 self.syn1 = zeros((len(wv.vocab), self.layer1_size), dtype=REAL)

TypeError: unsupported operand type(s) for +: 'int' and 'str'
`

@wwb306
Copy link

@wwb306 wwb306 commented Jul 18, 2019

节点类型要求是str类型

@DanielChen98
Copy link

@DanielChen98 DanielChen98 commented Oct 8, 2019

do you deal with this problem, I got the same problem

@tohich51
Copy link
Author

@tohich51 tohich51 commented Oct 9, 2019

No, i didn't manage to fix it

@ldmtwo
Copy link

@ldmtwo ldmtwo commented Jun 8, 2020

I encountered this using FastText, which also uses the same Word2Vec backend from gensim. It seems the model was corrupt in my case. No idea why, but I started a new training cycle to move on.

And that code they use is really weird: wv.index2word[i] + str(self.seed)

@radkoff
Copy link

@radkoff radkoff commented Jul 19, 2020

For me, this happened when using a graph with integer node names. String nodes worked fine. If you don't want to wait for a fix in gensim, you can relabel them with relabel_nodes().

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.