class_docstr: This class computes mean perplexity of distributions in the last dimension of inputs. It is a wrapper around
  :doc:`torch.distributions.Categorical.perplexity<pytorch:distributions>` method. You have to provide either 
  ``probs`` or ``logits`` to the :meth:`update` method. The class computes perplexities for distributions passed to 
  :meth:`update` method in ``probs`` or ``logits`` arguments and averages the perplexities. Reducing results between
  all workers is done via SUM operations.
  See `PyTorch Lightning Metrics <https://pytorch-lightning.readthedocs.io/en/stable/ecosystem/metrics.html>`_ 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)
      validate_args:
          If ``True`` values of :meth:`update` method parameters are checked. ``logits`` has to not contain NaNs and
          ``probs`` last dim has to be valid probability distribution.
code: def __init__(
      self,
      dist_sync_on_step=False,
      process_group=None,
      validate_args=True,
  ):
      super().__init__(
          dist_sync_on_step=dist_sync_on_step,
          process_group=process_group,
      )
      self.validate_args = validate_args
      self.add_state(
          "perplexities_sum",
          torch.tensor(0.0, dtype=torch.float64),
          dist_reduce_fx="sum",
      )
      # Total number of distributions seen since last reset
      self.add_state(
          "num_distributions",
          torch.tensor(0, dtype=torch.int64),
          dist_reduce_fx="sum",
      )
  
imports: import torch
  from torch.distributions.categorical import Categorical
  from torchmetrics import Metric
label_desc: Use image node_id 1 to create a new Perplexity object from inherited base classes: Metric with example: obj = Perplexity(dist_sync_on_step, process_group, validate_args)