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