def encoder(name, hparams, inputs, target_space):
  """Compute encoder outputs and attention bias."""
  with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
    (encoder_input,
     encoder_self_attention_bias,
     encoder_decoder_attention_bias) = (
         transformer_prepare_encoder(inputs, target_space, hparams))
    encoder_input = tf.nn.dropout(encoder_input,
                                  rate=hparams.layer_prepostprocess_dropout)
    encoder_output = transformer_encoder(encoder_input,
                                         encoder_self_attention_bias,
                                         hparams)
    return encoder_output, encoder_decoder_attention_bias
Compute encoder outputs and attention bias.
tensor2tensor/models/research/transformer_vae_flow_prior_ops.py