Fasttext: Python load_model outputs blank lines to the console

Created on 21 Sep 2019  路  3Comments  路  Source: facebookresearch/fastText

The python bindings don't seem to have a way to run in silent or quiet mode. Simply loading a model prints a blank line to the screen.

For example, this simple script does nothing but load a model:

#!/usr/bin/env python3

import fasttext

model = fasttext.load_model('lid.176.ftz')

The script itself does not print anything to the console, but load_model prints a blank line:

$ ./test_fasttext.py

$

Python version 3.7.4 with fasttext version 0.9.1 on Linux.

bug

Most helpful comment

I also came across this issue. It was particularly annoying, since it would bubble an empty line (instead of the warning) to stderr every time I'd load the model. For this particular case, I had to apply the model across rows of a dask dataframe, and it can't be serialized, so I have that same function also load the model. This led to a bunch of empty lines being bubbled up to stderr.

To hack around it, I just did the following:

import fasttext
fasttext.FastText.eprint = print

Then I was able to see the print statement. From there, silencing the statement was simple:

with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
    model = fasttext.load_model('lid.176.bin')

Hope this helps someone else!

All 3 comments

Hi @alanorth ,
Thank you for reporting the issue.

We will have a look.
Regards,
Onur

@Celebio it seems this line causes the blank line to print when you use load_module:

eprint("Warning : `load_model` does not return WordVectorModel or SupervisedModel any more, but a `FastText` object which is very similar.")

I commented it out and compiled the module locally and tested with a simple script test.py:

#!/usr/bin/env python3

import fasttext

model = fasttext.load_model('lid.176.ftz')

I also came across this issue. It was particularly annoying, since it would bubble an empty line (instead of the warning) to stderr every time I'd load the model. For this particular case, I had to apply the model across rows of a dask dataframe, and it can't be serialized, so I have that same function also load the model. This led to a bunch of empty lines being bubbled up to stderr.

To hack around it, I just did the following:

import fasttext
fasttext.FastText.eprint = print

Then I was able to see the print statement. From there, silencing the statement was simple:

with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
    model = fasttext.load_model('lid.176.bin')

Hope this helps someone else!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shriiitk picture shriiitk  路  3Comments

yasonk picture yasonk  路  3Comments

ereday picture ereday  路  3Comments

pengyu picture pengyu  路  3Comments

hughbzhang picture hughbzhang  路  3Comments