2

I am trying to load a trained fasttext model using gensim. The model has been trained on some data. Earlier, I have used model.save() with a extension of .bin to use it later. After the training process and saving the model using model.save in .bin format, generates 3 files respectively. They are:

1) .bin

2) bin.trainable vectors_ngrams_lockf

3) bin.wv.vectors_ngrams

Now I am unable to load the trained binary file (.bin).

But I don't understand why I am getting a error named:

raise NotImplementedError("Supervised fastText models are not supported") NotImplementedError: Supervised fastText models are not supported

After going through many blogs, peoples have suggested that gensim does not supports supervised training. It's fine. My question is how can I be able to load the trained binary model. Shall I need to train the model differently.

Any help is appreciated.

What I have tried after the training process:

import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
from gensim.models import FastText, fasttext
model = FastText.load_fasttext_format('m1.bin')
print(model)
M S
  • 894
  • 1
  • 13
  • 41

1 Answers1

2

If the model was saved with gensim's native .save() method, you'd load it with .load() - not load_fasttext_format(), which is only for models saved in the raw format used by Facebook's original FastText C++ code.

gojomo
  • 52,260
  • 14
  • 86
  • 115
  • Okay thanks gojomo I will try this. Does there is a need to import something in this case? I mean it will work with the module, from gensim.models import FastText. – M S Mar 14 '20 at 20:10
  • Yeah I have used and save the model using the native `model•save(name.bin)`. I have trained model with parameters as dimension, window, minimum_count and iteration. Does there is a need to specify the training type. I mean supervised or unsupervised. Shall this need to be specified during the training. – M S Mar 14 '20 at 20:14
  • 1
    If you trained the model with `gensim`, it's not a supervised-mode FT model, because `gensim` doesn't support that. Yes, it's the `FastText.load()` class method you'd use to load a `FastText` model that was previously `.save()`d. See: https://radimrehurek.com/gensim/models/fasttext.html#gensim.models.fasttext.FastText.load – gojomo Mar 14 '20 at 20:18