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
fdce3ca3
Commit
fdce3ca3
authored
Jul 25, 2019
by
liyinqiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean the local memory codes in FNNLM.
parent
2921f79d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
9 行增加
和
23 行删除
+9
-23
source/sample/fnnlm/FNNLM.cpp
+9
-23
没有找到文件。
source/sample/fnnlm/FNNLM.cpp
查看文件 @
fdce3ca3
...
@@ -68,8 +68,8 @@ void Read(const char * fn, FNNModel &model);
...
@@ -68,8 +68,8 @@ void Read(const char * fn, FNNModel &model);
void
Test
(
const
char
*
test
,
const
char
*
result
,
FNNModel
&
model
);
void
Test
(
const
char
*
test
,
const
char
*
result
,
FNNModel
&
model
);
int
LoadNGrams
(
FILE
*
file
,
int
n
,
NGram
*
ngrams
,
int
sentNum
,
int
wordNum
);
int
LoadNGrams
(
FILE
*
file
,
int
n
,
NGram
*
ngrams
,
int
sentNum
,
int
wordNum
);
void
InitZeroOneTensor2D
(
XTensor
&
tensor
,
int
rowNum
,
int
colNum
,
int
*
rows
,
int
*
cols
,
void
InitZeroOneTensor2D
(
XTensor
&
tensor
,
int
rowNum
,
int
colNum
,
int
*
rows
,
int
*
cols
,
int
itemNum
,
int
devID
,
XMem
*
mem
);
int
itemNum
,
int
devID
);
void
MakeWordBatch
(
XTensor
&
batch
,
NGram
*
ngrams
,
int
ngramNum
,
int
n
,
int
vSize
,
int
devID
,
XMem
*
mem
);
void
MakeWordBatch
(
XTensor
&
batch
,
NGram
*
ngrams
,
int
ngramNum
,
int
n
,
int
vSize
,
int
devID
);
void
Forward
(
XTensor
inputs
[],
XTensor
&
output
,
FNNModel
&
model
,
FNNNet
&
net
);
void
Forward
(
XTensor
inputs
[],
XTensor
&
output
,
FNNModel
&
model
,
FNNNet
&
net
);
void
Backward
(
XTensor
inputs
[],
XTensor
&
output
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
,
void
Backward
(
XTensor
inputs
[],
XTensor
&
output
,
XTensor
&
gold
,
LOSS_FUNCTION_NAME
loss
,
FNNModel
&
model
,
FNNModel
&
grad
,
FNNNet
&
net
);
FNNModel
&
model
,
FNNModel
&
grad
,
FNNNet
&
net
);
...
@@ -229,11 +229,6 @@ void LoadArgs(int argc, const char ** argv, FNNModel &model)
...
@@ -229,11 +229,6 @@ void LoadArgs(int argc, const char ** argv, FNNModel &model)
fprintf
(
stderr
,
" -dev=%d
\n
"
,
model
.
devID
);
fprintf
(
stderr
,
" -dev=%d
\n
"
,
model
.
devID
);
}
}
}
}
for
(
int
i
=
0
;
i
<
argc
;
i
++
){
if
(
!
strcmp
(
argv
[
i
],
"-mempool"
))
model
.
mem
=
new
XMem
(
model
.
devID
);
}
}
}
/* check model settings */
/* check model settings */
...
@@ -262,11 +257,6 @@ void Copy(FNNModel &tgt, FNNModel &src)
...
@@ -262,11 +257,6 @@ void Copy(FNNModel &tgt, FNNModel &src)
tgt
.
vSize
=
src
.
vSize
;
tgt
.
vSize
=
src
.
vSize
;
tgt
.
devID
=
src
.
devID
;
tgt
.
devID
=
src
.
devID
;
tgt
.
useMemPool
=
src
.
useMemPool
;
tgt
.
useMemPool
=
src
.
useMemPool
;
if
(
src
.
mem
!=
NULL
){
tgt
.
mem
=
new
XMem
(
src
.
mem
->
devID
,
src
.
mem
->
mode
,
src
.
mem
->
maxBlockSize
,
src
.
mem
->
blockNum
,
src
.
mem
->
bufSize
);
}
}
}
/*
/*
...
@@ -459,10 +449,10 @@ void Train(const char * train, bool isShuffled, FNNModel &model)
...
@@ -459,10 +449,10 @@ void Train(const char * train, bool isShuffled, FNNModel &model)
/* make the input tensor for position i */
/* make the input tensor for position i */
for
(
int
i
=
0
;
i
<
model
.
n
-
1
;
i
++
)
for
(
int
i
=
0
;
i
<
model
.
n
-
1
;
i
++
)
MakeWordBatch
(
inputs
[
i
],
ngrams
,
ngramNum
,
i
,
model
.
vSize
,
model
.
devID
,
model
.
mem
);
MakeWordBatch
(
inputs
[
i
],
ngrams
,
ngramNum
,
i
,
model
.
vSize
,
model
.
devID
);
/* make the gold tensor */
/* make the gold tensor */
MakeWordBatch
(
gold
,
ngrams
,
ngramNum
,
model
.
n
-
1
,
model
.
vSize
,
model
.
devID
,
model
.
mem
);
MakeWordBatch
(
gold
,
ngrams
,
ngramNum
,
model
.
n
-
1
,
model
.
vSize
,
model
.
devID
);
if
(
!
autoDiff
){
if
(
!
autoDiff
){
/* prepare an empty network for building the fnn */
/* prepare an empty network for building the fnn */
...
@@ -474,8 +464,6 @@ void Train(const char * train, bool isShuffled, FNNModel &model)
...
@@ -474,8 +464,6 @@ void Train(const char * train, bool isShuffled, FNNModel &model)
/* forward computation */
/* forward computation */
Forward
(
inputs
,
output
,
model
,
net
);
Forward
(
inputs
,
output
,
model
,
net
);
/* backward computation to obtain gradients */
/* backward computation to obtain gradients */
Backward
(
inputs
,
output
,
gold
,
CROSSENTROPY
,
model
,
grad
,
net
);
Backward
(
inputs
,
output
,
gold
,
CROSSENTROPY
,
model
,
grad
,
net
);
...
@@ -727,10 +715,9 @@ The indexed cell is set to 1, and 0 otherwise.
...
@@ -727,10 +715,9 @@ The indexed cell is set to 1, and 0 otherwise.
>> cols - column index
>> cols - column index
>> itemNum - number of non-zero items
>> itemNum - number of non-zero items
>> devID - device id
>> devID - device id
>> mem - memory pool
*/
*/
void
InitZeroOneTensor2D
(
XTensor
&
tensor
,
int
rowNum
,
int
colNum
,
int
*
rows
,
int
*
cols
,
void
InitZeroOneTensor2D
(
XTensor
&
tensor
,
int
rowNum
,
int
colNum
,
int
*
rows
,
int
*
cols
,
int
itemNum
,
int
devID
,
XMem
*
mem
)
int
itemNum
,
int
devID
)
{
{
InitTensor2DV2
(
&
tensor
,
rowNum
,
colNum
,
X_FLOAT
,
devID
);
InitTensor2DV2
(
&
tensor
,
rowNum
,
colNum
,
X_FLOAT
,
devID
);
...
@@ -749,9 +736,8 @@ make a tensor that encodes a batch of words
...
@@ -749,9 +736,8 @@ make a tensor that encodes a batch of words
>> n - indicate which word is encode for each ngram
>> n - indicate which word is encode for each ngram
>> vSize - vocabulary size
>> vSize - vocabulary size
>> devID - device id
>> devID - device id
>> mem - memory pool
*/
*/
void
MakeWordBatch
(
XTensor
&
batch
,
NGram
*
ngrams
,
int
ngramNum
,
int
n
,
int
vSize
,
int
devID
,
XMem
*
mem
)
void
MakeWordBatch
(
XTensor
&
batch
,
NGram
*
ngrams
,
int
ngramNum
,
int
n
,
int
vSize
,
int
devID
)
{
{
int
*
rows
=
new
int
[
ngramNum
];
int
*
rows
=
new
int
[
ngramNum
];
int
*
cols
=
new
int
[
ngramNum
];
int
*
cols
=
new
int
[
ngramNum
];
...
@@ -761,7 +747,7 @@ void MakeWordBatch(XTensor &batch, NGram * ngrams, int ngramNum, int n, int vSiz
...
@@ -761,7 +747,7 @@ void MakeWordBatch(XTensor &batch, NGram * ngrams, int ngramNum, int n, int vSiz
cols
[
i
]
=
ngrams
[
i
].
words
[
n
];
cols
[
i
]
=
ngrams
[
i
].
words
[
n
];
}
}
InitZeroOneTensor2D
(
batch
,
ngramNum
,
vSize
,
rows
,
cols
,
ngramNum
,
devID
,
mem
);
InitZeroOneTensor2D
(
batch
,
ngramNum
,
vSize
,
rows
,
cols
,
ngramNum
,
devID
);
delete
[]
rows
;
delete
[]
rows
;
delete
[]
cols
;
delete
[]
cols
;
...
@@ -1170,10 +1156,10 @@ void Test(const char * test, const char * result, FNNModel &model)
...
@@ -1170,10 +1156,10 @@ void Test(const char * test, const char * result, FNNModel &model)
/* make the input tensor for position i */
/* make the input tensor for position i */
for
(
int
i
=
0
;
i
<
model
.
n
-
1
;
i
++
)
for
(
int
i
=
0
;
i
<
model
.
n
-
1
;
i
++
)
MakeWordBatch
(
inputs
[
i
],
ngrams
,
ngramNum
,
i
,
model
.
vSize
,
model
.
devID
,
model
.
mem
);
MakeWordBatch
(
inputs
[
i
],
ngrams
,
ngramNum
,
i
,
model
.
vSize
,
model
.
devID
);
/* make the gold tensor */
/* make the gold tensor */
MakeWordBatch
(
gold
,
ngrams
,
ngramNum
,
model
.
n
-
1
,
model
.
vSize
,
model
.
devID
,
model
.
mem
);
MakeWordBatch
(
gold
,
ngrams
,
ngramNum
,
model
.
n
-
1
,
model
.
vSize
,
model
.
devID
);
if
(
!
autoDiff
)
{
if
(
!
autoDiff
)
{
/* prepare an empty network for building the fnn */
/* prepare an empty network for building the fnn */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论