Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
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
Emmay
NiuTrans.Tensor
Commits
35e084b0
Commit
35e084b0
authored
Oct 15, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add padding on the encoder side for t2t MT
parent
6f90577d
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
115 行增加
和
58 行删除
+115
-58
source/sample/transformer/T2TModel.cpp
+35
-2
source/sample/transformer/T2TModel.h
+1
-1
source/sample/transformer/T2TTrainer.cpp
+73
-52
source/sample/transformer/T2TTrainer.h
+6
-3
没有找到文件。
source/sample/transformer/T2TModel.cpp
查看文件 @
35e084b0
...
@@ -174,10 +174,10 @@ make the network for machine translation (with the output softmax layer)
...
@@ -174,10 +174,10 @@ make the network for machine translation (with the output softmax layer)
>> inputEnc - input tensor of the encoder
>> inputEnc - input tensor of the encoder
>> inputDec - input tensor of the decoder
>> inputDec - input tensor of the decoder
>> output - output tensor (distribution)
>> output - output tensor (distribution)
>> padding
- padding of the sequences
>> padding
Enc - padding of the sequences (on the encoder side)
>> isTraining - indicates whether the model is for training
>> isTraining - indicates whether the model is for training
*/
*/
void
T2TModel
::
MakeMT
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
output
,
XTensor
&
padding
,
bool
isTraining
)
void
T2TModel
::
MakeMT
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
output
,
XTensor
&
padding
Enc
,
bool
isTraining
)
{
{
XTensor
encoding
;
XTensor
encoding
;
XTensor
decoding
;
XTensor
decoding
;
...
@@ -199,11 +199,44 @@ void T2TModel::MakeMT(XTensor &inputEnc, XTensor &inputDec, XTensor &output, XTe
...
@@ -199,11 +199,44 @@ void T2TModel::MakeMT(XTensor &inputEnc, XTensor &inputDec, XTensor &output, XTe
_SetDataLowTri
(
&
maskDec
,
1e9
F
,
0
);
_SetDataLowTri
(
&
maskDec
,
1e9
F
,
0
);
_ScaleAndShiftMe
(
&
maskDec
,
1.0
F
,
-
1e9
F
);
_ScaleAndShiftMe
(
&
maskDec
,
1.0
F
,
-
1e9
F
);
/* padding on the source side */
int
*
dimsPadding
=
new
int
[
paddingEnc
.
order
+
2
];
for
(
int
i
=
0
;
i
<
paddingEnc
.
order
-
1
;
i
++
)
dimsPadding
[
i
]
=
paddingEnc
.
GetDim
(
i
);
dimsPadding
[
paddingEnc
.
order
-
1
]
=
paddingEnc
.
GetDim
(
-
1
);
dimsPadding
[
paddingEnc
.
order
]
=
paddingEnc
.
GetDim
(
-
1
);
XTensor
*
padding2
=
NewTensorBuf
(
paddingEnc
.
order
+
1
,
dimsPadding
,
paddingEnc
.
dataType
,
paddingEnc
.
denseRatio
,
paddingEnc
.
devID
,
paddingEnc
.
mem
);
for
(
int
i
=
0
;
i
<
padding2
->
order
;
i
++
)
dimsPadding
[
i
+
1
]
=
padding2
->
GetDim
(
i
);
dimsPadding
[
0
]
=
nhead
;
XTensor
*
padding3
=
NewTensorBuf
(
paddingEnc
.
order
+
2
,
dimsPadding
,
paddingEnc
.
dataType
,
paddingEnc
.
denseRatio
,
paddingEnc
.
devID
,
paddingEnc
.
mem
);
/* mask of the padding */
_Unsqueeze
(
&
paddingEnc
,
padding2
,
paddingEnc
.
order
-
1
,
paddingEnc
.
GetDim
(
-
1
));
_Unsqueeze
(
padding2
,
padding3
,
0
,
nhead
);
_ScaleAndShiftMe
(
padding3
,
1e9
F
,
-
1e9
F
);
InitTensor
(
&
maskEnc
,
padding3
);
maskEnc
.
SetZeroAll
();
/* generate the mask on the source language side (for padding) */
_Sum
(
&
maskEnc
,
padding3
,
&
maskEnc
);
encoding
=
MakeEncoder
(
inputEnc
,
maskEnc
,
isTraining
);
encoding
=
MakeEncoder
(
inputEnc
,
maskEnc
,
isTraining
);
decoding
=
MakeDecoder
(
inputDec
,
encoding
,
maskDec
,
isTraining
);
decoding
=
MakeDecoder
(
inputDec
,
encoding
,
maskDec
,
isTraining
);
outputLayer
.
Make
(
decoding
,
output
);
outputLayer
.
Make
(
decoding
,
output
);
delete
[]
dims
;
delete
[]
dims
;
delete
[]
dimsPadding
;
DelTensorBuf
(
padding2
);
DelTensorBuf
(
padding3
);
}
}
/*
/*
...
...
source/sample/transformer/T2TModel.h
查看文件 @
35e084b0
...
@@ -78,7 +78,7 @@ public:
...
@@ -78,7 +78,7 @@ public:
void
MakeLM
(
XTensor
&
input
,
XTensor
&
output
,
XTensor
&
padding
,
bool
isTraining
);
void
MakeLM
(
XTensor
&
input
,
XTensor
&
output
,
XTensor
&
padding
,
bool
isTraining
);
/* make the network for machine translation (with the output softmax layer) */
/* make the network for machine translation (with the output softmax layer) */
void
MakeMT
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
output
,
XTensor
&
padding
,
bool
isTraining
);
void
MakeMT
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
output
,
XTensor
&
padding
Enc
,
bool
isTraining
);
/* get parameter matrics */
/* get parameter matrics */
void
GetParams
(
XList
&
list
);
void
GetParams
(
XList
&
list
);
...
...
source/sample/transformer/T2TTrainer.cpp
查看文件 @
35e084b0
差异被折叠。
点击展开。
source/sample/transformer/T2TTrainer.h
查看文件 @
35e084b0
...
@@ -166,7 +166,8 @@ public:
...
@@ -166,7 +166,8 @@ public:
/* load a batch of sequences */
/* load a batch of sequences */
int
LoadBatch
(
FILE
*
file
,
bool
isLM
,
int
LoadBatch
(
FILE
*
file
,
bool
isLM
,
XTensor
*
batch
,
XTensor
*
padding
,
XTensor
*
output
,
XTensor
*
batchEnc
,
XTensor
*
paddingEnc
,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
int
*
seqs
,
int
*
seqs
,
int
vsEnc
,
int
vsDec
,
int
sBatch
,
int
wBatch
,
int
vsEnc
,
int
vsDec
,
int
sBatch
,
int
wBatch
,
bool
isSorted
,
int
&
wCount
,
bool
isSorted
,
int
&
wCount
,
...
@@ -174,14 +175,16 @@ public:
...
@@ -174,14 +175,16 @@ public:
/* load a batch of sequences (for language modeling) */
/* load a batch of sequences (for language modeling) */
int
LoadBatchLM
(
FILE
*
file
,
int
LoadBatchLM
(
FILE
*
file
,
XTensor
*
batch
,
XTensor
*
padding
,
XTensor
*
output
,
XTensor
*
batchEnc
,
XTensor
*
paddingEnc
,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
int
*
seqs
,
int
vs
,
int
sBatch
,
int
wBatch
,
int
*
seqs
,
int
vs
,
int
sBatch
,
int
wBatch
,
bool
isSorted
,
int
&
wCount
,
bool
isSorted
,
int
&
wCount
,
int
devID
,
XMem
*
mem
);
int
devID
,
XMem
*
mem
);
/* load a batch of sequences (for machine translation) */
/* load a batch of sequences (for machine translation) */
int
LoadBatchMT
(
FILE
*
file
,
int
LoadBatchMT
(
FILE
*
file
,
XTensor
*
batch
,
XTensor
*
padding
,
XTensor
*
output
,
XTensor
*
batchEnc
,
XTensor
*
paddingEnc
,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
int
*
seqs
,
int
vsEnc
,
int
vsDec
,
int
sBatch
,
int
wBatch
,
int
*
seqs
,
int
vsEnc
,
int
vsDec
,
int
sBatch
,
int
wBatch
,
bool
isSorted
,
int
&
wCount
,
bool
isSorted
,
int
&
wCount
,
int
devID
,
XMem
*
mem
);
int
devID
,
XMem
*
mem
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论