class_docstr: PrePostProcessLayer
class_docstr_tok: ["PrePostProcessLayer"]
code: def __init__(self, process_cmd, d_model, dropout_rate):
      super(PrePostProcessLayer, self).__init__()
      self.process_cmd = process_cmd
      self.functors = []
      for cmd in self.process_cmd:
          if cmd == "a":  # add residual connection
              self.functors.append(
                  lambda x, y: x + y if y is not None else x
              )
          elif cmd == "n":  # add layer normalization
              self.functors.append(
                  self.add_sublayer(
                      "layer_norm_%d" % len(self.sublayers()),
                      paddle.nn.LayerNorm(
                          normalized_shape=d_model,
                          weight_attr=paddle.ParamAttr(
                              initializer=paddle.nn.initializer.Constant(
                                  1.0
                              )
                          ),
                          bias_attr=paddle.ParamAttr(
                              initializer=paddle.nn.initializer.Constant(
                                  0.0
                              )
                          ),
                      ),
                  )
              )
          elif cmd == "d":  # add dropout
              self.functors.append(
                  lambda x: F.dropout(
                      x, p=dropout_rate, mode="downscale_in_infer"
                  )
                  if dropout_rate
                  else x
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import paddle
  from paddle import ParamAttr, nn
  from paddle import nn, ParamAttr
  from paddle.nn import functional
  import numpy
label_desc: Use image node_id 1 to create a new PrePostProcessLayer object from inherited base classes: nn with example: obj = PrePostProcessLayer(process_cmd, d_model, dropout_rate)