code: def __init__(
      self,
      d_model,
      nhead,
      dim_feedforward=2048,
      attention_dropout_rate=0.0,
      residual_dropout_rate=0.1,
      with_self_attn=True,
      with_cross_attn=False,
      epsilon=1e-5,
  ):
      super(TransformerBlock, self).__init__()
      self.with_self_attn = with_self_attn
      if with_self_attn:
          self.self_attn = MultiheadAttention(
              d_model,
              nhead,
              dropout=attention_dropout_rate,
              self_attn=with_self_attn,
          )
          self.norm1 = LayerNorm(d_model, epsilon=epsilon)
          self.dropout1 = Dropout(residual_dropout_rate)
      self.with_cross_attn = with_cross_attn
      if with_cross_attn:
          self.cross_attn = MultiheadAttention(  # for self_attn of encoder or cross_attn of decoder
              d_model, nhead, dropout=attention_dropout_rate
          )
          self.norm2 = LayerNorm(d_model, epsilon=epsilon)
          self.dropout2 = Dropout(residual_dropout_rate)
  
      self.mlp = Mlp(
          in_features=d_model,
          hidden_features=dim_feedforward,
          act_layer=nn.ReLU,
          drop=residual_dropout_rate,
      )
  
      self.norm3 = LayerNorm(d_model, epsilon=epsilon)
  
      self.dropout3 = Dropout(residual_dropout_rate)
  
imports: import math
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from paddle.nn import LayerList
  from paddle.nn import Dropout, Linear, LayerNorm
  import numpy
  from ppocr.modeling.backbones.rec_svtrnet import Mlp, zeros_, ones_
  from paddle.nn.initializer import XavierNormal
label_desc: Use image node_id 1 to create a new TransformerBlock object from inherited base classes: nn with example: obj = TransformerBlock(d_model, nhead, dim_feedforward, attention_dropout_rate, residual_dropout_rate, with__attn, with_cross_attn, epsilon)