Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASR]add squeezeformer model #2755

Merged
merged 9 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/aishell/asr1/conf/chunk_squeezeformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ encoder_conf:
normalize_before: false
activation_type: 'swish'
pos_enc_layer_type: 'rel_pos'
do_rel_shift: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议 do_rel_shift 保留吧。

time_reduction_layer_type: 'stream'
causal: true
use_dynamic_chunk: true
Expand Down
2 changes: 1 addition & 1 deletion examples/aishell/asr1/conf/squeezeformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ encoder_conf:
normalize_before: false
activation_type: 'swish'
pos_enc_layer_type: 'rel_pos'
time_reduction_layer_type: 'conv2d'
time_reduction_layer_type: 'conv1d'

# decoder related
decoder: transformer
Expand Down
5 changes: 1 addition & 4 deletions paddlespeech/s2t/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def __init__(self,
n_head,
n_feat,
dropout_rate,
do_rel_shift=False,
adaptive_scale=False,
init_weights=False):
"""Construct an RelPositionMultiHeadedAttention object.
Expand All @@ -229,7 +228,6 @@ def __init__(self,
pos_bias_v = self.create_parameter(
(self.h, self.d_k), default_initializer=I.XavierUniform())
self.add_parameter('pos_bias_v', pos_bias_v)
self.do_rel_shift = do_rel_shift
self.adaptive_scale = adaptive_scale
zh794390558 marked this conversation as resolved.
Show resolved Hide resolved
if self.adaptive_scale:
ada_scale = self.create_parameter(
Expand Down Expand Up @@ -369,8 +367,7 @@ def forward(self,
matrix_bd = paddle.matmul(q_with_bias_v, p, transpose_y=True)
# Remove rel_shift since it is useless in speech recognition,
# and it requires special attention for streaming.
if self.do_rel_shift:
matrix_bd = self.rel_shift(matrix_bd)
# matrix_bd = self.rel_shift(matrix_bd)

scores = (matrix_ac + matrix_bd) / math.sqrt(
self.d_k) # (batch, head, time1, time2)
Expand Down
5 changes: 1 addition & 4 deletions paddlespeech/s2t/modules/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ def __init__(self,
input_dropout_rate: float=0.1,
pos_enc_layer_type: str="rel_pos",
time_reduction_layer_type: str="conv1d",
do_rel_shift: bool=True,
feed_forward_dropout_rate: float=0.1,
attention_dropout_rate: float=0.1,
cnn_module_kernel: int=31,
Expand Down Expand Up @@ -549,8 +548,6 @@ def __init__(self,
input_dropout_rate (float): Dropout rate of input projection layer.
pos_enc_layer_type (str): Self attention type.
time_reduction_layer_type (str): Conv1d or Conv2d reduction layer.
do_rel_shift (bool): Whether to do relative shift
operation on rel-attention module.
cnn_module_kernel (int): Kernel size of CNN module.
activation_type (str): Encoder activation function type.
cnn_module_kernel (int): Kernel size of convolution module.
Expand Down Expand Up @@ -590,7 +587,7 @@ def __init__(self,
else:
encoder_selfattn_layer = RelPositionMultiHeadedAttention
encoder_selfattn_layer_args = (attention_heads, encoder_dim,
attention_dropout_rate, do_rel_shift,
attention_dropout_rate,
adaptive_scale, init_weights)

# feed-forward module definition
Expand Down