class_docstr: Default RNNLM for `LMInterface` Implementation.
  
  Note:
      PyTorch seems to have memory leak when one GPU compute this after data parallel.
      If parallel GPUs compute this, it seems to be fine.
      See also https://github.com/espnet/espnet/issues/1075
class_docstr_tok: ["Default","RNNLM","for","`","LMInterface","`","Implementation",".","Note",":","PyTorch","seems","to","have","memory","leak","when","one","GPU","compute","this","after","data","parallel",".","If","parallel","GPUs","compute","this",",","it","seems","to","be","fine",".","See","also","https",":","\/\/github.com\/espnet\/espnet\/issues\/1075"]
docstr: Score new token batch.
  
  Args:
      ys (torch.Tensor): torch.int64 prefix tokens (n_batch, ylen).
      states (List[Any]): Scorer states for prefix tokens.
      xs (torch.Tensor):
          The encoder feature that generates ys (n_batch, xlen, n_feat).
  
  Returns:
      tuple[torch.Tensor, List[Any]]: Tuple of
          batchfied scores for next token with shape of `(n_batch, n_vocab)`
          and next state list for ys.
docstr_tok: ["Score","new","token","batch",".","Args",":","ys","(","torch.Tensor",")",":","torch.int64","prefix","tokens","(","n_batch",",","ylen",")",".","states","(","List","[","Any","]",")",":","Scorer","states","for","prefix","tokens",".","xs","(","torch.Tensor",")",":","The","encoder","feature","that","generates","ys","(","n_batch",",","xlen",",","n_feat",")",".","Returns",":","tuple","[","torch.Tensor",",","List","[","Any","]","]",":","Tuple","of","batchfied","scores","for","next","token","with","shape","of","`","(","n_batch",",","n_vocab",")","`","and","next","state","list","for","ys","."]
code: def batch_score(
      self, ys: torch.Tensor, states: List[Any], xs: torch.Tensor
  ) -> Tuple[torch.Tensor, List[Any]]:
      """Score new token batch.
  
      Args:
          ys (torch.Tensor): torch.int64 prefix tokens (n_batch, ylen).
          states (List[Any]): Scorer states for prefix tokens.
          xs (torch.Tensor):
              The encoder feature that generates ys (n_batch, xlen, n_feat).
  
      Returns:
          tuple[torch.Tensor, List[Any]]: Tuple of
              batchfied scores for next token with shape of `(n_batch, n_vocab)`
              and next state list for ys.
  
      """
      # merge states
      n_batch = len(ys)
      n_layers = self.model.predictor.n_layers
      if self.model.predictor.typ == "lstm":
          keys = ("c", "h")
      else:
          keys = ("h",)
  
      if states[0] is None:
          states = None
      else:
          # transpose state of [batch, key, layer] into [key, layer, batch]
          states = {
              k: [
                  torch.stack([states[b][k][i] for b in range(n_batch)])
                  for i in range(n_layers)
              ]
              for k in keys
          }
      states, logp = self.model.predict(states, ys[:, -1])
  
      # transpose state of [key, layer, batch] into [batch, key, layer]
      return (
          logp,
          [
              {
                  k: [states[k][i][b] for i in range(n_layers)]
                  for k in keys
              }
              for b in range(n_batch)
          ],
      )
  
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 8 for calling the DefaultRNNLM obj's underlying member method code with example usage: obj.batch_score(ys, states, xs) and returns: logp,  unknown