Criterion¶
Label Smoothed Cross Entropy Loss¶
-
class
kospeech.criterion.label_smoothed_cross_entropy.
LabelSmoothedCrossEntropyLoss
(num_classes: int, ignore_index: int, smoothing: float = 0.1, dim: int = - 1, reduction='sum')[source]¶ Label smoothed cross entropy loss function.
- Parameters
- Inputs: logits, target
logits (torch.Tensor): probability distribution value from model and it has a logarithm shape target (torch.Tensor): ground-thruth encoded to integers which directly point a word in label
- Returns: label_smoothed
label_smoothed (float): sum of loss
Joint CTC-CrossEntropy Loss¶
-
class
kospeech.criterion.joint_ctc_cross_entropy.
JointCTCCrossEntropyLoss
(num_classes: int, ignore_index: int, dim: int = - 1, reduction='mean', ctc_weight: float = 0.3, cross_entropy_weight: float = 0.7, blank_id: int = None, smoothing: float = 0.1)[source]¶ Label smoothed cross entropy loss function.
- Parameters
num_classes (int) – the number of classfication
ignore_index (int) – Indexes that are ignored when calculating loss
dim (int) – dimension of calculation loss
reduction (str) – reduction method [sum, mean] (default: sum)
ctc_weight (float) – weight of ctc loss
cross_entropy_weight (float) – weight of cross entropy loss
- Inputs: logit, target
logit (torch.Tensor): probability distribution value from model and it has a logarithm shape target (torch.Tensor): ground-thruth encoded to integers which directly point a word in label
- Returns: label_smoothed
label_smoothed (Tensor): sum of loss
Transducer Loss¶
-
class
kospeech.criterion.transducer.
TransducerLoss
(blank_id)[source]¶ Transducer loss module.
- Parameters
blank_id (int) – blank symbol id
-
forward
(log_probs: torch.FloatTensor, targets: torch.IntTensor, input_lengths: torch.IntTensor, target_lengths: torch.IntTensor) → torch.FloatTensor[source]¶ Compute path-aware regularization transducer loss.
- Parameters
log_probs (torch.FloatTensor) – Batch of predicted sequences (batch, maxlen_in, maxlen_out+1, odim)
targets (torch.IntTensor) – Batch of target sequences (batch, maxlen_out)
input_lengths (torch.IntTensor) – batch of lengths of predicted sequences (batch)
target_lengths (torch.IntTensor) – batch of lengths of target sequences (batch)
- Returns
transducer loss
- Return type
loss (torch.FloatTensor)