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
909c7236
Commit
909c7236
authored
Apr 03, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coding of predictor
parent
df09abef
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
79 行增加
和
2 行删除
+79
-2
source/sample/transformer/T2TPredictor.cpp
+30
-0
source/sample/transformer/T2TPredictor.h
+13
-0
source/sample/transformer/T2TSearch.cpp
+19
-0
source/sample/transformer/T2TSearch.h
+3
-0
source/tensor/XTensor.cpp
+14
-2
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
909c7236
...
...
@@ -28,6 +28,36 @@ namespace transformer
{
/* constructor */
T2TStateBundle
::
T2TStateBundle
()
{
states
=
NULL
;
}
/* de-constructor */
T2TStateBundle
::~
T2TStateBundle
()
{
if
(
states
!=
NULL
)
delete
[]
states
;
}
/*
create states
>> num - number of states
*/
void
T2TStateBundle
::
MakeStates
(
int
num
)
{
CheckNTErrors
(
num
>
0
,
"invalid number"
);
if
(
states
!=
NULL
)
delete
[]
states
;
states
=
new
T2TState
[
num
];
for
(
int
i
=
0
;
i
<
num
;
i
++
)
states
[
i
].
last
=
NULL
;
}
/* constructor */
T2TPredictor
::
T2TPredictor
()
{
}
...
...
source/sample/transformer/T2TPredictor.h
查看文件 @
909c7236
...
...
@@ -65,6 +65,19 @@ public:
/* layers on the decoder side */
XList
layersDec
;
/* list of states */
T2TState
*
states
;
public
:
/* constructor */
T2TStateBundle
();
/* de-constructor */
~
T2TStateBundle
();
/* create states */
void
MakeStates
(
int
num
);
};
/* The predictor reads the current state and then predicts the next.
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
909c7236
...
...
@@ -118,12 +118,31 @@ void T2TSearch::Generate(T2TStateBundle * beam)
score
.
Reshape
(
order
,
dimsBeam
);
/* keep the most promissing candidates in the beam */
TopK
(
score
,
scoreTopK
,
index
,
0
,
beamSize
);
score
.
Reshape
(
order
,
dims
);
}
/*
expand the search graph
>> beam - the beam that keeps a number of states
*/
void
T2TSearch
::
Expand
(
T2TStateBundle
*
prev
,
T2TStateBundle
*
beam
)
{
beam
->
MakeStates
(
beam
->
prediction
.
unitNum
);
T2TState
*
states
=
beam
->
states
;
XTensor
&
predict
=
beam
->
prediction
;
XTensor
index
=
*
NewTensorBuf
(
predict
.
order
-
1
,
predict
.
dimSize
,
X_FLOAT
,
1.0
F
,
predict
.
devID
,
predict
.
mem
);
index
.
SetAscendingOrder
(
-
1
);
DelTensorBuf
(
&
index
);
}
/*
save the output sequences in a tensor
>> beam - the beam that keeps a number of states
*/
...
...
source/sample/transformer/T2TSearch.h
查看文件 @
909c7236
...
...
@@ -60,6 +60,9 @@ public:
/* generate token indices via beam pruning */
void
Generate
(
T2TStateBundle
*
beam
);
/* expand the search graph */
void
Expand
(
T2TStateBundle
*
prev
,
T2TStateBundle
*
beam
);
/* save the output sequences in a tensor */
void
DumpOutput
(
T2TStateBundle
*
beam
,
XTensor
*
output
);
};
...
...
source/tensor/XTensor.cpp
查看文件 @
909c7236
...
...
@@ -969,8 +969,20 @@ set the cell to the ascending order along a given dimension
*/
void
XTensor
::
SetAscendingOrder
(
int
dim
)
{
CheckNTErrors
((
dim
>=
0
&&
dim
<
order
),
"Wrong dimension specified!"
);
CheckNTErrors
((
dataType
==
X_INT
),
"TODO!"
);
CheckNTErrors
(
dim
<
order
,
"Wrong dimension specified!"
);
CheckNTErrors
(
dataType
==
X_INT
,
"TODO!"
);
if
(
dim
<
0
){
int
o
=
order
;
int
ds
[
MAX_TENSOR_DIM_NUM
];
memcpy
(
ds
,
dimSize
,
sizeof
(
int
)
*
order
);
Reshape
(
unitNum
);
SetAscendingOrder
(
0
);
Reshape
(
o
,
ds
);
return
;
}
int
dimRDI
=
order
-
dim
-
1
;
if
(
devID
>=
0
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论