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

[S2T]Wav2vec2多条语音推理,只能得到最后一条语音的预测结果 #3983

Closed
kongdebug opened this issue Jan 29, 2025 · 5 comments
Assignees
Labels

Comments

@kongdebug
Copy link

执行以下代码,只能得到最后一条语音的结果:

result_transcripts, result_tokenids = model.decode(
        audio_tensor,
        text_feature=text_feature,
        decoding_method=decode_config.decoding_method,
        beam_size=decode_config.beam_size,
        tokenizer=w2w_config.tokenizer, )

查看源代码paddlespeech\s2t\models\wav2vec2\wav2vec2_ASR.py发现是由于该段代码的问题:

for sequence in hyps:
    # Decode token terms to words 
    predicted_tokens = text_feature.convert_ids_to_tokens(
        sequence)
tmp_res = []
tmp_res_tokenids = []
for c in predicted_tokens:
    if c == "[CLS]":
        continue
    elif c == "[SEP]" or c == "[PAD]":
        break
    else:
        tmp_res.append(c)
        tmp_res_tokenids.append(text_feature.vocab[c])
res.append(''.join(tmp_res))
res_tokenids.append(tmp_res_tokenids)

从tmp_res = []开始就把他写出了循环外,所以最后只能得到最后一条语音的结果。将该部分代码移入循环内即可解决。想提PR但是网有点不好,总是报错time out

@zxcd
Copy link
Collaborator

zxcd commented Feb 5, 2025

感觉是你的用法不太正确,在使用model.decode时这里默认放进去的是单条语音,而非多条。

多条使用的话建议参考#3957 中我在最后给出的示例,将VectorExecutor 修改为SSLExecutor

具体wav2vec2模型相关的参数可参考:https://github.com/zxcd/PaddleSpeech/blob/doc/demos/speech_ssl/README.md

@zxcd zxcd assigned zxcd and unassigned zh794390558 Feb 5, 2025
@zxcd zxcd added Question and removed Bug labels Feb 5, 2025
@kongdebug
Copy link
Author

感觉是你的用法不太正确,在使用model.decode时这里默认放进去的是单条语音,而非多条。

多条使用的话建议参考#3957 中我在最后给出的示例,将VectorExecutor 修改为SSLExecutor

具体wav2vec2模型相关的参数可参考:https://github.com/zxcd/PaddleSpeech/blob/doc/demos/speech_ssl/README.md

我看了的SSLExecutor代码,里面audio_file参数好像只支持单条语音文件,不是多条语音同时推理的吧。按照我提供的代码修改方式后model.decode既可以单条语音推理也可以多条语音推理。你可以仔细看看代码,谢谢

@zxcd
Copy link
Collaborator

zxcd commented Feb 5, 2025

感觉是你的用法不太正确,在使用model.decode时这里默认放进去的是单条语音,而非多条。
多条使用的话建议参考#3957 中我在最后给出的示例,将VectorExecutor 修改为SSLExecutor
具体wav2vec2模型相关的参数可参考:https://github.com/zxcd/PaddleSpeech/blob/doc/demos/speech_ssl/README.md

我看了的SSLExecutor代码,里面audio_file参数好像只支持单条语音文件,不是多条语音同时推理的吧。按照我提供的代码修改方式后model.decode既可以单条语音推理也可以多条语音推理。你可以仔细看看代码,谢谢

audio_file 只支持单条语音,因此你可以看到我在 issue 中给出的示例是通过 for 循环进行了嵌套,我理解这部分应该没有什么问题。

另外你现在的用法我理解本质上是将多条语音进行了合并推理,在总时长过长的情况下是无法保证模型精度的。

@kongdebug
Copy link
Author

因此你可以看到我在 issue 中给出的示例是通过 for 循环进行了嵌套

哦哦原来你是这个意思,issue但是for循环嵌套每次推理的也是单条语音。我的客户是想要一次推理n条语音,在修改前,我将4条语音转为一个batch为4的张量输入,model.decode出来的结果只有最后一条语音的。就是因为decode代码里的for循环,每次都会覆盖之前的结果。这样的代码如果你觉得是没问题的那我就close这条issue了,我已经实现我想要的功能了,只是觉得decode的代码可以像这样小改一下。

@zxcd
Copy link
Collaborator

zxcd commented Feb 5, 2025

如果是指多batch size的推理,这部分确实还没有做完善的支持,后续优化的时候会参考您的建议,感谢您的支持:D

@zxcd zxcd closed this as completed Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants