code: def compute_perplexity(tensor: torch.Tensor):
      """Compute perplexity of a tensor. The tensor has shape (batch_size,
      sequence_length, vocab_size).
      The softmax has already been computed over the vocab dimension.
      """
      return torch.exp(
          -torch.sum(tensor * torch.log(tensor), dim=-1)
      ).mean()
  
file_path: nebuly/optimization/forward_forward/forward_forward/utils/utils.py
imports: from collections import Generator
  import torch.utils.data
label_desc: Use image node_id 1 for calling a global function with example usage: compute_perplexity(tensor) and returns: torch