Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
a506198f
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
226
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看板
提交
a506198f
编写于
7月 04, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs
上级
59b4b872
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
23 deletion
+24
-23
deep_speech_2/deploy.py
deep_speech_2/deploy.py
+3
-2
deep_speech_2/deploy/ctc_beam_search_decoder.cpp
deep_speech_2/deploy/ctc_beam_search_decoder.cpp
+14
-14
deep_speech_2/deploy/scorer.cpp
deep_speech_2/deploy/scorer.cpp
+7
-7
未找到文件。
deep_speech_2/deploy.py
浏览文件 @
a506198f
...
...
@@ -58,7 +58,7 @@ parser.add_argument(
help
=
"Manifest path for decoding. (default: %(default)s)"
)
parser
.
add_argument
(
"--model_filepath"
,
default
=
'
ds2_new_models_0628/params.pass-51
.tar.gz'
,
default
=
'
checkpoints/params.latest
.tar.gz'
,
type
=
str
,
help
=
"Model filepath. (default: %(default)s)"
)
parser
.
add_argument
(
...
...
@@ -162,9 +162,10 @@ def infer():
for
i
,
probs
in
enumerate
(
probs_split
)
]
# external scorer
ext_scorer
=
Scorer
(
args
.
alpha
,
args
.
beta
,
args
.
language_model_path
)
## decode and print
## decode and print
wer_sum
,
wer_counter
=
0
,
0
for
i
,
probs
in
enumerate
(
probs_split
):
beam_result
=
ctc_beam_search_decoder
(
...
...
deep_speech_2/deploy/ctc_beam_search_decoder.cpp
浏览文件 @
a506198f
...
...
@@ -15,10 +15,10 @@ bool pair_comp_second_rev(const std::pair<T1, T2> a, const std::pair<T1, T2> b)
return
a
.
second
>
b
.
second
;
}
/* CTC beam search decoder in C++, the interface is consistent with the original
/* CTC beam search decoder in C++, the interface is consistent with the original
decoder in Python version.
*/
std
::
vector
<
std
::
pair
<
double
,
std
::
string
>
>
std
::
vector
<
std
::
pair
<
double
,
std
::
string
>
>
ctc_beam_search_decoder
(
std
::
vector
<
std
::
vector
<
double
>
>
probs_seq
,
int
beam_size
,
std
::
vector
<
std
::
string
>
vocabulary
,
...
...
@@ -29,15 +29,15 @@ std::vector<std::pair<double, std::string> >
)
{
int
num_time_steps
=
probs_seq
.
size
();
// assign space ID
// assign space ID
std
::
vector
<
std
::
string
>::
iterator
it
=
std
::
find
(
vocabulary
.
begin
(),
vocabulary
.
end
(),
" "
);
int
space_id
=
it
-
vocabulary
.
begin
();
if
(
space_id
>=
vocabulary
.
size
())
{
std
::
cout
<<
"The character space is not in the vocabulary!"
;
exit
(
1
);
exit
(
1
);
}
// initialize
// two sets containing selected and candidate prefixes respectively
std
::
map
<
std
::
string
,
double
>
prefix_set_prev
,
prefix_set_next
;
...
...
@@ -47,7 +47,7 @@ std::vector<std::pair<double, std::string> >
prefix_set_prev
[
"
\t
"
]
=
1.0
;
probs_b_prev
[
"
\t
"
]
=
1.0
;
probs_nb_prev
[
"
\t
"
]
=
0.0
;
for
(
int
time_step
=
0
;
time_step
<
num_time_steps
;
time_step
++
)
{
prefix_set_next
.
clear
();
probs_b_cur
.
clear
();
...
...
@@ -70,8 +70,8 @@ std::vector<std::pair<double, std::string> >
}
prob_idx
=
std
::
vector
<
std
::
pair
<
int
,
double
>
>
(
prob_idx
.
begin
(),
prob_idx
.
begin
()
+
cutoff_len
);
}
// extend prefix
for
(
std
::
map
<
std
::
string
,
double
>::
iterator
it
=
prefix_set_prev
.
begin
();
// extend prefix
for
(
std
::
map
<
std
::
string
,
double
>::
iterator
it
=
prefix_set_prev
.
begin
();
it
!=
prefix_set_prev
.
end
();
it
++
)
{
std
::
string
l
=
it
->
first
;
if
(
prefix_set_next
.
find
(
l
)
==
prefix_set_next
.
end
())
{
...
...
@@ -109,12 +109,12 @@ std::vector<std::pair<double, std::string> >
}
}
prefix_set_next
[
l
]
=
probs_b_cur
[
l
]
+
probs_nb_cur
[
l
];
prefix_set_next
[
l
]
=
probs_b_cur
[
l
]
+
probs_nb_cur
[
l
];
}
probs_b_prev
=
probs_b_cur
;
probs_nb_prev
=
probs_nb_cur
;
std
::
vector
<
std
::
pair
<
std
::
string
,
double
>
>
std
::
vector
<
std
::
pair
<
std
::
string
,
double
>
>
prefix_vec_next
(
prefix_set_next
.
begin
(),
prefix_set_next
.
end
());
std
::
sort
(
prefix_vec_next
.
begin
(),
prefix_vec_next
.
end
(),
pair_comp_second_rev
<
std
::
string
,
double
>
);
int
k
=
beam_size
<
prefix_vec_next
.
size
()
?
beam_size
:
prefix_vec_next
.
size
();
...
...
@@ -124,7 +124,7 @@ std::vector<std::pair<double, std::string> >
// post processing
std
::
vector
<
std
::
pair
<
double
,
std
::
string
>
>
beam_result
;
for
(
std
::
map
<
std
::
string
,
double
>::
iterator
it
=
prefix_set_prev
.
begin
();
for
(
std
::
map
<
std
::
string
,
double
>::
iterator
it
=
prefix_set_prev
.
begin
();
it
!=
prefix_set_prev
.
end
();
it
++
)
{
if
(
it
->
second
>
0.0
&&
it
->
first
.
size
()
>
1
)
{
double
prob
=
it
->
second
;
...
...
@@ -133,8 +133,8 @@ std::vector<std::pair<double, std::string> >
if
(
ext_scorer
!=
NULL
&&
sentence
[
sentence
.
size
()
-
1
]
!=
' '
)
{
prob
=
prob
*
ext_scorer
->
get_score
(
sentence
);
}
double
log_prob
=
log
(
it
->
second
);
beam_result
.
push_back
(
std
::
pair
<
double
,
std
::
string
>
(
log_prob
,
it
->
first
));
double
log_prob
=
log
(
prob
);
beam_result
.
push_back
(
std
::
pair
<
double
,
std
::
string
>
(
log_prob
,
sentence
));
}
}
// sort the result and return
...
...
deep_speech_2/deploy/scorer.cpp
浏览文件 @
a506198f
...
...
@@ -35,7 +35,7 @@ inline void strip(std::string &str, char ch=' ') {
break
;
}
}
if
(
start
==
0
&&
end
==
str
.
size
()
-
1
)
return
;
if
(
start
>
end
)
{
std
::
string
emp_str
;
...
...
@@ -47,13 +47,12 @@ inline void strip(std::string &str, char ch=' ') {
int
Scorer
::
word_count
(
std
::
string
sentence
)
{
strip
(
sentence
);
int
cnt
=
0
;
int
cnt
=
1
;
for
(
int
i
=
0
;
i
<
sentence
.
size
();
i
++
)
{
if
(
sentence
[
i
]
==
' '
&&
sentence
[
i
-
1
]
!=
' '
)
{
cnt
++
;
}
}
if
(
cnt
>
0
)
cnt
++
;
return
cnt
;
}
...
...
@@ -68,15 +67,16 @@ double Scorer::language_model_score(std::string sentence) {
ret
=
model
->
FullScore
(
state
,
vocab
,
out_state
);
state
=
out_state
;
}
double
score
=
ret
.
prob
;
return
pow
(
10
,
score
);
//log10 prob
double
log_prob
=
ret
.
prob
;
return
log_prob
;
}
double
Scorer
::
get_score
(
std
::
string
sentence
)
{
double
lm_score
=
language_model_score
(
sentence
);
int
word_cnt
=
word_count
(
sentence
);
double
final_score
=
pow
(
lm_score
,
_alpha
)
*
pow
(
word_cnt
,
_beta
);
double
final_score
=
pow
(
10
,
_alpha
*
lm_score
)
*
pow
(
word_cnt
,
_beta
);
return
final_score
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录