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
f14850ad
Commit
f14850ad
authored
Mar 26, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more code
parent
f701be0e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
10 行删除
+23
-10
source/sample/transformer/T2TPredictor.cpp
+18
-8
source/sample/transformer/T2TPredictor.h
+5
-2
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
f14850ad
...
...
@@ -38,17 +38,27 @@ T2TPredictor::~T2TPredictor()
}
/*
create an initial state
>> model - the t2t model
>> state - the state to be initialized
*/
void
T2TPredictor
::
Init
(
T2TModel
*
model
,
T2TStateBundle
*
state
)
{
}
/*
read a state
>> model - the t2t model that keeps the network created so far
>>
current
- a set of states. It keeps
>>
state
- a set of states. It keeps
1) hypotheses (states)
2) probablities of hypotheses
3) parts of the network for expanding to the next state
*/
void
T2TPredictor
::
Read
(
T2TModel
*
model
,
T2TStateBundle
*
current
)
void
T2TPredictor
::
Read
(
T2TModel
*
model
,
T2TStateBundle
*
state
)
{
m
=
model
;
cur
=
current
;
s
=
state
;
}
/*
...
...
@@ -63,25 +73,25 @@ void T2TPredictor::Predict(T2TStateBundle * next)
AttDecoder
&
decoder
=
*
m
->
decoder
;
/* word indices of previous positions */
XTensor
&
inputLast
=
*
(
XTensor
*
)
cur
->
decoderLayers
.
GetItem
(
0
);
XTensor
&
inputLast
=
*
(
XTensor
*
)
s
->
decoderLayers
.
GetItem
(
0
);
/* word indices of positions up to next state */
XTensor
&
input
=
*
NewTensor
();
input
=
Concatenate
(
inputLast
,
cur
->
prediction
,
inputLast
.
GetDim
(
-
1
));
input
=
Concatenate
(
inputLast
,
s
->
prediction
,
inputLast
.
GetDim
(
-
1
));
/* prediction probabilities */
XTensor
&
output
=
next
->
prediction
;
/* encoder output */
XTensor
&
outputEnc
=
*
(
XTensor
*
)
cur
->
encoderLayers
.
GetItem
(
-
1
);
XTensor
&
outputEnc
=
*
(
XTensor
*
)
s
->
encoderLayers
.
GetItem
(
-
1
);
/* empty tensors (for masking?) */
XTensor
nullMask
;
/* make the decoding network and generate the output probabilities */
output
=
decoder
.
Make
(
cur
->
prediction
,
outputEnc
,
nullMask
,
nullMask
,
false
);
output
=
decoder
.
Make
(
s
->
prediction
,
outputEnc
,
nullMask
,
nullMask
,
false
);
next
->
encoderLayers
.
AddList
(
&
cur
->
encoderLayers
);
next
->
encoderLayers
.
AddList
(
&
s
->
encoderLayers
);
next
->
decoderLayers
.
Add
(
&
input
);
next
->
decoderLayers
.
Add
(
&
output
);
}
...
...
source/sample/transformer/T2TPredictor.h
查看文件 @
f14850ad
...
...
@@ -78,7 +78,7 @@ class T2TPredictor
T2TModel
*
m
;
/* current state */
T2TStateBundle
*
cur
;
T2TStateBundle
*
s
;
public
:
/* constructor */
...
...
@@ -87,8 +87,11 @@ public:
/* de-constructor */
~
T2TPredictor
();
/* create an initial state */
void
Init
(
T2TModel
*
model
,
T2TStateBundle
*
state
);
/* read a state */
void
Read
(
T2TModel
*
model
,
T2TStateBundle
*
current
);
void
Read
(
T2TModel
*
model
,
T2TStateBundle
*
state
);
/* predict the next state */
void
Predict
(
T2TStateBundle
*
next
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论