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

[Hackathon 7th] 修复 s2t 示例错误 #3950

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion examples/ted_en_zh/st0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ source path.h
bash ./local/data.sh
CUDA_VISIBLE_DEVICES= ./local/train.sh conf/transformer_mtl_noam.yaml transformer_mtl_noam
avg.sh latest exp/transformer_mtl_noam/checkpoints 5
CUDA_VISIBLE_DEVICES= ./local/test.sh conf/transformer_mtl_noam.yaml exp/transformer_mtl_noam/checkpoints/avg_5
CUDA_VISIBLE_DEVICES= ./local/test.sh conf/transformer_mtl_noam.yaml conf/tuning/decode.yaml exp/transformer_mtl_noam/checkpoints/avg_5
```
The performance of the released models are shown below:
### Transformer
Expand Down
3 changes: 0 additions & 3 deletions paddlespeech/s2t/exps/u2_st/bin/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def main(config, args):

if __name__ == "__main__":
parser = default_argument_parser()
# save asr result to
parser.add_argument(
"--result_file", type=str, help="path of save the asr result")
args = parser.parse_args()
print_arguments(args, globals())

Expand Down
4 changes: 4 additions & 0 deletions paddlespeech/s2t/frontend/featurizer/text_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def defeaturize(self, idxs):
"""
assert self.vocab_path_or_list, "toidx need vocab path or vocab list"
tokens = []
# unwrap `idxs`` like `[[1,2,3]]`
if idxs and isinstance(idxs[0], (list, tuple)) and len(idxs) == 1:
idxs = idxs[0]

for idx in idxs:
if idx == self.eos_id:
break
Expand Down
6 changes: 6 additions & 0 deletions paddlespeech/s2t/io/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ def get_dataloader(mode: str, config, args):
config['subsampling_factor'] = 1
config['num_encs'] = 1
config['shortest_first'] = False
config['minibatches'] = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

load the params from config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

细说???
这里的 config 本来就是 clone 过来的,应该是本来就木有这几个值,还需要从哪里 load?最好是有默认值 ~

Copy link
Collaborator

Choose a reason for hiding this comment

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

好的

config['batch_count'] = 'auto'
config['batch_bins'] = 0
config['batch_frames_in'] = 0
config['batch_frames_out'] = 0
config['batch_frames_inout'] = 0
elif mode == 'valid':
config['manifest'] = config.dev_manifest
config['train_mode'] = False
Expand Down
8 changes: 4 additions & 4 deletions paddlespeech/s2t/models/u2_st/u2_st.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def _calc_st_loss(
ys_in_lens = ys_pad_lens + 1

# 1. Forward decoder
decoder_out, _ = self.st_decoder(encoder_out, encoder_mask, ys_in_pad,
ys_in_lens)
decoder_out, *_ = self.st_decoder(encoder_out, encoder_mask, ys_in_pad,
ys_in_lens)

# 2. Compute attention loss
loss_att = self.criterion_att(decoder_out, ys_out_pad)
Expand Down Expand Up @@ -203,8 +203,8 @@ def _calc_att_loss(
ys_in_lens = ys_pad_lens + 1

# 1. Forward decoder
decoder_out, _ = self.decoder(encoder_out, encoder_mask, ys_in_pad,
ys_in_lens)
decoder_out, *_ = self.decoder(encoder_out, encoder_mask, ys_in_pad,
ys_in_lens)

# 2. Compute attention loss
loss_att = self.criterion_att(decoder_out, ys_out_pad)
Expand Down
16 changes: 8 additions & 8 deletions paddlespeech/s2t/modules/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def __init__(self,
concat_after=concat_after, ) for _ in range(num_blocks)
])

def forward(
self,
memory: paddle.Tensor,
memory_mask: paddle.Tensor,
ys_in_pad: paddle.Tensor,
ys_in_lens: paddle.Tensor,
r_ys_in_pad: paddle.Tensor=paddle.empty([0]),
reverse_weight: float=0.0) -> Tuple[paddle.Tensor, paddle.Tensor]:
def forward(self,
Copy link
Collaborator

Choose a reason for hiding this comment

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

only code style changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typing hint for the output changed from

-> Tuple[paddle.Tensor, paddle.Tensor]:

to

-> Tuple[paddle.Tensor, paddle.Tensor, paddle.Tensor]:

Copy link
Collaborator

Choose a reason for hiding this comment

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

好的

memory: paddle.Tensor,
memory_mask: paddle.Tensor,
ys_in_pad: paddle.Tensor,
ys_in_lens: paddle.Tensor,
r_ys_in_pad: paddle.Tensor=paddle.empty([0]),
reverse_weight: float=0.0
) -> Tuple[paddle.Tensor, paddle.Tensor, paddle.Tensor]:
"""Forward decoder.
Args:
memory: encoded memory, float32 (batch, maxlen_in, feat)
Expand Down