snorkel-team / snorkel

A system for quickly generating training data with weak supervision
https://snorkel.org
Apache License 2.0
5.81k stars 857 forks source link

LabelModel.fit() Not Showing Output in Jupyter Notebook/Jupyterlab Cell #1638

Closed zanussbaum closed 3 years ago

zanussbaum commented 3 years ago

Issue description

When calling LabelModel.fit() (with a verbose LabelModel), there is no output to the cell on the loss of the model. Is this expected because of errors in Jupyter? Are there any workarounds? It's tougher to gauge how well the model is doing and to tune it accordingly. Would it be possible to instead return the loss from fit() like some frameworks do?

Code example/repro steps

label_model = LabelModel(cardinality=2, verbose=False) label_model.fit(L_train=L_train, n_epochs=100, log_freq=10, seed=123, lr=3e-5)

Expected behavior

Loss printed out 10 times (100 / 10)

System info

ajratner commented 3 years ago

Hi @zanussbaum I assume you ran it with verbose=True, just to check first (says False above)? We can try to repro!

zanussbaum commented 3 years ago

Oops yes I copied the wrong code snippet. Just retried with verbose=True and still not working. However adding

logger = logging.getLogger()
logger.setLevel(logging.INFO)

seems to fix the problem. Is this an error on Jupyter's end then?

anerirana commented 3 years ago

Hi @bhancock8, @vincentschen, I checked this issue, and looks like it is not specific to Jupyter. Even when running the code on my local machine I had to specifically set the logging level to INFO, to be able to see the loss logs. The default level is WARNING. If required, I can fix it by changing the log level in _set_logger() method when check() returns True and verbose is also True. Please let me know if I should proceed with this.

bhancock8 commented 3 years ago

That's sounds reasonable. If verbose=True, then we can set the logging level for the label model's logger to be at INFO rather than WARNING. If you can make that change in a PR and tag me, I'd be happy to review and get that merged!