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
4dbd1f23
Commit
4dbd1f23
authored
Jul 09, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debugging
parent
979698b4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
44 行增加
和
4 行删除
+44
-4
source/sample/transformer/T2TPredictor.cpp
+4
-2
source/sample/transformer/T2TSearch.cpp
+10
-2
source/tensor/XTensor.cpp
+27
-0
source/tensor/XTensor.h
+3
-0
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
4dbd1f23
...
...
@@ -145,7 +145,8 @@ predict the next state
>> inputEnc - input of the encoder
>> paddingEnc - padding of the encoder
*/
void
T2TPredictor
::
Predict
(
T2TStateBundle
*
next
,
XTensor
*
encoding
,
XTensor
*
inputEnc
,
XTensor
*
paddingEnc
)
void
T2TPredictor
::
Predict
(
T2TStateBundle
*
next
,
XTensor
*
encoding
,
XTensor
*
inputEnc
,
XTensor
*
paddingEnc
)
{
int
dims
[
MAX_TENSOR_DIM_NUM
];
...
...
@@ -162,7 +163,8 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
/* the first token */
XTensor
first
;
CheckNTErrors
(
inputEnc
->
order
>=
2
,
"Wrong order of the tensor!"
);
for
(
int
i
=
0
;
i
<
inputEnc
->
order
-
1
;
i
++
)
dims
[
i
]
=
inputEnc
->
GetDim
(
i
);
dims
[
inputEnc
->
order
-
1
]
=
1
;
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
4dbd1f23
...
...
@@ -94,6 +94,14 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
/* make the encoding network */
encoding
=
model
->
MakeEncoder
(
*
input
,
maskEnc
,
false
);
encoding
.
SetName
(
ENCODING_NAME
);
XTensor
encodingBeam
=
Unsqueeze
(
encoding
,
encoding
.
order
-
2
,
beamSize
);
XTensor
inputBeam
=
Unsqueeze
(
*
input
,
input
->
order
-
2
,
beamSize
);
XTensor
paddingBeam
=
Unsqueeze
(
*
padding
,
padding
->
order
-
2
,
beamSize
);
encodingBeam
.
ReshapeMerged
(
encodingBeam
.
order
-
4
);
inputBeam
.
ReshapeMerged
(
inputBeam
.
order
-
4
);
paddingBeam
.
ReshapeMerged
(
paddingBeam
.
order
-
4
);
/* max output-length = 2 * source-length */
maxLength
=
input
->
GetDim
(
-
1
)
*
2
;
...
...
@@ -103,7 +111,7 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
T2TStateBundle
*
first
=
states
;
/* create the first state */
predictor
.
Create
(
model
,
&
encoding
,
input
,
beamSize
,
first
);
predictor
.
Create
(
model
,
&
encoding
Beam
,
input
,
beamSize
,
first
);
predictor
.
SetStartSymbol
(
startSymbol
);
first
->
isStart
=
true
;
...
...
@@ -117,7 +125,7 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
predictor
.
Read
(
model
,
cur
);
/* predict the next state */
predictor
.
Predict
(
next
,
&
encoding
,
input
,
padding
);
predictor
.
Predict
(
next
,
&
encoding
Beam
,
&
inputBeam
,
&
paddingBeam
);
/* compute the model score (given the prediction probability) */
Score
(
cur
,
next
);
...
...
source/tensor/XTensor.cpp
查看文件 @
4dbd1f23
...
...
@@ -642,6 +642,33 @@ void XTensor::Reshape(const int rowNum, const int colNum)
Reshape
(
2
,
dims
);
}
/*
reshape the tensor by merging two consecutive dimensions
>> i - dimension i
>> j - i + 1
*/
void
XTensor
::
ReshapeMerged
(
const
int
i
,
const
int
j
)
{
if
(
i
<
0
)
return
;
int
di
=
i
;
int
dj
=
j
<
0
?
i
+
1
:
j
;
CheckNTErrors
(
di
<
order
,
"Wrong dimension index!"
);
int
dims
[
MAX_TENSOR_DIM_NUM
];
for
(
int
k
=
0
;
k
<
di
;
k
++
)
dims
[
k
]
=
dimSize
[
k
];
dims
[
di
]
=
dimSize
[
di
]
*
dimSize
[
dj
];
for
(
int
k
=
dj
+
1
;
k
<
order
;
k
++
)
dims
[
k
-
1
]
=
dimSize
[
k
];
Reshape
(
order
-
1
,
dims
);
}
/* get the number of items in the data array */
int
XTensor
::
GetSize
()
const
{
...
...
source/tensor/XTensor.h
查看文件 @
4dbd1f23
...
...
@@ -274,6 +274,9 @@ public:
/* reshape the tensor to a matrix */
void
Reshape
(
const
int
rowNum
,
const
int
colNum
);
/* reshape the tensor by merging two consecutive dimensions */
void
ReshapeMerged
(
const
int
i
,
const
int
j
=
-
1
);
/* get the number of items in the data array */
int
GetSize
()
const
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论