Skip to content

Commit

Permalink
Ensure next_index available when loading old stored KeyedVectors mode…
Browse files Browse the repository at this point in the history
…ls (#3117)

* fix #3114: ensure next_index available

* rm trailing whitespace
  • Loading branch information
gojomo authored Mar 18, 2022
1 parent a936521 commit 766b9e1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def _load_specials(self, *args, **kwargs):
# fixup rename of vocab into map
if 'key_to_index' not in self.__dict__:
self._upconvert_old_vocab()
# ensure older instances have next_index
if not hasattr(self, 'next_index'):
self.next_index = len(self)

def _upconvert_old_vocab(self):
"""Convert a loaded, pre-gensim-4.0.0 version instance that had a 'vocab' dict of data objects."""
Expand Down

0 comments on commit 766b9e1

Please sign in to comment.