mindtext.modules.encoder.seq2seq

class mindtext.modules.encoder.seq2seq.FeedForward (in_channels: int, hidden_size: int, out_channels: int, hidden_act: str = “relu”, hidden_dropout_prob: float = 0.1, compute_type: mindspore.dtype = mstype.float32)

init (in_channels: int, hidden_size: int, out_channels: int, hidden_act: str = “relu”, hidden_dropout_prob: float = 0.1, compute_type: mindspore.dtype = mstype.float32)

参数

  • hidden_size (int): 隐藏层大小。

  • in_channels (int): 输入层的大小。

  • out_channels (int): 输出层的大小。

  • hidden_act (str): bert的激活函数,默认为“relu”。

  • hidden_dropout_prob (_float): dropout的大小,默认为0.1。

  • compute_type (mindspore.dtype): Bert模型的计算数据类型,默认为mstype.float32。

construct (input_tensor: mindspore.Tensor)

参数

  • input_tensor (mindspore.Tensor): 前馈神经网络的输入。

返回

  • output (mindspore.Tensor): 前馈神经网络的输出。

class mindtext.modules.encoder.seq2seq.EncoderCell (batch_size: int, hidden_size: int = 1024, num_attention_heads: int = 16, intermediate_size: int = 4096, attention_probs_dropout_prob: float = 0.1, use_one_hot_embeddings: bool = False, initializer_range: float = 0.02, hidden_dropout_prob: float = 0.1, hidden_act: str = “relu”, compute_type: mindspore.dtype = mstype.float32)

init (batch_size: int, hidden_size: int = 1024, num_attention_heads: int = 16, intermediate_size: int = 4096, attention_probs_dropout_prob: float = 0.1, use_one_hot_embeddings: bool = False, initializer_range: float = 0.02, hidden_dropout_prob: float = 0.1, hidden_act: str = “relu”, compute_type: mindspore.dtype = mstype.float32)

参数

  • batch_size (int): 输入数据集的batch size。

  • hidden_size (int): 编码层的大小,默认为1024。

  • num_attention_heads (int): 注意力头数量,默认为16。

  • intermediate_size (int): 中间层的隐藏维度大小,默认为4096。

  • attention_probs_dropout_prob (float): BertAttention的dropout概率,默认为0.02。

  • use_one_hot_embeddings (bool): 是否使用one hot编码格式,默认为False。

  • initializer_range (float): 截断正态分布的初始值,默认为0.02。

  • hidden_dropout_prob (_float): dropout的大小,默认为0.1。

  • hidden_act (str): bert的激活函数,默认为“relu”。

  • compute_type (mindspore.dtype): Bert模型的计算数据类型,默认为mstype.float32。

construct (hidden_states: mindspore.Tensor, attention_mask: mindspore.Tensor, seq_length: int)

参数

  • hidden_states (mindspore.Tensor): 编码层的隐藏状态,shape为(batch_size, seq_len, hidden_size)。

  • attention_mask (mindspore.Tensor): attention_mask。

  • seq_length (int): 输入序列的长度。

返回

  • output (mindspore.Tensor): encoder的输出。

class mindtext.modules.encoder.seq2seq.TransformerEncoder (batch_size: int, hidden_size: int, num_hidden_layers: int, num_attention_heads: int = 16, intermediate_size: int = 4096, attention_probs_dropout_prob: float = 0.1, initializer_range: float = 0.02, hidden_dropout_prob: float = 0.1, hidden_act: str = “relu”, compute_type: mindspore.dtype = mstype.float32)

init (batch_size: int, hidden_size: int, num_hidden_layers: int, num_attention_heads: int = 16, intermediate_size: int = 4096, attention_probs_dropout_prob: float = 0.1, initializer_range: float = 0.02, hidden_dropout_prob: float = 0.1, hidden_act: str = “relu”, compute_type: mindspore.dtype = mstype.float32)

参数

  • batch_size (int): 输入数据集的batch size。

  • hidden_size (int): 编码层的大小。

  • num_hidden_layer (int): 编码层的隐藏层数量。

  • num_attention_heads (int): 注意力头数量,默认为16。

  • intermediate_size (int): 中间层的隐藏维度大小,默认为4096。

  • attention_probs_dropout_prob (float): BertAttention的dropout概率,默认为0.1。

  • initializer_range (float): 截断正态分布的初始值,默认为0.02。

  • hidden_dropout_prob (_float): dropout的大小,默认为0.1。

  • hidden_act (str): bert的激活函数,默认为“gelu”。

  • compute_type (mindspore.dtype): Bert模型的计算数据类型,默认为mstype.float32。

construct (hidden_states: mindspore.Tensor, attention_mask: mindspore.Tensor, seq_length: int)

参数

  • hidden_states (mindspore.Tensor): 编码层的隐藏状态,shape为(batch_size, seq_len, hidden_size)。

  • attention_mask (mindspore.Tensor):自注意力隐藏状态的mask矩阵(2D或者3D),值是[0/1]或者[True/False],shape为(seq_len, seq_len)或者(batch_size, seq_len, seq_len)。

  • seq_length (int):输入的长度。

返回

  • output (mindspore.Tensor): encoder的输出。