code: def transformer(
      src,
      tgt,
      embed_dim=512,
      num_heads=8,
      num_encoder_layers=6,
      num_decoder_layers=6,
      dim_feedforward=2048,
      dropout=0.1,
      activation=None,
      src_additive_mask=None,
      tgt_additive_mask=None,
      memory_additive_mask=None,
      src_key_padding_mask=None,
      tgt_key_padding_mask=None,
      memory_key_padding_mask=None,
      rng=None,
      add_attn_bias=False,
      fix_parameters=False,
  ):
      r"""Transformer.
  
      We use the following notations to describe the inputs and outputs below.
      :math:`L_T`: target sequence length, :math:`L_S`: source sequence length, :math:`B`: batch size, :math:`E`: embedding dimension.
  
      References:
  
          A. Vaswani et al. "Attention is All You Need."
          NIPS. 2017.
          <https://papers.nips.cc/paper/7181-attention-is-all-you-need.pdf>
  
      Examples:
  
      .. code-block:: python
  
          src = nn.Variable((src_len, batch_size, embed_dim),need_grad=True)
          tgt = nn.Variable((tgt_len, batch_size, embed_dim),need_grad=True)
          out = PF.transformer(src, tgt, num_heads=16, num_encoder_layers=12)
          out.forward()
  
      Args:
          src (~nnabla.Variable): Input source sequence to the encoder with shape:math:`(L_S, B, E)`.
          tgt (~nnabla.Variable): Input target sequence to the decoder with shape :math:`(L_T, B, E)`.
          embed_dim (int, optional): Embedding dimension to be used. Default is 512.
          num_heads (int, optional): Number of attention heads. Default is 12.
          num_encoder_layers (int, optional): Number of encoder layers to stack. Default is 6.
          num_decoder_layers (int, optional): Number of decoder layers to stack. Default is 6.
          dim_feedforward (int, optional): Dimension of the feedforward network model. Default is 2048.
          dropout (float, optional): Dropout ratio applied. Default is 0.1.
          activation (function, optional): Non-linear activation function to be used. Default is None, which is set as F.relu in the code.
          src_additive_mask (~nnabla.Variable, optional): Additive mask for the src sequence (optional). :math:`(L_S, L_S)`.
          tgt_additive_mask (~nnabla.Variable, optional): Additive mask for the tgt sequence (optional). :math:`(L_T, L_T)`.
          memory_additive_mask (~nnabla.Variable, optional): Additive mask for the encoder output (optional). :math:`(L_T, L_S)`.
          src_key_padding_mask (~nnabla.Variable, optional): Key padding mask for src keys per batch (optional). :math:`(B, L_S)`. Specified padding elements will be ignored by the attention layer. Values must be either 1 or 0.
          tgt_key_padding_mask (~nnabla.Variable, optional): Key padding mask for tgt keys per batch (optional). :math:`(B, L_T)`. Specified padding elements will be ignored by the attention layer. Values must be either 1 or 0.
          memory_key_padding_mask (~nnabla.Variable, optional): Key padding mask for memory keys per batch (optional). :math:`(B, L_S)`. Specified padding elements will be ignored by the attention layer. Values must be either 1 or 0.
          rng (numpy.random.RandomState, optional): Random generator for Initializer. Default is None.
          add_attn_bias (bool, optional): Specify whether to add attention bias parameters for key and value. Default is False.
          fix_parameters (bool, optional): When set to `True`, the weights and biases will not be updated. Default is False.
  
      Returns:
          ~nnabla.Variable: Output :math:`y` with shape :math:`(L_T, B, E)`
      """
      assert (
          src.shape[1] == tgt.shape[1]
      ), "the batch number of source and target must be equal"
      assert (
          src.shape[2] == embed_dim and tgt.shape[2] == embed_dim
      ), "the feature dimension of source and target must be equal to embed_dim"
  
      memory = src
  
      for i in range(num_encoder_layers):
          memory = transformer_encode(
              memory,
              embed_dim=embed_dim,
              num_heads=num_heads,
              dim_feedforward=dim_feedforward,
              dropout=dropout,
              activation=activation,
              src_additive_mask=src_additive_mask,
              src_key_padding_mask=src_key_padding_mask,
              rng=rng,
              add_attn_bias=add_attn_bias,
              fix_parameters=fix_parameters,
              name="encoder{:02d}".format(i),
          )
  
      output = tgt
  
      for i in range(num_decoder_layers):
          output = transformer_decode(
              output,
              memory,
              embed_dim=embed_dim,
              num_heads=num_heads,
              dim_feedforward=dim_feedforward,
              dropout=dropout,
              activation=activation,
              tgt_additive_mask=tgt_additive_mask,
              memory_additive_mask=memory_additive_mask,
              tgt_key_padding_mask=tgt_key_padding_mask,
              memory_key_padding_mask=memory_key_padding_mask,
              rng=rng,
              add_attn_bias=add_attn_bias,
              fix_parameters=fix_parameters,
              name="decoder{:02d}".format(i),
          )
  
      return output
  
imports: from six import exec_
  import numpy
  import nnabla
  import nnabla.functions
  from nnabla.parameter import get_parameter_or_create, get_parameter
  from nnabla.initializer import calc_uniform_lim_glorot, ConstantInitializer, NormalInitializer, UniformInitializer, WeightNormalizationScaleInitializer
label_desc: Use image node_id 46 for calling a global function with example usage: transformer(src, tgt, embed_dim, num_heads, num_encoder_layers, num_decoder_layers, dim_feedforward, dropout, activation, src_additive_mask, tgt_additive_mask, memory_additive_mask, src_key_padding_mask, tgt_key_padding_mask, memory_key_padding_mask, rng, add_attn_bias, fix_parameters) and returns: output