Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
5b446f63
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看板
未验证
提交
5b446f63
编写于
12月 15, 2021
作者:
J
Jackwaterveg
提交者:
GitHub
12月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Config]clear the u2 decode config for asr (#1107)
* clear the u2 decode config * rename the vocab_filepath and cmvn_path
上级
7c6ea140
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
37 addition
and
102 deletion
+37
-102
paddlespeech/cli/asr/infer.py
paddlespeech/cli/asr/infer.py
+4
-10
paddlespeech/cli/st/infer.py
paddlespeech/cli/st/infer.py
+1
-8
paddlespeech/s2t/exps/deepspeech2/bin/test_hub.py
paddlespeech/s2t/exps/deepspeech2/bin/test_hub.py
+1
-1
paddlespeech/s2t/exps/deepspeech2/model.py
paddlespeech/s2t/exps/deepspeech2/model.py
+1
-1
paddlespeech/s2t/exps/u2/bin/test_wav.py
paddlespeech/s2t/exps/u2/bin/test_wav.py
+1
-7
paddlespeech/s2t/exps/u2/model.py
paddlespeech/s2t/exps/u2/model.py
+1
-7
paddlespeech/s2t/exps/u2_kaldi/model.py
paddlespeech/s2t/exps/u2_kaldi/model.py
+1
-7
paddlespeech/s2t/exps/u2_st/model.py
paddlespeech/s2t/exps/u2_st/model.py
+0
-14
paddlespeech/s2t/frontend/featurizer/speech_featurizer.py
paddlespeech/s2t/frontend/featurizer/speech_featurizer.py
+1
-1
paddlespeech/s2t/frontend/featurizer/text_featurizer.py
paddlespeech/s2t/frontend/featurizer/text_featurizer.py
+12
-11
paddlespeech/s2t/models/lm/dataset.py
paddlespeech/s2t/models/lm/dataset.py
+1
-1
paddlespeech/s2t/models/u2/u2.py
paddlespeech/s2t/models/u2/u2.py
+3
-14
paddlespeech/s2t/models/u2_st/u2_st.py
paddlespeech/s2t/models/u2_st/u2_st.py
+0
-14
paddlespeech/s2t/transform/cmvn.py
paddlespeech/s2t/transform/cmvn.py
+10
-6
未找到文件。
paddlespeech/cli/asr/infer.py
浏览文件 @
5b446f63
...
@@ -179,7 +179,7 @@ class ASRExecutor(BaseExecutor):
...
@@ -179,7 +179,7 @@ class ASRExecutor(BaseExecutor):
self
.
collate_fn_test
=
SpeechCollator
.
from_config
(
self
.
config
)
self
.
collate_fn_test
=
SpeechCollator
.
from_config
(
self
.
config
)
text_feature
=
TextFeaturizer
(
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
config
.
model
.
input_dim
=
self
.
collate_fn_test
.
feature_size
self
.
config
.
model
.
input_dim
=
self
.
collate_fn_test
.
feature_size
self
.
config
.
model
.
output_dim
=
text_feature
.
vocab_size
self
.
config
.
model
.
output_dim
=
text_feature
.
vocab_size
...
@@ -192,7 +192,7 @@ class ASRExecutor(BaseExecutor):
...
@@ -192,7 +192,7 @@ class ASRExecutor(BaseExecutor):
res_path
,
self
.
config
.
collator
.
spm_model_prefix
)
res_path
,
self
.
config
.
collator
.
spm_model_prefix
)
text_feature
=
TextFeaturizer
(
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
config
.
model
.
input_dim
=
self
.
config
.
collator
.
feat_dim
self
.
config
.
model
.
input_dim
=
self
.
config
.
collator
.
feat_dim
self
.
config
.
model
.
output_dim
=
text_feature
.
vocab_size
self
.
config
.
model
.
output_dim
=
text_feature
.
vocab_size
...
@@ -279,7 +279,7 @@ class ASRExecutor(BaseExecutor):
...
@@ -279,7 +279,7 @@ class ASRExecutor(BaseExecutor):
audio
=
paddle
.
to_tensor
(
audio
,
dtype
=
'float32'
).
unsqueeze
(
axis
=
0
)
audio
=
paddle
.
to_tensor
(
audio
,
dtype
=
'float32'
).
unsqueeze
(
axis
=
0
)
text_feature
=
TextFeaturizer
(
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
_inputs
[
"audio"
]
=
audio
self
.
_inputs
[
"audio"
]
=
audio
self
.
_inputs
[
"audio_len"
]
=
audio_len
self
.
_inputs
[
"audio_len"
]
=
audio_len
...
@@ -295,7 +295,7 @@ class ASRExecutor(BaseExecutor):
...
@@ -295,7 +295,7 @@ class ASRExecutor(BaseExecutor):
"""
"""
text_feature
=
TextFeaturizer
(
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
cfg
=
self
.
config
.
decoding
cfg
=
self
.
config
.
decoding
audio
=
self
.
_inputs
[
"audio"
]
audio
=
self
.
_inputs
[
"audio"
]
...
@@ -321,13 +321,7 @@ class ASRExecutor(BaseExecutor):
...
@@ -321,13 +321,7 @@ class ASRExecutor(BaseExecutor):
audio_len
,
audio_len
,
text_feature
=
text_feature
,
text_feature
=
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
ctc_weight
=
cfg
.
ctc_weight
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/cli/st/infer.py
浏览文件 @
5b446f63
...
@@ -180,7 +180,7 @@ class STExecutor(BaseExecutor):
...
@@ -180,7 +180,7 @@ class STExecutor(BaseExecutor):
res_path
,
self
.
config
.
collator
.
spm_model_prefix
)
res_path
,
self
.
config
.
collator
.
spm_model_prefix
)
self
.
text_feature
=
TextFeaturizer
(
self
.
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
config
.
model
.
input_dim
=
self
.
config
.
collator
.
feat_dim
self
.
config
.
model
.
input_dim
=
self
.
config
.
collator
.
feat_dim
self
.
config
.
model
.
output_dim
=
self
.
text_feature
.
vocab_size
self
.
config
.
model
.
output_dim
=
self
.
text_feature
.
vocab_size
...
@@ -292,14 +292,7 @@ class STExecutor(BaseExecutor):
...
@@ -292,14 +292,7 @@ class STExecutor(BaseExecutor):
audio_len
,
audio_len
,
text_feature
=
self
.
text_feature
,
text_feature
=
self
.
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
None
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
word_reward
=
cfg
.
word_reward
,
word_reward
=
cfg
.
word_reward
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/s2t/exps/deepspeech2/bin/test_hub.py
浏览文件 @
5b446f63
...
@@ -41,7 +41,7 @@ class DeepSpeech2Tester_hub():
...
@@ -41,7 +41,7 @@ class DeepSpeech2Tester_hub():
self
.
audio_file
=
args
.
audio_file
self
.
audio_file
=
args
.
audio_file
self
.
collate_fn_test
=
SpeechCollator
.
from_config
(
config
)
self
.
collate_fn_test
=
SpeechCollator
.
from_config
(
config
)
self
.
_text_featurizer
=
TextFeaturizer
(
self
.
_text_featurizer
=
TextFeaturizer
(
unit_type
=
config
.
collator
.
unit_type
,
vocab
_filepath
=
None
)
unit_type
=
config
.
collator
.
unit_type
,
vocab
=
None
)
def
compute_result_transcripts
(
self
,
audio
,
audio_len
,
vocab_list
,
cfg
):
def
compute_result_transcripts
(
self
,
audio
,
audio_len
,
vocab_list
,
cfg
):
result_transcripts
=
self
.
model
.
decode
(
result_transcripts
=
self
.
model
.
decode
(
...
...
paddlespeech/s2t/exps/deepspeech2/model.py
浏览文件 @
5b446f63
...
@@ -286,7 +286,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
...
@@ -286,7 +286,7 @@ class DeepSpeech2Tester(DeepSpeech2Trainer):
def
__init__
(
self
,
config
,
args
):
def
__init__
(
self
,
config
,
args
):
super
().
__init__
(
config
,
args
)
super
().
__init__
(
config
,
args
)
self
.
_text_featurizer
=
TextFeaturizer
(
self
.
_text_featurizer
=
TextFeaturizer
(
unit_type
=
config
.
collator
.
unit_type
,
vocab
_filepath
=
None
)
unit_type
=
config
.
collator
.
unit_type
,
vocab
=
None
)
def
ordid2token
(
self
,
texts
,
texts_len
):
def
ordid2token
(
self
,
texts
,
texts_len
):
""" ord() id to chr() chr """
""" ord() id to chr() chr """
...
...
paddlespeech/s2t/exps/u2/bin/test_wav.py
浏览文件 @
5b446f63
...
@@ -44,7 +44,7 @@ class U2Infer():
...
@@ -44,7 +44,7 @@ class U2Infer():
self
.
text_feature
=
TextFeaturizer
(
self
.
text_feature
=
TextFeaturizer
(
unit_type
=
config
.
collator
.
unit_type
,
unit_type
=
config
.
collator
.
unit_type
,
vocab
_filepath
=
config
.
collator
.
vocab_filepath
,
vocab
=
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
config
.
collator
.
spm_model_prefix
)
paddle
.
set_device
(
'gpu'
if
self
.
args
.
ngpu
>
0
else
'cpu'
)
paddle
.
set_device
(
'gpu'
if
self
.
args
.
ngpu
>
0
else
'cpu'
)
...
@@ -91,13 +91,7 @@ class U2Infer():
...
@@ -91,13 +91,7 @@ class U2Infer():
ilen
,
ilen
,
text_feature
=
self
.
text_feature
,
text_feature
=
self
.
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
ctc_weight
=
cfg
.
ctc_weight
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/s2t/exps/u2/model.py
浏览文件 @
5b446f63
...
@@ -437,7 +437,7 @@ class U2Tester(U2Trainer):
...
@@ -437,7 +437,7 @@ class U2Tester(U2Trainer):
super
().
__init__
(
config
,
args
)
super
().
__init__
(
config
,
args
)
self
.
text_feature
=
TextFeaturizer
(
self
.
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
vocab_list
=
self
.
text_feature
.
vocab_list
self
.
vocab_list
=
self
.
text_feature
.
vocab_list
...
@@ -469,13 +469,7 @@ class U2Tester(U2Trainer):
...
@@ -469,13 +469,7 @@ class U2Tester(U2Trainer):
audio_len
,
audio_len
,
text_feature
=
self
.
text_feature
,
text_feature
=
self
.
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
ctc_weight
=
cfg
.
ctc_weight
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/s2t/exps/u2_kaldi/model.py
浏览文件 @
5b446f63
...
@@ -393,7 +393,7 @@ class U2Tester(U2Trainer):
...
@@ -393,7 +393,7 @@ class U2Tester(U2Trainer):
super
().
__init__
(
config
,
args
)
super
().
__init__
(
config
,
args
)
self
.
text_feature
=
TextFeaturizer
(
self
.
text_feature
=
TextFeaturizer
(
unit_type
=
self
.
config
.
collator
.
unit_type
,
unit_type
=
self
.
config
.
collator
.
unit_type
,
vocab
_filepath
=
self
.
config
.
collator
.
vocab_filepath
,
vocab
=
self
.
config
.
collator
.
vocab_filepath
,
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
spm_model_prefix
=
self
.
config
.
collator
.
spm_model_prefix
)
self
.
vocab_list
=
self
.
text_feature
.
vocab_list
self
.
vocab_list
=
self
.
text_feature
.
vocab_list
...
@@ -425,13 +425,7 @@ class U2Tester(U2Trainer):
...
@@ -425,13 +425,7 @@ class U2Tester(U2Trainer):
audio_len
,
audio_len
,
text_feature
=
self
.
text_feature
,
text_feature
=
self
.
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
ctc_weight
=
cfg
.
ctc_weight
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/s2t/exps/u2_st/model.py
浏览文件 @
5b446f63
...
@@ -437,14 +437,7 @@ class U2STTester(U2STTrainer):
...
@@ -437,14 +437,7 @@ class U2STTester(U2STTrainer):
audio_len
,
audio_len
,
text_feature
=
text_feature
,
text_feature
=
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
word_reward
=
cfg
.
word_reward
,
word_reward
=
cfg
.
word_reward
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
@@ -475,14 +468,7 @@ class U2STTester(U2STTrainer):
...
@@ -475,14 +468,7 @@ class U2STTester(U2STTrainer):
audio_len
,
audio_len
,
text_feature
=
text_feature
,
text_feature
=
text_feature
,
decoding_method
=
cfg
.
decoding_method
,
decoding_method
=
cfg
.
decoding_method
,
lang_model_path
=
cfg
.
lang_model_path
,
beam_alpha
=
cfg
.
alpha
,
beam_beta
=
cfg
.
beta
,
beam_size
=
cfg
.
beam_size
,
beam_size
=
cfg
.
beam_size
,
cutoff_prob
=
cfg
.
cutoff_prob
,
cutoff_top_n
=
cfg
.
cutoff_top_n
,
num_processes
=
cfg
.
num_proc_bsearch
,
ctc_weight
=
cfg
.
ctc_weight
,
word_reward
=
cfg
.
word_reward
,
word_reward
=
cfg
.
word_reward
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
decoding_chunk_size
=
cfg
.
decoding_chunk_size
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
num_decoding_left_chunks
=
cfg
.
num_decoding_left_chunks
,
...
...
paddlespeech/s2t/frontend/featurizer/speech_featurizer.py
浏览文件 @
5b446f63
...
@@ -55,7 +55,7 @@ class SpeechFeaturizer():
...
@@ -55,7 +55,7 @@ class SpeechFeaturizer():
self
.
text_feature
=
TextFeaturizer
(
self
.
text_feature
=
TextFeaturizer
(
unit_type
=
unit_type
,
unit_type
=
unit_type
,
vocab
_filepath
=
vocab_filepath
,
vocab
=
vocab_filepath
,
spm_model_prefix
=
spm_model_prefix
,
spm_model_prefix
=
spm_model_prefix
,
maskctc
=
maskctc
)
maskctc
=
maskctc
)
self
.
vocab_size
=
self
.
text_feature
.
vocab_size
self
.
vocab_size
=
self
.
text_feature
.
vocab_size
...
...
paddlespeech/s2t/frontend/featurizer/text_featurizer.py
浏览文件 @
5b446f63
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
# limitations under the License.
# limitations under the License.
"""Contains the text featurizer class."""
"""Contains the text featurizer class."""
from
pprint
import
pformat
from
pprint
import
pformat
from
typing
import
Union
import
sentencepiece
as
spm
import
sentencepiece
as
spm
...
@@ -31,11 +32,7 @@ __all__ = ["TextFeaturizer"]
...
@@ -31,11 +32,7 @@ __all__ = ["TextFeaturizer"]
class
TextFeaturizer
():
class
TextFeaturizer
():
def
__init__
(
self
,
def
__init__
(
self
,
unit_type
,
vocab
,
spm_model_prefix
=
None
,
maskctc
=
False
):
unit_type
,
vocab_filepath
,
spm_model_prefix
=
None
,
maskctc
=
False
):
"""Text featurizer, for processing or extracting features from text.
"""Text featurizer, for processing or extracting features from text.
Currently, it supports char/word/sentence-piece level tokenizing and conversion into
Currently, it supports char/word/sentence-piece level tokenizing and conversion into
...
@@ -44,7 +41,7 @@ class TextFeaturizer():
...
@@ -44,7 +41,7 @@ class TextFeaturizer():
Args:
Args:
unit_type (str): unit type, e.g. char, word, spm
unit_type (str): unit type, e.g. char, word, spm
vocab
_filepath (str): Filepath to load vocabulary for token indices conversion
.
vocab
Option[str, list]: Filepath to load vocabulary for token indices conversion, or vocab list
.
spm_model_prefix (str, optional): spm model prefix. Defaults to None.
spm_model_prefix (str, optional): spm model prefix. Defaults to None.
"""
"""
assert
unit_type
in
(
'char'
,
'spm'
,
'word'
)
assert
unit_type
in
(
'char'
,
'spm'
,
'word'
)
...
@@ -52,12 +49,12 @@ class TextFeaturizer():
...
@@ -52,12 +49,12 @@ class TextFeaturizer():
self
.
unk
=
UNK
self
.
unk
=
UNK
self
.
maskctc
=
maskctc
self
.
maskctc
=
maskctc
if
vocab
_filepath
:
if
vocab
:
self
.
vocab_dict
,
self
.
_id2token
,
self
.
vocab_list
,
self
.
unk_id
,
self
.
eos_id
,
self
.
blank_id
=
self
.
_load_vocabulary_from_file
(
self
.
vocab_dict
,
self
.
_id2token
,
self
.
vocab_list
,
self
.
unk_id
,
self
.
eos_id
,
self
.
blank_id
=
self
.
_load_vocabulary_from_file
(
vocab
_filepath
,
maskctc
)
vocab
,
maskctc
)
self
.
vocab_size
=
len
(
self
.
vocab_list
)
self
.
vocab_size
=
len
(
self
.
vocab_list
)
else
:
else
:
logger
.
warning
(
"TextFeaturizer: not have vocab file."
)
logger
.
warning
(
"TextFeaturizer: not have vocab file
or vocab list
."
)
if
unit_type
==
'spm'
:
if
unit_type
==
'spm'
:
spm_model
=
spm_model_prefix
+
'.model'
spm_model
=
spm_model_prefix
+
'.model'
...
@@ -207,9 +204,13 @@ class TextFeaturizer():
...
@@ -207,9 +204,13 @@ class TextFeaturizer():
return
decode
(
tokens
)
return
decode
(
tokens
)
def
_load_vocabulary_from_file
(
self
,
vocab_filepath
:
str
,
maskctc
:
bool
):
def
_load_vocabulary_from_file
(
self
,
vocab
:
Union
[
str
,
list
],
maskctc
:
bool
):
"""Load vocabulary from file."""
"""Load vocabulary from file."""
vocab_list
=
load_dict
(
vocab_filepath
,
maskctc
)
if
isinstance
(
vocab
,
list
):
vocab_list
=
vocab
else
:
vocab_list
=
load_dict
(
vocab
,
maskctc
)
assert
vocab_list
is
not
None
assert
vocab_list
is
not
None
logger
.
debug
(
f
"Vocab:
{
pformat
(
vocab_list
)
}
"
)
logger
.
debug
(
f
"Vocab:
{
pformat
(
vocab_list
)
}
"
)
...
...
paddlespeech/s2t/models/lm/dataset.py
浏览文件 @
5b446f63
...
@@ -42,7 +42,7 @@ class TextCollatorSpm():
...
@@ -42,7 +42,7 @@ class TextCollatorSpm():
assert
(
vocab_filepath
is
not
None
)
assert
(
vocab_filepath
is
not
None
)
self
.
text_featurizer
=
TextFeaturizer
(
self
.
text_featurizer
=
TextFeaturizer
(
unit_type
=
unit_type
,
unit_type
=
unit_type
,
vocab
_filepath
=
vocab_filepath
,
vocab
=
vocab_filepath
,
spm_model_prefix
=
spm_model_prefix
)
spm_model_prefix
=
spm_model_prefix
)
self
.
eos_id
=
self
.
text_featurizer
.
eos_id
self
.
eos_id
=
self
.
text_featurizer
.
eos_id
self
.
blank_id
=
self
.
text_featurizer
.
blank_id
self
.
blank_id
=
self
.
text_featurizer
.
blank_id
...
...
paddlespeech/s2t/models/u2/u2.py
浏览文件 @
5b446f63
...
@@ -717,13 +717,7 @@ class U2BaseModel(ASRInterface, nn.Layer):
...
@@ -717,13 +717,7 @@ class U2BaseModel(ASRInterface, nn.Layer):
feats_lengths
:
paddle
.
Tensor
,
feats_lengths
:
paddle
.
Tensor
,
text_feature
:
Dict
[
str
,
int
],
text_feature
:
Dict
[
str
,
int
],
decoding_method
:
str
,
decoding_method
:
str
,
lang_model_path
:
str
,
beam_alpha
:
float
,
beam_beta
:
float
,
beam_size
:
int
,
beam_size
:
int
,
cutoff_prob
:
float
,
cutoff_top_n
:
int
,
num_processes
:
int
,
ctc_weight
:
float
=
0.0
,
ctc_weight
:
float
=
0.0
,
decoding_chunk_size
:
int
=-
1
,
decoding_chunk_size
:
int
=-
1
,
num_decoding_left_chunks
:
int
=-
1
,
num_decoding_left_chunks
:
int
=-
1
,
...
@@ -737,13 +731,7 @@ class U2BaseModel(ASRInterface, nn.Layer):
...
@@ -737,13 +731,7 @@ class U2BaseModel(ASRInterface, nn.Layer):
decoding_method (str): decoding mode, e.g.
decoding_method (str): decoding mode, e.g.
'attention', 'ctc_greedy_search',
'attention', 'ctc_greedy_search',
'ctc_prefix_beam_search', 'attention_rescoring'
'ctc_prefix_beam_search', 'attention_rescoring'
lang_model_path (str): lm path.
beam_alpha (float): lm weight.
beam_beta (float): length penalty.
beam_size (int): beam size for search
beam_size (int): beam size for search
cutoff_prob (float): for prune.
cutoff_top_n (int): for prune.
num_processes (int):
ctc_weight (float, optional): ctc weight for attention rescoring decode mode. Defaults to 0.0.
ctc_weight (float, optional): ctc weight for attention rescoring decode mode. Defaults to 0.0.
decoding_chunk_size (int, optional): decoding chunk size. Defaults to -1.
decoding_chunk_size (int, optional): decoding chunk size. Defaults to -1.
<0: for decoding, use full chunk.
<0: for decoding, use full chunk.
...
@@ -839,12 +827,13 @@ class U2Model(U2DecodeModel):
...
@@ -839,12 +827,13 @@ class U2Model(U2DecodeModel):
def
__init__
(
self
,
configs
:
dict
):
def
__init__
(
self
,
configs
:
dict
):
vocab_size
,
encoder
,
decoder
,
ctc
=
U2Model
.
_init_from_config
(
configs
)
vocab_size
,
encoder
,
decoder
,
ctc
=
U2Model
.
_init_from_config
(
configs
)
model_conf
=
configs
.
get
(
'model_conf'
,
dict
())
super
().
__init__
(
super
().
__init__
(
vocab_size
=
vocab_size
,
vocab_size
=
vocab_size
,
encoder
=
encoder
,
encoder
=
encoder
,
decoder
=
decoder
,
decoder
=
decoder
,
ctc
=
ctc
,
ctc
=
ctc
,
**
configs
[
'model_conf'
]
)
**
model_conf
)
@
classmethod
@
classmethod
def
_init_from_config
(
cls
,
configs
:
dict
):
def
_init_from_config
(
cls
,
configs
:
dict
):
...
@@ -893,7 +882,7 @@ class U2Model(U2DecodeModel):
...
@@ -893,7 +882,7 @@ class U2Model(U2DecodeModel):
**
configs
[
'decoder_conf'
])
**
configs
[
'decoder_conf'
])
# ctc decoder and ctc loss
# ctc decoder and ctc loss
model_conf
=
configs
[
'model_conf'
]
model_conf
=
configs
.
get
(
'model_conf'
,
dict
())
dropout_rate
=
model_conf
.
get
(
'ctc_dropout_rate'
,
0.0
)
dropout_rate
=
model_conf
.
get
(
'ctc_dropout_rate'
,
0.0
)
grad_norm_type
=
model_conf
.
get
(
'ctc_grad_norm_type'
,
None
)
grad_norm_type
=
model_conf
.
get
(
'ctc_grad_norm_type'
,
None
)
ctc
=
CTCDecoder
(
ctc
=
CTCDecoder
(
...
...
paddlespeech/s2t/models/u2_st/u2_st.py
浏览文件 @
5b446f63
...
@@ -522,14 +522,7 @@ class U2STBaseModel(nn.Layer):
...
@@ -522,14 +522,7 @@ class U2STBaseModel(nn.Layer):
feats_lengths
:
paddle
.
Tensor
,
feats_lengths
:
paddle
.
Tensor
,
text_feature
:
Dict
[
str
,
int
],
text_feature
:
Dict
[
str
,
int
],
decoding_method
:
str
,
decoding_method
:
str
,
lang_model_path
:
str
,
beam_alpha
:
float
,
beam_beta
:
float
,
beam_size
:
int
,
beam_size
:
int
,
cutoff_prob
:
float
,
cutoff_top_n
:
int
,
num_processes
:
int
,
ctc_weight
:
float
=
0.0
,
word_reward
:
float
=
0.0
,
word_reward
:
float
=
0.0
,
decoding_chunk_size
:
int
=-
1
,
decoding_chunk_size
:
int
=-
1
,
num_decoding_left_chunks
:
int
=-
1
,
num_decoding_left_chunks
:
int
=-
1
,
...
@@ -543,14 +536,7 @@ class U2STBaseModel(nn.Layer):
...
@@ -543,14 +536,7 @@ class U2STBaseModel(nn.Layer):
decoding_method (str): decoding mode, e.g.
decoding_method (str): decoding mode, e.g.
'fullsentence',
'fullsentence',
'simultaneous'
'simultaneous'
lang_model_path (str): lm path.
beam_alpha (float): lm weight.
beam_beta (float): length penalty.
beam_size (int): beam size for search
beam_size (int): beam size for search
cutoff_prob (float): for prune.
cutoff_top_n (int): for prune.
num_processes (int):
ctc_weight (float, optional): ctc weight for attention rescoring decode mode. Defaults to 0.0.
decoding_chunk_size (int, optional): decoding chunk size. Defaults to -1.
decoding_chunk_size (int, optional): decoding chunk size. Defaults to -1.
<0: for decoding, use full chunk.
<0: for decoding, use full chunk.
>0: for decoding, use fixed chunk size as set.
>0: for decoding, use fixed chunk size as set.
...
...
paddlespeech/s2t/transform/cmvn.py
浏览文件 @
5b446f63
...
@@ -168,13 +168,17 @@ class GlobalCMVN():
...
@@ -168,13 +168,17 @@ class GlobalCMVN():
norm_means
=
True
,
norm_means
=
True
,
norm_vars
=
True
,
norm_vars
=
True
,
std_floor
=
1.0e-20
):
std_floor
=
1.0e-20
):
self
.
cmvn_path
=
cmvn_path
# cmvn_path: Option[str, dict]
cmvn
=
cmvn_path
self
.
cmvn
=
cmvn
self
.
norm_means
=
norm_means
self
.
norm_means
=
norm_means
self
.
norm_vars
=
norm_vars
self
.
norm_vars
=
norm_vars
self
.
std_floor
=
std_floor
self
.
std_floor
=
std_floor
if
isinstance
(
cmvn
,
dict
):
with
open
(
cmvn_path
)
as
f
:
cmvn_stats
=
cmvn
cmvn_stats
=
json
.
load
(
f
)
else
:
with
open
(
cmvn
)
as
f
:
cmvn_stats
=
json
.
load
(
f
)
self
.
count
=
cmvn_stats
[
'frame_num'
]
self
.
count
=
cmvn_stats
[
'frame_num'
]
self
.
mean
=
np
.
array
(
cmvn_stats
[
'mean_stat'
])
/
self
.
count
self
.
mean
=
np
.
array
(
cmvn_stats
[
'mean_stat'
])
/
self
.
count
self
.
square_sums
=
np
.
array
(
cmvn_stats
[
'var_stat'
])
self
.
square_sums
=
np
.
array
(
cmvn_stats
[
'var_stat'
])
...
@@ -183,8 +187,8 @@ class GlobalCMVN():
...
@@ -183,8 +187,8 @@ class GlobalCMVN():
def
__repr__
(
self
):
def
__repr__
(
self
):
return
f
"""
{
self
.
__class__
.
__name__
}
(
return
f
"""
{
self
.
__class__
.
__name__
}
(
cmvn_path=
{
self
.
cmvn
_path
}
,
cmvn_path=
{
self
.
cmvn
}
,
norm_means=
{
self
.
norm_means
}
,
norm_means=
{
self
.
norm_means
}
,
norm_vars=
{
self
.
norm_vars
}
,)"""
norm_vars=
{
self
.
norm_vars
}
,)"""
def
__call__
(
self
,
x
,
uttid
=
None
):
def
__call__
(
self
,
x
,
uttid
=
None
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录