speechbrain.utils.callchains module
Chaining together callables, if some require relative lengths
Summary
Classes:
Chain together callables. |
Functions:
Check if func takes |
|
Return the name of the relative-lengths argument of |
Reference
- speechbrain.utils.callchains.lengths_arg_exists(func)[source]
Check if func takes
lengthskeyword argument.- Parameters:
func (callable) – The function, method, or other callable to search for the lengths arg.
- Return type:
True if func takes
lengthskeyword argument.
- speechbrain.utils.callchains.lengths_arg_name(func)[source]
Return the name of the relative-lengths argument of
func, if any.Both
lengths(the general SpeechBrain convention) andwav_lens(the name used by e.g. the HuggingFace integration lobes) are recognized.- Parameters:
func (callable) – The function, method, or other callable to search for a lengths arg.
- Returns:
The name of the lengths argument, or None if
funcdoes not take one.- Return type:
str or None
- class speechbrain.utils.callchains.LengthsCapableChain(*funcs)[source]
Bases:
objectChain together callables. Can handle relative lengths.
This is a more light-weight version of speechbrain.nnet.containers.LengthsCapableSequential
- Parameters:
*funcs (list, optional) – Any number of functions or other callables, given in order of execution.
- __call__(x, lengths=None)[source]
Run the chain of callables on the given input
- Parameters:
x (Any) – The main input
lengths (Any) – The lengths argument which will be conditionally passed to any functions in the chain that take a ‘lengths’ (or ‘wav_lens’) argument. In SpeechBrain the convention is to use relative lengths.
- Returns:
The input as processed by each function. If no functions were given,
simply returns the input.
Note
By convention, if a callable in the chain returns multiple outputs (returns a tuple), only the first output is passed to the next callable in the chain.