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

support python 3+ on learn_embedding method. #87

Open
ghost opened this issue Jan 4, 2020 · 6 comments
Open

support python 3+ on learn_embedding method. #87

ghost opened this issue Jan 4, 2020 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 4, 2020

learn_embeddings needs minor modification to accept the python3+ 's map function. implemented below

def learn_embeddings(walks):
'''
Learn embeddings by optimizing the Skipgram objective using SGD.
'''
#print(type(walks))
#walks = [map(str, walk) for walk in walks]
walks= [str(j) for i in walks for j in i]

@ghost
Copy link
Author

ghost commented Jan 7, 2020

Actually that alone does not fix the issue with Python3 implementation. Above solution I offered has to be changed to the following.

def learn_embeddings(walks):
'''
Learn embeddings by optimizing the Skipgram objective using SGD.
'''
walks = [str(walk) for walk in walks]

model = Word2Vec([walks], size=args.dimensions, window=args.window_size, min_count=1, sg=1, workers=args.workers, iter=args.iter) 	
model.wv.save_word2vec_format(args.output)

print('vocalublary', list(model.wv.vocab), 'length', len(list(model.wv.vocab)))

return

@wen-fei
Copy link

wen-fei commented Feb 1, 2020

why you add '[]' for variable 'walks' again? this mean get walk list embedding instead of node in walks?

@wen-fei
Copy link

wen-fei commented Feb 1, 2020

fix at #35

@liun-online
Copy link

hi, thanks your modification! But in my try, walks = [str(walk) for walk in walks] doesn't work, and the final embeddings are of random walks rather than nodes. In my opinion, only list() is needed. Maybe, you can try this walks = [list(map(str, walk)) for walk in walks]. Meanwhile, '[]' can be removed.

@RuYunW
Copy link

RuYunW commented Dec 3, 2020

can change this sentence to
walks = np.array(walks, dtype=str).tolist()

the origin map function aims to change the type of each element into str

@shoegazerstella
Copy link

shoegazerstella commented Feb 9, 2021

The following works fine on python3:


def learn_embeddings(walks):
	'''
	Learn embeddings by optimizing the Skipgram objective using SGD.
	'''
	walks = [list(map(str, walk)) for walk in walks]
	model = Word2Vec(walks, size=args.dimensions, window=args.window_size, min_count=0, sg=1, workers=args.workers, iter=args.iter)
	model.wv.save_word2vec_format(args.output)

	print('vocalublary', list(model.wv.vocab), 'length', len(list(model.wv.vocab)))
	
	return

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

4 participants