class_docstr: Output layer for language models. It supports `CrossEntropyLoss` per word.
  
  Args:
      loss_fn (CrossEntropyLoss): Cross-entropy loss component. Defaults to None.
  
  Attributes:
      loss_fn: Cross-entropy loss component for computing loss.
class_docstr_tok: ["Output","layer","for","language","models",".","It","supports","`","CrossEntropyLoss","`","per","word",".","Args",":","loss_fn","(","CrossEntropyLoss",")",":","Cross-entropy","loss","component",".","Defaults","to","None",".","Attributes",":","loss_fn",":","Cross-entropy","loss","component","for","computing","loss","."]
code: def calculate_perplexity(sequence_loss: torch.Tensor) -> torch.Tensor:
      try:
          ppl = torch.exp(sequence_loss)
      except OverflowError:
          ppl = float("inf")
      return ppl
  
file_path: pytext/pytext/models/output_layers/lm_output_layer.py
imports: from typing import Any, Dict, List, Optional, Tuple
  import torch
  from pytext.config.component import create_loss
  from pytext.data.utils import Vocabulary
  from pytext.fields import FieldMeta
  from pytext.loss import CrossEntropyLoss, Loss
  from pytext.utils.usage import log_class_usage
  from .output_layer_base import OutputLayerBase
label_desc: Use image node_id 5 for calling the LMOutputLayer obj's underlying member method code with example usage: obj.calculate_perplexity(sequence_loss) and returns: ppl