class_docstr: This criterion relies on the model to supply losses.
  The losses should be a dictionary of name -> scalar returned by
  the model either by including it in the net_output dict or by
  implementing a get_losses(net_output, sample) method. The final loss is
  a scaled sum of all losses according to weights in loss_weights.
  If no weights are provided, then all losses are scaled by 1.0.
  
  The losses will be automatically logged. Additional keys from
  net_output dict can be logged via the log_keys parameter.
class_docstr_tok: ["This","criterion","relies","on","the","model","to","supply","losses",".","The","losses","should","be","a","dictionary","of","name","-",">","scalar","returned","by","the","model","either","by","including","it","in","the","net_output","dict","or","by","implementing","a","get_losses","(","net_output",",","sample",")","method",".","The","final","loss","is","a","scaled","sum","of","all","losses","according","to","weights","in","loss_weights",".","If","no","weights","are","provided",",","then","all","losses","are","scaled","by","1.0",".","The","losses","will","be","automatically","logged",".","Additional","keys","from","net_output","dict","can","be","logged","via","the","log_keys","parameter","."]
code: def __init__(
      self, task, loss_weights=None, log_keys=None, can_sum=True
  ):
      super().__init__(task)
      self.loss_weights = loss_weights
      self.log_keys = log_keys
      self.can_sum = can_sum
  
file_path: fairseq/fairseq/criterions/model_criterion.py
imports: import logging
  from dataclasses import dataclass, field
  from typing import Dict, List
  import torch
  from fairseq import utils
  from fairseq.logging import metrics
  from fairseq.criterions import FairseqCriterion, register_criterion
  from fairseq.dataclass import FairseqDataclass
  from fairseq.logging.meters import safe_round
label_desc: Use image node_id 1 to create a new ModelCriterion object from inherited base classes: FairseqCriterion with example: obj = ModelCriterion(task, loss_weights, log_keys, can_sum)