docstr: Returns average perplexity for each sample in the batch  
docstr_tok: ["Returns","average","perplexity","for","each","sample","in","the","batch"]
code: def _get_per_sample_perplexity(self, logits, labels):
      """Returns average perplexity for each sample in the batch"""
  
      loss_fct = torch.nn.CrossEntropyLoss(
          ignore_index=-100, reduction="none"
      )
      unreduced_loss = loss_fct(
          logits.view(-1, logits.size(-1)),
          labels.view(-1),
      )
      unreduced_loss = unreduced_loss.reshape(labels.shape)
      mask_0 = unreduced_loss != 0
      per_sample_perplexity = torch.exp(
          (unreduced_loss * mask_0).sum(axis=1) / mask_0.sum(axis=1)
      )
  
      return per_sample_perplexity
  
file_path: NeMo/nemo/collections/nlp/models/question_answering/qa_base_model.py
imports: from typing import Optional
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from nemo.collections.nlp.data.question_answering.data_processor.qa_processing import EVALUATION_MODE, INFERENCE_MODE, TRAINING_MODE
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.utils import logging
label_desc: Use image node_id 7 for calling the BaseQAModel obj's underlying member method code with example usage: obj._get_per_sample_perplexity(logits, labels) and returns: per_sample_perplexity