Skip to content

Commit

Permalink
Changed import method to fix travis cyclic dependency fail
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolgulati committed Jan 28, 2017
1 parent 6c74483 commit 5b78e5d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gensim/models/wrappers/varembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import logging
try:
import morfessor
from morfessor.io import MorfessorIO
MORFESSOR_AVAILABLE = 1
except ImportError:
# Morfessor Package not found. Will only allow reading varembed vectors without morpheme embeddings.
Expand Down Expand Up @@ -75,7 +75,7 @@ def load_varembed_format(cls, vectors, morfessor_model=None, use_morphemes=False
if MORFESSOR_AVAILABLE == -1:
logger.warning('Could not import morfessor. Not using morpheme embeddings')
else:
morfessor_model = morfessor.MorfessorIO().read_binary_model_file(morfessor_model)
morfessor_model = MorfessorIO().read_binary_model_file(morfessor_model)
result.ensemble_morpheme_embeddings(morfessor_model, morpho_embeddings, morpho_to_ix)
logger.info('Loaded varembed model vectors from %s', vectors)
return result
Expand All @@ -89,7 +89,6 @@ def load_word_embeddings(self, word_embeddings, word_to_ix):
counts[word] = counts.get(word, 0) + 1
self.vocab_size = len(counts)
self.vector_size = word_embeddings.shape[1]

self.wv.syn0 = np.zeros((self.vocab_size, self.vector_size))
self.wv.index2word = [None]*self.vocab_size
logger.info("Corpus has %i words", len(self.wv.vocab))
Expand All @@ -102,6 +101,7 @@ def load_word_embeddings(self, word_embeddings, word_to_ix):


def ensemble_morpheme_embeddings(self, morfessor_model, morpho_embeddings, morpho_to_ix):
""" Method to include morpheme embeddings into varembed vectors """
for word in self.wv.vocab:
morpheme_embedding = np.array(
[morpho_embeddings[morpho_to_ix.get(m, -1)] for m in
Expand Down

0 comments on commit 5b78e5d

Please sign in to comment.