class_docstr: A self attention layer
  
  Input is a list which consists of 2 ndarrays.
  1. Token id ndarray: shape [batch, seqLen] with the word token indices in the vocabulary
  2. Position id ndarray: shape [batch, seqLen] with positions in the sentence.
  Output is a list which contains:
  1. The states of Transformer layer.
  2. The pooled output which processes the hidden state of the last layer with regard to the first
  token of the sequence. This would be useful for segment-level tasks.
  
  # Arguments
  nBlock: block number
  hidden_drop: drop probability off projection
  attn_drop: drop probability of attention
  n_head: head number
  initializer_range: weight initialization range
  bidirectional: whether unidirectional or bidirectional
  output_all_block: whether output all blocks' output
  embedding_layer: embedding layer
  input_shape: input shape
class_docstr_tok: ["A","self","attention","layer","Input","is","a","list","which","consists","of","2","ndarrays",".","1",".","Token","id","ndarray",":","shape","[","batch",",","seqLen","]","with","the","word","token","indices","in","the","vocabulary","2",".","Position","id","ndarray",":","shape","[","batch",",","seqLen","]","with","positions","in","the","sentence",".","Output","is","a","list","which","contains",":","1",".","The","states","of","Transformer","layer",".","2",".","The","pooled","output","which","processes","the","hidden","state","of","the","last","layer","with","regard","to","the","first","token","of","the","sequence",".","This","would","be","useful","for","segment-level","tasks",".","#","Arguments","nBlock",":","block","number","hidden_drop",":","drop","probability","off","projection","attn_drop",":","drop","probability","of","attention","n_head",":","head","number","initializer_range",":","weight","initialization","range","bidirectional",":","whether","unidirectional","or","bidirectional","output_all_block",":","whether","output","all","blocks","'","output","embedding_layer",":","embedding","layer","input_shape",":","input","shape"]
docstr: vocab: vocabulary size of training data, default is 40990
  seq_len: max sequence length of training data, default is 77
  n_block: block number, default is 12
  hidden_drop: drop probability of projection, default is 0.1
  attn_drop: drop probability of attention, default is 0.1
  n_head: head number, default is 12
  hidden_size: is also embedding size
  embedding_drop: drop probability of embedding layer, default is 0.1
  initializer_range: weight initialization range, default is 0.02
  bidirectional: whether unidirectional or bidirectional, default is unidirectional
  output_all_block: whether output all blocks' output
docstr_tok: ["vocab",":","vocabulary","size","of","training","data",",","default","is","40990","seq_len",":","max","sequence","length","of","training","data",",","default","is","77","n_block",":","block","number",",","default","is","12","hidden_drop",":","drop","probability","of","projection",",","default","is","0.1","attn_drop",":","drop","probability","of","attention",",","default","is","0.1","n_head",":","head","number",",","default","is","12","hidden_size",":","is","also","embedding","size","embedding_drop",":","drop","probability","of","embedding","layer",",","default","is","0.1","initializer_range",":","weight","initialization","range",",","default","is","0.02","bidirectional",":","whether","unidirectional","or","bidirectional",",","default","is","unidirectional","output_all_block",":","whether","output","all","blocks","'","output"]
code: def init(
      cls,
      vocab=40990,
      seq_len=77,
      n_block=12,
      hidden_drop=0.1,
      attn_drop=0.1,
      n_head=12,
      hidden_size=768,
      embedding_drop=0.1,
      initializer_range=0.02,
      bidirectional=False,
      output_all_block=False,
  ):
      """
      vocab: vocabulary size of training data, default is 40990
      seq_len: max sequence length of training data, default is 77
      n_block: block number, default is 12
      hidden_drop: drop probability of projection, default is 0.1
      attn_drop: drop probability of attention, default is 0.1
      n_head: head number, default is 12
      hidden_size: is also embedding size
      embedding_drop: drop probability of embedding layer, default is 0.1
      initializer_range: weight initialization range, default is 0.02
      bidirectional: whether unidirectional or bidirectional, default is unidirectional
      output_all_block: whether output all blocks' output
      """
      if hidden_size < 0:
          invalidInputError(
              False,
              "hidden_size must be greater than 0 with default embedding layer",
          )
      from bigdl.dllib.nn.layer import Squeeze
  
      word_input = InputLayer(input_shape=(seq_len,))
      postion_input = InputLayer(input_shape=(seq_len,))
  
      embedding = Sequential()
      embedding.add(
          Merge(layers=[word_input, postion_input], mode="concat")
      ).add(Reshape([seq_len * 2])).add(
          Embedding(
              vocab,
              hidden_size,
              input_length=seq_len * 2,
              weights=np.random.normal(
                  0.0, initializer_range, (vocab, hidden_size)
              ),
          )
      ).add(
          Dropout(embedding_drop)
      ).add(
          Reshape((seq_len, 2, hidden_size))
      ).add(
          KerasLayerWrapper(Sum(dimension=3, squeeze=True))
      )
      # walk around for bug #1208, need remove this line after the bug fixed
      embedding.add(KerasLayerWrapper(Squeeze(dim=3)))
  
      shape = ((seq_len,), (seq_len,))
      return TransformerLayer(
          n_block,
          hidden_drop,
          attn_drop,
          n_head,
          initializer_range,
          bidirectional,
          output_all_block,
          embedding,
          input_shape=shape,
      )
  
imports: import numpy
  import math
  from bigdl.dllib.nn.layer import Sum
  from bigdl.dllib.nn.layer import Layer
  from bigdl.dllib.utils.file_utils import callZooFunc
  from bigdl.dllib.keras.engine import ZooKerasLayer
  from bigdl.dllib.keras.layers import *
  from bigdl.dllib.keras.models import Sequential
  from bigdl.dllib.keras.models import Model
  import bigdl.dllib.keras.autograd
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 12 for calling the TransformerLayer obj's underlying member method code with example usage: obj.init(cls, vocab, seq_len, n_block, hidden_drop, attn_drop, n_head, hidden_size, embedding_drop, initializer_range, bidirectional, output_all_block) and returns: TransformerLayer