Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
1d7ade10
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
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看板
提交
1d7ade10
编写于
6月 07, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add annotations
上级
142a79fa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
8 deletion
+8
-8
deep_speech_2/decoder.py
deep_speech_2/decoder.py
+5
-6
deep_speech_2/infer.py
deep_speech_2/infer.py
+3
-2
未找到文件。
deep_speech_2/decoder.py
浏览文件 @
1d7ade10
...
@@ -68,9 +68,9 @@ class Scorer(object):
...
@@ -68,9 +68,9 @@ class Scorer(object):
# execute evaluation
# execute evaluation
def
evaluate
(
self
,
sentence
,
bos
=
True
,
eos
=
False
):
def
evaluate
(
self
,
sentence
,
bos
=
True
,
eos
=
False
):
lm
=
self
.
language_model_score
(
sentence
,
bos
,
eos
)
lm
=
self
.
language_model_score
(
sentence
,
bos
,
eos
)
word_c
ou
nt
=
self
.
word_count
(
sentence
)
word_cnt
=
self
.
word_count
(
sentence
)
score
=
np
.
power
(
lm
,
self
.
_alpha
)
\
score
=
np
.
power
(
lm
,
self
.
_alpha
)
\
*
np
.
power
(
word_c
ou
nt
,
self
.
_beta
)
*
np
.
power
(
word_cnt
,
self
.
_beta
)
return
score
return
score
...
@@ -104,19 +104,18 @@ def ctc_beam_search_decoder(probs_seq,
...
@@ -104,19 +104,18 @@ def ctc_beam_search_decoder(probs_seq,
:rtype: list
:rtype: list
'''
'''
# dimension check
for
prob_list
in
probs_seq
:
for
prob_list
in
probs_seq
:
if
not
len
(
prob_list
)
==
len
(
vocabulary
)
+
1
:
if
not
len
(
prob_list
)
==
len
(
vocabulary
)
+
1
:
raise
ValueError
(
"probs dimension mismatchedd with vocabulary"
)
raise
ValueError
(
"probs dimension mismatchedd with vocabulary"
)
max_time_steps
=
len
(
probs_seq
)
max_time_steps
=
len
(
probs_seq
)
if
not
max_time_steps
>
0
:
raise
ValueError
(
"probs_seq shouldn't be empty"
)
# blank_id check
probs_dim
=
len
(
probs_seq
[
0
])
probs_dim
=
len
(
probs_seq
[
0
])
if
not
blank_id
<
probs_dim
:
if
not
blank_id
<
probs_dim
:
raise
ValueError
(
"blank_id shouldn't be greater than probs dimension"
)
raise
ValueError
(
"blank_id shouldn't be greater than probs dimension"
)
# assign space_id
if
' '
not
in
vocabulary
:
if
' '
not
in
vocabulary
:
raise
ValueError
(
"space doesn't exist in vocabulary"
)
raise
ValueError
(
"space doesn't exist in vocabulary"
)
space_id
=
vocabulary
.
index
(
' '
)
space_id
=
vocabulary
.
index
(
' '
)
...
...
deep_speech_2/infer.py
浏览文件 @
1d7ade10
...
@@ -77,7 +77,7 @@ parser.add_argument(
...
@@ -77,7 +77,7 @@ parser.add_argument(
"--language_model_path"
,
"--language_model_path"
,
default
=
"./data/1Billion.klm"
,
default
=
"./data/1Billion.klm"
,
type
=
str
,
type
=
str
,
help
=
"Path for language model. (default: %(default)
d
)"
)
help
=
"Path for language model. (default: %(default)
s
)"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--alpha"
,
"--alpha"
,
default
=
0.0
,
default
=
0.0
,
...
@@ -93,7 +93,7 @@ args = parser.parse_args()
...
@@ -93,7 +93,7 @@ args = parser.parse_args()
def
infer
():
def
infer
():
"""
"""
Max-ctc-decoding
for DeepSpeech2.
Inference
for DeepSpeech2.
"""
"""
# initialize data generator
# initialize data generator
data_generator
=
DataGenerator
(
data_generator
=
DataGenerator
(
...
@@ -174,6 +174,7 @@ def infer():
...
@@ -174,6 +174,7 @@ def infer():
print
(
"
\n
Target Transcription:
\t
%s"
%
target_transcription
)
print
(
"
\n
Target Transcription:
\t
%s"
%
target_transcription
)
for
index
in
range
(
args
.
num_results_per_sample
):
for
index
in
range
(
args
.
num_results_per_sample
):
result
=
beam_search_result
[
index
]
result
=
beam_search_result
[
index
]
#output: index, log prob, beam result
print
(
"Beam %d: %f
\t
%s"
%
(
index
,
result
[
0
],
result
[
1
]))
print
(
"Beam %d: %f
\t
%s"
%
(
index
,
result
[
0
],
result
[
1
]))
else
:
else
:
raise
ValueError
(
"Decoding method [%s] is not supported."
%
method
)
raise
ValueError
(
"Decoding method [%s] is not supported."
%
method
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录