Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
FairseqDecoder
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
libei
FairseqDecoder
Commits
8feddb2d
Commit
8feddb2d
authored
Mar 20, 2019
by
libei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support rpr model convert
parent
ed1f4232
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
0 行删除
+28
-0
scripts/convert_t2t_to_fairseq.py
+28
-0
没有找到文件。
scripts/convert_t2t_to_fairseq.py
查看文件 @
8feddb2d
...
...
@@ -195,6 +195,16 @@ def load_param():
param_dict
[
'enc_
%
d_out_trans_w'
%
layer_id
]
=
output_tarns_w
param_dict
[
'enc_
%
d_out_trans_b'
%
layer_id
]
=
tf
.
reshape
(
output_trans_b
,
[
1
,
-
1
])
# step 10. optional. used for relative position representation
if
use_relative_position_representation
is
not
None
and
use_relative_position_representation
:
rp_key
=
_get_tensor
(
'body/encoder/layer_
%
d/encoder_self_attention/dot_product_attention_relative/relative_positions_keys/embeddings'
%
layer_id
)
rp_value
=
_get_tensor
(
'body/encoder/layer_
%
d/encoder_self_attention/dot_product_attention_relative/relative_positions_values/embeddings'
%
layer_id
)
param_dict
[
'enc_
%
d_rp_key'
%
layer_id
]
=
rp_key
param_dict
[
'enc_
%
d_rp_value'
%
layer_id
]
=
rp_value
# step 3. layer normalization
layer_normal_bias
=
_get_tensor
(
'body/encoder/layer_
%
d/layer_norm/layer_norm_bias'
%
layer_id
)
layer_normal_scale
=
_get_tensor
(
'body/encoder/layer_
%
d/layer_norm/layer_norm_scale'
%
layer_id
)
...
...
@@ -273,6 +283,14 @@ def load_param():
param_dict
[
'dec_
%
d_decatt_out_trans_w'
%
layer_id
]
=
output_tarns_w
param_dict
[
'dec_
%
d_decatt_out_trans_b'
%
layer_id
]
=
tf
.
reshape
(
output_trans_b
,
[
1
,
-
1
])
if
use_relative_position_representation
:
rp_key
=
_get_tensor
(
'body/decoder/layer_
%
d/decoder_self_attention/dot_product_attention_relative/relative_positions_keys/embeddings'
%
layer_id
)
rp_value
=
_get_tensor
(
'body/decoder/layer_
%
d/decoder_self_attention/dot_product_attention_relative/relative_positions_values/embeddings'
%
layer_id
)
param_dict
[
'dec_
%
d_rp_key'
%
layer_id
]
=
rp_key
param_dict
[
'dec_
%
d_rp_value'
%
layer_id
]
=
rp_value
# layer normalization
layer_normal_bias
=
_get_tensor
(
'body/decoder/layer_
%
d/layer_norm/layer_norm_bias'
%
layer_id
)
layer_normal_scale
=
_get_tensor
(
'body/decoder/layer_
%
d/layer_norm/layer_norm_scale'
%
layer_id
)
...
...
@@ -450,6 +468,10 @@ def convert_settings(settings):
if
share_decoder_input_and_softmax
:
args
[
'share_decoder_input_output_embed'
]
=
True
if
use_relative_position_representation
:
args
[
'max_relative_length'
]
=
int
(
settings
[
'max_relative_length'
])
args
[
'arch'
]
=
'relative_transformer'
return
argparse
.
Namespace
(
**
args
)
...
...
@@ -509,6 +531,9 @@ def convert_param():
model
[
'
%
s.in_proj_bias'
%
p1
]
=
_get_param_numpy
(
'enc_
%
d_qvk_trans_b'
%
p2
,
sess
,
transpose
=
True
)
model
[
'
%
s.out_proj.weight'
%
p1
]
=
_get_param_numpy
(
'enc_
%
d_out_trans_w'
%
p2
,
sess
,
transpose
=
True
)
model
[
'
%
s.out_proj.bias'
%
p1
]
=
_get_param_numpy
(
'enc_
%
d_out_trans_b'
%
p2
,
sess
,
transpose
=
True
)
if
use_relative_position_representation
:
model
[
'
%
s.relative_position_keys'
%
p1
]
=
_get_param_numpy
(
'enc_
%
d_rp_key'
%
p2
,
sess
,
transpose
=
False
)
model
[
'
%
s.relative_position_values'
%
p1
]
=
_get_param_numpy
(
'enc_
%
d_rp_value'
%
p2
,
sess
,
transpose
=
False
)
p1
=
'encoder.layers.
%
d'
%
layer_id
...
...
@@ -567,6 +592,9 @@ def convert_param():
model
[
'
%
s.in_proj_bias'
%
p1
]
=
_get_param_numpy
(
'dec_
%
d_decatt_qvk_trans_b'
%
p2
,
sess
,
transpose
=
True
)
model
[
'
%
s.out_proj.weight'
%
p1
]
=
_get_param_numpy
(
'dec_
%
d_decatt_out_trans_w'
%
p2
,
sess
,
transpose
=
True
)
model
[
'
%
s.out_proj.bias'
%
p1
]
=
_get_param_numpy
(
'dec_
%
d_decatt_out_trans_b'
%
p2
,
sess
,
transpose
=
True
)
if
use_relative_position_representation
:
model
[
'
%
s.relative_position_keys'
%
p1
]
=
_get_param_numpy
(
'dec_
%
d_rp_key'
%
p2
,
sess
,
transpose
=
False
)
model
[
'
%
s.relative_position_values'
%
p1
]
=
_get_param_numpy
(
'dec_
%
d_rp_value'
%
p2
,
sess
,
transpose
=
False
)
p1
=
'decoder.layers.
%
d.encoder_attn'
%
layer_id
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论