Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
b7bdaf6f
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 2 年 前同步成功
通知
210
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看板
提交
b7bdaf6f
编写于
10月 26, 2021
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add lm conf and load
上级
082c6b7d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
22 deletion
+49
-22
deepspeech/decoders/recog.py
deepspeech/decoders/recog.py
+16
-12
deepspeech/models/lm/transformer.py
deepspeech/models/lm/transformer.py
+2
-1
examples/librispeech/s2/conf/lm/transformer.yaml
examples/librispeech/s2/conf/lm/transformer.yaml
+13
-0
examples/librispeech/s2/local/recog.sh
examples/librispeech/s2/local/recog.sh
+7
-6
examples/librispeech/s2/run.sh
examples/librispeech/s2/run.sh
+11
-3
未找到文件。
deepspeech/decoders/recog.py
浏览文件 @
b7bdaf6f
...
@@ -49,6 +49,21 @@ def load_trained_model(args):
...
@@ -49,6 +49,21 @@ def load_trained_model(args):
model
=
exp
.
model
model
=
exp
.
model
return
model
,
char_list
,
exp
,
confs
return
model
,
char_list
,
exp
,
confs
def
get_config
(
config_path
):
stream
=
open
(
config_path
,
mode
=
'r'
,
encoding
=
"utf-8"
)
config
=
yaml
.
load
(
stream
,
Loader
=
yaml
.
FullLoader
)
stream
.
close
()
return
config
def
load_trained_lm
(
args
):
lm_args
=
get_config
(
args
.
rnnlm_conf
)
# NOTE: for a compatibility with less than 0.5.0 version models
lm_model_module
=
getattr
(
lm_args
,
"model_module"
,
"default"
)
lm_class
=
dynamic_import_lm
(
lm_model_module
)
lm
=
lm_class
(
lm_args
.
model
)
model_dict
=
paddle
.
load
(
args
.
rnnlm
)
lm
.
set_state_dict
(
model_dict
)
return
lm
def
recog_v2
(
args
):
def
recog_v2
(
args
):
"""Decode with custom models that implements ScorerInterface.
"""Decode with custom models that implements ScorerInterface.
...
@@ -79,18 +94,7 @@ def recog_v2(args):
...
@@ -79,18 +94,7 @@ def recog_v2(args):
preprocess_args
=
{
"train"
:
False
},
)
preprocess_args
=
{
"train"
:
False
},
)
if
args
.
rnnlm
:
if
args
.
rnnlm
:
lm_path
=
args
.
rnnlm
lm
=
load_trained_lm
(
args
)
lm
=
TransformerLM
(
n_vocab
=
5002
,
pos_enc
=
None
,
embed_unit
=
128
,
att_unit
=
512
,
head
=
8
,
unit
=
2048
,
layer
=
16
,
dropout_rate
=
0.5
,
)
model_dict
=
paddle
.
load
(
lm_path
)
lm
.
set_state_dict
(
model_dict
)
lm
.
eval
()
lm
.
eval
()
else
:
else
:
lm
=
None
lm
=
None
...
...
deepspeech/models/lm/transformer.py
浏览文件 @
b7bdaf6f
...
@@ -42,7 +42,8 @@ class TransformerLM(nn.Layer, LMInterface, BatchScorerInterface):
...
@@ -42,7 +42,8 @@ class TransformerLM(nn.Layer, LMInterface, BatchScorerInterface):
dropout_rate
:
float
=
0.5
,
dropout_rate
:
float
=
0.5
,
emb_dropout_rate
:
float
=
0.0
,
emb_dropout_rate
:
float
=
0.0
,
att_dropout_rate
:
float
=
0.0
,
att_dropout_rate
:
float
=
0.0
,
tie_weights
:
bool
=
False
,
):
tie_weights
:
bool
=
False
,
**
kwargs
):
nn
.
Layer
.
__init__
(
self
)
nn
.
Layer
.
__init__
(
self
)
if
pos_enc
==
"sinusoidal"
:
if
pos_enc
==
"sinusoidal"
:
...
...
examples/librispeech/s2/conf/lm/transformer.yaml
0 → 100644
浏览文件 @
b7bdaf6f
model_module
:
transformer
model
:
n_vocab
:
5002
pos_enc
:
null
embed_unit
:
128
att_unit
:
512
head
:
8
unit
:
2048
layer
:
16
dropout_rate
:
0.5
emb_dropout_rate
:
0.0
att_dropout_rate
:
0.0
tie_weights
:
False
examples/librispeech/s2/local/recog.sh
浏览文件 @
b7bdaf6f
...
@@ -11,9 +11,10 @@ tag=
...
@@ -11,9 +11,10 @@ tag=
decode_config
=
conf/decode/decode.yaml
decode_config
=
conf/decode/decode.yaml
# lm params
# lm params
lang_model
=
rnnlm.model.best
lang_model
=
transformerLM.pdparams
lmexpdir
=
exp/train_rnnlm_pytorch_lm_transformer_cosine_batchsize32_lr1e-4_layer16_unigram5000_ngpu4/
lmexpdir
=
exp/lm/transformer
lmtag
=
'nolm'
rnnlm_config_path
=
conf/lm/transformer.yaml
lmtag
=
'transformer'
train_set
=
train_960
train_set
=
train_960
recog_set
=
"test-clean test-other dev-clean dev-other"
recog_set
=
"test-clean test-other dev-clean dev-other"
...
@@ -91,9 +92,9 @@ for dmethd in join_ctc; do
...
@@ -91,9 +92,9 @@ for dmethd in join_ctc; do
--recog-json
${
feat_recog_dir
}
/split
${
nj
}
/JOB/manifest.
${
rtask
}
\
--recog-json
${
feat_recog_dir
}
/split
${
nj
}
/JOB/manifest.
${
rtask
}
\
--result-label
${
decode_dir
}
/data.JOB.json
\
--result-label
${
decode_dir
}
/data.JOB.json
\
--model-conf
${
config_path
}
\
--model-conf
${
config_path
}
\
--model
${
ckpt_prefix
}
.pdparams
--model
${
ckpt_prefix
}
.pdparams
\
--rnnlm-conf
${
rnnlm_config_path
}
\
#--rnnlm ${lmexpdir}/${lang_model} \
--rnnlm
${
lmexpdir
}
/
${
lang_model
}
score_sclite.sh
--bpe
${
nbpe
}
--bpemodel
${
bpemodel
}
--wer
false
${
decode_dir
}
${
dict
}
score_sclite.sh
--bpe
${
nbpe
}
--bpemodel
${
bpemodel
}
--wer
false
${
decode_dir
}
${
dict
}
...
...
examples/librispeech/s2/run.sh
浏览文件 @
b7bdaf6f
...
@@ -33,16 +33,24 @@ if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
...
@@ -33,16 +33,24 @@ if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
fi
fi
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
#
test ckpt avg_n
#
attetion resocre decoder
./local/test.sh
${
conf_path
}
${
dict_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
||
exit
-1
./local/test.sh
${
conf_path
}
${
dict_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
||
exit
-1
fi
fi
if
[
${
stage
}
-le
4
]
&&
[
${
stop_stage
}
-ge
4
]
;
then
if
[
${
stage
}
-le
4
]
&&
[
${
stop_stage
}
-ge
4
]
&&
${
use_lm
}
==
true
;
then
# join ctc decoder, use transformerlm to score
if
[
!
-f
exp/lm/transformer/transformerLM.pdparams
]
;
then
wget https://deepspeech.bj.bcebos.com/transformer_lm/transformerLM.pdparams exp/lm/transformer/
fi
bash
local
/recog.sh
--ckpt_prefix
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
fi
if
[
${
stage
}
-le
5
]
&&
[
${
stop_stage
}
-ge
5
]
;
then
# ctc alignment of test data
# ctc alignment of test data
CUDA_VISIBLE_DEVICES
=
0 ./local/align.sh
${
conf_path
}
${
dict_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
||
exit
-1
CUDA_VISIBLE_DEVICES
=
0 ./local/align.sh
${
conf_path
}
${
dict_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
||
exit
-1
fi
fi
if
[
${
stage
}
-le
5
]
&&
[
${
stop_stage
}
-ge
5
]
;
then
if
[
${
stage
}
-le
6
]
&&
[
${
stop_stage
}
-ge
6
]
;
then
# export ckpt avg_n
# export ckpt avg_n
CUDA_VISIBLE_DEVICES
=
./local/export.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
.jit
CUDA_VISIBLE_DEVICES
=
./local/export.sh
${
conf_path
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
exp/
${
ckpt
}
/checkpoints/
${
avg_ckpt
}
.jit
fi
fi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录