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
杨迪
NiuTrans.Tensor
Commits
d38bed87
Commit
d38bed87
authored
Jul 06, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debugging
parent
b155f4c1
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
2 行删除
+21
-2
source/sample/transformer/T2TModel.cpp
+16
-2
source/sample/transformer/T2TPredictor.cpp
+5
-0
没有找到文件。
source/sample/transformer/T2TModel.cpp
查看文件 @
d38bed87
...
...
@@ -23,6 +23,7 @@
#include "T2TModel.h"
#include "T2TUtility.h"
#include "../../tensor/core/CHeader.h"
#include "../../tensor/XUtility.h"
namespace
transformer
{
...
...
@@ -366,8 +367,13 @@ void T2TModel::MakeMTMaskDec(XTensor &inputEnc, XTensor &inputDec,
This matrix can be used to block the attention to current or following words in
a given sequence. */
_SetDataLowTri
(
&
maskDec
,
1e9
F
,
0
);
maskDec
.
Dump
(
stderr
,
"mask: "
);
_ScaleAndShiftMe
(
&
maskDec
,
1.0
F
,
-
1e9
F
);
maskDec
.
Dump
(
stderr
,
"mask: "
);
/* encoder-decoder mask that prevents the attention to padding dummy words */
dims
[
inputDec
.
order
+
1
]
=
inputEnc
.
GetDim
(
inputEnc
.
order
-
1
);
InitTensor
(
&
maskEncDec
,
inputDec
.
order
+
2
,
dims
,
X_FLOAT
,
1.0
F
,
paddingEnc
.
devID
,
paddingEnc
.
mem
);
...
...
@@ -445,6 +451,8 @@ dump the parameters
*/
void
T2TModel
::
Dump
(
const
char
*
fn
)
{
double
startT
=
GetClockSec
();
FILE
*
file
=
fopen
(
fn
,
"wb"
);
CheckNTErrors
(
file
,
"Cannot open the model file"
);
...
...
@@ -459,12 +467,16 @@ void T2TModel::Dump(const char * fn)
fclose
(
file
);
XPRINT
(
0
,
stderr
,
"[INFO] model saved
\n
"
);
double
elapsed
=
GetClockSec
()
-
startT
;
XPRINT1
(
0
,
stderr
,
"[INFO] model saved (took %.1fs)
\n
"
,
elapsed
);
}
/* read the parameters */
void
T2TModel
::
Read
(
const
char
*
fn
)
{
double
startT
=
GetClockSec
();
FILE
*
file
=
fopen
(
fn
,
"rb"
);
CheckNTErrors
(
file
,
"Cannot open the model file"
);
...
...
@@ -479,7 +491,9 @@ void T2TModel::Read(const char * fn)
fclose
(
file
);
XPRINT
(
0
,
stderr
,
"[INFO] model loaded
\n
"
);
double
elapsed
=
GetClockSec
()
-
startT
;
XPRINT1
(
0
,
stderr
,
"[INFO] model loaded (took %.1fs)
\n
"
,
elapsed
);
}
}
source/sample/transformer/T2TPredictor.cpp
查看文件 @
d38bed87
...
...
@@ -193,6 +193,11 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
/* decoder mask */
m
->
MakeMTMaskDec
(
*
inputEnc
,
inputDec
,
*
paddingEnc
,
paddingDec
,
maskDec
,
maskEncDec
);
inputDec
.
Dump
(
stderr
,
"inputdec: "
);
//encoding->Dump(stderr, "encoding: ");
maskDec
.
Dump
(
stderr
,
"maskdec: "
);
maskEncDec
.
Dump
(
stderr
,
"mask-enc-dec: "
);
/* make the decoding network */
decoding
=
decoder
.
Make
(
inputDec
,
*
encoding
,
maskDec
,
maskEncDec
,
false
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论