Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
a4f5a680
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看板
提交
a4f5a680
编写于
3月 22, 2022
作者:
H
huangyuxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some format, test=asr
上级
e991d82a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
110 addition
and
50 deletion
+110
-50
paddlespeech/s2t/models/u2/u2.py
paddlespeech/s2t/models/u2/u2.py
+3
-2
paddlespeech/s2t/modules/activation.py
paddlespeech/s2t/modules/activation.py
+2
-1
paddlespeech/s2t/modules/align.py
paddlespeech/s2t/modules/align.py
+102
-37
paddlespeech/s2t/modules/encoder.py
paddlespeech/s2t/modules/encoder.py
+0
-1
paddlespeech/s2t/modules/initializer.py
paddlespeech/s2t/modules/initializer.py
+3
-9
未找到文件。
paddlespeech/s2t/models/u2/u2.py
浏览文件 @
a4f5a680
...
...
@@ -36,6 +36,7 @@ from paddlespeech.s2t.modules.ctc import CTCDecoderBase
from
paddlespeech.s2t.modules.decoder
import
TransformerDecoder
from
paddlespeech.s2t.modules.encoder
import
ConformerEncoder
from
paddlespeech.s2t.modules.encoder
import
TransformerEncoder
from
paddlespeech.s2t.modules.initializer
import
DefaultInitializerContext
from
paddlespeech.s2t.modules.loss
import
LabelSmoothingLoss
from
paddlespeech.s2t.modules.mask
import
make_pad_mask
from
paddlespeech.s2t.modules.mask
import
mask_finished_preds
...
...
@@ -50,7 +51,6 @@ from paddlespeech.s2t.utils.tensor_utils import pad_sequence
from
paddlespeech.s2t.utils.tensor_utils
import
th_accuracy
from
paddlespeech.s2t.utils.utility
import
log_add
from
paddlespeech.s2t.utils.utility
import
UpdateConfig
from
paddlespeech.s2t.modules.initializer
import
DefaultInitializerContext
# from paddlespeech.s2t.modules.initializer import initialize
__all__
=
[
"U2Model"
,
"U2InferModel"
]
...
...
@@ -786,7 +786,8 @@ class U2Model(U2DecodeModel):
model_conf
=
configs
.
get
(
'model_conf'
,
dict
())
init_type
=
model_conf
.
get
(
"init_type"
,
None
)
with
DefaultInitializerContext
(
init_type
):
vocab_size
,
encoder
,
decoder
,
ctc
=
U2Model
.
_init_from_config
(
configs
)
vocab_size
,
encoder
,
decoder
,
ctc
=
U2Model
.
_init_from_config
(
configs
)
super
().
__init__
(
vocab_size
=
vocab_size
,
...
...
paddlespeech/s2t/modules/activation.py
浏览文件 @
a4f5a680
...
...
@@ -16,8 +16,9 @@ from collections import OrderedDict
import
paddle
from
paddle
import
nn
from
paddle.nn
import
functional
as
F
from
paddlespeech.s2t.modules.align
import
Linear
from
paddlespeech.s2t.modules.align
import
Conv2D
from
paddlespeech.s2t.modules.align
import
Linear
from
paddlespeech.s2t.utils.log
import
Log
logger
=
Log
(
__name__
).
getlog
()
...
...
paddlespeech/s2t/modules/align.py
浏览文件 @
a4f5a680
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
paddle
from
paddle
import
nn
from
paddlespeech.s2t.modules.initializer
import
KaimingUniform
from
paddlespeech.s2t.modules.initializer
import
KaimingUniform
"""
To align the initializer between paddle and torch,
the API below are set defalut initializer with priority higger than global initializer.
...
...
@@ -10,65 +23,117 @@ global_init_type = None
class
LayerNorm
(
nn
.
LayerNorm
):
def
__init__
(
self
,
normalized_shape
,
epsilon
=
1e-05
,
weight_attr
=
None
,
bias_attr
=
None
,
name
=
None
):
def
__init__
(
self
,
normalized_shape
,
epsilon
=
1e-05
,
weight_attr
=
None
,
bias_attr
=
None
,
name
=
None
):
if
weight_attr
is
None
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Constant
(
1.0
))
if
bias_attr
is
None
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Constant
(
0.0
))
super
(
LayerNorm
,
self
).
__init__
(
normalized_shape
,
epsilon
,
weight_attr
,
bias_attr
,
name
)
super
(
LayerNorm
,
self
).
__init__
(
normalized_shape
,
epsilon
,
weight_attr
,
bias_attr
,
name
)
class
BatchNorm1D
(
nn
.
BatchNorm1D
):
def
__init__
(
self
,
num_features
,
momentum
=
0.9
,
epsilon
=
1e-05
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCL'
,
name
=
None
):
class
BatchNorm1D
(
nn
.
BatchNorm1D
):
def
__init__
(
self
,
num_features
,
momentum
=
0.9
,
epsilon
=
1e-05
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCL'
,
name
=
None
):
if
weight_attr
is
None
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Constant
(
1.0
))
if
bias_attr
is
None
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Constant
(
0.0
))
super
(
BatchNorm1D
,
self
).
__init__
(
num_features
,
momentum
,
epsilon
,
weight_attr
,
bias_attr
,
data_format
,
name
)
super
(
BatchNorm1D
,
self
).
__init__
(
num_features
,
momentum
,
epsilon
,
weight_attr
,
bias_attr
,
data_format
,
name
)
class
Embedding
(
nn
.
Embedding
):
def
__init__
(
self
,
num_embeddings
,
embedding_dim
,
padding_idx
=
None
,
sparse
=
False
,
weight_attr
=
None
,
name
=
None
):
def
__init__
(
self
,
num_embeddings
,
embedding_dim
,
padding_idx
=
None
,
sparse
=
False
,
weight_attr
=
None
,
name
=
None
):
if
weight_attr
is
None
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Normal
())
super
(
Embedding
,
self
).
__init__
(
num_embeddings
,
embedding_dim
,
padding_idx
,
sparse
,
weight_attr
,
name
)
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
nn
.
initializer
.
Normal
())
super
(
Embedding
,
self
).
__init__
(
num_embeddings
,
embedding_dim
,
padding_idx
,
sparse
,
weight_attr
,
name
)
class
Linear
(
nn
.
Linear
):
def
__init__
(
self
,
in_features
,
out_features
,
weight_attr
=
None
,
bias_attr
=
None
,
name
=
None
):
if
weight_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
if
bias_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Linear
,
self
).
__init__
(
in_features
,
out_features
,
weight_attr
,
bias_attr
,
name
)
def
__init__
(
self
,
in_features
,
out_features
,
weight_attr
=
None
,
bias_attr
=
None
,
name
=
None
):
if
weight_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
if
bias_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Linear
,
self
).
__init__
(
in_features
,
out_features
,
weight_attr
,
bias_attr
,
name
)
class
Conv1D
(
nn
.
Conv1D
):
def
__init__
(
self
,
in_channels
,
out_channels
,
kernel_size
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
groups
=
1
,
padding_mode
=
'zeros'
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCL'
):
def
__init__
(
self
,
in_channels
,
out_channels
,
kernel_size
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
groups
=
1
,
padding_mode
=
'zeros'
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCL'
):
if
weight_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
print
(
"set kaiming_uniform"
)
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
if
bias_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Conv1D
,
self
).
__init__
(
in_channels
,
out_channels
,
kernel_size
,
stride
,
padding
,
dilation
,
groups
,
padding_mode
,
weight_attr
,
bias_attr
,
data_format
)
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Conv1D
,
self
).
__init__
(
in_channels
,
out_channels
,
kernel_size
,
stride
,
padding
,
dilation
,
groups
,
padding_mode
,
weight_attr
,
bias_attr
,
data_format
)
class
Conv2D
(
nn
.
Conv2D
):
def
__init__
(
self
,
in_channels
,
out_channels
,
kernel_size
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
groups
=
1
,
padding_mode
=
'zeros'
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCHW'
):
if
weight_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
if
bias_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Conv2D
,
self
).
__init__
(
in_channels
,
out_channels
,
kernel_size
,
stride
,
padding
,
dilation
,
groups
,
padding_mode
,
weight_attr
,
bias_attr
,
data_format
)
def
__init__
(
self
,
in_channels
,
out_channels
,
kernel_size
,
stride
=
1
,
padding
=
0
,
dilation
=
1
,
groups
=
1
,
padding_mode
=
'zeros'
,
weight_attr
=
None
,
bias_attr
=
None
,
data_format
=
'NCHW'
):
if
weight_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
weight_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
if
bias_attr
is
None
:
if
global_init_type
==
"kaiming_uniform"
:
bias_attr
=
paddle
.
ParamAttr
(
initializer
=
KaimingUniform
())
super
(
Conv2D
,
self
).
__init__
(
in_channels
,
out_channels
,
kernel_size
,
stride
,
padding
,
dilation
,
groups
,
padding_mode
,
weight_attr
,
bias_attr
,
data_format
)
paddlespeech/s2t/modules/encoder.py
浏览文件 @
a4f5a680
...
...
@@ -24,7 +24,6 @@ from typeguard import check_argument_types
from
paddlespeech.s2t.modules.activation
import
get_activation
from
paddlespeech.s2t.modules.align
import
LayerNorm
from
paddlespeech.s2t.modules.align
import
Linear
from
paddlespeech.s2t.modules.attention
import
MultiHeadedAttention
from
paddlespeech.s2t.modules.attention
import
RelPositionMultiHeadedAttention
from
paddlespeech.s2t.modules.conformer_convolution
import
ConvolutionModule
...
...
paddlespeech/s2t/modules/initializer.py
浏览文件 @
a4f5a680
...
...
@@ -12,15 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
numpy
as
np
from
paddle
import
nn
from
paddle.fluid
import
framework
from
paddle.fluid
import
unique_name
from
paddle.fluid.core
import
VarDesc
from
paddle.fluid.framework
import
default_main_program
from
paddle.fluid.framework
import
in_dygraph_mode
from
paddle.fluid.initializer
import
Initializer
from
paddle.fluid.initializer
import
MSRAInitializer
from
typeguard
import
check_argument_types
__all__
=
[
'KaimingUniform'
]
...
...
@@ -160,16 +155,15 @@ class DefaultInitializerContext(object):
with DefaultInitializerContext("kaiming_uniform"):
code for setup_model
"""
def
__init__
(
self
,
init_type
=
None
):
self
.
init_type
=
init_type
def
__enter__
(
self
):
from
paddlespeech.s2t.modules
import
align
align
.
global_init_type
=
self
.
init_type
return
self
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
from
paddlespeech.s2t.modules
import
align
align
.
global_init_type
=
None
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录