class_docstr: Self-attention layer (specification key: `self_attention`).
  
  Args:
      size (int >= 0): Layer output size, 0 implies additionally removing the axis
          (<span style="color:#C00000"><b>required</b></span>).
      attention_size (int > 0): Query/key size
          (<span style="color:#00C000"><b>default</b></span>: same as output size).
      bias (bool): Whether to add a trainable bias variable
          (<span style="color:#00C000"><b>default</b></span>: false).
      activation ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' |
          'softmax' | 'softplus' | 'softsign' | 'swish' | 'tanh'): Activation nonlinearity
          (<span style="color:#00C000"><b>default</b></span>: none).
      dropout (parameter, 0.0 <= float < 1.0): Dropout rate
          (<span style="color:#00C000"><b>default</b></span>: 0.0).
      initialization_scale (float > 0.0): Initialization scale
          (<span style="color:#00C000"><b>default</b></span>: 1.0).
      vars_trainable (bool): Whether layer variables are trainable
          (<span style="color:#00C000"><b>default</b></span>: true).
      l2_regularization (float >= 0.0): Scalar controlling L2 regularization
          (<span style="color:#00C000"><b>default</b></span>: inherit value of parent module).
      name (string): Layer name
          (<span style="color:#00C000"><b>default</b></span>: internally chosen).
      input_spec (specification): <span style="color:#00C000"><b>internal use</b></span>.
class_docstr_tok: ["Self-attention","layer","(","specification","key",":","`","self_attention","`",")",".","Args",":","size","(","int",">","=","0",")",":","Layer","output","size",",","0","implies","additionally","removing","the","axis","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",")",".","attention_size","(","int",">","0",")",":","Query\/key","size","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","same","as","output","size",")",".","bias","(","bool",")",":","Whether","to","add","a","trainable","bias","variable","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","false",")",".","activation","(","'crelu","'","|","'elu","'","|","'leaky-relu","'","|","'none","'","|","'relu","'","|","'selu","'","|","'sigmoid","'","|","'softmax","'","|","'softplus","'","|","'softsign","'","|","'swish","'","|","'tanh","'",")",":","Activation","nonlinearity","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","none",")",".","dropout","(","parameter",",","0.0","<","=","float","<","1.0",")",":","Dropout","rate","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","0.0",")",".","initialization_scale","(","float",">","0.0",")",":","Initialization","scale","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","1.0",")",".","vars_trainable","(","bool",")",":","Whether","layer","variables","are","trainable","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","true",")",".","l2_regularization","(","float",">","=","0.0",")",":","Scalar","controlling","L2","regularization","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","inherit","value","of","parent","module",")",".","name","(","string",")",":","Layer","name","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","internally","chosen",")",".","input_spec","(","specification",")",":","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","internal","use","<","\/b",">","<","\/span",">","."]
code: def __init__(
      self,
      *,
      size,
      attention_size=None,
      bias=False,
      activation=None,
      dropout=0.0,
      initialization_scale=1.0,
      vars_trainable=True,
      l2_regularization=None,
      name=None,
      input_spec=None,
  ):
      super().__init__(
          size=size,
          bias=bias,
          activation=activation,
          dropout=dropout,
          vars_trainable=vars_trainable,
          l2_regularization=l2_regularization,
          name=name,
          input_spec=input_spec,
      )
  
      self.attention_size = (
          size if attention_size is None else attention_size
      )
  
      if input_spec.rank <= 1:
          raise TensorforceError.value(
              name="SelfAttention",
              argument="input_spec[shape]",
              value=str(input_spec.shape),
              hint="is not rank >= 2",
          )
  
      self.query = self.submodule(
          name="query",
          module=Linear,
          size=self.attention_size,
          bias=bias,
          vars_trainable=vars_trainable,
          input_spec=input_spec,
      )
      self.key = self.submodule(
          name="key",
          module=Linear,
          size=self.attention_size,
          bias=bias,
          vars_trainable=vars_trainable,
          input_spec=input_spec,
      )
      self.value = self.submodule(
          name="value",
          module=Linear,
          size=size,
          bias=bias,
          initialization_scale=initialization_scale,
          vars_trainable=vars_trainable,
          input_spec=input_spec,
      )
  
      self.architecture_kwargs["size"] = str(size)
      self.architecture_kwargs["attention_size"] = str(
          self.attention_size
      )
      self.architecture_kwargs["bias"] = str(bias)
      if activation is not None:
          self.architecture_kwargs["activation"] = str(activation)
      if dropout != 0.0:
          self.architecture_kwargs["dropout"] = str(dropout)
      if initialization_scale != 1.0:
          self.architecture_kwargs["initialization_scale"] = str(
              initialization_scale
          )
      if not vars_trainable:
          self.architecture_kwargs["trainable"] = str(vars_trainable)
      if l2_regularization is not None:
          self.architecture_kwargs["l2_regularization"] = str(
              l2_regularization
          )
  
file_path: tensorforce/tensorforce/core/layers/attention.py
imports: import numpy
  import tensorflow
  from tensorforce import TensorforceError, util
  from tensorforce.core import TensorSpec, tf_function, tf_util
  from tensorforce.core.layers import Linear, TransformationBase
label_desc: Use image node_id 1 to create a new SelfAttention object from inherited base classes: TransformationBase with example: obj = SelfAttention()