class_docstr: A wrapper for pytorch RNNLM.
class_docstr_tok: ["A","wrapper","for","pytorch","RNNLM","."]
docstr: Compute the loss value for an input and label pair.
  
  Notes:
      It also computes accuracy and stores it to the attribute.
      When ``label_key`` is ``int``, the corresponding element in ``args``
      is treated as ground truth labels. And when it is ``str``, the
      element in ``kwargs`` is used.
      The all elements of ``args`` and ``kwargs`` except the groundtruth
      labels are features.
      It feeds features to the predictor and compare the result
      with ground truth labels.
  
  :param torch.Tensor state : the LM state
  :param list[torch.Tensor] args : Input minibatch
  :param dict[torch.Tensor] kwargs : Input minibatch
  :return loss value
  :rtype torch.Tensor
docstr_tok: ["Compute","the","loss","value","for","an","input","and","label","pair",".","Notes",":","It","also","computes","accuracy","and","stores","it","to","the","attribute",".","When","``","label_key","``","is","``","int","``",",","the","corresponding","element","in","``","args","``","is","treated","as","ground","truth","labels",".","And","when","it","is","``","str","``",",","the","element","in","``","kwargs","``","is","used",".","The","all","elements","of","``","args","``","and","``","kwargs","``","except","the","groundtruth","labels","are","features",".","It","feeds","features","to","the","predictor","and","compare","the","result","with","ground","truth","labels",".",":","param","torch.Tensor","state",":","the","LM","state",":","param","list","[","torch.Tensor","]","args",":","Input","minibatch",":","param","dict","[","torch.Tensor","]","kwargs",":","Input","minibatch",":","return","loss","value",":","rtype","torch.Tensor"]
code: def forward(self, state, *args, **kwargs):
      """Compute the loss value for an input and label pair.
  
      Notes:
          It also computes accuracy and stores it to the attribute.
          When ``label_key`` is ``int``, the corresponding element in ``args``
          is treated as ground truth labels. And when it is ``str``, the
          element in ``kwargs`` is used.
          The all elements of ``args`` and ``kwargs`` except the groundtruth
          labels are features.
          It feeds features to the predictor and compare the result
          with ground truth labels.
  
      :param torch.Tensor state : the LM state
      :param list[torch.Tensor] args : Input minibatch
      :param dict[torch.Tensor] kwargs : Input minibatch
      :return loss value
      :rtype torch.Tensor
  
      """
      if isinstance(self.label_key, int):
          if not (-len(args) <= self.label_key < len(args)):
              msg = "Label key %d is out of bounds" % self.label_key
              raise ValueError(msg)
          t = args[self.label_key]
          if self.label_key == -1:
              args = args[:-1]
          else:
              args = args[: self.label_key] + args[self.label_key + 1 :]
      elif isinstance(self.label_key, str):
          if self.label_key not in kwargs:
              msg = 'Label key "%s" is not found' % self.label_key
              raise ValueError(msg)
          t = kwargs[self.label_key]
          del kwargs[self.label_key]
  
      self.y = None
      self.loss = None
      state, self.y = self.predictor(state, *args, **kwargs)
      self.loss = self.lossfun(self.y, t)
      return state, self.loss
  
imports: import logging
  from typing import Any, List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from espnet.nets.lm_interface import LMInterface
  from espnet.nets.pytorch_backend.e2e_asr import to_device
  from espnet.nets.scorer_interface import BatchScorerInterface
  from espnet.utils.cli_utils import strtobool
label_desc: Use image node_id 2 for calling the ClassifierWithState obj's underlying member method code with example usage: obj.forward(state) and returns: state,  self