Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
ea25eef3
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea25eef3
编写于
4月 16, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
word2vec demo support sparse remote update
上级
f6c5b6fd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
9 deletion
+25
-9
demo/word2vec/api_train_v2.py
demo/word2vec/api_train_v2.py
+22
-6
paddle/api/PaddleAPI.h
paddle/api/PaddleAPI.h
+1
-1
paddle/api/ParameterUpdater.cpp
paddle/api/ParameterUpdater.cpp
+2
-2
未找到文件。
demo/word2vec/train_v2.py
→
demo/word2vec/
api_
train_v2.py
浏览文件 @
ea25eef3
...
@@ -2,26 +2,38 @@ import math
...
@@ -2,26 +2,38 @@ import math
import
paddle.v2
as
paddle
import
paddle.v2
as
paddle
dictsize
=
1953
embsize
=
32
embsize
=
32
hiddensize
=
256
hiddensize
=
256
N
=
5
N
=
5
def
wordemb
(
inlayer
):
def
wordemb
(
inlayer
):
wordemb
=
paddle
.
layer
.
table_projection
(
wordemb
=
paddle
.
layer
.
embedding
(
input
=
inlayer
,
input
=
inlayer
,
size
=
embsize
,
size
=
embsize
,
param_attr
=
paddle
.
attr
.
Param
(
param_attr
=
paddle
.
attr
.
Param
(
name
=
"_proj"
,
name
=
"_proj"
,
initial_std
=
0.001
,
initial_std
=
0.001
,
learning_rate
=
1
,
learning_rate
=
1
,
l2_rate
=
0
,
))
l2_rate
=
0
,
sparse_update
=
True
))
return
wordemb
return
wordemb
def
main
():
def
main
():
paddle
.
init
(
use_gpu
=
False
,
trainer_count
=
1
)
# for local training
cluster_train
=
False
if
not
cluster_train
:
paddle
.
init
(
use_gpu
=
False
,
trainer_count
=
1
)
else
:
paddle
.
init
(
use_gpu
=
False
,
trainer_count
=
1
,
port
=
7164
,
ports_num
=
1
,
ports_num_for_sparse
=
1
,
num_gradient_servers
=
1
)
word_dict
=
paddle
.
dataset
.
imikolov
.
build_dict
()
word_dict
=
paddle
.
dataset
.
imikolov
.
build_dict
()
dict_size
=
len
(
word_dict
)
dict_size
=
len
(
word_dict
)
firstword
=
paddle
.
layer
.
data
(
firstword
=
paddle
.
layer
.
data
(
...
@@ -65,11 +77,15 @@ def main():
...
@@ -65,11 +77,15 @@ def main():
result
.
metrics
)
result
.
metrics
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
predictword
,
label
=
nextword
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
predictword
,
label
=
nextword
)
parameters
=
paddle
.
parameters
.
create
(
cost
)
parameters
=
paddle
.
parameters
.
create
(
cost
)
ada
m_optimizer
=
paddle
.
optimizer
.
Adam
(
ada
grad
=
paddle
.
optimizer
.
AdaGrad
(
learning_rate
=
3e-3
,
learning_rate
=
3e-3
,
regularization
=
paddle
.
optimizer
.
L2Regularization
(
8e-4
))
regularization
=
paddle
.
optimizer
.
L2Regularization
(
8e-4
))
trainer
=
paddle
.
trainer
.
SGD
(
cost
,
parameters
,
adam_optimizer
)
trainer
=
paddle
.
trainer
.
SGD
(
cost
,
parameters
,
adagrad
,
is_local
=
not
cluster_train
)
trainer
.
train
(
trainer
.
train
(
paddle
.
batch
(
paddle
.
dataset
.
imikolov
.
train
(
word_dict
,
N
),
32
),
paddle
.
batch
(
paddle
.
dataset
.
imikolov
.
train
(
word_dict
,
N
),
32
),
num_passes
=
30
,
num_passes
=
30
,
...
...
paddle/api/PaddleAPI.h
浏览文件 @
ea25eef3
...
@@ -821,7 +821,7 @@ public:
...
@@ -821,7 +821,7 @@ public:
static
ParameterUpdater
*
createLocalUpdater
(
OptimizationConfig
*
config
);
static
ParameterUpdater
*
createLocalUpdater
(
OptimizationConfig
*
config
);
static
ParameterUpdater
*
createRemoteUpdater
(
OptimizationConfig
*
config
,
static
ParameterUpdater
*
createRemoteUpdater
(
OptimizationConfig
*
config
,
int
passCount
,
int
passCount
,
bool
use
r
SparseUpdater
);
bool
useSparseUpdater
);
~
ParameterUpdater
();
~
ParameterUpdater
();
/**
/**
...
...
paddle/api/ParameterUpdater.cpp
浏览文件 @
ea25eef3
...
@@ -29,11 +29,11 @@ ParameterUpdater *ParameterUpdater::createLocalUpdater(
...
@@ -29,11 +29,11 @@ ParameterUpdater *ParameterUpdater::createLocalUpdater(
}
}
ParameterUpdater
*
ParameterUpdater
::
createRemoteUpdater
(
ParameterUpdater
*
ParameterUpdater
::
createRemoteUpdater
(
OptimizationConfig
*
config
,
int
passCount
,
bool
use
r
SparseUpdater
)
{
OptimizationConfig
*
config
,
int
passCount
,
bool
useSparseUpdater
)
{
auto
updater
=
new
ParameterUpdater
();
auto
updater
=
new
ParameterUpdater
();
auto
remoteUpdater
=
new
paddle
::
RemoteParameterUpdater
(
auto
remoteUpdater
=
new
paddle
::
RemoteParameterUpdater
(
config
->
m
->
getConfig
(),
passCount
,
nullptr
);
config
->
m
->
getConfig
(),
passCount
,
nullptr
);
if
(
use
r
SparseUpdater
)
{
if
(
useSparseUpdater
)
{
std
::
unique_ptr
<
paddle
::
ParameterUpdater
>
remoteUpdaterPtr
;
std
::
unique_ptr
<
paddle
::
ParameterUpdater
>
remoteUpdaterPtr
;
remoteUpdaterPtr
.
reset
(
remoteUpdater
);
remoteUpdaterPtr
.
reset
(
remoteUpdater
);
auto
sparseRemoteUpdater
=
auto
sparseRemoteUpdater
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录