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
d583bfcb
Commit
d583bfcb
authored
Mar 03, 2019
by
libeineu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix share all embedding and share decoder embedding with the softmax bugs
parent
400e4f5a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
6 行删除
+7
-6
convert_model.sh
+1
-1
scripts/convert_t2t_to_fairseq.py
+6
-5
没有找到文件。
convert_model.sh
查看文件 @
d583bfcb
...
...
@@ -7,7 +7,7 @@ set -e
# more device will not be used. e.g. you set device=(0 1 2 3), but you only choose three evalset, the gpu=3 will not be used
device
=(
0 1 2 3 4 5 6 7
)
# your tag, must set!
tag
=
base
line
tag
=
base
25_shared
# you should select model params for choosing the correct num heads
params
=
transformer_base
model_dir
=
t2tmodel/
$tag
/ensemble15
...
...
scripts/convert_t2t_to_fairseq.py
查看文件 @
d583bfcb
...
...
@@ -139,8 +139,7 @@ def load_param():
# source embedding, shape is src_vocab * emb_size
if
share_all_embedding
:
src_emb_tensor
=
_get_tensor
(
'symbol_modality_{}_{}/shared/weights'
.
format
(
src_vocab_size
,
emb_size
),
shard
=
shard
)
src_emb_tensor
=
_get_tensor
(
'symbol_modality_{}_{}/shared/weights'
.
format
(
src_vocab_size
,
emb_size
),
shard
=
shard
)
else
:
src_emb_tensor
=
_get_tensor
(
'symbol_modality_{}_{}/input_emb/weights'
.
format
(
src_vocab_size
,
emb_size
),
shard
=
shard
)
param_dict
[
'src_emb'
]
=
src_emb_tensor
...
...
@@ -241,7 +240,6 @@ def load_param():
# step 8. dense transformer weight matrix
if
use_dense
:
layer_weight
=
_get_tensor
(
'body/encoder/layer_history/layer_weight'
)
print
(
type
(
layer_weight
))
param_dict
[
'enc_layer_weight'
]
=
layer_weight
# decoder
...
...
@@ -552,12 +550,14 @@ def convert_param():
model['decoder.embed_tokens.weight'] = torch.cat([lua_row, pad_row, eos_row, unk_row, embed[4:, :]], dim=0)
"""
lua_row
=
torch
.
zeros
(
1
,
embed
.
size
(
1
))
model
[
'decoder.embed_tokens.weight'
]
=
torch
.
cat
([
lua_row
,
embed
],
dim
=
0
)
if
not
share_all_embedding
:
model
[
'decoder.embed_tokens.weight'
]
=
torch
.
cat
([
lua_row
,
embed
],
dim
=
0
)
# model['decoder.embed_positions._float_tensor'] = torch.Tensor([])
# in fairseq, pos-index is from 2
pos_emb
=
_get_param_numpy
(
"tgt_pos_emb"
,
sess
)
pos_emb
=
torch
.
cat
([
torch
.
zeros
(
2
,
pos_emb
.
size
(
1
)),
pos_emb
[:
-
2
,
:]],
dim
=
0
)
model
[
'decoder.embed_positions.weight'
]
=
pos_emb
for
layer_id
in
range
(
int
(
tgt_layer_num
)):
p1
=
'decoder.layers.
%
d.self_attn'
%
layer_id
...
...
@@ -624,7 +624,8 @@ def convert_param():
"""
# lua_row = torch.zeros(1, softmax_w_tensor.size(1)).fill_(float('-inf'))
lua_row
=
torch
.
zeros
(
1
,
softmax_w_tensor
.
size
(
1
))
model
[
'decoder.embed_out'
]
=
torch
.
cat
([
lua_row
,
softmax_w_tensor
],
dim
=
0
)
if
share_all_embedding
==
False
and
share_decoder_input_and_softmax
==
False
:
model
[
'decoder.embed_out'
]
=
torch
.
cat
([
lua_row
,
softmax_w_tensor
],
dim
=
0
)
return
model
def
write_vocab
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论