def _extract_layer_types(self):
    """Parse the layer string.

    Returns:
      list[tuple[str, str]]: Encoder layers: list of (attention, feed-forward)
      list[tuple[str, str, str]]: Decoder layers: list of (self-attention,
        enc-dec attention, feed-forward)
    """
    hparams = self._hparams
    layer_types = hparams.layer_types

    # If the architecture has not explicitly been set, we just construct a
    # standard transformer with the fallback values
    if not layer_types:
      layer_types = SEP_LAYER.join(
          [hparams.default_att] * hparams.num_hidden_layers)

    # If encoder not explicitly defined, the encoder will have the same
    # structure as the decoder
    layer_types = layer_types.split(SEP_ENCODEC)
    if len(layer_types) == 1:
      layer_types *= 2

    # Some models don't need the encoder (ex: language modeling)
    # TODO(epot): What are the other conditions (has_input ?)
    if hparams.prepend_mode != "none":
      layer_types[0] = ""

    # Extend the blocks and fill them with the default values if not specified
    final_layers = ([], [])
    for i, blocks_str_joined in enumerate(layer_types):
      for blocks_str in blocks_str_joined.split(SEP_LAYER):
        if not blocks_str:
          continue
        blocks_list = blocks_str.split(SEP_FF)
        # Eventually use the fallback values for the layer_types. If the
        # encoder is empty, do not use the enco-deco attention.
        self_att = blocks_list[0] or hparams.default_att
        ende_att = hparams.default_att if layer_types[0] else "_"
        ff = hparams.default_ff
        if len(blocks_list) > 1:
          ff = blocks_list[-1]
        if len(blocks_list) == 3:
          ende_att = blocks_list[1]
        if i == 0:  # Encoder
          blocks_tuple = (self_att, ff)
        elif i == 1:  # Decoder
          blocks_tuple = (self_att, ende_att, ff)
        final_layers[i].append(blocks_tuple)

    return final_layers
Parse the layer string.

    Returns:
      list[tuple[str, str]]: Encoder layers: list of (attention, feed-forward)
      list[tuple[str, str, str]]: Decoder layers: list of (self-attention,
        enc-dec attention, feed-forward)
    
tensor2tensor/models/research/transformer_moe.py