Skip to content

Commit

Permalink
Fix memory consumption in AuthorTopicModel (#2122)
Browse files Browse the repository at this point in the history
* Fix quadratic iteration

* Update comment

* Move from list to set
  • Loading branch information
philipphager authored and piskvorky committed Jul 13, 2018
1 parent 46ccefb commit 96444a7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gensim/models/atmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,13 @@ def update(self, corpus=None, author2doc=None, doc2author=None, chunksize=None,
self.doc2author[d] = a_list

# 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)
train_corpus_idx = set()
# Collect all documents of authors.
for doc_ids in self.author2doc.values():
train_corpus_idx.update(doc_ids)

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

# train_corpus_idx is only a list of indexes, so "len" is valid.
lencorpus = len(train_corpus_idx)
Expand Down

0 comments on commit 96444a7

Please sign in to comment.