class_docstr: Creates an embedding from all features for a sequence attribute; facilitates MLM.
  
  This layer combines all features for an attribute and embeds them using a
  transformer, optionally doing masked language modeling. The layer is meant only for
  attributes with sequence-level features, such as `text`, `response` and
  `action_text`.
  
  Internally, this layer applies the following steps:
  1. Combine features using `RasaFeatureCombiningLayer`.
  2. Apply a dense layer(s) to the combined features.
  3. Optionally, and only during training for the `text` attribute, apply masking to
      the features and create further helper variables for masked language modeling.
  4. Embed the features using a transformer, effectively reducing variable-length
      sequences of features to fixed-size embeddings.
  
  Arguments:
      attribute: Name of attribute (e.g. `text` or `label`) whose features will be
          processed.
      attribute_signature: A dictionary containing two lists of feature signatures,
          one for each feature type (`sentence` or `sequence`) of the given attribute.
      config: A model config used for correctly parameterising the underlying layers.
  
  Input shape:
      Tuple of three input tensors:
          sequence_features: List of 3-D dense or sparse tensors, each with shape
              `(batch_size, max_seq_length, input_dim)` where `input_dim` can be
              different for sparse vs dense tensors. See the input shape of
              `ConcatenateSparseDenseFeatures` for more information.
          sentence_features: List of 3-D dense or sparse tensors, each with shape
              `(batch_size, 1, input_dim)` where `input_dim` can be different for
              sparse vs dense tensors, and can differ from that in
              `sequence_features`. See the input shape of
              `ConcatenateSparseDenseFeatures` for more information.
          sequence_feature_lengths: Dense tensor of shape `(batch_size, )`.
  
  Output shape:
      outputs: `(batch_size, seq_length, units)` where `units` matches the underlying
          transformer's output size (if present), otherwise it matches the output size
          of the `Ffnn` block applied to the combined features, or it's the output
          size of the underlying `RasaFeatureCombiningLayer` if the `Ffnn` block has 0
          layers. `seq_length` is the sum of the sequence dimension
          sizes of sequence- and sentence-level features (for details, see the output
          shape of `RasaFeatureCombiningLayer`). If both feature types are present,
          then `seq_length` will be 1 + the length of the longest sequence of real
          tokens across all examples in the given batch.
      seq_sent_features: `(batch_size, seq_length, hidden_dim)`, where `hidden_dim` is
          the output size of the underlying `Ffnn` block, or the output size of the
          underlying `RasaFeatureCombiningLayer` if the `Ffnn` block has 0 layers.
      mask_combined_sequence_sentence: `(batch_size, seq_length, 1)`
      token_ids: `(batch_size, seq_length, id_dim)`. `id_dim` is 2 when no dense
          sequence-level features are present. Otherwise, it's arbitrarily chosen to
          match the last dimension size of the first dense sequence-level feature in
          the input list of features.
      mlm_boolean_mask: `(batch_size, seq_length, 1)`, empty tensor if not doing MLM.
      attention_weights: `(transformer_layers, batch_size, num_transformer_heads,
          seq_length, seq_length)`, empty tensor if the transformer has 0 layers.
  
  Raises:
      A `TFLayerConfigException` if no feature signatures for sequence-level features
          are provided.
  
  Attributes:
      output_units: The last dimension size of the layer's first output (`outputs`).
class_docstr_tok: ["Creates","an","embedding","from","all","features","for","a","sequence","attribute",";","facilitates","MLM",".","This","layer","combines","all","features","for","an","attribute","and","embeds","them","using","a","transformer",",","optionally","doing","masked","language","modeling",".","The","layer","is","meant","only","for","attributes","with","sequence-level","features",",","such","as","`","text","`",",","`","response","`","and","`","action_text","`",".","Internally",",","this","layer","applies","the","following","steps",":","1",".","Combine","features","using","`","RasaFeatureCombiningLayer","`",".","2",".","Apply","a","dense","layer","(","s",")","to","the","combined","features",".","3",".","Optionally",",","and","only","during","training","for","the","`","text","`","attribute",",","apply","masking","to","the","features","and","create","further","helper","variables","for","masked","language","modeling",".","4",".","Embed","the","features","using","a","transformer",",","effectively","reducing","variable-length","sequences","of","features","to","fixed-size","embeddings",".","Arguments",":","attribute",":","Name","of","attribute","(","e.g",".","`","text","`","or","`","label","`",")","whose","features","will","be","processed",".","attribute_signature",":","A","dictionary","containing","two","lists","of","feature","signatures",",","one","for","each","feature","type","(","`","sentence","`","or","`","sequence","`",")","of","the","given","attribute",".","config",":","A","model","config","used","for","correctly","parameterising","the","underlying","layers",".","Input","shape",":","Tuple","of","three","input","tensors",":","sequence_features",":","List","of","3-D","dense","or","sparse","tensors",",","each","with","shape","`","(","batch_size",",","max_seq_length",",","input_dim",")","`","where","`","input_dim","`","can","be","different","for","sparse","vs","dense","tensors",".","See","the","input","shape","of","`","ConcatenateSparseDenseFeatures","`","for","more","information",".","sentence_features",":","List","of","3-D","dense","or","sparse","tensors",",","each","with","shape","`","(","batch_size",",","1",",","input_dim",")","`","where","`","input_dim","`","can","be","different","for","sparse","vs","dense","tensors",",","and","can","differ","from","that","in","`","sequence_features","`",".","See","the","input","shape","of","`","ConcatenateSparseDenseFeatures","`","for","more","information",".","sequence_feature_lengths",":","Dense","tensor","of","shape","`","(","batch_size",",",")","`",".","Output","shape",":","outputs",":","`","(","batch_size",",","seq_length",",","units",")","`","where","`","units","`","matches","the","underlying","transformer","'s","output","size","(","if","present",")",",","otherwise","it","matches","the","output","size","of","the","`","Ffnn","`","block","applied","to","the","combined","features",",","or","it","'s","the","output","size","of","the","underlying","`","RasaFeatureCombiningLayer","`","if","the","`","Ffnn","`","block","has","0","layers",".","`","seq_length","`","is","the","sum","of","the","sequence","dimension","sizes","of","sequence-","and","sentence-level","features","(","for","details",",","see","the","output","shape","of","`","RasaFeatureCombiningLayer","`",")",".","If","both","feature","types","are","present",",","then","`","seq_length","`","will","be","1","+","the","length","of","the","longest","sequence","of","real","tokens","across","all","examples","in","the","given","batch",".","seq_sent_features",":","`","(","batch_size",",","seq_length",",","hidden_dim",")","`",",","where","`","hidden_dim","`","is","the","output","size","of","the","underlying","`","Ffnn","`","block",",","or","the","output","size","of","the","underlying","`","RasaFeatureCombiningLayer","`","if","the","`","Ffnn","`","block","has","0","layers",".","mask_combined_sequence_sentence",":","`","(","batch_size",",","seq_length",",","1",")","`","token_ids",":","`","(","batch_size",",","seq_length",",","id_dim",")","`",".","`","id_dim","`","is","2","when","no","dense","sequence-level","features","are","present",".","Otherwise",",","it","'s","arbitrarily","chosen","to","match","the","last","dimension","size","of","the","first","dense","sequence-level","feature","in","the","input","list","of","features",".","mlm_boolean_mask",":","`","(","batch_size",",","seq_length",",","1",")","`",",","empty","tensor","if","not","doing","MLM",".","attention_weights",":","`","(","transformer_layers",",","batch_size",",","num_transformer_heads",",","seq_length",",","seq_length",")","`",",","empty","tensor","if","the","transformer","has","0","layers",".","Raises",":","A","`","TFLayerConfigException","`","if","no","feature","signatures","for","sequence-level","features","are","provided",".","Attributes",":","output_units",":","The","last","dimension","size","of","the","layer","'s","first","output","(","`","outputs","`",")","."]
docstr: Produces helper variables for masked language modelling (only in training).
  
  The `token_ids` embeddings can be viewed as token-level labels/unique IDs of all
  input tokens (to be used later in the MLM loss) because these embeddings aren't
  affected by dropout or masking and are effectively always unique for different
  input tokens (and same for the same tokens).
  `token_ids` share the batch and sequence dimension with the combined sequence-
  and sentence-level features, the last dimension is unimportant and mimics the
  first dense sequence-level feature in the list of features, or alternatively the
  last dimension will have size 2 if there are only sparse sequence features
  present.
docstr_tok: ["Produces","helper","variables","for","masked","language","modelling","(","only","in","training",")",".","The","`","token_ids","`","embeddings","can","be","viewed","as","token-level","labels\/unique","IDs","of","all","input","tokens","(","to","be","used","later","in","the","MLM","loss",")","because","these","embeddings","aren't","affected","by","dropout","or","masking","and","are","effectively","always","unique","for","different","input","tokens","(","and","same","for","the","same","tokens",")",".","`","token_ids","`","share","the","batch","and","sequence","dimension","with","the","combined","sequence-","and","sentence-level","features",",","the","last","dimension","is","unimportant","and","mimics","the","first","dense","sequence-level","feature","in","the","list","of","features",",","or","alternatively","the","last","dimension","will","have","size","2","if","there","are","only","sparse","sequence","features","present","."]
code: def _create_mlm_tensors(
      self,
      sequence_features: List[Union[tf.Tensor, tf.SparseTensor]],
      seq_sent_features: tf.Tensor,
      mask_sequence: tf.Tensor,
      sentence_features_present: bool,
      training: bool,
  ) -> Tuple[tf.Tensor, tf.Tensor, tf.Tensor]:
      """Produces helper variables for masked language modelling (only in training).
  
      The `token_ids` embeddings can be viewed as token-level labels/unique IDs of all
      input tokens (to be used later in the MLM loss) because these embeddings aren't
      affected by dropout or masking and are effectively always unique for different
      input tokens (and same for the same tokens).
      `token_ids` share the batch and sequence dimension with the combined sequence-
      and sentence-level features, the last dimension is unimportant and mimics the
      first dense sequence-level feature in the list of features, or alternatively the
      last dimension will have size 2 if there are only sparse sequence features
      present.
      """
      token_ids = self._features_as_token_ids(sequence_features)
  
      # Pad in the sequence dimension to match the shape of combined sequence- and
      # sentence-level features. This means padding by 1 if sentence-level features
      # are present (those effectively have sequence length of 1) and not padding
      # otherwise.
      if sentence_features_present:
          token_ids = tf.pad(token_ids, [[0, 0], [0, 1], [0, 0]])
          mask_sequence = tf.pad(
              mask_sequence, [[0, 0], [0, 1], [0, 0]]
          )
  
      # mlm_boolean_mask has the same shape as the tensor with all combined features
      # (except the last dimension), with True meaning tokens that are masked and
      # False meaning tokens that aren't masked or that are fake (padded) tokens.
      # Note that only sequence-level features are masked, nothing happens to the
      # sentence-level features in the combined features tensor.
      seq_sent_features, mlm_boolean_mask = self._tf_layers[
          self.MLM_INPUT_MASK
      ](seq_sent_features, mask_sequence, training)
  
      return seq_sent_features, token_ids, mlm_boolean_mask
  
imports: import tensorflow
  import numpy
  from typing import Text, List, Dict, Any, Union, Optional, Tuple, Callable
  from rasa.shared.nlu.constants import TEXT
  from rasa.utils.tensorflow.model_data import FeatureSignature
  from rasa.utils.tensorflow.constants import REGULARIZATION_CONSTANT, CONNECTION_DENSITY, NUM_TRANSFORMER_LAYERS, TRANSFORMER_SIZE, NUM_HEADS, UNIDIRECTIONAL_ENCODER, KEY_RELATIVE_ATTENTION, VALUE_RELATIVE_ATTENTION, MAX_RELATIVE_POSITION, MASKED_LM, HIDDEN_LAYERS_SIZES, DROP_RATE, SPARSE_INPUT_DROPOUT, DENSE_INPUT_DROPOUT, DENSE_DIMENSION, CONCAT_DIMENSION, DROP_RATE_ATTENTION, SEQUENCE, SENTENCE
  from rasa.utils.tensorflow import layers
  from rasa.utils.tensorflow.exceptions import TFLayerConfigException
  from rasa.utils.tensorflow.transformer import TransformerEncoder
  from rasa.nlu.constants import DEFAULT_TRANSFORMER_SIZE
label_desc: Use image node_id 7 for calling the RasaSequenceLayer obj's underlying member method code with example usage: obj._create_mlm_tensors(sequence_features, seq_sent_features, mask_sequence, sentence_features_present, training) and returns: seq_sent_features,  token_ids,  mlm_boolean_mask