简体   繁体   中英

Use huggingface transformers without IPyWidgets

I am trying to use the huggingface transformers library in a hosted Jupyter notebook platform called Deepnote. I want to download a model through the pipeline class but unfortunately deepnote does not support IPyWidgets. Is there a way to disable IPywidgets when using transformers? Specifically the below command.


classifier = pipeline("zero-shot-classification")

And the error I receive.

ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

Note: Installing IPyWidgets is not an option

You have to disable transformers logging. Even though it is possible to use transformers.logging.set_verbosity to change the log level, it's not possible to set it to logging.NOTSET which is required to skip using IProgress and tqdm . So we need to hack it like this:

import transformers
import logging
transformers.logging.get_verbosity = lambda: logging.NOTSET

# transformers.logging.get_verbosity()

After that you should be able to use:

from transformers import pipeline
pipeline('sentiment-analysis')('we love you')

Check out my Deepnote project for details;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM