class_docstr: Transformer Encoder.
class_docstr_tok: ["Transformer","Encoder","."]
code: def __init__(
      self,
      seq_length,
      num_layers,
      num_heads,
      hidden_dim,
      mlp_dim,
      dropout_rate,
      attention_dropout_rate,
  ):
      super().__init__()
      self.pos_embedding = nn.Parameter(
          torch.empty(seq_length, 1, hidden_dim).normal_(std=0.02)
      )
      self.dropout = nn.Dropout(dropout_rate)
      layers = []
      for i in range(num_layers):
          layers.append(
              (
                  f"layer_{i}",
                  EncoderBlock(
                      num_heads,
                      hidden_dim,
                      mlp_dim,
                      dropout_rate,
                      attention_dropout_rate,
                  ),
              )
          )
      self.layers = nn.Sequential(OrderedDict(layers))
      self.ln = LayerNorm(hidden_dim)
  
imports: import copy
  import logging
  import math
  from collections import OrderedDict
  from functools import partial
  from typing import Dict, List, Mapping, NamedTuple, Union
  import torch
  import torch.nn
  from classy_vision.models import ClassyModel, register_model
  from .lecun_normal_init import lecun_normal_init
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: nn with example: obj = Encoder(seq_length, num_layers, num_heads, hidden_dim, mlp_dim, dropout_rate, attention_dropout_rate)