speechbrain.utils.check_yaml module

Tests for checking consistency between yaml files and their corresponding training scripts.

Authors
  • Mirco Ravanelli 2022

  • Andreas Nautsch 2022

Summary

Functions:

check_module_vars

Checks if the variables self.moduled.var are properly declared in the hparam file.

check_yaml_vs_script

Checks consistency between the given yaml file (hparams_file) and the script file.

detect_script_vars

Detects from the input script file (script_file) which of given variables (var_lst) are demanded.

extract_patterns

Extracts a variables from start_pattern to end_pattern.

get_yaml_var

Extracts from the input yaml file (hparams_file) the list of variables that should be used in the script file.

Reference

speechbrain.utils.check_yaml.get_yaml_var(hparam_file)[source]

Extracts from the input yaml file (hparams_file) the list of variables that should be used in the script file.

Parameters

hparam_file (path) – Path of the yaml file containing the hyperparameters.

Returns

var_list – list of the variables declared in the yaml file (sub-variables are not included).

Return type

list

speechbrain.utils.check_yaml.detect_script_vars(script_file, var_lst)[source]

Detects from the input script file (script_file) which of given variables (var_lst) are demanded.

Parameters
  • script_file (path) – Path of the script file needing the hyperparameters.

  • var_lst (list) – list of the variables declared in the yaml file.

Returns

detected_var – list of the variables detected in the script file.

Return type

list

speechbrain.utils.check_yaml.check_yaml_vs_script(hparam_file, script_file)[source]

Checks consistency between the given yaml file (hparams_file) and the script file. The function detects if there are variables declared in the yaml file, but not used in the script file.

Parameters
  • hparam_file (path) – Path of the yaml file containing the hyperparameters.

  • script_file (path) – Path of the script file (.py) containing the training recipe.

Returns

This function returns False if some mismatch is detected and True otherwise. An error is raised to inform about which variable has been declared but not used.

Return type

Bool

speechbrain.utils.check_yaml.extract_patterns(lines, start_pattern, end_pattern)[source]

Extracts a variables from start_pattern to end_pattern.

Parameters
  • lines (list) – List of strings to parse.

  • start_pattern (string) – String that indicated the start of the pattern.

  • end_pattern (string) – String that indicated the end of the pattern.

Returns

var_lst – List of variables detected.

Return type

list

speechbrain.utils.check_yaml.check_module_vars(hparam_file, script_file, module_key='modules:', module_var='self.modules.')[source]

Checks if the variables self.moduled.var are properly declared in the hparam file.

Parameters
  • hparam_file (path) – Path of the yaml file containing the hyperparameters.

  • script_file (path) – Path of the script file (.py) containing the training recipe.

  • module_key (string) – String that denoted the start of the module in the hparam file.

  • module_var (string) – String that denoted the start of the module in the script file.

Returns

This function returns False if some mismatch is detected and True otherwise. An error is raised to inform about which variable has been used but not declared.

Return type

Bool