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 memory consumption in AuthorTopicModel #2122

Merged
merged 3 commits into from
Jul 13, 2018
Merged
Changes from 2 commits
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
6 changes: 3 additions & 3 deletions gensim/models/atmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,9 @@ def update(self, corpus=None, author2doc=None, doc2author=None, chunksize=None,

# Train on all documents of authors in input_corpus.
train_corpus_idx = []
for _ in author2doc.keys(): # For all authors in input corpus.
for doc_ids in self.author2doc.values(): # For all documents in total corpus.
train_corpus_idx.extend(doc_ids)
# Collect all documents of authors.
for doc_ids in self.author2doc.values():
train_corpus_idx.extend(doc_ids)
Copy link
Owner

Choose a reason for hiding this comment

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

Why keep train_corpus_idx as list in the first place? It looks like it's converted to a set right below, so maybe better to make it a set from the start?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is true, indeed. I would propose something like this:

# Train on all documents of authors in input_corpus.
train_corpus_idx = set()
# Collect all documents of authors.
for doc_ids in self.author2doc.values():
    train_corpus_idx.update(doc_ids)

train_corpus_idx = list(train_corpus_idx)

Copy link
Owner

Choose a reason for hiding this comment

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

I'm not familiar with the algo, but for the sake of reproducibility, I'd replace list(train_corpus_idx) with sorted(train_corpus_idx). That will remove randomness from the ordering of values, while still producing a list.


# Make the list of training documents unique.
train_corpus_idx = list(set(train_corpus_idx))
Expand Down