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
d5abb971
Commit
d5abb971
authored
Jun 11, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reshape tensors to fit into SumDim and etc.
parent
75385ebe
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
12 行删除
+24
-12
source/sample/transformer/T2TPredictor.cpp
+5
-10
source/sample/transformer/T2TSearch.cpp
+19
-2
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
d5abb971
...
...
@@ -190,18 +190,13 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
CheckNTErrors
(
decoding
.
order
>=
2
,
"The tensor must be of order 2 or larger!"
);
for
(
int
i
=
0
;
i
<
decoding
.
order
-
1
;
i
++
)
dims
[
i
]
=
decoding
.
GetDim
(
i
);
dims
[
decoding
.
order
-
2
]
=
1
;
int
stride
=
decoding
.
GetDim
(
decoding
.
order
-
2
);
InitTensor
(
&
selectSrc
,
decoding
.
order
-
1
,
dims
,
X_INT
);
InitTensor
(
&
selectTgt
,
decoding
.
order
-
1
,
dims
,
X_INT
);
InitTensor
1D
(
&
selectSrc
,
1
,
X_INT
);
InitTensor
1D
(
&
selectTgt
,
1
,
X_INT
);
int
stride
=
decoding
.
GetDim
(
decoding
.
order
-
2
);
for
(
int
i
=
0
;
i
<
selectSrc
.
unitNum
;
i
++
){
selectSrc
.
SetInt
(
i
*
stride
+
stride
-
1
,
i
);
selectTgt
.
SetInt
(
i
,
i
);
}
selectSrc
.
SetInt
(
stride
-
1
,
0
);
selectTgt
.
SetInt
(
0
,
0
);
selectSrc
.
SetDevice
(
decoding
.
devID
,
decoding
.
mem
);
selectTgt
.
SetDevice
(
decoding
.
devID
,
decoding
.
mem
);
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
d5abb971
...
...
@@ -142,10 +142,20 @@ void T2TSearch::Score(T2TStateBundle * prev, T2TStateBundle * beam)
XTensor
lp
;
XTensor
mask
;
int
order
=
prob
.
order
;
int
outputSize
=
prob
.
GetDim
(
-
1
);
int
dims
[
MAX_TENSOR_DIM_NUM
];
for
(
int
i
=
0
;
i
<
order
;
i
++
)
dims
[
i
]
=
prob
.
GetDim
(
i
);
InitTensor
(
&
score
,
&
prob
);
prob
.
Reshape
(
prob
.
unitNum
/
outputSize
,
outputSize
);
score
.
Reshape
(
score
.
unitNum
/
outputSize
,
outputSize
);
probPathPrev
.
Reshape
(
probPathPrev
.
unitNum
);
/* the log-scale probability of the entire sequence */
_Sum
(
&
prob
,
&
probPathPrev
,
&
score
);
_Sum
Dim
(
&
prob
,
&
probPathPrev
,
&
score
,
0
);
InitTensor
(
&
len
,
&
lenPrev
);
InitTensor
(
&
lp
,
&
lenPrev
);
...
...
@@ -155,8 +165,15 @@ void T2TSearch::Score(T2TStateBundle * prev, T2TStateBundle * beam)
/* the GNMT-like length penalty */
lp
=
T2TLengthPenalizer
::
GNMT
(
len
,
alpha
);
lp
.
Reshape
(
lp
.
unitNum
);
/* score = log-prob/lp */
_Div
(
&
score
,
&
lp
,
&
score
);
_DivDim
(
&
score
,
&
lp
,
&
score
,
0
);
prob
.
Reshape
(
order
,
dims
);
score
.
Reshape
(
order
,
dims
);
probPathPrev
.
Reshape
(
order
-
1
,
dims
);
lp
.
Reshape
(
order
-
1
,
dims
);
InitTensor
(
&
mask
,
&
prev
->
endMark
);
CopyValues
(
prev
->
endMark
,
mask
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论