        loss_fct = nn.CrossEntropyLoss(weight=torch.tensor([1.0, 2.0, 3.0]))
        loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
        return (loss, outputs) if return_outputs else loss
```
Another way to customize the training loop behavior for the PyTorch [Trainer] is to use callbacks that can inspect the training loop state (for progress reporting, logging on TensorBoard or other ML platforms...) and take decisions (like early stopping).
Trainer
[[autodoc]] Trainer
    - all
Seq2SeqTrainer
[[autodoc]] Seq2SeqTrainer
    - evaluate
    - predict
TrainingArguments
[[autodoc]] TrainingArguments
    - all
Seq2SeqTrainingArguments
[[autodoc]] Seq2SeqTrainingArguments
    - all
Checkpoints
By default, [Trainer] will save all checkpoints in the output_dir you set in the
