# Buggy code
def load_dict(self, file_handle, encoding="utf8"):
    vocab_size, nwords, _ = self.struct_unpack(file_handle, "@3i")
    # Vocab stored by [Dictionary::save](https://github.com/facebookresearch/fastText/blob/master/src/dictionary.cc)
    assert len(self.wv.vocab) == nwords, "mismatch between vocab sizes"
    assert len(self.wv.vocab) == vocab_size, "mismatch between vocab sizes"
    self.struct_unpack(file_handle, "@1q")  # number of tokens
    if self.new_format:
        (pruneidx_size,) = self.struct_unpack(file_handle, "@q")
    for i in range(nwords):
        word_bytes = b""
        char_byte = file_handle.read(1)
        # Read vocab word
        while char_byte != b"\x00":
            word_bytes += char_byte
            char_byte = file_handle.read(1)
        word = word_bytes.decode(encoding)
        count, _ = self.struct_unpack(file_handle, "@qb")
        assert self.wv.vocab[word].index == i, (
            "mismatch between gensim word index and fastText word index"
        )
        self.wv.vocab[word].count = count

    if self.new_format:
        for j in range(pruneidx_size):
            self.struct_unpack(file_handle, "@2i")


# Traceback (AssertionError)
Traceback (most recent call last):
File "app.py", line 18, in <module>
model = FastText.load_fasttext_format(os.path.abspath('./wiki.fr'))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/wrappers/fasttext.py", line 238, in load_fasttext_format
model.load_binary_data('%s.bin' % model_file)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/wrappers/fasttext.py", line 255, in load_binary_data
self.load_dict(f)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gensim/models/wrappers/fasttext.py", line 277, in load_dict
assert len(self.wv.vocab) == vocab_size, 'mismatch between vocab sizes'
AssertionError: mismatch between vocab sizes

# Fixed code
def load_dict(self, file_handle, encoding="utf8"):
    vocab_size, nwords, _ = self.struct_unpack(file_handle, "@3i")
    # Vocab stored by [Dictionary::save](https://github.com/facebookresearch/fastText/blob/master/src/dictionary.cc)
    logger.info(
        "loading %s words for fastText model from %s", vocab_size, self.file_name
    )

    self.struct_unpack(file_handle, "@1q")  # number of tokens
    if self.new_format:
        (pruneidx_size,) = self.struct_unpack(file_handle, "@q")
    for i in range(vocab_size):
        word_bytes = b""
        char_byte = file_handle.read(1)
        # Read vocab word
        while char_byte != b"\x00":
            word_bytes += char_byte
            char_byte = file_handle.read(1)
        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)

    assert len(self.wv.vocab) == nwords, (
        "mismatch between final vocab size ({} words), "
        "and expected number of words ({} words)".format(len(self.wv.vocab), nwords)
    )
    if len(self.wv.vocab) != vocab_size:
        # expecting to log this warning only for pretrained french vector, wiki.fr
        logger.warning(
            "mismatch between final vocab size (%s words), and expected vocab size (%s words)",
            len(self.wv.vocab),
            vocab_size,
        )

    if self.new_format:
        for j in range(pruneidx_size):
            self.struct_unpack(file_handle, "@2i")