class_docstr: This class computes mean perplexity across the batches of sequences.
  
  You have to provide ``log_probs`` (float tensor of shape [batch_size x seq_length x vocab_size]) and
  ``labels`` (int tensor of shape [batch_size x seq_length] with values from the range [0, vocab_size-1])
  to the :meth:`update` method. If some of the sequences are shorter than seq_length, you can also provide
  an optional argument ``mask`` (bool tensor of shape [batch_size x seq_length]) which masks out tokens
  not participating in perplexity computation.
  
  See :doc:`PyTorch Lightning Metrics<pytorch-lightning:metrics>` for the metric usage instructions.
  
  Args:
      dist_sync_on_step:
          Synchronize metric state across processes at each ``forward()`` before returning the value at the step.
      process_group:
          Specify the process group on which synchronization is called. default: ``None`` (which selects the entire
              world)
      dist_sync_fn:
          Callback that performs the allgather operation on the metric state. When ``None``, DDP will be used
              to perform the allgather.
class_docstr_tok: ["This","class","computes","mean","perplexity","across","the","batches","of","sequences",".","You","have","to","provide","``","log_probs","``","(","float","tensor","of","shape","[","batch_size","x","seq_length","x","vocab_size","]",")","and","``","labels","``","(","int","tensor","of","shape","[","batch_size","x","seq_length","]","with","values","from","the","range","[","0",",","vocab_size-1","]",")","to","the",":","meth",":","`","update","`","method",".","If","some","of","the","sequences","are","shorter","than","seq_length",",","you","can","also","provide","an","optional","argument","``","mask","``","(","bool","tensor","of","shape","[","batch_size","x","seq_length","]",")","which","masks","out","tokens","not","participating","in","perplexity","computation",".","See",":","doc",":","`","PyTorch","Lightning","Metrics","<","pytorch-lightning",":","metrics",">","`","for","the","metric","usage","instructions",".","Args",":","dist_sync_on_step",":","Synchronize","metric","state","across","processes","at","each","``","forward","(",")","``","before","returning","the","value","at","the","step",".","process_group",":","Specify","the","process","group","on","which","synchronization","is","called",".","default",":","``","None","``","(","which","selects","the","entire","world",")","dist_sync_fn",":","Callback","that","performs","the","allgather","operation","on","the","metric","state",".","When","``","None","``",",","DDP","will","be","used","to","perform","the","allgather","."]
code: def __init__(
      self,
      dist_sync_on_step=False,
      process_group=None,
      dist_sync_fn=None,
  ):
      super().__init__(
          dist_sync_on_step=dist_sync_on_step,
          process_group=process_group,
          dist_sync_fn=dist_sync_fn,
      )
  
      # Total sum of exponentiated average negative log likelihoods
      self.add_state(
          "perplexities_sum",
          default=torch.tensor(0.0, dtype=torch.float64),
          dist_reduce_fx="sum",
      )
      # Total number of sequences in all batches
      self.add_state(
          "num_sequences",
          default=torch.tensor(0, dtype=torch.int64),
          dist_reduce_fx="sum",
      )
  
imports: import torch
  from torchmetrics import Metric
label_desc: Use image node_id 1 to create a new SequencePerplexity object from inherited base classes: Metric with example: obj = SequencePerplexity(dist_sync_on_step, process_group, dist_sync_fn)