paddlespeech.t2s.modules.transformer.decoder 模块

解码器定义。

class paddlespeech.t2s.modules.transformer.decoder.Decoder(odim, selfattention_layer_type='selfattn', attention_dim=256, attention_heads=4, conv_wshare=4, conv_kernel_length=11, conv_usebias=False, linear_units=2048, num_blocks=6, dropout_rate=0.1, positional_dropout_rate=0.1, self_attention_dropout_rate=0.0, src_attention_dropout_rate=0.0, input_layer='embed', use_output_layer=True, pos_enc_class=<class 'paddlespeech.t2s.modules.transformer.embedding.PositionalEncoding'>, normalize_before=True, concat_after=False)[来源]

基础: Layer

转换器解码器模块。

Args:
odim (int):

输出维度。

self_attention_layer_type (str):

自注意力层类型。

attention_dim (int):

注意力的维度。

attention_heads (int):

多头注意力的头数量。

conv_wshare (int):

卷积核的数量。仅在 self_attention_layer_type == "lightconv*" 或 "dynamiconv*" 中使用。

conv_kernel_length (Union[int, str]):

卷积的内核大小字符串(例如 71_71_71_71_71_71)。仅在 self_attention_layer_type == "lightconv*" 或 "dynamiconv*" 时使用。

conv_usebias (bool):

是否在卷积中使用偏差。仅在 self_attention_layer_type == "lightconv*" 或 "dynamiconv*" 时使用。

linear_units(int):

位置逐步前馈的单元数量。

num_blocks (int):

解码器块的数量。

dropout_rate (float):

dropout 率。

positional_dropout_rate (float):

添加位置编码后的 dropout 率。

self_attention_dropout_rate (float):

自注意力中的 dropout 率。

src_attention_dropout_rate (float):

源注意力中的丢弃率。

input_layer (Union[str, nn.Layer]):

输入层类型。

use_output_layer (bool):

是否使用输出层。

pos_enc_class (nn.Layer):

位置编码模块类。

PositionalEncoding `or `ScaledPositionalEncoding
normalize_before (bool):

是否在第一个模块之前使用层归一化。

concat_after (bool):

是否连接注意力层的输入和输出。 如果为真,将应用额外的线性变换。 即 x -> x + linear(concat(x, att(x))) 如果为假,则不应用额外的线性变换。即 x -> x + att(x)

方法

__call__(*inputs, **kwargs)

将self作为一个函数调用。

add_parameter(name, parameter)

添加一个参数实例。

add_sublayer(name, sublayer)

添加一个子层实例。

apply(fn)

递归地将 fn 应用到每个子层(由 .sublayers() 返回)以及自身。

batch_score(ys, states, xs)

评分新标记批次(必需)。

buffers([include_sublayers])

返回当前层及其子层中的所有缓冲区的列表。

children()

返回一个迭代器,遍历直接子层。

clear_gradients()

清除此层所有参数的梯度。

create_parameter(shape[, attr, dtype, ...])

为该层创建参数。

create_tensor([name, persistable, dtype])

为该层创建张量。

create_variable([name, persistable, dtype])

为该层创建张量。

eval()

将该层及其所有子层设置为评估模式。

extra_repr()

该层的额外表示,您可以自定义实现自己的层。

forward(tgt, tgt_mask, memory, memory_mask)

前向解码器。参数: tgt(Tensor): 输入的标记ID,int64 (#batch, maxlen_out) 如果 input_layer == "embed"。在其他情况下,输入张量 (#batch, maxlen_out, odim)。 tgt_mask(Tensor): 输入的标记掩码 (#batch, maxlen_out)。 memory(Tensor): 编码的记忆,float32 (#batch, maxlen_in, feat)。 memory_mask(Tensor): 编码的记忆掩码 (#batch, maxlen_in)。

forward_one_step(tgt, tgt_mask, memory[, cache])

向前一步。

full_name()

此层的完整名称,由 name_scope + "/" + MyLayer.__class__.__name__ 组成

load_dict(state_dict[, use_structured_name])

从 state_dict 设置参数和可持久化缓存。

named_buffers([prefix, include_sublayers])

返回一个迭代器,遍历层中的所有缓冲区,生成名称和张量的元组。

named_children()

返回一个直接子层的迭代器,同时提供层的名称和层本身。

named_parameters([prefix, include_sublayers])

返回一个迭代器,遍历层中的所有参数,生成名称和参数的元组。

named_sublayers([prefix, include_self, ...])

返回Layer中所有子层的迭代器,生成名称和子层的元组。

parameters([include_sublayers])

返回当前层及其子层的所有参数的列表。

register_buffer(name, tensor[, persistable])

将一个张量注册为该层的缓冲区。

register_forward_post_hook(hook)

为层注册一个前向后钩子。

register_forward_pre_hook(hook)

为层注册一个前向预钩子。

score(ys, state, x)

得分。

set_dict(state_dict[, use_structured_name])

从 state_dict 设置参数和可持久化的缓冲区。

set_state_dict(state_dict[, use_structured_name])

从state_dict设置参数和持久化缓冲区。

state_dict([destination, include_sublayers, ...])

获取当前层及其子层的所有参数和可持久化缓冲区。

sublayers([include_self])

返回子层的列表。

to([device, dtype, blocking])

通过给定的设备、数据类型和阻塞方式转换层的参数和缓冲区。

to_static_state_dict([destination, ...])

获取当前层及其子层的所有参数和缓冲区。

train()

将此层及其所有子层设置为训练模式。

向后

注册状态字典钩子

batch_score(ys: Tensor, states: List[Any], xs: Tensor) Tuple[Tensor, List[Any]][来源]

评分新令牌批次(必需)。

Args:
ys(Tensor):

paddle.int64 前缀标记 (n_batch, ylen).

states(List[Any]):

前缀令牌的评分器状态。

xs(Tensor):

生成ys的编码器特征(n_batch,xlen,n_feat)。

Returns:
tuple[Tensor, List[Any]]:

下一个标记的批次得分元组,形状为 (n_batch, n_vocab),以及 ys 的下一个状态列表。

forward(tgt, tgt_mask, memory, memory_mask)[来源]

前向解码器。 参数:

tgt(Tensor):

输入令牌ID,int64(#batch,maxlen_out),如果 input_layer == "embed"。在其他情况下,输入张量(#batch,maxlen_out,odim)。

tgt_mask(Tensor):

输入令牌掩码 (#batch, maxlen_out).

memory(Tensor):

编码的内存,float32 (#batch, maxlen_in, feat).

memory_mask(Tensor):

编码的内存掩码 (#batch, maxlen_in)。

Returns:
Tensor:

如果 use_output_layer 为 True,则解码的令牌分数在 softmax 之前 (#batch, maxlen_out, odim)。 在其他情况下,最终块输出 (#batch, maxlen_out, attention_dim)。

Tensor:

在softmax之前的分数掩码 (#batch, maxlen_out)。

forward_one_step(tgt, tgt_mask, memory, cache=None)[来源]

向前一步。

Args:
tgt(Tensor):

输入令牌ID,int64 (#批次,最大输出长度)。

tgt_mask(Tensor):

输入令牌掩码 (#batch, maxlen_out).

memory(Tensor):

编码的内存,float32 (#batch, maxlen_in, feat).

cache((List[Tensor]), optional):

缓存张量列表。 (默认值 = None)

Returns:
Tensor:

输出张量 (batch, maxlen_out, odim)。

List[Tensor]:

每个解码器层的缓存张量列表。

score(ys, state, x)[来源]

分数。