Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Python load_model outputs blank lines to the console #909

Closed
alanorth opened this issue Sep 21, 2019 · 3 comments
Closed

Python load_model outputs blank lines to the console #909

alanorth opened this issue Sep 21, 2019 · 3 comments
Labels

Comments

@alanorth
Copy link

alanorth commented Sep 21, 2019

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.

@Celebio Celebio added the bug label Sep 23, 2019
@Celebio
Copy link
Member

Celebio commented Sep 23, 2019

Hi @alanorth ,
Thank you for reporting the issue.

We will have a look.
Regards,
Onur

@alanorth
Copy link
Author

alanorth commented Oct 1, 2019

@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')

@dataframing
Copy link

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!

facebook-github-bot pushed a commit that referenced this issue Dec 23, 2019
Summary: This commit fixes the issue reported on #909

Reviewed By: EdouardGrave

Differential Revision: D17630124

fbshipit-source-id: 9a9120b485711647266b547c6910633f83b3155f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants