Search code examples
pythonwarningsfasttext

Can't suppress fasttext warning: 'load_model' does not return [...]


I'm struggling to suppress a specific warning related to fasttext.

The warning is Warning : 'load_model' does not return WordVectorModel or SupervisedModel any more, but a 'FastText' object which is very similar.

And here is the offending block of code:

with warnings.catch_warnings():
    warnings.filterwarnings('ignore')
    return fasttext.load_model(str(model_path))  # this line

I've attempted several ways to suppress the warning, mostly from this thread without success.

I'm using Python 3.8, fasttext v0.9.2.


Solution

  • For fasttext v0.9.2 this can be solved by adding the monkey patch below to your code (as per this GitHub issue).

    import fasttext
    
    fasttext.FastText.eprint = lambda x: None
    

    As mentioned in that same GitHub issue, the warning message was removed in this commit in May 2020, which will likely be in the next official release (v0.9.3), whenever that is.