Logging¶
🤗 Transformers has a centralized logging system, so that you can setup the verbosity of the library easily.
Currently the default verbosity of the library is WARNING
.
To change the level of verbosity, just use one of the direct setters. For instance, here is how to change the verbosity to the INFO level.
import transformers
transformers.logging.set_verbosity_info()
You can also use the environment variable TRANSFORMERS_VERBOSITY
to override the default verbosity. You can set it
to one of the following: debug
, info
, warning
, error
, critical
. For example:
TRANSFORMERS_VERBOSITY=error ./myprogram.py
All the methods of this logging module are documented below, the main ones are
transformers.logging.get_verbosity()
to get the current level of verbosity in the logger and
transformers.logging.set_verbosity()
to set the verbosity to the level of your choice. In order (from the least
verbose to the most verbose), those levels (with their corresponding int values in parenthesis) are:
transformers.logging.CRITICAL
ortransformers.logging.FATAL
(int value, 50): only report the most critical errors.transformers.logging.ERROR
(int value, 40): only report errors.transformers.logging.WARNING
ortransformers.logging.WARN
(int value, 30): only reports error and warnings. This the default level used by the library.transformers.logging.INFO
(int value, 20): reports error, warnings and basic information.transformers.logging.DEBUG
(int value, 10): report all information.
Base setters¶
-
transformers.logging.
set_verbosity_error
()¶ Set the verbosity to the
ERROR
level.
-
transformers.logging.
set_verbosity_warning
()¶ Set the verbosity to the
WARNING
level.
-
transformers.logging.
set_verbosity_info
()¶ Set the verbosity to the
INFO
level.
-
transformers.logging.
set_verbosity_debug
()¶ Set the verbosity to the
DEBUG
level.
Other functions¶
-
transformers.logging.
get_verbosity
() → int¶ Return the current level for the 🤗 Transformers’s root logger as an int.
- Returns
The logging level.
- Return type
int
Note
🤗 Transformers has following logging levels:
50:
transformers.logging.CRITICAL
ortransformers.logging.FATAL
40:
transformers.logging.ERROR
30:
transformers.logging.WARNING
ortransformers.logging.WARN
20:
transformers.logging.INFO
10:
transformers.logging.DEBUG
-
transformers.logging.
set_verbosity
(verbosity: int) → None¶ Set the verbosity level for the 🤗 Transformers’s root logger.
- Parameters
verbosity (
int
) –Logging level, e.g., one of:
transformers.logging.CRITICAL
ortransformers.logging.FATAL
transformers.logging.ERROR
transformers.logging.WARNING
ortransformers.logging.WARN
transformers.logging.INFO
transformers.logging.DEBUG
-
transformers.logging.
get_logger
(name: Optional[str] = None) → logging.Logger¶ Return a logger with the specified name.
This function is not supposed to be directly accessed unless you are writing a custom transformers module.
-
transformers.logging.
enable_default_handler
() → None¶ Enable the default handler of the HuggingFace Transformers’s root logger.
-
transformers.logging.
disable_default_handler
() → None¶ Disable the default handler of the HuggingFace Transformers’s root logger.
-
transformers.logging.
enable_explicit_format
() → None¶ Enable explicit formatting for every HuggingFace Transformers’s logger. The explicit formatter is as follows:
[LEVELNAME|FILENAME|LINE NUMBER] TIME >> MESSAGE
All handlers currently bound to the root logger are affected by this method.
-
transformers.logging.
reset_format
() → None¶ Resets the formatting for HuggingFace Transformers’s loggers.
All handlers currently bound to the root logger are affected by this method.