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.
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!
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:
Then I was able to see the print statement. From there, silencing the statement was simple:
Hope this helps someone else!