Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
d8f03326
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d8f03326
编写于
7月 19, 2022
作者:
H
Hui Zhang
提交者:
GitHub
7月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2162 from 0x45f/new_api
[asr]Supprot dy2st for conformer
上级
d098e027
e21cceea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
8 deletion
+20
-8
paddlespeech/s2t/__init__.py
paddlespeech/s2t/__init__.py
+13
-4
paddlespeech/s2t/models/u2/u2.py
paddlespeech/s2t/models/u2/u2.py
+4
-2
paddlespeech/s2t/modules/encoder.py
paddlespeech/s2t/modules/encoder.py
+2
-2
paddlespeech/s2t/modules/encoder_layer.py
paddlespeech/s2t/modules/encoder_layer.py
+1
-0
未找到文件。
paddlespeech/s2t/__init__.py
浏览文件 @
d8f03326
...
@@ -156,13 +156,22 @@ def is_broadcastable(shp1, shp2):
...
@@ -156,13 +156,22 @@ def is_broadcastable(shp1, shp2):
return
True
return
True
def
broadcast_shape
(
shp1
,
shp2
):
result
=
[]
for
a
,
b
in
zip
(
shp1
[::
-
1
],
shp2
[::
-
1
]):
result
.
append
(
max
(
a
,
b
))
return
result
[::
-
1
]
def
masked_fill
(
xs
:
paddle
.
Tensor
,
def
masked_fill
(
xs
:
paddle
.
Tensor
,
mask
:
paddle
.
Tensor
,
mask
:
paddle
.
Tensor
,
value
:
Union
[
float
,
int
]):
value
:
Union
[
float
,
int
]):
assert
is_broadcastable
(
xs
.
shape
,
mask
.
shape
)
is
True
,
(
xs
.
shape
,
bshape
=
broadcast_shape
(
xs
.
shape
,
mask
.
shape
)
mask
.
shape
)
mask
.
stop_gradient
=
True
bshape
=
paddle
.
broadcast_shape
(
xs
.
shape
,
mask
.
shape
)
tmp
=
paddle
.
ones
(
shape
=
[
len
(
bshape
)],
dtype
=
'int32'
)
mask
=
mask
.
broadcast_to
(
bshape
)
for
index
in
range
(
len
(
bshape
)):
tmp
[
index
]
=
bshape
[
index
]
mask
=
mask
.
broadcast_to
(
tmp
)
trues
=
paddle
.
ones_like
(
xs
)
*
value
trues
=
paddle
.
ones_like
(
xs
)
*
value
xs
=
paddle
.
where
(
mask
,
trues
,
xs
)
xs
=
paddle
.
where
(
mask
,
trues
,
xs
)
return
xs
return
xs
...
...
paddlespeech/s2t/models/u2/u2.py
浏览文件 @
d8f03326
...
@@ -625,10 +625,12 @@ class U2BaseModel(ASRInterface, nn.Layer):
...
@@ -625,10 +625,12 @@ class U2BaseModel(ASRInterface, nn.Layer):
(elayers, head, cache_t1, d_k * 2), where
(elayers, head, cache_t1, d_k * 2), where
`head * d_k == hidden-dim` and
`head * d_k == hidden-dim` and
`cache_t1 == chunk_size * num_decoding_left_chunks`.
`cache_t1 == chunk_size * num_decoding_left_chunks`.
`d_k * 2` for att key & value.
`d_k * 2` for att key & value. Default is 0-dims Tensor,
it is used for dy2st.
cnn_cache (paddle.Tensor): cache tensor for cnn_module in conformer,
cnn_cache (paddle.Tensor): cache tensor for cnn_module in conformer,
(elayers, b=1, hidden-dim, cache_t2), where
(elayers, b=1, hidden-dim, cache_t2), where
`cache_t2 == cnn.lorder - 1`
`cache_t2 == cnn.lorder - 1`. Default is 0-dims Tensor,
it is used for dy2st.
Returns:
Returns:
paddle.Tensor: output of current input xs,
paddle.Tensor: output of current input xs,
...
...
paddlespeech/s2t/modules/encoder.py
浏览文件 @
d8f03326
...
@@ -250,11 +250,11 @@ class BaseEncoder(nn.Layer):
...
@@ -250,11 +250,11 @@ class BaseEncoder(nn.Layer):
r_cnn_cache
=
[]
r_cnn_cache
=
[]
for
i
,
layer
in
enumerate
(
self
.
encoders
):
for
i
,
layer
in
enumerate
(
self
.
encoders
):
# att_cache[i:i+1] = (1, head, cache_t1, d_k*2)
# att_cache[i:i+1] = (1, head, cache_t1, d_k*2)
# cnn_cache[i
] = (
B=1, hidden-dim, cache_t2)
# cnn_cache[i
:i+1] = (1,
B=1, hidden-dim, cache_t2)
xs
,
_
,
new_att_cache
,
new_cnn_cache
=
layer
(
xs
,
_
,
new_att_cache
,
new_cnn_cache
=
layer
(
xs
,
att_mask
,
pos_emb
,
xs
,
att_mask
,
pos_emb
,
att_cache
=
att_cache
[
i
:
i
+
1
]
if
elayers
>
0
else
att_cache
,
att_cache
=
att_cache
[
i
:
i
+
1
]
if
elayers
>
0
else
att_cache
,
cnn_cache
=
cnn_cache
[
i
]
if
paddle
.
shape
(
cnn_cache
)[
0
]
>
0
else
cnn_cache
,
cnn_cache
=
cnn_cache
[
i
:
i
+
1
]
if
paddle
.
shape
(
cnn_cache
)[
0
]
>
0
else
cnn_cache
,
)
)
# new_att_cache = (1, head, attention_key_size, d_k*2)
# new_att_cache = (1, head, attention_key_size, d_k*2)
# new_cnn_cache = (B=1, hidden-dim, cache_t2)
# new_cnn_cache = (B=1, hidden-dim, cache_t2)
...
...
paddlespeech/s2t/modules/encoder_layer.py
浏览文件 @
d8f03326
...
@@ -250,6 +250,7 @@ class ConformerEncoderLayer(nn.Layer):
...
@@ -250,6 +250,7 @@ class ConformerEncoderLayer(nn.Layer):
# convolution module
# convolution module
# Fake new cnn cache here, and then change it in conv_module
# Fake new cnn cache here, and then change it in conv_module
new_cnn_cache
=
paddle
.
zeros
([
0
,
0
,
0
],
dtype
=
x
.
dtype
)
new_cnn_cache
=
paddle
.
zeros
([
0
,
0
,
0
],
dtype
=
x
.
dtype
)
cnn_cache
=
paddle
.
squeeze
(
cnn_cache
,
axis
=
0
)
if
self
.
conv_module
is
not
None
:
if
self
.
conv_module
is
not
None
:
residual
=
x
residual
=
x
if
self
.
normalize_before
:
if
self
.
normalize_before
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录