Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9ff48b05
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看板
提交
9ff48b05
编写于
8月 22, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reorganize cpp files
上级
ac3a49c0
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
69 addition
and
20 deletion
+69
-20
deep_speech_2/deploy.py
deep_speech_2/deploy.py
+3
-3
deep_speech_2/deploy/ctc_decoders.cpp
deep_speech_2/deploy/ctc_decoders.cpp
+3
-1
deep_speech_2/deploy/ctc_decoders.h
deep_speech_2/deploy/ctc_decoders.h
+1
-1
deep_speech_2/deploy/ctc_decoders.i
deep_speech_2/deploy/ctc_decoders.i
+1
-0
deep_speech_2/deploy/decoder_setup.py
deep_speech_2/deploy/decoder_setup.py
+4
-2
deep_speech_2/deploy/decoder_utils.cpp
deep_speech_2/deploy/decoder_utils.cpp
+5
-0
deep_speech_2/deploy/decoder_utils.h
deep_speech_2/deploy/decoder_utils.h
+15
-0
deep_speech_2/deploy/scorer.cpp
deep_speech_2/deploy/scorer.cpp
+6
-6
deep_speech_2/deploy/scorer.h
deep_speech_2/deploy/scorer.h
+5
-5
deep_speech_2/deploy/swig_decoders.py
deep_speech_2/deploy/swig_decoders.py
+26
-2
未找到文件。
deep_speech_2/deploy.py
浏览文件 @
9ff48b05
...
...
@@ -11,7 +11,7 @@ import paddle.v2 as paddle
from
data_utils.data
import
DataGenerator
from
model
import
deep_speech2
from
deploy.swig_decoders
import
*
from
swig_scorer
import
Lm
Scorer
from
swig_scorer
import
Scorer
from
error_rate
import
wer
import
utils
import
time
...
...
@@ -19,7 +19,7 @@ import time
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
.
add_argument
(
"--num_samples"
,
default
=
10
0
,
default
=
10
,
type
=
int
,
help
=
"Number of samples for inference. (default: %(default)s)"
)
parser
.
add_argument
(
...
...
@@ -164,7 +164,7 @@ def infer():
]
# external scorer
ext_scorer
=
Lm
Scorer
(
args
.
alpha
,
args
.
beta
,
args
.
language_model_path
)
ext_scorer
=
Scorer
(
args
.
alpha
,
args
.
beta
,
args
.
language_model_path
)
## decode and print
time_begin
=
time
.
time
()
...
...
deep_speech_2/deploy/ctc_decoders.cpp
浏览文件 @
9ff48b05
...
...
@@ -5,9 +5,11 @@
#include <cmath>
#include <limits>
#include "ctc_decoders.h"
#include "decoder_utils.h"
typedef
double
log_prob_type
;
template
<
typename
T1
,
typename
T2
>
bool
pair_comp_first_rev
(
const
std
::
pair
<
T1
,
T2
>
a
,
const
std
::
pair
<
T1
,
T2
>
b
)
{
...
...
@@ -81,7 +83,7 @@ std::vector<std::pair<double, std::string> >
std
::
vector
<
std
::
string
>
vocabulary
,
int
blank_id
,
double
cutoff_prob
,
Lm
Scorer
*
ext_scorer
,
Scorer
*
ext_scorer
,
bool
nproc
)
{
// dimension check
int
num_time_steps
=
probs_seq
.
size
();
...
...
deep_speech_2/deploy/ctc_decoders.h
浏览文件 @
9ff48b05
...
...
@@ -28,7 +28,7 @@ std::vector<std::pair<double, std::string> >
std
::
vector
<
std
::
string
>
vocabulary
,
int
blank_id
,
double
cutoff_prob
=
1
.
0
,
Lm
Scorer
*
ext_scorer
=
NULL
,
Scorer
*
ext_scorer
=
NULL
,
bool
nproc
=
false
);
...
...
deep_speech_2/deploy/ctc_decoders.i
浏览文件 @
9ff48b05
...
...
@@ -19,4 +19,5 @@ namespace std{
}
%
import
scorer
.
h
%
import
decoder_utils
.
h
%
include
"ctc_decoders.h"
deep_speech_2/deploy/decoder_setup.py
浏览文件 @
9ff48b05
...
...
@@ -39,8 +39,10 @@ os.system('swig -python -c++ ./ctc_decoders.i')
ctc_beam_search_decoder_module
=
[
Extension
(
name
=
'_swig_ctc_decoders'
,
sources
=
FILES
+
[
'scorer.cpp'
,
'ctc_decoders_wrap.cxx'
,
'ctc_decoders.cpp'
],
sources
=
FILES
+
[
'scorer.cpp'
,
'ctc_decoders_wrap.cxx'
,
'ctc_decoders.cpp'
,
'decoder_utils.cpp'
],
language
=
'C++'
,
include_dirs
=
[
'.'
,
'./kenlm'
],
libraries
=
LIBS
,
...
...
deep_speech_2/deploy/decoder_utils.cpp
0 → 100644
浏览文件 @
9ff48b05
#include <limits>
#include <algorithm>
#include <cmath>
#include "decoder_utils.h"
deep_speech_2/deploy/decoder_utils.h
0 → 100644
浏览文件 @
9ff48b05
#ifndef DECODER_UTILS_H
#define DECODER_UTILS_H
#pragma once
#include <utility>
/*
template <typename T1, typename T2>
bool pair_comp_first_rev(const std::pair<T1, T2> a, const std::pair<T1, T2> b);
template <typename T1, typename T2>
bool pair_comp_second_rev(const std::pair<T1, T2> a, const std::pair<T1, T2> b);
template <typename T> T log_sum_exp(T x, T y);
*/
#endif // DECODER_UTILS_H
deep_speech_2/deploy/scorer.cpp
浏览文件 @
9ff48b05
...
...
@@ -7,7 +7,7 @@
using
namespace
lm
::
ngram
;
LmScorer
::
Lm
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
->
_beta
=
beta
;
...
...
@@ -18,7 +18,7 @@ LmScorer::LmScorer(float alpha, float beta, std::string lm_model_path) {
this
->
_language_model
=
LoadVirtual
(
lm_model_path
.
c_str
());
}
LmScorer
::~
Lm
Scorer
(){
Scorer
::~
Scorer
(){
delete
(
lm
::
base
::
Model
*
)
this
->
_language_model
;
}
...
...
@@ -57,7 +57,7 @@ inline void strip(std::string &str, char ch=' ') {
}
}
int
Lm
Scorer
::
word_count
(
std
::
string
sentence
)
{
int
Scorer
::
word_count
(
std
::
string
sentence
)
{
strip
(
sentence
);
int
cnt
=
1
;
for
(
int
i
=
0
;
i
<
sentence
.
size
();
i
++
)
{
...
...
@@ -68,7 +68,7 @@ int LmScorer::word_count(std::string sentence) {
return
cnt
;
}
double
Lm
Scorer
::
language_model_score
(
std
::
string
sentence
)
{
double
Scorer
::
language_model_score
(
std
::
string
sentence
)
{
lm
::
base
::
Model
*
model
=
(
lm
::
base
::
Model
*
)
this
->
_language_model
;
State
state
,
out_state
;
lm
::
FullScoreReturn
ret
;
...
...
@@ -84,12 +84,12 @@ double LmScorer::language_model_score(std::string sentence) {
return
log_prob
;
}
void
Lm
Scorer
::
reset_params
(
float
alpha
,
float
beta
)
{
void
Scorer
::
reset_params
(
float
alpha
,
float
beta
)
{
this
->
_alpha
=
alpha
;
this
->
_beta
=
beta
;
}
double
Lm
Scorer
::
get_score
(
std
::
string
sentence
,
bool
log
)
{
double
Scorer
::
get_score
(
std
::
string
sentence
,
bool
log
)
{
double
lm_score
=
language_model_score
(
sentence
);
int
word_cnt
=
word_count
(
sentence
);
...
...
deep_speech_2/deploy/scorer.h
浏览文件 @
9ff48b05
...
...
@@ -8,10 +8,10 @@
* count and language model scoring.
* Example:
*
Lm
Scorer ext_scorer(alpha, beta, "path_to_language_model.klm");
* Scorer ext_scorer(alpha, beta, "path_to_language_model.klm");
* double score = ext_scorer.get_score("sentence_to_score");
*/
class
Lm
Scorer
{
class
Scorer
{
private:
float
_alpha
;
float
_beta
;
...
...
@@ -23,9 +23,9 @@ private:
double
language_model_score
(
std
::
string
);
public:
Lm
Scorer
(){}
Lm
Scorer
(
float
alpha
,
float
beta
,
std
::
string
lm_model_path
);
~
Lm
Scorer
();
Scorer
(){}
Scorer
(
float
alpha
,
float
beta
,
std
::
string
lm_model_path
);
~
Scorer
();
// reset params alpha & beta
void
reset_params
(
float
alpha
,
float
beta
);
...
...
deep_speech_2/deploy/swig_decoders.py
浏览文件 @
9ff48b05
...
...
@@ -4,7 +4,8 @@ from __future__ import division
from
__future__
import
print_function
import
swig_ctc_decoders
import
multiprocessing
#import multiprocessing
from
pathos.multiprocessing
import
Pool
def
ctc_best_path_decoder
(
probs_seq
,
vocabulary
):
...
...
@@ -73,14 +74,37 @@ def ctc_beam_search_decoder_batch(probs_split,
if
not
num_processes
>
0
:
raise
ValueError
(
"Number of processes must be positive!"
)
pool
=
multiprocessing
.
Pool
(
processes
=
num_processes
)
pool
=
Pool
(
processes
=
num_processes
)
results
=
[]
args_list
=
[]
for
i
,
probs_list
in
enumerate
(
probs_split
):
args
=
(
probs_list
,
beam_size
,
vocabulary
,
blank_id
,
cutoff_prob
,
ext_scoring_func
)
args_list
.
append
(
args
)
results
.
append
(
pool
.
apply_async
(
ctc_beam_search_decoder
,
args
))
pool
.
close
()
pool
.
join
()
beam_search_results
=
[
result
.
get
()
for
result
in
results
]
"""
len_args = len(probs_split)
beam_search_results = pool.map(ctc_beam_search_decoder,
probs_split,
[beam_size for i in xrange(len_args)],
[vocabulary for i in xrange(len_args)],
[blank_id for i in xrange(len_args)],
[cutoff_prob for i in xrange(len_args)],
[ext_scoring_func for i in xrange(len_args)]
)
"""
'''
processes = [mp.Process(target=ctc_beam_search_decoder,
args=(probs_list, beam_size, vocabulary, blank_id, cutoff_prob,
ext_scoring_func) for probs_list in probs_split]
for p in processes:
p.start()
for p in processes:
p.join()
beam_search_results = []
'''
return
beam_search_results
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录