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

ctc_decoder的一些问题 #376

Closed
fanlu opened this issue Oct 14, 2017 · 12 comments
Closed

ctc_decoder的一些问题 #376

fanlu opened this issue Oct 14, 2017 · 12 comments
Assignees
Labels

Comments

@fanlu
Copy link

fanlu commented Oct 14, 2017

在编译使用中遇到了一些问题。
在swig目录中执行sh setup.sh ,报了一个错

Install decoders ...
decoder_utils.h:55: Error: Syntax error in input(1).
running install

最终安装成功了

Processing dependencies for swig-decoders==0.1
Finished processing dependencies for swig-decoders==0.1

但是执行python -c "import swig_decoders"还是报以下错误:

Traceback (most recent call last):
File "", line 1, in 
ImportError: No module named swig_decoders

@kuke 给了解决方案:

decoder_utils.h:55: Error: Syntax error in input(1)
This error results from that the version of swig is too low. Please upgrade swig first then reinstall the decoders.

升级到3.0.12后问题解决。


但目前仍有两个问题:

  1. 在mac上执行会报这个问题:
openfst-1.6.3/src/include/fst/types.h:19:10: fatal error: 'cstdint' file not found
  1. 还有一个使用的问题:在中文的处理中,ctc_beam_search_decoder.cpp 第122行,c == space_id 中文是没有空格的,怎么把语言模型的转移概率加进去呢?

@kuke @lcy-seso

@kuke
Copy link
Collaborator

kuke commented Oct 14, 2017

hi, @fanlu 谢谢你的反馈。你的两个问题,回答如下:

1)我们还没有在mac上测试过decoder的编译,在mac上使用,你可以试用下docker镜像paddlepaddle/models:deep-speech-2,其中所有的依赖已经安装好,稍后会更新在README中;

2)decoder是兼容中文的,注意ctc_beam_search_decoder.cpp的第37-43行,如果vocabulary中没有空格,space_id就会被赋值为一个无效的index (-2)。

Thanks!

@fanlu
Copy link
Author

fanlu commented Oct 14, 2017

@kuke 恩,space_id是 -2 的话,c 也不能是 -2 。这个方法块就进不来,ext_scorer kenlm 就加不进来吧?

if (ext_scorer != nullptr &&
              (c == space_id || ext_scorer->is_character_based())) {
            PathTrie *prefix_toscore = nullptr;
            // skip scoring the space
            if (ext_scorer->is_character_based()) {
              prefix_toscore = prefix_new;
            } else {
              prefix_toscore = prefix;
            }

            double score = 0.0;
            std::vector<std::string> ngram;
            ngram = ext_scorer->make_ngram(prefix_toscore);
            score = ext_scorer->get_log_cond_prob(ngram) * ext_scorer->alpha;
            log_p += score;
            log_p += ext_scorer->beta;
          }

我的理解是英文是空格分割的,当有空格的时候就可以算prefix的score了,而中文没有空格,所以任何时候都可以计算这个score,而且kenlm的score python 接口传入的中文参数是空格分割的,如model.score(u"中 华 人 民 共 和 国")

另外blank_id space_id能指定成别的吗,如blank_id是 0 而不是 vocabulary.size()

@kuke
Copy link
Collaborator

kuke commented Oct 14, 2017

@fanlu 你的理解部分正确,通常的中文语言模型是基于字符的,所以is_character_based()这个函数返回值为true,对于中文来讲这个if条件始终是满足的(假设ext_scorer != nullptr)

blank_id现在只能是vocabulary.size(),但是space可以在vocabulary中的任何位置

@fanlu
Copy link
Author

fanlu commented Oct 14, 2017

@kuke 哦,是个||,我看过你写的py的版本,过于纠结空格忘了仔细看代码了,我的错,谢谢!也希望能跟python版本似的可以指定blank_id的位置。
另外,Mandarin LM http://cloud.dlnel.org/filepub/?uuid=d21861e4-4ed6-45bb-ad8e-ae417a43195e这个地址下载到705M左右,总是失败

@pkuyym
Copy link
Contributor

pkuyym commented Oct 14, 2017

这个应该是服务器的问题,目前服务器有60s的限制,请参考 #301

@kuke
Copy link
Collaborator

kuke commented Oct 14, 2017

@fanlu python版的blank_id其实也只能是固定的,现在已经改过来了

@fanlu
Copy link
Author

fanlu commented Oct 14, 2017

@kuke 恩,应该是固定的。不过不能固定到0吗?

@fanlu
Copy link
Author

fanlu commented Oct 14, 2017

@pkuyym 谢谢,搞定

@kuke
Copy link
Collaborator

kuke commented Oct 14, 2017

@fanlu blank_id固定为零不妥,会使vocabulary的index从1开始,比较自然的做法是放到最后

@fanlu
Copy link
Author

fanlu commented Oct 17, 2017

@kuke 因为我用别的框架训练的模型的blank_id是0,所以想让vocabulary的index从1开始,这个需要怎么改呢?

@ghost
Copy link

ghost commented Dec 14, 2017

@kuke 因为我用mxnet框架训练的模型的blank_id是0,所以想让vocabulary的index从1开始,这个需要怎么改呢?

@shanyi15
Copy link
Collaborator

您好,此issue在近一个月内暂无更新,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持!
Hello, this issue has not been updated in the past month. We will close it today for the sake of other user‘s experience. If you still need to follow up on this question after closing, please feel free to reopen it. In that case, we will get back to you within 24 hours. We apologize for the inconvenience caused by the closure and thank you so much for your support of PaddlePaddle Group!

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

5 participants