Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions python/paddle/nn/layer/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,10 +1340,16 @@ class CTCLoss(Layer):
blank: int
reduction: _ReduceMode

def __init__(self, blank: int = 0, reduction: _ReduceMode = 'mean') -> None:
def __init__(
self,
blank: int = 0,
reduction: _ReduceMode = 'mean',
zero_infinity: bool = False,
) -> None:
super().__init__()
self.blank = blank
self.reduction = reduction
self.zero_infinity = zero_infinity

def forward(
self,
Expand All @@ -1352,8 +1358,19 @@ def forward(
input_lengths: Tensor,
label_lengths: Tensor,
norm_by_times: bool = False,
zero_infinity: bool = False,
zero_infinity: bool | None = None,
) -> Tensor:
if zero_infinity is None:
return paddle.nn.functional.ctc_loss(
log_probs,
labels,
input_lengths,
label_lengths,
self.blank,
self.reduction,
norm_by_times=norm_by_times,
zero_infinity=self.zero_infinity,
)
return paddle.nn.functional.ctc_loss(
log_probs,
labels,
Expand Down
Loading