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

Make token2id mapping reproducible #1715

Merged
merged 5 commits into from
Nov 23, 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
2 changes: 1 addition & 1 deletion gensim/corpora/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def doc2bow(self, document, allow_update=False, return_missing=False):

token2id = self.token2id
if allow_update or return_missing:
missing = sorted((x for x in iteritems(counter) if x[0] not in token2id), key=lambda x: (x[1], x[0]))
missing = sorted((x for x in iteritems(counter) if x[0] not in token2id), key=lambda x: x[0])
Copy link
Owner

Choose a reason for hiding this comment

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

sort works lexicographically by default; no need for the key parameter at all.

if allow_update:
for w, _ in missing:
# new id = number of ids made so far;
Expand Down