speechbrain.utils.logger module

Managing the logger, utilities

Author

Summary

Classes:

TqdmCompatibleStreamHandler

TQDM compatible StreamHandler.

Functions:

format_order_of_magnitude

Formats number to the appropriate order of magnitude for printing.

get_environment_description

Returns a string describing the current Python / SpeechBrain environment.

setup_logging

Setup logging configuration.

Reference

class speechbrain.utils.logger.TqdmCompatibleStreamHandler(stream=None)[source]

Bases: logging.StreamHandler

TQDM compatible StreamHandler.

Writes and prints should be passed through tqdm.tqdm.write so that the tqdm progressbar doesn’t get messed up.

emit(record)[source]
speechbrain.utils.logger.setup_logging(config_path='log-config.yaml', overrides={}, default_level=20)[source]

Setup logging configuration.

Parameters
  • config_path (str) – The path to a logging config file.

  • default_level (int) – The level to use if the config file is not found.

  • overrides (dict) – A dictionary of the same structure as the config dict with any updated values that need to be applied.

speechbrain.utils.logger.format_order_of_magnitude(number, abbreviate=True)[source]

Formats number to the appropriate order of magnitude for printing.

Parameters
  • number (int, float) – The number to format.

  • abbreviate (bool) – Whether to use abbreviations (k,M,G) or words (Thousand, Million, Billion). Numbers will be either like: “123.5k” or “123.5 Thousand”.

Returns

The formatted number. Note that the order of magnitude token is part of the string.

Return type

str

Example

>>> print(format_order_of_magnitude(123456))
123.5k
>>> print(format_order_of_magnitude(0.00000123, abbreviate=False))
1.2 millionths
>>> print(format_order_of_magnitude(5, abbreviate=False))
5
speechbrain.utils.logger.get_environment_description()[source]

Returns a string describing the current Python / SpeechBrain environment.

Useful for making experiments as replicable as possible.

Returns

The string is formatted ready to be written to a file.

Return type

str

Example

>>> get_environment_description().splitlines()[0]
'SpeechBrain system description'