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
67096d88
Commit
67096d88
authored
Mar 22, 2021
by
huchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
7b6840d4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
18 行增加
和
14 行删除
+18
-14
source/sample/transformer/train/TrainDataSet.cpp
+7
-14
source/sample/transformer/train/TrainDataSet.h
+5
-0
source/sample/transformer/train/Trainer.cpp
+6
-0
没有找到文件。
source/sample/transformer/train/TrainDataSet.cpp
查看文件 @
67096d88
...
@@ -124,10 +124,10 @@ bool TrainDataSet::LoadBatchToBuf()
...
@@ -124,10 +124,10 @@ bool TrainDataSet::LoadBatchToBuf()
rewind
(
fp
);
rewind
(
fp
);
int
srcVocabSize
=
0
;
/*
int srcVocabSize = 0;
int
tgtVocabSize
=
0
;
int tgtVocabSize = 0;
*/
fread
(
&
srcVocabSize
,
sizeof
(
int
),
1
,
fp
);
fread
(
&
srcVocabSize
,
sizeof
(
srcVocabSize
),
1
,
fp
);
fread
(
&
tgtVocabSize
,
sizeof
(
int
),
1
,
fp
);
fread
(
&
tgtVocabSize
,
sizeof
(
tgtVocabSize
),
1
,
fp
);
fread
(
&
totalSampleNum
,
sizeof
(
totalSampleNum
),
1
,
fp
);
fread
(
&
totalSampleNum
,
sizeof
(
totalSampleNum
),
1
,
fp
);
}
}
...
@@ -224,12 +224,6 @@ bool TrainDataSet::GetBatchSimple(XList* inputs, XList* golds)
...
@@ -224,12 +224,6 @@ bool TrainDataSet::GetBatchSimple(XList* inputs, XList* golds)
InitTensor2D
(
paddingDec
,
sc
,
maxTgtLen
,
X_FLOAT
);
InitTensor2D
(
paddingDec
,
sc
,
maxTgtLen
,
X_FLOAT
);
InitTensor2D
(
label
,
sc
,
maxTgtLen
,
X_INT
);
InitTensor2D
(
label
,
sc
,
maxTgtLen
,
X_INT
);
inputs
->
Add
(
batchEnc
);
inputs
->
Add
(
paddingEnc
);
golds
->
Add
(
batchDec
);
golds
->
Add
(
paddingDec
);
golds
->
Add
(
label
);
curIdx
+=
sc
;
curIdx
+=
sc
;
batchEnc
->
SetData
(
batchEncValues
,
batchEnc
->
unitNum
);
batchEnc
->
SetData
(
batchEncValues
,
batchEnc
->
unitNum
);
...
@@ -271,10 +265,8 @@ void TrainDataSet::Init(const char* dataFile, int myBatchSize, int myBucketSize,
...
@@ -271,10 +265,8 @@ void TrainDataSet::Init(const char* dataFile, int myBatchSize, int myBucketSize,
fp
=
fopen
(
dataFile
,
"rb"
);
fp
=
fopen
(
dataFile
,
"rb"
);
CheckNTErrors
(
fp
,
"can not open the training file"
);
CheckNTErrors
(
fp
,
"can not open the training file"
);
int
srcVocabSize
=
0
;
fread
(
&
srcVocabSize
,
sizeof
(
srcVocabSize
),
1
,
fp
);
int
tgtVocabSize
=
0
;
fread
(
&
tgtVocabSize
,
sizeof
(
tgtVocabSize
),
1
,
fp
);
fread
(
&
srcVocabSize
,
sizeof
(
int
),
1
,
fp
);
fread
(
&
tgtVocabSize
,
sizeof
(
int
),
1
,
fp
);
CheckNTErrors
(
srcVocabSize
>
0
,
"Invalid source vocabulary size"
);
CheckNTErrors
(
srcVocabSize
>
0
,
"Invalid source vocabulary size"
);
CheckNTErrors
(
tgtVocabSize
>
0
,
"Invalid target vocabulary size"
);
CheckNTErrors
(
tgtVocabSize
>
0
,
"Invalid target vocabulary size"
);
...
@@ -286,6 +278,7 @@ void TrainDataSet::Init(const char* dataFile, int myBatchSize, int myBucketSize,
...
@@ -286,6 +278,7 @@ void TrainDataSet::Init(const char* dataFile, int myBatchSize, int myBucketSize,
isTraining
=
training
;
isTraining
=
training
;
buf
=
new
XList
;
buf
=
new
XList
;
curIdx
=
0
;
}
}
/* group samples with similar length into buckets */
/* group samples with similar length into buckets */
...
...
source/sample/transformer/train/TrainDataSet.h
查看文件 @
67096d88
...
@@ -127,6 +127,11 @@ public:
...
@@ -127,6 +127,11 @@ public:
/* the buffer (a list) of samples */
/* the buffer (a list) of samples */
XList
*
buf
;
XList
*
buf
;
/* */
int
srcVocabSize
;
int
tgtVocabSize
;
public
:
public
:
/* get the maximum source sentence length in a range */
/* get the maximum source sentence length in a range */
...
...
source/sample/transformer/train/Trainer.cpp
查看文件 @
67096d88
...
@@ -214,6 +214,12 @@ void Trainer::Train(const char* fn, const char* validFN,
...
@@ -214,6 +214,12 @@ void Trainer::Train(const char* fn, const char* validFN,
batchLoader
.
GetBatchSimple
((
XList
*
)(
&
inputs
),
(
XList
*
)(
&
golds
));
batchLoader
.
GetBatchSimple
((
XList
*
)(
&
inputs
),
(
XList
*
)(
&
golds
));
batchEnc
.
SetDevice
(
model
->
devID
);
paddingEnc
.
SetDevice
(
model
->
devID
);
batchDec
.
SetDevice
(
model
->
devID
);
paddingDec
.
SetDevice
(
model
->
devID
);
label
.
SetDevice
(
model
->
devID
);
CheckNTErrors
(
batchEnc
.
order
==
2
,
"wrong tensor order of the sequence batch"
);
CheckNTErrors
(
batchEnc
.
order
==
2
,
"wrong tensor order of the sequence batch"
);
/* output probabilities */
/* output probabilities */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论