class_docstr: Implements a combined loss from translation and target words prediction.
  
  References:
    [1] https://research.google.com/pubs/archive/37180.pdf
    [2] https://arxiv.org/abs/1708.01771
    [3] https://discuss.pytorch.org/t/writing-warp-loss-layer/3715
  
  TODO(T38581791):
    Although this implementation is faster than [3] (3s/it vs 70s/it), it is
    still much slower than `WordPredictionCriterion`.
    Need to explore ways to speed it up -- it looks like the training time
    increases after each iteration. This happens because it becomes harder
    to search after each update.
class_docstr_tok: ["Implements","a","combined","loss","from","translation","and","target","words","prediction",".","References",":","[","1","]","https",":","\/\/research.google.com\/pubs\/archive\/37180.pdf","[","2","]","https",":","\/\/arxiv.org\/abs\/1708.01771","[","3","]","https",":","\/\/discuss.pytorch.org\/t\/writing-warp-loss-layer\/3715","TODO","(","T38581791",")",":","Although","this","implementation","is","faster","than","[","3","]","(","3s\/it","vs","70s\/it",")",",","it","is","still","much","slower","than","`","WordPredictionCriterion","`",".","Need","to","explore","ways","to","speed","it","up","--","it","looks","like","the","training","time","increases","after","each","iteration",".","This","happens","because","it","becomes","harder","to","search","after","each","update","."]
docstr: Sets ranking for weights based on the number of labels.
  
  Args:
      n_labels: Number of labels
      rank_weights_type: Type of the ranking.
  
  Raises:
      AssertionError: Number of labels <= 1
      NotImplementedError: rank_weights_type is not 'uniform'
docstr_tok: ["Sets","ranking","for","weights","based","on","the","number","of","labels",".","Args",":","n_labels",":","Number","of","labels","rank_weights_type",":","Type","of","the","ranking",".","Raises",":","AssertionError",":","Number","of","labels","<","=","1","NotImplementedError",":","rank_weights_type","is","not","'uniform","'"]
code: def set_rank_weights(self, n_labels, rank_weights_type="uniform"):
      """Sets ranking for weights based on the number of labels.
  
      Args:
          n_labels: Number of labels
          rank_weights_type: Type of the ranking.
  
      Raises:
          AssertionError: Number of labels <= 1
          NotImplementedError: rank_weights_type is not 'uniform'
      """
      assert n_labels > 1
      if rank_weights_type == "uniform":
          self.rank_weights = (
              1.0 / (n_labels - 1) * maybe_cuda(torch.ones(n_labels))
          )
      else:
          raise NotImplementedError(
              "Rank weights type {} not implemented".format(
                  rank_weights_type
              )
          )
  
imports: import abc
  import math
  import torch
  from fairseq import utils
  from fairseq.criterions import register_criterion
  from fairseq.criterions.label_smoothed_cross_entropy import LabelSmoothedCrossEntropyCriterion
  from pytorch_translate.utils import maybe_cuda
label_desc: Use image node_id 2 for calling the WARPLossCriterion obj's underlying member method code with example usage: obj.set_rank_weights(n_labels, rank_weights_type) without return types