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
3bc771f4
Commit
3bc771f4
authored
Mar 17, 2021
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
b199a6ee
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
24 行删除
+19
-24
source/sample/transformer/Model.h
+16
-8
source/sample/transformer/train/TrainDataSet.h
+3
-16
没有找到文件。
source/sample/transformer/Model.h
查看文件 @
3bc771f4
...
...
@@ -24,17 +24,18 @@
#include "Encoder.h"
#include "Decoder.h"
#include "Utility.h"
#include "submodel/FNN.h"
#include "submodel/Output.h"
#include "Utility.h"
#include "submodel/Attention.h"
#include "../../train/XModel.h"
namespace
nmt
{
/* a nmt model that keeps parameters of the encoder,
/* a
n
nmt model that keeps parameters of the encoder,
the decoder and the output layer (softmax). */
class
Model
class
Model
:
public
XModel
{
public
:
/* device id */
...
...
@@ -85,26 +86,26 @@ public:
/* make the encoding network */
XTensor
MakeDecoder
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
*
mask
,
XTensor
&
MaskEncDec
,
bool
isTraining
);
XTensor
&
MaskEncDec
,
bool
isTraining
);
/* make the network for language modeling (with the output softmax layer) */
void
MakeLM
(
XTensor
&
input
,
XTensor
&
output
,
XTensor
&
padding
,
bool
isTraining
);
/* make the network for machine translation (with the output softmax layer) */
void
MakeMT
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
output
,
XTensor
&
paddingEnc
,
XTensor
&
paddingDec
,
bool
isTraining
);
XTensor
&
paddingEnc
,
XTensor
&
paddingDec
,
bool
isTraining
);
/* make the mask for training MT models */
void
MakeMTMask
(
XTensor
&
inputEnc
,
XTensor
&
inputDec
,
XTensor
&
paddingEnc
,
XTensor
&
paddingDec
,
XTensor
&
maskEnc
,
XTensor
&
maskDec
,
XTensor
&
maskEncDec
);
XTensor
&
paddingEnc
,
XTensor
&
paddingDec
,
XTensor
&
maskEnc
,
XTensor
&
maskDec
,
XTensor
&
maskEncDec
);
/* make the mask of the encoder */
void
MakeMTMaskEnc
(
XTensor
&
paddingEnc
,
XTensor
&
maskEnc
);
/* make the mask of the decoder */
void
MakeMTMaskDec
(
XTensor
&
paddingEnc
,
XTensor
&
paddingDec
,
XTensor
&
maskDec
,
XTensor
&
maskEncDec
);
XTensor
&
maskDec
,
XTensor
&
maskEncDec
);
/* get parameter matrices */
void
GetParams
(
TensorList
&
list
);
...
...
@@ -114,6 +115,13 @@ public:
/* read the parameters */
void
Read
(
FILE
*
file
);
public
:
/* clone the model (overloaded method of XModel) */
XModel
*
Clone
(
int
devID
);
/* run the neural network (overloaded method of XModel) */
bool
RunSimple
(
XList
*
inputs
,
XList
*
outputs
,
XList
*
golds
,
XList
*
losses
);
};
}
...
...
source/sample/transformer/train/TrainDataSet.h
查看文件 @
3bc771f4
...
...
@@ -29,6 +29,7 @@
#include "../../../tensor/XList.h"
#include "../../../tensor/XTensor.h"
#include "../../../tensor/XGlobal.h"
#include "../../../train/XBaseTemplate.h"
#define MAX_WORD_NUM 120
...
...
@@ -56,7 +57,8 @@ struct TrainExample {
};
/* A `TrainDataSet` is associated with a file which contains training data. */
struct
TrainDataSet
{
struct
TrainDataSet
:
public
DataDistributeBase
{
public
:
/* the data buffer */
TrainBufferType
buffer
;
...
...
@@ -98,21 +100,6 @@ public:
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
XTensor
*
label
,
size_t
minSentBatch
,
size_t
batchSize
,
int
devID
);
/* load the samples into the buffer (a list) */
bool
LoadBatchToBuf
(
XList
*
buf
);
/* load the samples into tensors from the buffer */
static
bool
LoadBatch
(
XList
*
buf
,
XTensor
*
batchEnc
,
XTensor
*
paddingEnc
,
XTensor
*
batchDec
,
XTensor
*
paddingDec
,
XTensor
*
label
,
size_t
minSentBatch
,
size_t
batchSize
,
int
devID
,
int
&
wc
,
int
&
sc
);
/* release the samples in a buffer */
static
void
ClearSamples
(
XList
*
buf
);
/* initialization function */
void
Init
(
const
char
*
dataFile
,
int
bucketSize
,
bool
training
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论