code: def _baseline_perplexity(preds, target, ignore_index):
      """Baseline implementation of perplexity metric based upon PyTorch Cross Entropy."""
      preds = preds.reshape(-1, preds.shape[-1])
      target = target.reshape(-1)
      cross_entropy = F.cross_entropy(preds, target)
      return torch.exp(cross_entropy)
  
file_path: torchmetrics/tests/unittests/text/test_perplexity.py
imports: from functools import partial
  import pytest
  import torch
  from torch.nn import functional
  from torchmetrics.functional.text.perplexity import perplexity
  from torchmetrics.text.perplexity import Perplexity
  from unittests.helpers.testers import MetricTester
  from unittests.text.inputs import MASK_INDEX, _logits_inputs_fp32, _logits_inputs_fp32_with_mask, _logits_inputs_fp64, _logits_inputs_fp64_with_mask
label_desc: Use image node_id 1 for calling a global function with example usage: _baseline_perplexity(preds, target, ignore_index) and returns: torch