def build_criterion(vocab_size, padding_idx, smoothing): if smoothing == 0.: logging.info(f'Building CrossEntropyLoss') criterion = nn.CrossEntropyLoss(ignore_index=padding_idx, size_average=False) else: logging.info(f'Building LabelSmoothingLoss (smoothing: {smoothing})') criterion = LabelSmoothing(padding_idx, smoothing) return criterion
def build_gnmt_criterion(vocab_size, padding_idx, smoothing): if smoothing == 0.: loss_weight = torch.ones(vocab_size) loss_weight[padding_idx] = 0 criterion = CrossEntropyWrapper(weight=loss_weight, size_average=False) else: criterion = LabelSmoothing(padding_idx, smoothing) return criterion
def build_criterion(vocab_size, padding_idx, smoothing, fusion): if smoothing == 0.: logging.info(f'Building CrossEntropyLoss') loss_weight = torch.ones(vocab_size) loss_weight[padding_idx] = 0 criterion = nn.CrossEntropyLoss(weight=loss_weight, size_average=False) else: logging.info(f'Building LabelSmoothingLoss (smoothing: {smoothing})') criterion = LabelSmoothing(padding_idx, smoothing, fusion=fusion) return criterion
def build_criterion(vocab_size, padding_idx, smoothing): if smoothing == 0.: logging.info(f'Building CrossEntropyLoss') loss_weight = torch.ones(vocab_size) loss_weight[padding_idx] = 0 criterion = nn.CrossEntropyLoss(weight=loss_weight, size_average=False) gnmt_print(key=mlperf_log.MODEL_HP_LOSS_FN, value='Cross Entropy') else: logging.info(f'Building LabelSmoothingLoss (smoothing: {smoothing})') criterion = LabelSmoothing(padding_idx, smoothing) gnmt_print(key=mlperf_log.MODEL_HP_LOSS_FN, value='Cross Entropy with label smoothing') gnmt_print(key=mlperf_log.MODEL_HP_LOSS_SMOOTHING, value=smoothing) return criterion