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

Fix wordrank max_iter_dump calculation. Fix #1216 #1217

Merged
merged 3 commits into from
Mar 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gensim/models/wrappers/wordrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def train(cls, wr_path, corpus_file, out_path, size=100, window=15, symmetric=1,
with smart_open(meta_file, 'wb') as f:
meta_info = "{0} {1}\n{2} {3}\n{4} {5}".format(numwords, numwords, numlines, cooccurrence_shuf_file, numwords, vocab_file)
f.write(meta_info.encode('utf-8'))

if iter % dump_period == 0:
iter += 1
else:
logger.warning('Resultant embedding would be from %d iteration', iter - iter % dump_period)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this warning tells the user nothing -- can you rephrase/add context/suggestions what to do about it?

Also, iteration => iterations and dump_period as an argument to warning(), rather than formatted string.


wr_args = {
'path': 'meta',
Expand Down Expand Up @@ -141,7 +146,7 @@ def train(cls, wr_path, corpus_file, out_path, size=100, window=15, symmetric=1,
output = utils.check_output(args=cmd)

# use embeddings from max. iteration's dump
max_iter_dump = (iter - 1) - (iter - 1) % dump_period
max_iter_dump = iter - iter % dump_period
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use explicit brackets, don't rely on operator precedence.

copyfile('model_word_%d.txt' % max_iter_dump, 'wordrank.words')
copyfile('model_context_%d.txt' % max_iter_dump, 'wordrank.contexts')
model = cls.load_wordrank_model('wordrank.words', os.path.join('meta', vocab_file), 'wordrank.contexts', sorted_vocab, ensemble)
Expand Down