Skip to content

Commit

Permalink
GH-162: fix serialization issue for legacy models
Browse files Browse the repository at this point in the history
  • Loading branch information
aakbik committed Oct 19, 2018
1 parent 2956631 commit a09837b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions flair/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,16 @@ def embedding_length(self) -> int:

def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:

cache_path = '{}-tmp-cache.sqllite'.format(self.name) if self.cache_directory is None else os.path.join(
self.cache_directory, '{}-tmp-cache.sqllite'.format(os.path.basename(self.name)))

# by default, use_cache is false (for older pre-trained models TODO: remove in version 0.4)
if 'cache' not in self.__dict__ or 'cache_directory' not in self.__dict__ or not os.path.exists(cache_path):
# this whole block is for compatibility with older serialized models TODO: remove in version 0.4
if 'cache' not in self.__dict__ or 'cache_directory' not in self.__dict__:
self.use_cache = False
self.cache_directory = None
else:
cache_path = '{}-tmp-cache.sqllite'.format(self.name) if not self.cache_directory else os.path.join(
self.cache_directory, '{}-tmp-cache.sqllite'.format(os.path.basename(self.name)))
if not os.path.exists(cache_path):
self.use_cache = False
self.cache_directory = None

# if cache is used, try setting embeddings from cache first
if self.use_cache:
Expand Down

0 comments on commit a09837b

Please sign in to comment.