conformer_u2_layer
¶
the transformer model
Module Contents¶
Classes¶
TransformerEncoderLayer is made up of self-attn and feedforward network. |
|
ConformerDecoderLayer is made up of self-attn, multi-head-attn and feedforward network. |
- class conformer_u2_layer.ConformerU2EncoderLayer(d_model, nhead, cnn_module_kernel=15, dim_feedforward=2048, dropout=0.1, activation='gelu')¶
Bases:
tensorflow.keras.layers.Layer
TransformerEncoderLayer is made up of self-attn and feedforward network. This standard encoder layer is based on the paper “Attention Is All You Need”. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application. :param d_model: the number of expected features in the input (required). :param nhead: the number of heads in the multiheadattention models (required). :param dim_feedforward: the dimension of the feedforward network model (default=2048). :param dropout: the dropout value (default=0.1). :param activation: the activation function of intermediate layer, relu or gelu (default=relu).
- Examples::
>>> encoder_layer = ConformerU2EncoderLayer(d_model=512, nhead=8) >>> src = tf.random(10, 32, 512) >>> out = encoder_layer(src)
- call(src: tensorflow.Tensor, src_mask: Optional[tensorflow.Tensor] = None, mask_pad: Optional[tensorflow.Tensor] = None, output_cache: Optional[tensorflow.Tensor] = None, cnn_cache: Optional[tensorflow.Tensor] = None, training: Optional[bool] = None)¶
Pass the input through the encoder layer.
- Parameters
src – the sequence to the encoder layer (required).
src_mask – tf.zeros([1, 0, 256], dtype=tf.float32) the mask for the src sequence (optional).
- class conformer_u2_layer.ConformerU2DecoderLayer(d_model, nhead, dim_feedforward=2048, dropout=0.1, activation='gelu')¶
Bases:
tensorflow.keras.layers.Layer
ConformerDecoderLayer is made up of self-attn, multi-head-attn and feedforward network. This standard decoder layer is based on the paper “Attention Is All You Need”. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application. :param d_model: the number of expected features in the input (required). :param nhead: the number of heads in the multiheadattention models (required). :param dim_feedforward: the dimension of the feedforward network model (default=2048). :param dropout: the dropout value (default=0.1). :param activation: the activation function of intermediate layer, relu or gelu (default=relu).
- Examples::
>>> decoder_layer = ConformerU2DecoderLayer(d_model=512, nhead=8) >>> memory = tf.random(10, 32, 512) >>> tgt = tf.random(20, 32, 512) >>> out = decoder_layer(tgt, memory)
- call(tgt, memory, tgt_mask=None, memory_mask=None, training=None)¶
Pass the inputs (and mask) through the decoder layer.
- Parameters
tgt – the sequence to the decoder layer (required).
memory – the sequence from the last layer of the encoder (required).
tgt_mask – the mask for the tgt sequence (optional).
memory_mask – the mask for the memory sequence (optional).