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
434335e0
Commit
434335e0
authored
Jul 14, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate top-k probability for each position
parent
a4e6ab64
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
2 行删除
+15
-2
source/sample/transformer/T2TSearch.cpp
+15
-2
没有找到文件。
source/sample/transformer/T2TSearch.cpp
查看文件 @
434335e0
...
...
@@ -62,7 +62,7 @@ void T2TSearch::Init(int argc, char ** argv)
LoadParamFloat
(
argc
,
argv
,
"lenalpha"
,
&
alpha
,
0.2
F
);
LoadParamInt
(
argc
,
argv
,
"endid"
,
endSymbols
,
-
1
);
LoadParamInt
(
argc
,
argv
,
"startid"
,
&
startSymbol
,
-
1
);
if
(
endSymbols
[
0
]
>=
0
)
endSymbolNum
=
1
;
}
...
...
@@ -260,6 +260,7 @@ void T2TSearch::Generate(T2TStateBundle * beam)
XTensor
&
index
=
beam
->
prediction
;
XTensor
&
preID
=
beam
->
preID
;
XTensor
&
probPath
=
beam
->
probPath
;
XTensor
&
prob
=
beam
->
prob
;
int
order
=
score
.
order
;
CheckNTErrors
(
order
>=
3
,
"The tensor must be of order 2 or larger."
);
...
...
@@ -323,9 +324,13 @@ void T2TSearch::Generate(T2TStateBundle * beam)
for
(
int
i
=
0
;
i
<
indexCPU
.
unitNum
;
i
++
)
indexCPU
.
SetInt
(
i
*
stride
+
indexCPU
.
GetInt
(
i
),
i
);
/* sequence probability of top-k candidates */
CheckNTErrors
(
XTensor
::
IsSameShaped
(
&
prob
,
&
probPath
),
"Wrong tensor shape!"
);
/* sequence probability and prediction probability of top-k candidates */
XTensor
probPathTopK
;
InitTensor
(
&
probPathTopK
,
&
scoreTopK
);
XTensor
probTopK
;
InitTensor
(
&
probTopK
,
&
scoreTopK
);
for
(
int
i
=
0
;
i
<
probPath
.
order
;
i
++
){
dims
[
i
]
=
probPath
.
GetDim
(
i
);
...
...
@@ -335,19 +340,27 @@ void T2TSearch::Generate(T2TStateBundle * beam)
order
=
probPath
.
order
;
probPath
.
Reshape
(
1
,
probPath
.
unitNum
);
probPathTopK
.
Reshape
(
1
,
probPathTopK
.
unitNum
);
prob
.
Reshape
(
1
,
prob
.
unitNum
);
probTopK
.
Reshape
(
1
,
probTopK
.
unitNum
);
indexCPU
.
Dump
(
stderr
,
"indexCPU:"
);
_Gather
(
&
probPath
,
&
probPathTopK
,
probPathTopK
.
order
-
1
,
(
int
*
)
indexCPU
.
data
,
indexCPU
.
unitNum
);
_Gather
(
&
prob
,
&
probTopK
,
probTopK
.
order
-
1
,
(
int
*
)
indexCPU
.
data
,
indexCPU
.
unitNum
);
probPath
.
Reshape
(
order
,
dims
);
probPathTopK
.
Reshape
(
order
,
dimsTopK
);
prob
.
Reshape
(
order
,
dims
);
probTopK
.
Reshape
(
order
,
dimsTopK
);
indexCPU
.
Dump
(
stderr
,
"indexcpu:"
);
scoreTopK
.
Dump
(
stderr
,
"scoretopk:"
);
probPathTopK
.
Dump
(
stderr
,
"probpathtopk:"
);
probTopK
.
Dump
(
stderr
,
"probtopk:"
);
probPath
=
probPathTopK
;
prob
=
probTopK
;
}
/*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论