Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
ae05535e
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ae05535e
编写于
7月 10, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable loading language model in multiple format
上级
34f98e04
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
9 deletion
+19
-9
deep_speech_2/deploy.py
deep_speech_2/deploy.py
+5
-1
deep_speech_2/deploy/scorer.cpp
deep_speech_2/deploy/scorer.cpp
+12
-6
deep_speech_2/deploy/setup.sh
deep_speech_2/deploy/setup.sh
+2
-2
未找到文件。
deep_speech_2/deploy.py
浏览文件 @
ae05535e
...
...
@@ -14,6 +14,7 @@ from swig_ctc_beam_search_decoder import *
from
swig_scorer
import
Scorer
from
error_rate
import
wer
import
utils
import
time
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
.
add_argument
(
...
...
@@ -74,7 +75,7 @@ parser.add_argument(
)
parser
.
add_argument
(
"--beam_size"
,
default
=
5
00
,
default
=
2
00
,
type
=
int
,
help
=
"Width for beam search decoding. (default: %(default)d)"
)
parser
.
add_argument
(
...
...
@@ -166,6 +167,7 @@ def infer():
ext_scorer
=
Scorer
(
args
.
alpha
,
args
.
beta
,
args
.
language_model_path
)
## decode and print
time_begin
=
time
.
time
()
wer_sum
,
wer_counter
=
0
,
0
for
i
,
probs
in
enumerate
(
probs_split
):
beam_result
=
ctc_beam_search_decoder
(
...
...
@@ -183,6 +185,8 @@ def infer():
wer_counter
+=
1
print
(
"cur wer = %f , average wer = %f"
%
(
wer_cur
,
wer_sum
/
wer_counter
))
time_end
=
time
.
time
()
print
(
"total time = %f"
%
(
time_end
-
time_begin
))
def
main
():
...
...
deep_speech_2/deploy/scorer.cpp
浏览文件 @
ae05535e
#include <iostream>
#include <unistd.h>
#include "scorer.h"
#include "lm/model.hh"
#include "util/tokenize_piece.hh"
...
...
@@ -9,11 +10,16 @@ using namespace lm::ngram;
Scorer
::
Scorer
(
float
alpha
,
float
beta
,
std
::
string
lm_model_path
)
{
this
->
_alpha
=
alpha
;
this
->
_beta
=
beta
;
this
->
_language_model
=
new
Model
(
lm_model_path
.
c_str
());
if
(
access
(
lm_model_path
.
c_str
(),
F_OK
)
!=
0
)
{
std
::
cout
<<
"Invalid language model path!"
<<
std
::
endl
;
exit
(
1
);
}
this
->
_language_model
=
LoadVirtual
(
lm_model_path
.
c_str
());
}
Scorer
::~
Scorer
(){
delete
(
Model
*
)
this
->
_language_model
;
delete
(
lm
::
base
::
Model
*
)
this
->
_language_model
;
}
/* Strip a input sentence
...
...
@@ -63,14 +69,14 @@ int Scorer::word_count(std::string sentence) {
}
double
Scorer
::
language_model_score
(
std
::
string
sentence
)
{
Model
*
model
=
(
Model
*
)
this
->
_language_model
;
lm
::
base
::
Model
*
model
=
(
lm
::
base
::
Model
*
)
this
->
_language_model
;
State
state
,
out_state
;
lm
::
FullScoreReturn
ret
;
state
=
model
->
BeginSentenceState
(
);
model
->
BeginSentenceWrite
(
&
state
);
for
(
util
::
TokenIter
<
util
::
SingleCharacter
,
true
>
it
(
sentence
,
' '
);
it
;
++
it
){
lm
::
WordIndex
vocab
=
model
->
Get
Vocabulary
().
Index
(
*
it
);
ret
=
model
->
FullScore
(
state
,
vocab
,
out_state
);
lm
::
WordIndex
wid
=
model
->
Base
Vocabulary
().
Index
(
*
it
);
ret
=
model
->
BaseFullScore
(
&
state
,
wid
,
&
out_state
);
state
=
out_state
;
}
//log10 prob
...
...
deep_speech_2/deploy/setup.sh
浏览文件 @
ae05535e
...
...
@@ -3,9 +3,9 @@ echo "Run decoder setup ..."
python decoder_setup.py
install
rm
-r
./build
echo
"
\n
Run scorer setup ..."
echo
"Run scorer setup ..."
python scorer_setup.py
install
rm
-r
./build
echo
"
\n
Finish the installation of decoder and scorer."
echo
"Finish the installation of decoder and scorer."
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录