speechbrain.lobes.models.dual_path 模块
支持双路径语音分离的库。
- Authors
Cem Subakan 2020
Mirco Ravanelli 2020
萨穆埃莱·科内尔 2020
米尔科·布朗齐 2020
钟建元 2020
摘要
类:
计算累积层归一化。 |
|
DPT 网络块。 |
|
一个由ConvTranspose1d组成的解码器层。 |
|
用于双路径处理的计算块。 |
|
双路径模型是dualpathrnn、sepformer、dptnet的基础。 |
|
卷积编码器层。 |
|
该模块用于实现具有高效注意力的快速变换器模型。 |
|
计算全局层归一化。 |
|
当我们在双路径块中希望进行恒等变换时,使用此块。 |
|
用于PyTorch变换器的位置编码器。 |
|
一个使用pytorch transformer块的包装器。 |
|
ConformerEncoder的SpeechBrain实现的封装。 |
|
用于双路径管道的RNNBlock。 |
|
SpeechBrain实现的transformer编码器的封装。 |
|
sepformer模型的包装器,它结合了编码器、掩码网络和解码器 https://arxiv.org/abs/2010.13154 |
函数:
只是一个选择归一化类型的包装器。 |
参考
- class speechbrain.lobes.models.dual_path.GlobalLayerNorm(dim, shape, eps=1e-08, elementwise_affine=True)[source]
基础:
Module计算全局层归一化。
- Parameters:
Example
>>> x = torch.randn(5, 10, 20) >>> GLN = GlobalLayerNorm(10, 3) >>> x_norm = GLN(x)
- class speechbrain.lobes.models.dual_path.CumulativeLayerNorm(dim, elementwise_affine=True, eps=1e-08)[source]
基础:
LayerNorm计算累积层归一化。
- Parameters:
Example
>>> x = torch.randn(5, 10, 20) >>> CLN = CumulativeLayerNorm(10) >>> x_norm = CLN(x)
- speechbrain.lobes.models.dual_path.select_norm(norm, dim, shape, eps=1e-08)[source]
只是一个选择归一化类型的包装器。
- class speechbrain.lobes.models.dual_path.Encoder(kernel_size=2, out_channels=64, in_channels=1)[source]
基础:
Module卷积编码器层。
Example
>>> x = torch.randn(2, 1000) >>> encoder = Encoder(kernel_size=4, out_channels=64) >>> h = encoder(x) >>> h.shape torch.Size([2, 64, 499])
- class speechbrain.lobes.models.dual_path.Decoder(*args, **kwargs)[source]
基础类:
ConvTranspose1d一个由ConvTranspose1d组成的解码器层。
Example
>>> x = torch.randn(2, 100, 1000) >>> decoder = Decoder(kernel_size=4, in_channels=100, out_channels=1) >>> h = decoder(x) >>> h.shape torch.Size([2, 1003])
- class speechbrain.lobes.models.dual_path.IdentityBlock[source]
基础类:
object当我们需要在Dual_path块内进行恒等变换时,使用此块。
- Parameters:
**kwargs (dict) – 参数被忽略。
Example
>>> x = torch.randn(10, 100) >>> IB = IdentityBlock() >>> xhat = IB(x)
- class speechbrain.lobes.models.dual_path.FastTransformerBlock(attention_type, out_channels, num_layers=6, nhead=8, d_ffn=1024, dropout=0, activation='relu', reformer_bucket_size=32)[source]
基础:
Module此块用于实现具有高效注意力的快速变压器模型。
实现取自 https://fast-transformers.github.io/
- Parameters:
Example
# >>> x = torch.randn(10, 100, 64) # >>> block = FastTransformerBlock(‘linear’, 64) # >>> x = block(x) # >>> x.shape # torch.Size([10, 100, 64])
- class speechbrain.lobes.models.dual_path.PyTorchPositionalEncoding(d_model, dropout=0.1, max_len=5000)[source]
基础:
Module用于PyTorch变换器的位置编码器。
Example
>>> x = torch.randn(10, 100, 64) >>> enc = PyTorchPositionalEncoding(64) >>> x = enc(x)
- class speechbrain.lobes.models.dual_path.PytorchTransformerBlock(out_channels, num_layers=6, nhead=8, d_ffn=2048, dropout=0.1, activation='relu', use_positional_encoding=True)[source]
基础:
Module一个使用pytorch transformer块的包装器。
- Parameters:
Example
>>> x = torch.randn(10, 100, 64) >>> block = PytorchTransformerBlock(64) >>> x = block(x) >>> x.shape torch.Size([10, 100, 64])
- class speechbrain.lobes.models.dual_path.SBTransformerBlock(num_layers, d_model, nhead, d_ffn=2048, input_shape=None, kdim=None, vdim=None, dropout=0.1, activation='relu', use_positional_encoding=False, norm_before=False, attention_type='regularMHA')[source]
基础:
ModuleSpeechBrain实现的transformer编码器的封装。
- Parameters:
num_layers (int) – 层数。
d_model (int) – 表示的维度。
nhead (int) – 注意力头的数量。
d_ffn (int) – 位置前馈的维度。
input_shape (tuple) – 输入的形状。
kdim (int) – 键的维度(可选)。
vdim (int) – 值的维度(可选)。
dropout (float) – 丢弃率。
activation (str) – 激活函数。
use_positional_encoding (bool) – 如果为真,我们使用位置编码。
norm_before (bool) – 在转换之前使用归一化。
attention_type (str) – 使用的注意力类型,默认为“regularMHA”
Example
>>> x = torch.randn(10, 100, 64) >>> block = SBTransformerBlock(1, 64, 8) >>> x = block(x) >>> x.shape torch.Size([10, 100, 64])
- class speechbrain.lobes.models.dual_path.SBRNNBlock(input_size, hidden_channels, num_layers, rnn_type='LSTM', dropout=0, bidirectional=True)[source]
基础:
Module用于双路径管道的RNNBlock。
- Parameters:
Example
>>> x = torch.randn(10, 100, 64) >>> rnn = SBRNNBlock(64, 100, 1, bidirectional=True) >>> x = rnn(x) >>> x.shape torch.Size([10, 100, 200])
- class speechbrain.lobes.models.dual_path.DPTNetBlock(d_model, nhead, dim_feedforward=256, dropout=0, activation='relu')[source]
基础:
ModuleDPT 网络块。
- Parameters:
示例
>>> encoder_layer = DPTNetBlock(d_model=512, nhead=8) >>> src = torch.rand(10, 100, 512) >>> out = encoder_layer(src) >>> out.shape torch.Size([10, 100, 512])
- class speechbrain.lobes.models.dual_path.Dual_Computation_Block(intra_mdl, inter_mdl, out_channels, norm='ln', skip_around_intra=True, linear_layer_after_inter_intra=True)[source]
基础:
Module双路径处理的计算块。
- Parameters:
Example
>>> intra_block = SBTransformerBlock(1, 64, 8) >>> inter_block = SBTransformerBlock(1, 64, 8) >>> dual_comp_block = Dual_Computation_Block(intra_block, inter_block, 64) >>> x = torch.randn(10, 64, 100, 10) >>> x = dual_comp_block(x) >>> x.shape torch.Size([10, 64, 100, 10])
- class speechbrain.lobes.models.dual_path.Dual_Path_Model(in_channels, out_channels, intra_model, inter_model, num_layers=1, norm='ln', K=200, num_spks=2, skip_around_intra=True, linear_layer_after_inter_intra=True, use_global_pos_enc=False, max_length=20000)[source]
基础:
Module双路径模型是dualpathrnn、sepformer、dptnet的基础。
- Parameters:
in_channels (int) – 编码器输出端的通道数。
out_channels (int) – 将输入到内部和外部块的通道数。
intra_model (torch.nn.module) – 用于在块内处理的模型。
inter_model (torch.nn.module) – 用于跨块处理的模型,
num_layers (int) – 双计算块的层数。
norm (str) – 归一化类型。
K (int) – 块长度。
num_spks (int) – 源(说话者)的数量。
skip_around_intra (bool) – 跳过围绕内部的连接。
linear_layer_after_inter_intra (bool) – 在inter和intra之后的线性层。
use_global_pos_enc (bool) – 全局位置编码。
max_length (int) – 最大序列长度。
Example
>>> intra_block = SBTransformerBlock(1, 64, 8) >>> inter_block = SBTransformerBlock(1, 64, 8) >>> dual_path_model = Dual_Path_Model(64, 64, intra_block, inter_block, num_spks=2) >>> x = torch.randn(10, 64, 2000) >>> x = dual_path_model(x) >>> x.shape torch.Size([2, 10, 64, 2000])
- class speechbrain.lobes.models.dual_path.SepformerWrapper(encoder_kernel_size=16, encoder_in_nchannels=1, encoder_out_nchannels=256, masknet_chunksize=250, masknet_numlayers=2, masknet_norm='ln', masknet_useextralinearlayer=False, masknet_extraskipconnection=True, masknet_numspks=2, intra_numlayers=8, inter_numlayers=8, intra_nhead=8, inter_nhead=8, intra_dffn=1024, inter_dffn=1024, intra_use_positional=True, inter_use_positional=True, intra_norm_before=True, inter_norm_before=True)[source]
基础:
Modulesepformer模型的封装器,它结合了编码器、掩码网络和解码器 https://arxiv.org/abs/2010.13154
- Parameters:
encoder_kernel_size (int) – 编码器中使用的核大小
encoder_in_nchannels (int) – 输入音频的通道数
encoder_out_nchannels (int) – 编码器中使用的过滤器数量。 同时,也是输入到内部和外部块的通道数量。
masknet_chunksize (int) – 由内部块处理的块长度
masknet_numlayers (int) – 组合内部和外部块的层数
masknet_norm (str,) –
在masknet中使用的归一化类型 应该是以下之一:‘ln’ – 层归一化, ‘gln’ – 全局层归一化
’cln’ – 累积层归一化, ‘bn’ – 批归一化 – 更多详情请参见上面的select_norm函数
masknet_useextralinearlayer (bool) – 是否在内部和外部块的输出处使用线性层
masknet_extraskipconnection (bool) – 这会在内部块周围引入额外的跳跃连接
masknet_numspks (int) – 这决定了要估计的说话者数量
intra_numlayers (int) – 这决定了内部块中的层数
inter_numlayers (int) – 这决定了inter块中的层数
intra_nhead (int) – 这决定了内部块中并行注意力头的数量
inter_nhead (int) – 这决定了inter块中并行注意力头的数量
intra_dffn (int) – 内部块中位置前馈模型的维度数
inter_dffn (int) – 内部块中位置前馈模型的维度数量
intra_use_positional (bool) – 是否在内部块中使用位置编码
inter_use_positional (bool) – 是否在inter块中使用位置编码
intra_norm_before (bool) – 是否在内部块的转换之前使用归一化
inter_norm_before (bool) – 是否在内部块的转换之前使用归一化
Example
>>> model = SepformerWrapper() >>> inp = torch.rand(1, 160) >>> result = model.forward(inp) >>> result.shape torch.Size([1, 160, 2])
- class speechbrain.lobes.models.dual_path.SBConformerEncoderBlock(num_layers, d_model, nhead, d_ffn=2048, input_shape=None, kdim=None, vdim=None, dropout=0.1, activation='swish', kernel_size=31, bias=True, use_positional_encoding=True, attention_type='RelPosMHAXL')[source]
基础:
ModuleConformerEncoder 的 SpeechBrain 实现的封装器。
- Parameters:
num_layers (int) – 层数。
d_model (int) – 表示的维度。
nhead (int) – 注意力头的数量。
d_ffn (int) – 位置前馈的维度。
input_shape (tuple) – 输入的形状。
kdim (int) – 键的维度(可选)。
vdim (int) – 值的维度(可选)。
dropout (float) – 丢弃率。
activation (str) – 激活函数。
kernel_size (int) – 在conformer编码器中的核大小
bias (bool) – 在conformer编码器的卷积部分是否使用偏置
use_positional_encoding (bool) – 如果为真,我们使用位置编码。
attention_type (str) – 使用的注意力类型,默认为“RelPosMHAXL”
Example
>>> x = torch.randn(10, 100, 64) >>> block = SBConformerEncoderBlock(1, 64, 8) >>> from speechbrain.lobes.models.transformer.Transformer import PositionalEncoding >>> pos_enc = PositionalEncoding(64) >>> pos_embs = pos_enc(torch.ones(1, 199, 64)) >>> x = block(x) >>> x.shape torch.Size([10, 100, 64])