Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
8
Issues
8
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
NiuTrans
NiuTrans.Tensor
Commits
a7fe4564
Commit
a7fe4564
authored
Aug 18, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mask of the encoder
parent
80cfa480
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
15 行增加
和
5 行删除
+15
-5
source/sample/transformer/T2TEncoder.cpp
+4
-2
source/sample/transformer/T2TEncoder.h
+4
-1
source/sample/transformer/T2TLayerNormal.cpp
+1
-0
source/sample/transformer/T2TModel.cpp
+5
-1
source/tensor/core/getandset/SetData.cpp
+1
-1
没有找到文件。
source/sample/transformer/T2TEncoder.cpp
查看文件 @
a7fe4564
...
...
@@ -46,13 +46,15 @@ AttEncoder::~AttEncoder()
initialize the model
>> argc - number of arguments
>> argv - list of pointers to the arguments
>> myIsMasked - indicates whether the masked attention is employed
>> myDevID - device id
>> myMem - the memory pool
*/
void
AttEncoder
::
InitModel
(
int
argc
,
const
char
**
argv
,
int
myDevID
,
XMem
*
myMem
)
void
AttEncoder
::
InitModel
(
int
argc
,
const
char
**
argv
,
bool
myIsMasked
,
int
myDevID
,
XMem
*
myMem
)
{
devID
=
myDevID
;
mem
=
myMem
;
isMasked
=
myIsMasked
;
LoadParamInt
(
argc
,
argv
,
"nlayer"
,
&
nlayer
,
6
);
LoadParamInt
(
argc
,
argv
,
"hsize"
,
&
hSize
,
DEFAULT_EMBEDDING_SIZE
);
...
...
@@ -72,7 +74,7 @@ void AttEncoder::InitModel(int argc, const char ** argv, int myDevID, XMem * myM
/* initialize the stacked layers */
for
(
int
i
=
0
;
i
<
nlayer
;
i
++
){
attentions
[
i
].
InitModel
(
argc
,
argv
,
false
,
myDevID
,
myMem
);
attentions
[
i
].
InitModel
(
argc
,
argv
,
isMasked
,
myDevID
,
myMem
);
fnns
[
i
].
InitModel
(
argc
,
argv
,
myDevID
,
myMem
);
attLayerNorms
[
i
].
InitModel
(
argc
,
argv
,
myDevID
,
myMem
);
fnnLayerNorms
[
i
].
InitModel
(
argc
,
argv
,
myDevID
,
myMem
);
...
...
source/sample/transformer/T2TEncoder.h
查看文件 @
a7fe4564
...
...
@@ -76,6 +76,9 @@ public:
/* vocabulary size */
int
vSize
;
/* indicates whether masked attention is employed */
int
isMasked
;
/* embedding of word at each position */
T2TEmbedder
embedder
;
...
...
@@ -106,7 +109,7 @@ public:
~
AttEncoder
();
/* initialize the model */
void
InitModel
(
int
argc
,
const
char
**
argv
,
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
void
InitModel
(
int
argc
,
const
char
**
argv
,
bool
myIsMasked
,
int
myDevID
=
-
1
,
XMem
*
myMem
=
NULL
);
/* make the encoding network */
XTensor
Make
(
XTensor
&
input
,
XTensor
&
mask
);
...
...
source/sample/transformer/T2TLayerNormal.cpp
查看文件 @
a7fe4564
...
...
@@ -19,6 +19,7 @@
* $Created by: XIAO Tong (xiaotong@mail.neu.edu.cn) 2018-07-31
*/
#include <math.h>
#include "T2TLayerNormal.h"
#include "T2TUtility.h"
#include "T2TEmbedding.h"
...
...
source/sample/transformer/T2TModel.cpp
查看文件 @
a7fe4564
...
...
@@ -61,7 +61,7 @@ void T2TModel::InitModel(int argc, const char ** argv)
mem
=
new
XMem
(
devID
);
}
encoder
.
InitModel
(
argc
,
argv
,
devID
,
mem
);
encoder
.
InitModel
(
argc
,
argv
,
isLM
,
devID
,
mem
);
outputLayer
.
InitModel
(
argc
,
argv
,
devID
,
mem
);
}
...
...
@@ -93,6 +93,10 @@ void T2TModel::Make(XTensor &input, XTensor &output)
dims
[
i
]
=
input
.
GetDim
(
i
);
dims
[
input
.
order
-
1
]
=
len
;
XTensor
mask
(
input
.
order
,
dims
,
X_FLOAT
,
1.0
F
,
input
.
devID
,
input
.
mem
);
/* a upper triangular matrix where the cells of the upper triangular are set to -1e-9 */
_SetDataLowTri
(
&
mask
,
1e-9
,
-
1
);
_ScaleAndShiftMe
(
&
mask
,
1.0
F
,
-
1e-9
);
encoding
=
MakeEncoding
(
input
,
mask
);
outputLayer
.
Make
(
encoding
,
output
);
...
...
source/tensor/core/getandset/SetData.cpp
查看文件 @
a7fe4564
...
...
@@ -250,7 +250,7 @@ void _SetDataLowTri(XTensor * tensor, DTYPE p, int shift)
for
(
int
col
=
0
;
col
<
row
+
shift
;
col
++
){
d
[
row
*
l
+
col
]
=
row
;
}
for
(
int
col
=
row
+
shift
;
col
<
l
;
col
++
){
for
(
int
col
=
MAX
(
0
,
row
+
shift
)
;
col
<
l
;
col
++
){
d
[
row
*
l
+
col
]
=
0
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论