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
94495c05
Commit
94495c05
authored
Jun 21, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixes
parent
16ab02c5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
7 行删除
+16
-7
source/sample/transformer/T2TPredictor.cpp
+2
-0
source/sample/transformer/T2TSearch.cpp
+14
-7
没有找到文件。
source/sample/transformer/T2TPredictor.cpp
查看文件 @
94495c05
...
...
@@ -110,6 +110,8 @@ void T2TPredictor::Create(T2TModel * model, XTensor * top, const XTensor * input
state
->
probPath
.
SetZeroAll
();
state
->
nstep
.
SetZeroAll
();
state
->
endMark
.
SetZeroAll
();
state
->
stateNum
=
0
;
}
/*
...
...
source/sample/transformer/T2TSearch.cpp
查看文件 @
94495c05
...
...
@@ -31,6 +31,11 @@ namespace transformer
/* constructor */
T2TSearch
::
T2TSearch
()
{
alpha
=
0
;
maxLength
=
0
;
beamSize
=
0
;
batchSize
=
0
;
endSymbolNum
=
0
;
fullHypos
=
NULL
;
endSymbols
=
new
int
[
32
];
}
...
...
@@ -52,6 +57,7 @@ initialize the model
void
T2TSearch
::
Init
(
int
argc
,
char
**
argv
)
{
LoadParamInt
(
argc
,
argv
,
"beamsize"
,
&
beamSize
,
1
);
LoadParamInt
(
argc
,
argv
,
"batchsize"
,
&
batchSize
,
1
);
LoadParamFloat
(
argc
,
argv
,
"lenalpha"
,
&
alpha
,
0.2
F
);
LoadParamInt
(
argc
,
argv
,
"endid"
,
endSymbols
,
-
1
);
...
...
@@ -72,6 +78,10 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
XTensor
encoding
;
T2TPredictor
predictor
;
CheckNTErrors
(
endSymbolNum
>
0
,
"The search class is not initialized!"
);
Prepare
(
input
->
unitNum
/
input
->
GetDim
(
-
1
),
beamSize
);
/* encoder mask */
model
->
MakeMTMaskEnc
(
*
input
,
*
padding
,
maskEnc
);
...
...
@@ -83,7 +93,7 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
maxLength
=
input
->
GetDim
(
-
2
)
*
2
;
CheckNTErrors
(
maxLength
>
0
,
"no max length specified!"
);
T2TStateBundle
*
states
=
new
T2TStateBundle
[
maxLength
];
T2TStateBundle
*
states
=
new
T2TStateBundle
[
maxLength
+
1
];
T2TStateBundle
*
first
=
states
;
/* create the first state */
...
...
@@ -110,6 +120,9 @@ void T2TSearch::Search(T2TModel * model, XTensor * input, XTensor * padding, XTe
/* expand the search graph */
Expand
(
cur
,
next
);
/* push complete hypotheses into the heap */
Collect
(
next
);
}
delete
[]
states
;
...
...
@@ -241,8 +254,6 @@ void T2TSearch::Generate(T2TStateBundle * beam)
TopK
(
score
,
scoreTopK
,
index
,
-
1
,
beamSize
);
CopyValues
(
index
,
preID
);
preID
.
Dump
(
stderr
,
"preid:"
);
int
sizeVocab
=
score
.
GetDim
(
-
1
);
...
...
@@ -258,8 +269,6 @@ void T2TSearch::Generate(T2TStateBundle * beam)
in the vocabulary by dividing it with vocab-size and computing the remainder. */
Mod
(
index
,
sizeVocab
);
preID
.
Dump
(
stderr
,
"preid:"
);
score
.
Reshape
(
order
,
dims
);
/* we keep the top-k scores */
...
...
@@ -315,8 +324,6 @@ void T2TSearch::Expand(T2TStateBundle * prev, T2TStateBundle * beam)
CopyValues
(
probRef
,
prob
);
CopyValues
(
probPathRef
,
probPath
);
CopyValues
(
predictionRef
,
prediction
);
idRef
.
Dump
(
stderr
,
"idref:"
);
CheckNTErrors
(
beam
->
stateNum
==
id
.
unitNum
,
"Errors occur in counting!"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论