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","."]
docstr: Compute word prediction loss by comparing prediction of each word in the
  sentence with the true word.
  
  Args:
      logit (torch.Tensor): Logit returned by
          :class:`~pytext.models.language_models.lmlstm.LMLSTM`.
      targets (torch.Tensor): Not applicable for language models.
      context (Dict[str, Any]): Not applicable. Defaults to None.
      reduce (bool): Whether to reduce loss over the batch. Defaults to True.
  
  Returns:
      torch.Tensor: Word prediction loss.
docstr_tok: ["Compute","word","prediction","loss","by","comparing","prediction","of","each","word","in","the","sentence","with","the","true","word",".","Args",":","logit","(","torch.Tensor",")",":","Logit","returned","by",":","class",":","`","~pytext.models.language_models.lmlstm.LMLSTM","`",".","targets","(","torch.Tensor",")",":","Not","applicable","for","language","models",".","context","(","Dict","[","str",",","Any","]",")",":","Not","applicable",".","Defaults","to","None",".","reduce","(","bool",")",":","Whether","to","reduce","loss","over","the","batch",".","Defaults","to","True",".","Returns",":","torch.Tensor",":","Word","prediction","loss","."]
code: def get_loss(
      self,
      logit: torch.Tensor,
      target: torch.Tensor,
      context: Dict[str, Any],
      reduce=True,
  ) -> torch.Tensor:
      """Compute word prediction loss by comparing prediction of each word in the
      sentence with the true word.
  
      Args:
          logit (torch.Tensor): Logit returned by
              :class:`~pytext.models.language_models.lmlstm.LMLSTM`.
          targets (torch.Tensor): Not applicable for language models.
          context (Dict[str, Any]): Not applicable. Defaults to None.
          reduce (bool): Whether to reduce loss over the batch. Defaults to True.
  
      Returns:
          torch.Tensor: Word prediction loss.
  
      """
      if isinstance(target, tuple):
          target = target[0]
      # flatten the logit from [batch_size, seq_lens, dim] to
      # [batch_size * seq_lens, dim]
      return self.loss_fn(
          logit.view(-1, logit.size()[-1]), target.view(-1), reduce
      )
  
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 3 for calling the LMOutputLayer obj's underlying member method code with example usage: obj.get_loss(logit, target, context, reduce) and returns: self