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
411faffa
Commit
411faffa
authored
Jan 22, 2019
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean the code
parent
f04dfc79
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
4 行增加
和
56 行删除
+4
-56
source/sample/transformer/T2TTrainer.cpp
+4
-56
没有找到文件。
source/sample/transformer/T2TTrainer.cpp
查看文件 @
411faffa
...
...
@@ -570,6 +570,8 @@ int T2TTrainer::LoadBuf(FILE * file, bool isSorted, int step)
qsort
(
nodes
,
count
,
sizeof
(
SampleNode
),
CompareSampleNode
);
/* distribute samples into buckets. In each bucket, sequences have
similar a length */
if
(
bucketSize
>
0
)
{
int
bucketCount
=
0
;
int
low
=
0
;
...
...
@@ -741,13 +743,10 @@ int T2TTrainer::LoadBatchLM(FILE * file,
paddingDec
->
SetZeroAll
();
int
seqSize
=
0
;
int
wGold
=
0
;
int
*
batchEncValues
=
new
int
[
batchEnc
->
unitNum
];
MTYPE
*
goldOffsets
=
new
MTYPE
[
gold
->
unitNum
];
//MTYPE * paddingEncOffsets = new MTYPE[paddingEnc->unitNum];
//MTYPE * paddingDecOffsets = new MTYPE[paddingDec->unitNum];
int
wGold
=
0
;
memset
(
batchEncValues
,
0
,
sizeof
(
int
)
*
batchEnc
->
unitNum
);
...
...
@@ -757,8 +756,7 @@ int T2TTrainer::LoadBatchLM(FILE * file,
for
(
int
w
=
0
;
w
<
len
;
w
++
){
int
num
=
buf
[
seqOffset
[
s
]
+
w
];
batchEncValues
[(
int
)
batchEnc
->
GetOffset2D
(
s
-
seq
,
w
)]
=
num
;
//paddingEncOffsets[wCount] = paddingEnc->GetOffset2D(s - seq, w);
//paddingDecOffsets[wCount] = paddingDec->GetOffset2D(s - seq, w);
if
(
w
>
0
)
goldOffsets
[
wGold
++
]
=
gold
->
GetOffset3D
(
s
-
seq
,
w
-
1
,
num
);
...
...
@@ -783,8 +781,6 @@ int T2TTrainer::LoadBatchLM(FILE * file,
batchEnc
->
SetData
(
batchEncValues
,
batchEnc
->
unitNum
);
gold
->
SetDataBatched
(
goldOffsets
,
1.0
F
,
wGold
);
//paddingEnc->SetDataBatched(paddingEncOffsets, 1.0F, wCount);
//paddingDec->SetDataBatched(paddingDecOffsets, 1.0F, wCount);
XTensor
*
tmp
=
NewTensorBuf
(
paddingEnc
,
devID
,
mem
);
_ConvertDataType
(
batchEnc
,
tmp
);
...
...
@@ -798,8 +794,6 @@ int T2TTrainer::LoadBatchLM(FILE * file,
delete
[]
batchEncValues
;
delete
[]
goldOffsets
;
//delete[] paddingEncOffsets;
//delete[] paddingDecOffsets;
fflush
(
tf
);
...
...
@@ -841,8 +835,6 @@ int T2TTrainer::LoadBatchMT(FILE * file,
int
devID
,
XMem
*
mem
,
bool
isTraining
)
{
//if (nextSeq < 0 || nextSeq >= nseqBuf)
// LoadBuf(file, isSorted, 2);
if
(
nextBatch
<
0
||
nextBatch
>=
bufBatchSize
)
{
LoadBuf
(
file
,
isSorted
,
2
);
...
...
@@ -904,44 +896,6 @@ int T2TTrainer::LoadBatchMT(FILE * file,
qsort
(
bufBatch
,
bufBatchSize
,
sizeof
(
BatchNode
),
CompareBatchNode
);
}
/*int seq = MAX(nextSeq, 0);
int wcEnc = 0;
int wcDec = 0;
int wnEnc = 0;
int wnDec = 0;
int maxEnc = 0;
int maxDec = 0;
int sc = 0;
CheckNTErrors((nseqBuf - seq) % 2 == 0, "Input sequence must be paired!");
while(seq + sc < nseqBuf){
wnEnc = seqLen[seq + sc];
wnDec = isDoubledEnd ? seqLen[seq + sc + 1] : seqLen[seq + sc + 1] - 1;
int tcEnc = isBigBatch ? (wcEnc + wnEnc): MAX(maxEnc, wnEnc) * (sc + 2) / 2;
int tcDec = isBigBatch ? (wcDec + wnDec): MAX(maxDec, wnDec) * (sc + 2) / 2;
if(sc != 0 && sc > sBatch * 2 && (tcEnc > wBatch || tcDec > wBatch))
break;
wcEnc += wnEnc;
sc += 1;
if(maxEnc < wnEnc)
maxEnc = wnEnc;
wcDec += wnDec;
sc += 1;
if(maxDec < wnDec)
maxDec = wnDec;
}
nextSeq = seq + sc;*/
if
(
bufBatchSize
<=
0
)
return
0
;
...
...
@@ -1072,12 +1026,6 @@ float T2TTrainer::GetProb(XTensor * output, XTensor * gold, XTensor * wordProbs)
XTensor
probs
;
InitTensor
(
&
probs
,
output
);
//XTensor logOutput;
//InitTensor(&logOutput, output);
//_Log(output, &logOutput);
/* probs[i,j] = output[i,j] * gold[i,j] */
//_Multiply(&logOutput, gold, &probs);
_Multiply
(
output
,
gold
,
&
probs
);
/* probability of each word */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论