Skip to content
Open
Changes from all 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
5 changes: 3 additions & 2 deletions lda2vec/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def _loose_keys_ordered(self):
""" Get the loose keys in order of decreasing frequency"""
loose_counts = sorted(self.counts_loose.items(), key=lambda x: x[1],
reverse=True)
loose_counts = [i for i in loose_counts if i[0] not in self.specials.values()]
keys = np.array(loose_counts)[:, 0]
counts = np.array(loose_counts)[:, 1]
order = np.argsort(counts)[::-1].astype('int32')
Expand Down Expand Up @@ -415,7 +416,7 @@ def compact_to_flat(self, word_compact, *components):
self._check_finalized()
n_docs = word_compact.shape[0]
max_length = word_compact.shape[1]
idx = word_compact > self.n_specials
idx = word_compact >= self.n_specials
components_raveled = []
msg = "Length of each component must much `word_compact` size"
for component in components:
Expand Down Expand Up @@ -552,7 +553,7 @@ def compact_word_vectors(self, vocab, filename=None, array=None,
rep1 = lambda w: w.replace(' ', '_')
rep2 = lambda w: w.title().replace(' ', '_')
reps = [rep0, rep1, rep2]
for compact in np.arange(top):
for compact in np.arange(min(top, n_words)):
loose = self.compact_to_loose.get(compact, None)
if loose is None:
continue
Expand Down