class_docstr: Returns a layer that maps `(Q, K, V, mask)` to `(activations, mask)`.
  
  This layer type performs the inner workings of one pass of multi-head
  self-attention. It:
  
    - subdivides incoming Q/K/V activations into multi-head versions;
    - for each head, computes the scaled dot product of each Q-K pair;
    - applies mask to screen out positions that come from padding tokens
      (indicated by 0 value);
    - [in ``'train'`` mode] applies dropout to Q-K dot products;
    - for each head, computes Q-K attention strengths using a per-query softmax
      of the Q-K dot products;
    - for each head, for each query position, combines V vectors according
      to the Q-K attention strengths; and
    - concatenates and fuses resulting per-head vectors into outgoing
      activations matching original input activation shapes.
class_docstr_tok: ["Returns","a","layer","that","maps","`","(","Q",",","K",",","V",",","mask",")","`","to","`","(","activations",",","mask",")","`",".","This","layer","type","performs","the","inner","workings","of","one","pass","of","multi-head","self-attention",".","It",":","-","subdivides","incoming","Q\/K\/V","activations","into","multi-head","versions",";","-","for","each","head",",","computes","the","scaled","dot","product","of","each","Q-K","pair",";","-","applies","mask","to","screen","out","positions","that","come","from","padding","tokens","(","indicated","by","0","value",")",";","-","[","in","``","'train","'","``","mode","]","applies","dropout","to","Q-K","dot","products",";","-","for","each","head",",","computes","Q-K","attention","strengths","using","a","per-query","softmax","of","the","Q-K","dot","products",";","-","for","each","head",",","for","each","query","position",",","combines","V","vectors","according","to","the","Q-K","attention","strengths",";","and","-","concatenates","and","fuses","resulting","per-head","vectors","into","outgoing","activations","matching","original","input","activation","shapes","."]
docstr: Returns a new :py:class:`PureAttention` instance.
  
  Args:
    n_heads: Number of attention heads.
    dropout: Probababilistic rate for attention dropout, which overrides
        (sets to zero) some attention strengths derived from query-key
        matching. As a result, on a given forward pass, some value vectors
        don't contribute to the output, analogous to how regular dropout can
        cause some node activations to be ignored. Applies only if layer is
        created in ``'train'`` mode.
    mode: One of ``'train'``, ``'eval'``, or ``'predict'``.
code: def __init__(self, n_heads=1, dropout=0.0, mode="train"):
      """Returns a new :py:class:`PureAttention` instance.
  
      Args:
        n_heads: Number of attention heads.
        dropout: Probababilistic rate for attention dropout, which overrides
            (sets to zero) some attention strengths derived from query-key
            matching. As a result, on a given forward pass, some value vectors
            don't contribute to the output, analogous to how regular dropout can
            cause some node activations to be ignored. Applies only if layer is
            created in ``'train'`` mode.
        mode: One of ``'train'``, ``'eval'``, or ``'predict'``.
      """
      super().__init__(n_in=4, n_out=2)
      self._n_heads = n_heads
      self._dropout = dropout
      self._mode = mode
  
imports: import numpy
  from trax import fastmath
  from trax.fastmath import numpy
  from trax.layers import base
  from trax.layers import combinators
  from trax.layers import convolution
  from trax.layers import core
  from trax.layers import initializers
  from trax.layers.assert_shape import assert_shape
  from trax.layers.base import Fn
  from trax.layers.research import sparsity
label_desc: Use image node_id 1 to create a new PureAttention object from inherited base classes: base with example: obj = PureAttention(n_heads, dropout, mode)