class_docstr: Decoder layer.
  
  Args:
      eprojs (int): Dimension of input variables from encoder.
      odim (int): The output dimension.
      dtype (str): Decoder type.
      dlayers (int): Number of layers for decoder.
      dunits (int): Dimension of input vector of decoder.
      sos (int): Number to indicate the start of sequences.
      eos (int): Number to indicate the end of sequences.
      att (Module): Attention module defined at
          `espnet.espnet.nets.chainer_backend.attentions`.
      verbose (int): Verbosity level.
      char_list (List[str]): List of all characters.
      labeldist (numpy.array): Distributed array of counted transcript length.
      lsm_weight (float): Weight to use when calculating the training loss.
      sampling_probability (float): Threshold for scheduled sampling.
class_docstr_tok: ["Decoder","layer",".","Args",":","eprojs","(","int",")",":","Dimension","of","input","variables","from","encoder",".","odim","(","int",")",":","The","output","dimension",".","dtype","(","str",")",":","Decoder","type",".","dlayers","(","int",")",":","Number","of","layers","for","decoder",".","dunits","(","int",")",":","Dimension","of","input","vector","of","decoder",".","sos","(","int",")",":","Number","to","indicate","the","start","of","sequences",".","eos","(","int",")",":","Number","to","indicate","the","end","of","sequences",".","att","(","Module",")",":","Attention","module","defined","at","`","espnet.espnet.nets.chainer_backend.attentions","`",".","verbose","(","int",")",":","Verbosity","level",".","char_list","(","List","[","str","]",")",":","List","of","all","characters",".","labeldist","(","numpy.array",")",":","Distributed","array","of","counted","transcript","length",".","lsm_weight","(","float",")",":","Weight","to","use","when","calculating","the","training","loss",".","sampling_probability","(","float",")",":","Threshold","for","scheduled","sampling","."]
docstr: Core function of Decoder layer.
  
  Args:
      hs (list of chainer.Variable | N-dimension array):
          Input variable from encoder.
      ys (list of chainer.Variable | N-dimension array):
          Input variable of decoder.
  
  Returns:
      chainer.Variable: A variable holding a scalar array of the training loss.
      chainer.Variable: A variable holding a scalar array of the accuracy.
docstr_tok: ["Core","function","of","Decoder","layer",".","Args",":","hs","(","list","of","chainer.Variable","|","N-dimension","array",")",":","Input","variable","from","encoder",".","ys","(","list","of","chainer.Variable","|","N-dimension","array",")",":","Input","variable","of","decoder",".","Returns",":","chainer.Variable",":","A","variable","holding","a","scalar","array","of","the","training","loss",".","chainer.Variable",":","A","variable","holding","a","scalar","array","of","the","accuracy","."]
code: def __call__(self, hs, ys):
      """Core function of Decoder layer.
  
      Args:
          hs (list of chainer.Variable | N-dimension array):
              Input variable from encoder.
          ys (list of chainer.Variable | N-dimension array):
              Input variable of decoder.
  
      Returns:
          chainer.Variable: A variable holding a scalar array of the training loss.
          chainer.Variable: A variable holding a scalar array of the accuracy.
  
      """
      self.loss = None
      # prepare input and output word sequences with sos/eos IDs
      eos = self.xp.array([self.eos], "i")
      sos = self.xp.array([self.sos], "i")
      ys_in = [F.concat([sos, y], axis=0) for y in ys]
      ys_out = [F.concat([y, eos], axis=0) for y in ys]
  
      # padding for ys with -1
      # pys: utt x olen
      pad_ys_in = F.pad_sequence(ys_in, padding=self.eos)
      pad_ys_out = F.pad_sequence(ys_out, padding=-1)
  
      # get dim, length info
      batch = pad_ys_out.shape[0]
      olength = pad_ys_out.shape[1]
      logging.info(
          self.__class__.__name__
          + " input lengths:  "
          + str(self.xp.array([h.shape[0] for h in hs]))
      )
      logging.info(
          self.__class__.__name__
          + " output lengths: "
          + str(self.xp.array([y.shape[0] for y in ys_out]))
      )
  
      # initialization
      c_list = [None]  # list of cell state of each layer
      z_list = [None]  # list of hidden state of each layer
      for _ in range(1, self.dlayers):
          c_list.append(None)
          z_list.append(None)
      att_w = None
      z_all = []
      self.att.reset()  # reset pre-computation of h
  
      # pre-computation of embedding
      eys = self.embed(pad_ys_in)  # utt x olen x zdim
      eys = F.separate(eys, axis=1)
  
      # loop for an output sequence
      for i in range(olength):
          att_c, att_w = self.att(hs, z_list[0], att_w)
          if i > 0 and random.random() < self.sampling_probability:
              logging.info(" scheduled sampling ")
              z_out = self.output(z_all[-1])
              z_out = F.argmax(F.log_softmax(z_out), axis=1)
              z_out = self.embed(z_out)
              ey = F.hstack((z_out, att_c))  # utt x (zdim + hdim)
          else:
              ey = F.hstack((eys[i], att_c))  # utt x (zdim + hdim)
          z_list, c_list = self.rnn_forward(
              ey, z_list, c_list, z_list, c_list
          )
          z_all.append(z_list[-1])
  
      z_all = F.stack(z_all, axis=1).reshape(
          batch * olength, self.dunits
      )
      # compute loss
      y_all = self.output(z_all)
      self.loss = F.softmax_cross_entropy(y_all, F.flatten(pad_ys_out))
      # -1: eos, which is removed in the loss computation
      self.loss *= np.mean([len(x) for x in ys_in]) - 1
      acc = F.accuracy(y_all, F.flatten(pad_ys_out), ignore_label=-1)
      logging.info("att loss:" + str(self.loss.data))
  
      # show predicted character sequence for debug
      if self.verbose > 0 and self.char_list is not None:
          y_hat = y_all.reshape(batch, olength, -1)
          y_true = pad_ys_out
          for (i, y_hat_), y_true_ in zip(
              enumerate(y_hat.data), y_true.data
          ):
              if i == MAX_DECODER_OUTPUT:
                  break
              idx_hat = self.xp.argmax(y_hat_[y_true_ != -1], axis=1)
              idx_true = y_true_[y_true_ != -1]
              seq_hat = [self.char_list[int(idx)] for idx in idx_hat]
              seq_true = [self.char_list[int(idx)] for idx in idx_true]
              seq_hat = "".join(seq_hat).replace("<space>", " ")
              seq_true = "".join(seq_true).replace("<space>", " ")
              logging.info("groundtruth[%d]: " % i + seq_true)
              logging.info("prediction [%d]: " % i + seq_hat)
  
      if self.labeldist is not None:
          if self.vlabeldist is None:
              self.vlabeldist = chainer.Variable(
                  self.xp.asarray(self.labeldist)
              )
          loss_reg = -F.sum(
              F.scale(F.log_softmax(y_all), self.vlabeldist, axis=1)
          ) / len(ys_in)
          self.loss = (
              1.0 - self.lsm_weight
          ) * self.loss + self.lsm_weight * loss_reg
  
      return self.loss, acc
  
file_path: espnet/espnet/nets/chainer_backend/rnn/decoders.py
imports: import logging
  import random
  from argparse import Namespace
  import chainer
  import chainer.functions
  import chainer.links
  import numpy
  import espnet.nets.chainer_backend.deterministic_embed_id
  from espnet.nets.ctc_prefix_score import CTCPrefixScore
  from espnet.nets.e2e_asr_common import end_detect
label_desc: Use image node_id 3 for calling the Decoder obj's underlying member method code with example usage: obj.__call__(hs, ys) and returns: self,  acc