class_docstr: Container module with an encoder, a recurrent or transformer module, and a decoder.
class_docstr_tok: ["Container","module","with","an","encoder",",","a","recurrent","or","transformer","module",",","and","a","decoder","."]
code: def __init__(self, ntoken, ninp, nhead, nhid, nlayers, dropout=0.5):
      super().__init__()
      try:
          from torch.nn import (
              TransformerEncoder,
              TransformerEncoderLayer,
          )
      except Exception as e:
          raise ImportError(
              "TransformerEncoder module does not exist in PyTorch 1.1 or lower."
          ) from e
      self.model_type = "Transformer"
      self.src_mask = None
      self.pos_encoder = PositionalEncoding(ninp, dropout)
      encoder_layers = TransformerEncoderLayer(
          ninp, nhead, nhid, dropout
      )
      self.transformer_encoder = TransformerEncoder(
          encoder_layers, nlayers
      )
      self.encoder = nn.Embedding(ntoken, ninp)
      self.ninp = ninp
      self.decoder = nn.Linear(ninp, ntoken)
  
      self.init_weights()
  
imports: import math
  from collections import OrderedDict
  from typing import Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn, Tensor
label_desc: Use image node_id 1 to create a new TransformerModel object from inherited base classes: nn with example: obj = TransformerModel(ntoken, ninp, nhead, nhid, nlayers, dropout)