Criterion
Criterion is a Callable object which is the base class for all criterion objects in this toolkit. It serves the role of evaluating the model forward calculation results. Its output can be either a loss function used for training or an evaluation metric used for validation.
This base class has two abstract interface functions: criterion_init()
for criterion initialization and __call__()
for criterion forward calculation.
__call__()
must be overridden if you want to make your own Criterion implementation.criterion_init()
is not mandatory to be overridden because some criteria can directly be applied to the input data without any initialization such as speechain.criterion.accuracy.Accuracy.
Table of Contents
Criterion Library
/speechain
/criterion
/abs.py # Abstract class of Criterion. Base of all Criterion implementations.
/accuracy.py # Criterion implementation of classification accuracy. Mainly used for ASR teacher-forcing accuracy.
/bce_logits.py # Criterion implementation of binary cross entropy. Mainly used for TTS stop flag.
/cross_entropy.py # Criterion implementation of cross entropy. Mainly used for ASR seq2seq loss function.
/error_rate.py # Criterion implementation of word and char error rate. Mainly used for ASR evaluation.
/fbeta_score.py # Criterion implementation of F_beta score. Mainly used for evaluation of TTS stop flag.
/least_error.py # Criterion implementation of mean square error and mean absolute error. Mainly used for TTS seq2seq loss function.
API Document
- speechain.criterion.abs.Criterion.__init__
- speechain.criterion.abs.Criterion.criterion_init
- speechain.criterion.abs.Criterion.__call__
speechain.criterion.abs.Criterion.__init__(self, **criterion_conf)
- Description:
This initialization function is shared by all Criterion subclasses. Currently, the shared logic only contains calling the initialization function of the parent class. - Arguments:
- **criterion_conf:
The arguments used bycriterion_init()
for your customized Criterion initialization.
- **criterion_conf:
speechain.criterion.abs.Criterion.criterion_init(self, **criterion_conf)
- Description:
Abstract interface function for customized initialization of each Criterion subclass. This interface function is not mandatory to be overridden by your implementation. - Arguments:
- **criterion_conf:
The arguments used for customized Criterion initialization. For more details, please refer to the docstring of your target Criterion subclass.
- **criterion_conf:
speechain.criterion.abs.Criterion.__call__(self, **kwargs)
- Description:
This abstract interface function receives the model forward calculation results and ground-truth labels. The output is a scalar which could be either trainable for parameter optimization or non-trainable for information recording.
This interface function is mandatory to be overridden by your implementation. - Arguments:
- **kwargs:
model forward calculation results and ground-truth labels.
For more details, please refer to the docstring of__call__()
of your target Criterion subclass.
- **kwargs:
- Return:
A trainable or non-trainable scalar.
For more details, please refer to the docstring of__call__()
of your target Criterion subclass.