code: def _add_components(self, input_desc, input_dim, nonlinearities):
      dim = self.attention_input_dim()
      self_repair_scale = self.config["self-repair-scale"]
      target_rms = self.config["target-rms"]
      max_change = self.config["max-change"]
      ng_affine_options = self.config["ng-affine-options"]
      l2_regularize = self.config["l2-regularize"]
      learning_rate_factor = self.config["learning-rate-factor"]
      learning_rate_option = (
          "learning-rate-factor={0}".format(learning_rate_factor)
          if learning_rate_factor != 1.0
          else ""
      )
      l2_regularize_option = (
          "l2-regularize={0} ".format(l2_regularize)
          if l2_regularize != 0.0
          else ""
      )
      configs = []
      # First the affine node.
      line = (
          "component name={0}.affine"
          " type=NaturalGradientAffineComponent"
          " input-dim={1}"
          " output-dim={2}"
          " max-change={3}"
          " {4} {5} {6}"
          "".format(
              self.name,
              input_dim,
              dim,
              max_change,
              ng_affine_options,
              learning_rate_option,
              l2_regularize_option,
          )
      )
      configs.append(line)
  
      line = (
          "component-node name={0}.affine"
          " component={0}.affine input={1}"
          "".format(self.name, input_desc)
      )
      configs.append(line)
      cur_node = "{0}.affine".format(self.name)
  
      for nonlinearity in nonlinearities:
          if nonlinearity == "relu":
              line = (
                  "component name={0}.{1}"
                  " type=RectifiedLinearComponent dim={2}"
                  " self-repair-scale={3}"
                  "".format(
                      self.name, nonlinearity, dim, self_repair_scale
                  )
              )
  
          elif nonlinearity == "attention":
              line = (
                  "component name={0}.{1}"
                  " type=RestrictedAttentionComponent"
                  " value-dim={2}"
                  " key-dim={3}"
                  " num-left-inputs={4}"
                  " num-right-inputs={5}"
                  " num-left-inputs-required={6}"
                  " num-right-inputs-required={7}"
                  " output-context={8}"
                  " time-stride={9}"
                  " num-heads={10}"
                  " key-scale={11}"
                  "".format(
                      self.name,
                      nonlinearity,
                      self.config["value-dim"],
                      self.config["key-dim"],
                      self.config["num-left-inputs"],
                      self.config["num-right-inputs"],
                      self.config["num-left-inputs-required"],
                      self.config["num-right-inputs-required"],
                      self.config["output-context"],
                      self.config["time-stride"],
                      self.config["num-heads"],
                      self.config["key-scale"],
                  )
              )
              dim = self.attention_output_dim()
  
          elif nonlinearity == "sigmoid":
              line = (
                  "component name={0}.{1}"
                  " type=SigmoidComponent dim={2}"
                  " self-repair-scale={3}"
                  "".format(
                      self.name, nonlinearity, dim, self_repair_scale
                  )
              )
  
          elif nonlinearity == "tanh":
              line = (
                  "component name={0}.{1}"
                  " type=TanhComponent dim={2}"
                  " self-repair-scale={3}"
                  "".format(
                      self.name, nonlinearity, dim, self_repair_scale
                  )
              )
  
          elif nonlinearity == "renorm":
              line = (
                  "component name={0}.{1}"
                  " type=NormalizeComponent dim={2}"
                  " target-rms={3}"
                  "".format(self.name, nonlinearity, dim, target_rms)
              )
  
          elif nonlinearity == "batchnorm":
              line = (
                  "component name={0}.{1}"
                  " type=BatchNormComponent dim={2}"
                  " target-rms={3}"
                  "".format(self.name, nonlinearity, dim, target_rms)
              )
  
          elif nonlinearity == "dropout":
              line = (
                  "component name={0}.{1} type=DropoutComponent "
                  "dim={2} dropout-proportion={3}".format(
                      self.name,
                      nonlinearity,
                      dim,
                      self.config["dropout-proportion"],
                  )
              )
  
          else:
              raise RuntimeError(
                  "Unknown nonlinearity type: {0}".format(nonlinearity)
              )
  
          configs.append(line)
          line = (
              "component-node name={0}.{1}"
              " component={0}.{1} input={2}"
              "".format(self.name, nonlinearity, cur_node)
          )
  
          configs.append(line)
          cur_node = "{0}.{1}".format(self.name, nonlinearity)
      return configs
  
file_path: espnet/egs2/iwslt21_low_resource/asr1/steps/libs/nnet3/xconfig/attention.py
imports: from __future__ import print_function
  from __future__ import division
  import math
  import re
  import sys
  from libs.nnet3.xconfig.basic_layers import XconfigLayerBase
label_desc: Use image node_id 10 for calling the XconfigAttentionLayer obj's underlying member method code with example usage: obj._add_components(input_desc, input_dim, nonlinearities) and returns: configs