class_docstr: Transformer language model.
class_docstr_tok: ["Transformer","language","model","."]
docstr: Initialize class.
  
  Args:
      n_vocab (int): The size of the vocabulary
      args (argparse.Namespace): configurations. see py:method:`add_arguments`
docstr_tok: ["Initialize","class",".","Args",":","n_vocab","(","int",")",":","The","size","of","the","vocabulary","args","(","argparse.Namespace",")",":","configurations",".","see","py",":","method",":","`","add_arguments","`"]
code: def __init__(self, n_vocab, args):
      """Initialize class.
  
      Args:
          n_vocab (int): The size of the vocabulary
          args (argparse.Namespace): configurations. see py:method:`add_arguments`
  
      """
      nn.Module.__init__(self)
  
      # NOTE: for a compatibility with less than 0.9.7 version models
      emb_dropout_rate = getattr(args, "emb_dropout_rate", 0.0)
      # NOTE: for a compatibility with less than 0.9.7 version models
      tie_weights = getattr(args, "tie_weights", False)
      # NOTE: for a compatibility with less than 0.9.7 version models
      att_dropout_rate = getattr(args, "att_dropout_rate", 0.0)
  
      if args.pos_enc == "sinusoidal":
          pos_enc_class = PositionalEncoding
      elif args.pos_enc == "none":
  
          def pos_enc_class(*args, **kwargs):
              return nn.Sequential()  # indentity
  
      else:
          raise ValueError(f"unknown pos-enc option: {args.pos_enc}")
  
      self.embed = nn.Embedding(n_vocab, args.embed_unit)
  
      if emb_dropout_rate == 0.0:
          self.embed_drop = None
      else:
          self.embed_drop = nn.Dropout(emb_dropout_rate)
  
      self.encoder = Encoder(
          idim=args.embed_unit,
          attention_dim=args.att_unit,
          attention_heads=args.head,
          linear_units=args.unit,
          num_blocks=args.layer,
          dropout_rate=args.dropout_rate,
          attention_dropout_rate=att_dropout_rate,
          input_layer="linear",
          pos_enc_class=pos_enc_class,
      )
      self.decoder = nn.Linear(args.att_unit, n_vocab)
  
      logging.info("Tie weights set to {}".format(tie_weights))
      logging.info("Dropout set to {}".format(args.dropout_rate))
      logging.info("Emb Dropout set to {}".format(emb_dropout_rate))
      logging.info("Att Dropout set to {}".format(att_dropout_rate))
  
      if tie_weights:
          assert (
              args.att_unit == args.embed_unit
          ), "Tie Weights: True need embedding and final dimensions to match"
          self.decoder.weight = self.embed.weight
  
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.transformer.embedding import PositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.scorer_interface import BatchScorerInterface
  from espnet.utils.cli_utils import strtobool
label_desc: Use image node_id 2 to create a new TransformerLM object from inherited base classes: nn, LMInterface, BatchScorerInterface with example: obj = TransformerLM(n_vocab, args)