Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9e43b4f4
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9e43b4f4
编写于
11月 23, 2018
作者:
T
tangwei12
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add is_sparse
上级
16e350da
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
23 deletion
+14
-23
fluid/PaddleRec/word2vec/network_conf.py
fluid/PaddleRec/word2vec/network_conf.py
+10
-22
fluid/PaddleRec/word2vec/train.py
fluid/PaddleRec/word2vec/train.py
+4
-1
未找到文件。
fluid/PaddleRec/word2vec/network_conf.py
浏览文件 @
9e43b4f4
...
...
@@ -64,21 +64,11 @@ def skip_gram_word2vec(dict_size,
non_leaf_num
=
non_leaf_num
,
ptable
=
ptable
,
pcode
=
pcode
,
is_costum
=
True
)
is_costum
=
True
,
is_sparse
=
is_sparse
)
return
cost
def
get_loss
(
loss1
,
loss2
):
loss_op1
=
fluid
.
layers
.
elementwise_sub
(
fluid
.
layers
.
fill_constant_batch_size_like
(
input
=
loss1
,
shape
=
[
-
1
,
1
],
value
=
margin
,
dtype
=
'float32'
),
cos_q_pt
)
loss_op2
=
fluid
.
layers
.
elementwise_add
(
loss_op1
,
cos_q_nt
)
loss_op3
=
fluid
.
layers
.
elementwise_max
(
fluid
.
layers
.
fill_constant_batch_size_like
(
input
=
loss_op2
,
shape
=
[
-
1
,
1
],
value
=
0.0
,
dtype
=
'float32'
),
loss_op2
)
avg_cost
=
fluid
.
layers
.
mean
(
loss_op3
)
return
avg_cost
datas
=
[]
input_word
=
fluid
.
layers
.
data
(
name
=
"input_word"
,
shape
=
[
1
],
dtype
=
'int64'
)
...
...
@@ -87,14 +77,12 @@ def skip_gram_word2vec(dict_size,
datas
.
append
(
predict_word
)
if
with_hsigmoid
:
if
max_code_length
:
ptable
=
fluid
.
layers
.
data
(
name
=
'ptable'
,
shape
=
[
max_code_length
],
dtype
=
'int64'
)
pcode
=
fluid
.
layers
.
data
(
name
=
'pcode'
,
shape
=
[
max_code_length
],
dtype
=
'int64'
)
else
:
ptable
=
fluid
.
layers
.
data
(
name
=
'ptable'
,
shape
=
[
40
],
dtype
=
'int64'
)
pcode
=
fluid
.
layers
.
data
(
name
=
'pcode'
,
shape
=
[
40
],
dtype
=
'int64'
)
ptable
=
fluid
.
layers
.
data
(
name
=
'ptable'
,
shape
=
[
max_code_length
if
max_code_length
else
40
],
dtype
=
'int64'
)
pcode
=
fluid
.
layers
.
data
(
name
=
'pcode'
,
shape
=
[
max_code_length
if
max_code_length
else
40
],
dtype
=
'int64'
)
datas
.
append
(
ptable
)
datas
.
append
(
pcode
)
...
...
@@ -116,13 +104,13 @@ def skip_gram_word2vec(dict_size,
if
with_nce
:
cost_nce
=
nce_layer
(
emb
,
words
[
1
],
embedding_size
,
dict_size
,
5
,
"uniform"
,
word_frequencys
,
None
)
word_frequencys
,
None
)
cost
=
cost_nce
if
with_hsigmoid
:
cost_hs
=
hsigmoid_layer
(
emb
,
words
[
1
],
words
[
2
],
words
[
3
],
dict_size
)
cost
=
cost_hs
if
with_nce
and
with_hsigmoid
:
cost
=
fluid
.
layers
.
elementwise_add
(
cost_nce
,
cost
)
cost
=
fluid
.
layers
.
elementwise_add
(
cost_nce
,
cost
_hs
)
avg_cost
=
fluid
.
layers
.
reduce_mean
(
cost
)
...
...
fluid/PaddleRec/word2vec/train.py
浏览文件 @
9e43b4f4
...
...
@@ -87,7 +87,7 @@ def parse_args():
'--with_nce'
,
action
=
'store_true'
,
required
=
False
,
default
=
Tru
e
,
default
=
Fals
e
,
help
=
'using negtive sampling, (default: True)'
)
parser
.
add_argument
(
...
...
@@ -188,6 +188,9 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
def
train
():
args
=
parse_args
()
if
not
args
.
with_nce
and
not
args
.
with_hs
:
logger
.
error
(
"with_nce or with_hs must choose one"
)
if
not
os
.
path
.
isdir
(
args
.
model_output_dir
):
os
.
mkdir
(
args
.
model_output_dir
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录