Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better error message for unsupported fastText supervised models #1645

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
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
14 changes: 3 additions & 11 deletions gensim/models/wrappers/fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ def load_model_params(self, file_handle):
self.sample = t

def load_dict(self, file_handle, encoding='utf8'):
vocab_size, nwords, _ = self.struct_unpack(file_handle, '@3i')
vocab_size, nwords, nlabels = self.struct_unpack(file_handle, '@3i')
# Vocab stored by [Dictionary::save](https://github.com/facebookresearch/fastText/blob/master/src/dictionary.cc)
if nlabels > 0:
raise NotImplementedError("Supervised fastText models are not supported")
logger.info("loading %s words for fastText model from %s", vocab_size, self.file_name)

self.struct_unpack(file_handle, '@1q') # number of tokens
Expand All @@ -309,16 +311,6 @@ def load_dict(self, file_handle, encoding='utf8'):
word = word_bytes.decode(encoding)
count, _ = self.struct_unpack(file_handle, '@qb')

if i == nwords and i < vocab_size:
# To handle the error in pretrained vector wiki.fr (French).
# For more info : https://github.com/facebookresearch/fastText/issues/218

assert word == "__label__", (
'mismatched vocab_size ({}) and nwords ({}), extra word "{}"'
.format(vocab_size, nwords, word)
)
continue # don't add word to vocab

self.wv.vocab[word] = Vocab(index=i, count=count)
self.wv.index2word.append(word)

Expand Down
Loading