speechbrain.lobes.models.FastSpeech2 模块
用于FastSpeech 2的神经网络模块:快速且高质量的端到端文本到语音合成模型 作者 * Sathvik Udupa 2022 * Pradnya Kandarkar 2023 * Yingzhi Wang 2023
摘要
类:
学习输入文本与频谱图之间的对齐关系,使用高斯注意力机制。 |
|
二进制损失,强制软对齐与硬对齐匹配,如 |
|
持续时间预测层 |
|
用于标记的嵌入层 |
|
FastSpeech2 文本到语音模型。 |
|
带有内部对齐的FastSpeech2文本到语音模型。 |
|
CTC对齐损失 |
|
损失计算 |
|
包括内部对齐器的损失计算 |
|
FastSpeech2 卷积后处理网络 :param n_mel_channels: 卷积层的输入特征维度 :type n_mel_channels: int :param postnet_embedding_dim: 卷积层的输出特征维度 :type postnet_embedding_dim: int :param postnet_kernel_size: 后处理网络的卷积核大小 :type postnet_kernel_size: int :param postnet_n_convolutions: 卷积层的数量 :type postnet_n_convolutions: int :param postnet_dropout: 后处理网络的dropout概率 :type postnet_dropout: float |
|
该模块用于静音音素预测。 |
|
SSIM 损失为 (1 - SSIM) SSIM 的解释在这里 https://en.wikipedia.org/wiki/Structural_similarity |
|
根据每步的帧数对模型输入和目标进行零填充 |
|
根据每步结果的帧数对模型输入和目标进行零填充:元组 一个包含张量的元组,用作输入/目标 ( 填充后的文本, 填充后的持续时间, 输入长度, 填充后的梅尔频谱, 输出长度, len_x, 标签, 波形 ) |
函数:
在持续时间内的平均值。 |
|
音频信号的动态范围压缩 |
|
单调对齐搜索算法,numpy 的实现比 torch 更快。 |
|
计算原始音频信号的梅尔频谱图 |
|
根据持续时间对编码器输出进行上采样 |
参考
- class speechbrain.lobes.models.FastSpeech2.EncoderPreNet(n_vocab, blank_id, out_channels=512)[source]
基础:
Module用于标记的嵌入层
Example
>>> from speechbrain.nnet.embedding import Embedding >>> from speechbrain.lobes.models.FastSpeech2 import EncoderPreNet >>> encoder_prenet_layer = EncoderPreNet(n_vocab=40, blank_id=0, out_channels=384) >>> x = torch.rand(3, 5) >>> y = encoder_prenet_layer(x) >>> y.shape torch.Size([3, 5, 384])
- class speechbrain.lobes.models.FastSpeech2.PostNet(n_mel_channels=80, postnet_embedding_dim=512, postnet_kernel_size=5, postnet_n_convolutions=5, postnet_dropout=0.5)[source]
基础:
ModuleFastSpeech2 卷积后网络 :param n_mel_channels: 卷积层的输入特征维度 :type n_mel_channels: int :param postnet_embedding_dim: 卷积层的输出特征维度 :type postnet_embedding_dim: int :param postnet_kernel_size: 后网络卷积核大小 :type postnet_kernel_size: int :param postnet_n_convolutions: 卷积层数量 :type postnet_n_convolutions: int :param postnet_dropout: 后网络的丢弃概率 :type postnet_dropout: float
- class speechbrain.lobes.models.FastSpeech2.DurationPredictor(in_channels, out_channels, kernel_size, dropout=0.0, n_units=1)[source]
基础:
Module持续时间预测层
- Parameters:
Example
>>> from speechbrain.lobes.models.FastSpeech2 import FastSpeech2 >>> duration_predictor_layer = DurationPredictor(in_channels=384, out_channels=384, kernel_size=3) >>> x = torch.randn(3, 400, 384) >>> mask = torch.ones(3, 400, 384) >>> y = duration_predictor_layer(x, mask) >>> y.shape torch.Size([3, 400, 1])
- class speechbrain.lobes.models.FastSpeech2.SPNPredictor(enc_num_layers, enc_num_head, enc_d_model, enc_ffn_dim, enc_k_dim, enc_v_dim, enc_dropout, normalize_before, ffn_type, ffn_cnn_kernel_size_list, n_char, padding_idx)[source]
基础:
Module该模块用于无声音素预测器。它接收没有任何无声音素标记的音素序列作为输入,并预测是否应在某个位置后插入无声音素。这是为了避免由于输入序列中没有无声音素标记而在推理时出现快速节奏的问题。
- Parameters:
enc_num_layers (int) – 编码器中变压器层(TransformerEncoderLayer)的数量
enc_num_head (int) – 编码器变压器层中的多头注意力(MHA)头数
enc_d_model (int) – 编码器中期望的特征数量
enc_ffn_dim (int) – 前馈网络模型的维度
enc_k_dim (int) – 键的维度
enc_v_dim (int) – 值的维度
enc_dropout (float) – 编码器的Dropout
normalize_before (bool) – 是否在Transformer层中的MHA或FFN之前或之后应用归一化。
ffn_type (str) – 是否在transformer层内部使用卷积层代替前馈网络
ffn_cnn_kernel_size_list (list of int) – 如果ffn_type是1dcnn,则为2个1d-convs的卷积核大小
n_char (int) – 用于标记嵌入的符号数量
padding_idx (int) – 用于填充的索引
- class speechbrain.lobes.models.FastSpeech2.FastSpeech2(enc_num_layers, enc_num_head, enc_d_model, enc_ffn_dim, enc_k_dim, enc_v_dim, enc_dropout, dec_num_layers, dec_num_head, dec_d_model, dec_ffn_dim, dec_k_dim, dec_v_dim, dec_dropout, normalize_before, ffn_type, ffn_cnn_kernel_size_list, n_char, n_mels, postnet_embedding_dim, postnet_kernel_size, postnet_n_convolutions, postnet_dropout, padding_idx, dur_pred_kernel_size, pitch_pred_kernel_size, energy_pred_kernel_size, variance_predictor_dropout)[source]
基础:
ModuleFastSpeech2 文本到语音模型。 此类是模型的主要入口点,负责实例化所有子模块,这些子模块又管理各个神经网络层 简化结构:输入->标记嵌入 ->编码器 ->时长/音高/能量预测器 ->时长 上采样器 -> 解码器 -> 输出 在训练期间,使用教师强制(使用真实时长进行上采样)
- Parameters:
enc_num_layers (int) – 编码器中变压器层(TransformerEncoderLayer)的数量
enc_num_head (int) – 编码器变压器层中的多头注意力(MHA)头数
enc_d_model (int) – 编码器中期望的特征数量
enc_ffn_dim (int) – 前馈网络模型的维度
enc_k_dim (int) – 键的维度
enc_v_dim (int) – 值的维度
enc_dropout (float) – 编码器的Dropout
dec_num_layers (int) – 解码器中变压器层(TransformerEncoderLayer)的数量
dec_num_head (int) – 解码器变换层中的多头注意力(MHA)头数
dec_d_model (int) – 解码器中期望的特征数量
dec_ffn_dim (int) – 前馈网络模型的维度
dec_k_dim (int) – 键的维度
dec_v_dim (int) – 值的维度
dec_dropout (float) – 解码器的dropout
normalize_before (bool) – 是否在Transformer层中的MHA或FFN之前或之后应用归一化。
ffn_type (str) – 是否在transformer层内部使用卷积层代替前馈网络。
ffn_cnn_kernel_size_list (list of int) – 如果ffn_type是1dcnn,则为2个1d-convs的卷积核大小
n_char (int) – 用于标记嵌入的符号数量
n_mels (int) – 梅尔频谱图中的频段数量
postnet_embedding_dim (int) – 卷积层的输出特征维度
postnet_kernel_size (int) – postnet卷积核大小
postnet_n_convolutions (int) – 卷积层的数量
postnet_dropout (float) – postnet的dropout概率
padding_idx (int) – 用于填充的索引
dur_pred_kernel_size (int) – 持续时间预测器中的卷积核大小
pitch_pred_kernel_size (int) – 用于音高预测的核大小。
energy_pred_kernel_size (int) – 用于能量预测的核大小。
variance_predictor_dropout (float) – 方差预测器(时长/音高/能量)的dropout概率
Example
>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import FastSpeech2 >>> model = FastSpeech2( ... enc_num_layers=6, ... enc_num_head=2, ... enc_d_model=384, ... enc_ffn_dim=1536, ... enc_k_dim=384, ... enc_v_dim=384, ... enc_dropout=0.1, ... dec_num_layers=6, ... dec_num_head=2, ... dec_d_model=384, ... dec_ffn_dim=1536, ... dec_k_dim=384, ... dec_v_dim=384, ... dec_dropout=0.1, ... normalize_before=False, ... ffn_type='1dcnn', ... ffn_cnn_kernel_size_list=[9, 1], ... n_char=40, ... n_mels=80, ... postnet_embedding_dim=512, ... postnet_kernel_size=5, ... postnet_n_convolutions=5, ... postnet_dropout=0.5, ... padding_idx=0, ... dur_pred_kernel_size=3, ... pitch_pred_kernel_size=3, ... energy_pred_kernel_size=3, ... variance_predictor_dropout=0.5) >>> inputs = torch.tensor([ ... [13, 12, 31, 14, 19], ... [31, 16, 30, 31, 0], ... ]) >>> input_lengths = torch.tensor([5, 4]) >>> durations = torch.tensor([ ... [2, 4, 1, 5, 3], ... [1, 2, 4, 3, 0], ... ]) >>> mel_post, postnet_output, predict_durations, predict_pitch, avg_pitch, predict_energy, avg_energy, mel_lens = model(inputs, durations=durations) >>> mel_post.shape, predict_durations.shape (torch.Size([2, 15, 80]), torch.Size([2, 5])) >>> predict_pitch.shape, predict_energy.shape (torch.Size([2, 5, 1]), torch.Size([2, 5, 1]))
- forward(tokens, durations=None, pitch=None, energy=None, pace=1.0, pitch_rate=1.0, energy_rate=1.0)[source]
用于训练和推理的前向传递
- Parameters:
- Returns:
mel_post (torch.Tensor) – 解码器输出的mel频谱
postnet_output (torch.Tensor) – 后处理网络输出的mel频谱
predict_durations (torch.Tensor) – 每个token的预测持续时间
predict_pitch (torch.Tensor) – 每个token的预测音高
avg_pitch (torch.Tensor) – 如果输入音高不为None,则为每个token的目标音高 如果输入音高为None,则为None
predict_energy (torch.Tensor) – 每个token的预测能量
avg_energy (torch.Tensor) – 如果输入能量不为None,则为每个token的目标能量 如果输入能量为None,则为None
mel_length – mel频谱的预测长度
- speechbrain.lobes.models.FastSpeech2.average_over_durations(values, durs)[source]
持续时间内的平均值。
- Parameters:
值 (torch.Tensor) – 形状: [B, 1, T_de]
durs (torch.Tensor) – 形状: [B, T_en]
- Returns:
avg – 形状: [B, 1, T_en]
- Return type:
torch.Tensor
- speechbrain.lobes.models.FastSpeech2.upsample(feats, durs, pace=1.0, padding_value=0.0)[source]
根据持续时间对编码器输出进行上采样
- class speechbrain.lobes.models.FastSpeech2.TextMelCollate[source]
基础类:
object根据每步的帧数对模型输入和目标进行零填充
- __call__(batch)[source]
从归一化文本和梅尔频谱图中整理训练批次
- Parameters:
batch (list) – [text_normalized, mel_normalized]
- Returns:
text_padded (torch.Tensor)
dur_padded (torch.Tensor)
input_lengths (torch.Tensor)
mel_padded (torch.Tensor)
pitch_padded (torch.Tensor)
energy_padded (torch.Tensor)
output_lengths (torch.Tensor)
len_x (torch.Tensor)
labels (torch.Tensor)
wavs (torch.Tensor)
no_spn_seq_padded (torch.Tensor)
spn_labels_padded (torch.Tensor)
last_phonemes_padded (torch.Tensor)
- class speechbrain.lobes.models.FastSpeech2.Loss(log_scale_durations, ssim_loss_weight, duration_loss_weight, pitch_loss_weight, energy_loss_weight, mel_loss_weight, postnet_mel_loss_weight, spn_loss_weight=1.0, spn_loss_max_epochs=8)[source]
基础:
Module损失计算
- Parameters:
log_scale_durations (bool) – 对目标持续时间应用对数
ssim_loss_weight (float) – ssim损失的权重
duration_loss_weight (float) – 持续时间损失的权重
pitch_loss_weight (float) – 音高损失的权重
energy_loss_weight (float) – 能量损失的权重
mel_loss_weight (float) – mel损失的权重
postnet_mel_loss_weight (float) – postnet mel损失的权重
spn_loss_weight (float) – spn损失的权重
spn_loss_max_epochs (int) – 最大轮数
- speechbrain.lobes.models.FastSpeech2.mel_spectogram(sample_rate, hop_length, win_length, n_fft, n_mels, f_min, f_max, power, normalized, min_max_energy_norm, norm, mel_scale, compression, audio)[source]
计算原始音频信号的梅尔频谱图
- Parameters:
sample_rate (int) – 音频信号的采样率。
hop_length (int) – STFT窗口之间的跳跃长度。
win_length (int) – 窗口大小。
n_fft (int) – FFT的大小。
n_mels (int) – 梅尔滤波器组的数量。
f_min (float) – 最小频率。
f_max (float) – 最大频率。
power (float) – 用于幅度谱图的指数。
normalized (bool) – 是否在stft之后通过幅度进行归一化。
min_max_energy_norm (bool) – 是否通过最小-最大值进行归一化
norm (str 或 None) – 如果为“slaney”,则将三角梅尔权重除以梅尔频带的宽度
mel_scale (str) – 使用的比例:“htk” 或 “slaney”。
compression (bool) – 是否进行动态范围压缩
audio (torch.Tensor) – 输入音频信号
- Returns:
mel (torch.Tensor)
rmse (torch.Tensor)
- speechbrain.lobes.models.FastSpeech2.dynamic_range_compression(x, C=1, clip_val=1e-05)[source]
音频信号的动态范围压缩
- class speechbrain.lobes.models.FastSpeech2.SSIMLoss[source]
基础:
ModuleSSIM 损失为 (1 - SSIM) SSIM 的解释在这里 https://en.wikipedia.org/wiki/Structural_similarity
- sequence_mask(sequence_length, max_len=None)[source]
创建一个序列掩码,用于过滤序列张量中的填充。
- Parameters:
sequence_length (torch.Tensor) – 序列长度。
max_len (int) – 最大序列长度。默认为 None。
- Returns:
mask
- Return type:
[B, T_max]
- class speechbrain.lobes.models.FastSpeech2.TextMelCollateWithAlignment[source]
基础类:
object根据每步的帧数对模型输入和目标进行零填充 结果: 元组
一个张量元组,用作输入/目标 (
text_padded, dur_padded, input_lengths, mel_padded, output_lengths, len_x, labels, wavs
)
- __call__(batch)[source]
从归一化文本和梅尔频谱图中整理训练批次
- Parameters:
batch (list) – [text_normalized, mel_normalized]
- Returns:
phoneme_padded (torch.Tensor)
input_lengths (torch.Tensor)
mel_padded (torch.Tensor)
pitch_padded (torch.Tensor)
energy_padded (torch.Tensor)
output_lengths (torch.Tensor)
labels (torch.Tensor)
wavs (torch.Tensor)
- speechbrain.lobes.models.FastSpeech2.maximum_path_numpy(value, mask)[source]
单调对齐搜索算法,numpy 比 torch 实现运行得更快。
- Parameters:
value (torch.Tensor) – 输入对齐值 [b, t_x, t_y]
mask (torch.Tensor) – 输入对齐掩码 [b, t_x, t_y]
- Returns:
路径
- Return type:
torch.Tensor
Example
>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import maximum_path_numpy >>> alignment = torch.rand(2, 5, 100) >>> mask = torch.ones(2, 5, 100) >>> hard_alignments = maximum_path_numpy(alignment, mask)
- class speechbrain.lobes.models.FastSpeech2.AlignmentNetwork(in_query_channels=80, in_key_channels=512, attn_channels=80, temperature=0.0005)[source]
基础:
Module学习输入文本与使用高斯注意力机制的频谱图之间的对齐。
查询 -> 一维卷积 -> ReLU激活函数 -> 一维卷积 -> ReLU激活函数 -> 一维卷积 -> L2距离 -> softmax -> 对齐 键 -> 一维卷积 -> ReLU激活函数 -> 一维卷积 - - - - - - - - - - - -^
- Parameters:
Example
>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import AlignmentNetwork >>> aligner = AlignmentNetwork( ... in_query_channels=80, ... in_key_channels=512, ... attn_channels=80, ... temperature=0.0005, ... ) >>> phoneme_feats = torch.rand(2, 512, 20) >>> mels = torch.rand(2, 80, 100) >>> alignment_soft, alignment_logprob = aligner(mels, phoneme_feats, None, None) >>> alignment_soft.shape, alignment_logprob.shape (torch.Size([2, 1, 100, 20]), torch.Size([2, 1, 100, 20]))
- forward(queries, keys, mask, attn_prior)[source]
对齐器编码器的前向传递。
- Parameters:
queries (torch.Tensor) – 查询张量 [B, C, T_de]
keys (torch.Tensor) – 查询张量 [B, C_emb, T_en]
mask (torch.Tensor) – 查询掩码[B, T_de]
attn_prior (torch.Tensor) – 先验注意力张量 [B, 1, T_en, T_de]
- Returns:
attn (torch.Tensor) – 软注意力 [B, 1, T_en, T_de]
attn_logp (torch.Tensor) – 对数概率 [B, 1, T_en , T_de]
- class speechbrain.lobes.models.FastSpeech2.FastSpeech2WithAlignment(enc_num_layers, enc_num_head, enc_d_model, enc_ffn_dim, enc_k_dim, enc_v_dim, enc_dropout, in_query_channels, in_key_channels, attn_channels, temperature, dec_num_layers, dec_num_head, dec_d_model, dec_ffn_dim, dec_k_dim, dec_v_dim, dec_dropout, normalize_before, ffn_type, ffn_cnn_kernel_size_list, n_char, n_mels, postnet_embedding_dim, postnet_kernel_size, postnet_n_convolutions, postnet_dropout, padding_idx, dur_pred_kernel_size, pitch_pred_kernel_size, energy_pred_kernel_size, variance_predictor_dropout)[source]
基础:
Module带有内部对齐的FastSpeech2文本到语音模型。 此类是模型的主要入口点,负责实例化所有子模块,这些子模块又管理各个神经网络层。某些部分采用了以下实现: https://github.com/coqui-ai/TTS/blob/dev/TTS/tts/models/forward_tts.py
简化结构: 输入 -> 词嵌入 -> 编码器 -> 对齐器 -> 时长/音高/能量 -> 上采样器 -> 解码器 -> 输出
- Parameters:
enc_num_layers (int) – 编码器中变压器层(TransformerEncoderLayer)的数量
enc_num_head (int) – 编码器变压器层中的多头注意力(MHA)头数
enc_d_model (int) – 编码器中期望的特征数量
enc_ffn_dim (int) – 前馈网络模型的维度
enc_k_dim (int) – 键的维度
enc_v_dim (int) – 值的维度
enc_dropout (float) – 编码器的Dropout
in_query_channels (int) – 查询网络中的通道数。
in_key_channels (int) – 关键网络中的通道数。
attn_channels (int) – 注意力层中的内部通道数。
温度 (float) – 用于softmax的温度。
dec_num_layers (int) – 解码器中变压器层(TransformerEncoderLayer)的数量
dec_num_head (int) – 解码器变换层中的多头注意力(MHA)头数
dec_d_model (int) – 解码器中期望的特征数量
dec_ffn_dim (int) – 前馈网络模型的维度
dec_k_dim (int) – 键的维度
dec_v_dim (int) – 值的维度
dec_dropout (float) – 解码器的dropout
normalize_before (bool) – 是否在Transformer层中的MHA或FFN之前或之后应用归一化。
ffn_type (str) – 是否在transformer层内部使用卷积层代替前馈网络。
ffn_cnn_kernel_size_list (list of int) – 如果ffn_type是1dcnn,则为2个1d-convs的卷积核大小
n_char (int) – 用于标记嵌入的符号数量
n_mels (int) – 梅尔频谱图中的频段数量
postnet_embedding_dim (int) – 卷积层的输出特征维度
postnet_kernel_size (int) – postnet卷积核大小
postnet_n_convolutions (int) – 卷积层的数量
postnet_dropout (float) – postnet的dropout概率
padding_idx (int) – 用于填充的索引
dur_pred_kernel_size (int) – 持续时间预测器中的卷积核大小
pitch_pred_kernel_size (int) – 用于音高预测的核大小。
energy_pred_kernel_size (int) – 用于能量预测的核大小。
variance_predictor_dropout (float) – 方差预测器(时长/音高/能量)的dropout概率
Example
>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import FastSpeech2WithAlignment >>> model = FastSpeech2WithAlignment( ... enc_num_layers=6, ... enc_num_head=2, ... enc_d_model=384, ... enc_ffn_dim=1536, ... enc_k_dim=384, ... enc_v_dim=384, ... enc_dropout=0.1, ... in_query_channels=80, ... in_key_channels=384, ... attn_channels=80, ... temperature=0.0005, ... dec_num_layers=6, ... dec_num_head=2, ... dec_d_model=384, ... dec_ffn_dim=1536, ... dec_k_dim=384, ... dec_v_dim=384, ... dec_dropout=0.1, ... normalize_before=False, ... ffn_type='1dcnn', ... ffn_cnn_kernel_size_list=[9, 1], ... n_char=40, ... n_mels=80, ... postnet_embedding_dim=512, ... postnet_kernel_size=5, ... postnet_n_convolutions=5, ... postnet_dropout=0.5, ... padding_idx=0, ... dur_pred_kernel_size=3, ... pitch_pred_kernel_size=3, ... energy_pred_kernel_size=3, ... variance_predictor_dropout=0.5) >>> inputs = torch.tensor([ ... [13, 12, 31, 14, 19], ... [31, 16, 30, 31, 0], ... ]) >>> mels = torch.rand(2, 100, 80) >>> mel_post, postnet_output, durations, predict_pitch, avg_pitch, predict_energy, avg_energy, mel_lens, alignment_durations, alignment_soft, alignment_logprob, alignment_mas = model(inputs, mels) >>> mel_post.shape, durations.shape (torch.Size([2, 100, 80]), torch.Size([2, 5])) >>> predict_pitch.shape, predict_energy.shape (torch.Size([2, 5, 1]), torch.Size([2, 5, 1])) >>> alignment_soft.shape, alignment_mas.shape (torch.Size([2, 100, 5]), torch.Size([2, 100, 5]))
- forward(tokens, mel_spectograms=None, pitch=None, energy=None, pace=1.0, pitch_rate=1.0, energy_rate=1.0)[source]
用于训练和推理的前向传递
- Parameters:
- Returns:
mel_post (torch.Tensor) – 来自解码器的mel输出
postnet_output (torch.Tensor) – 来自后处理网络的mel输出
predict_durations (torch.Tensor) – 每个token的预测持续时间
predict_pitch (torch.Tensor) – 每个token的预测音高
avg_pitch (torch.Tensor) – 如果输入音高不为None,则为每个token的目标音高 如果输入音高为None,则为None
predict_energy (torch.Tensor) – 每个token的预测能量
avg_energy (torch.Tensor) – 如果输入能量不为None,则为每个token的目标能量 如果输入能量为None,则为None
mel_length – mel频谱图的预测长度
alignment_durations – 来自硬对齐映射的持续时间
alignment_soft (torch.Tensor) – 软对齐潜力
alignment_logprob (torch.Tensor) – 对数尺度的对齐潜力
alignment_mas (torch.Tensor) – 硬对齐映射
- class speechbrain.lobes.models.FastSpeech2.LossWithAlignment(log_scale_durations, ssim_loss_weight, duration_loss_weight, pitch_loss_weight, energy_loss_weight, mel_loss_weight, postnet_mel_loss_weight, aligner_loss_weight, binary_alignment_loss_weight, binary_alignment_loss_warmup_epochs, binary_alignment_loss_max_epochs)[source]
基础:
Module包括内部对齐器的损失计算
- Parameters:
log_scale_durations (bool) – 对目标持续时间应用对数
ssim_loss_weight (float) – ssim损失的权重
duration_loss_weight (float) – 持续时间损失的权重
pitch_loss_weight (float) – 音高损失的权重
energy_loss_weight (float) – 能量损失的权重
mel_loss_weight (float) – mel损失的权重
postnet_mel_loss_weight (float) – postnet mel损失的权重
aligner_loss_weight (float) – 对齐损失的权重
binary_alignment_loss_weight (float) – postnet mel损失的权重
binary_alignment_loss_warmup_epochs (int) – 逐渐增加二元损失影响的周期数。
binary_alignment_loss_max_epochs (int) – 从这个epoch开始,二进制损失的影响将被忽略。
- class speechbrain.lobes.models.FastSpeech2.ForwardSumLoss(blank_logprob=-1)[source]
基础:
ModuleCTC对齐损失
- Parameters:
blank_logprob (填充值)
Example
>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import ForwardSumLoss >>> loss_func = ForwardSumLoss() >>> attn_logprob = torch.rand(2, 1, 100, 5) >>> key_lens = torch.tensor([5, 5]) >>> query_lens = torch.tensor([100, 100]) >>> loss = loss_func(attn_logprob, key_lens, query_lens)
- class speechbrain.lobes.models.FastSpeech2.BinaryAlignmentLoss[source]
基础:
Module二元损失,强制软对齐与硬对齐匹配,如
https://arxiv.org/pdf/2108.10447.pdf中所述。 .. rubric:: 示例>>> import torch >>> from speechbrain.lobes.models.FastSpeech2 import BinaryAlignmentLoss >>> loss_func = BinaryAlignmentLoss() >>> alignment_hard = torch.randint(0, 2, (2, 100, 5)) >>> alignment_soft = torch.rand(2, 100, 5) >>> loss = loss_func(alignment_hard, alignment_soft)