Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"polish embedding method" #5140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions python/paddle/v2/framework/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def fc(input,
return helper.append_activation(pre_activation)


def embedding(input,
def embedding(Ids,
size,
name="default_embedding",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ensure the parameter name is the same, not the embedding layer name is the same.

data_type='float32',
param_attr=None,
program=None,
Expand All @@ -69,10 +70,8 @@ def embedding(input,
attr=helper.param_attr, shape=size, dtype=data_type)
tmp = helper.create_tmp_variable(data_type)
helper.append_op(
type='lookup_table',
inputs={'Ids': input,
'W': w},
outputs={'Out': tmp})
type='lookup_table', inputs={'Ids': Ids,
'W': w}, outputs={'Out': tmp})
return tmp


Expand Down
27 changes: 9 additions & 18 deletions python/paddle/v2/framework/tests/test_word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,33 @@
program=program,
init_program=init_program)

embed_param_attr_1 = {
'name': 'shared_w',
'init_attr': {
'max': 1.0,
'type': 'uniform_random',
'min': -1.0
}
}
embed_param_attr_2 = {'name': 'shared_w'}

embed_first = layers.embedding(
input=first_word,
Ids=first_word,
name="embed_table",
size=[dict_size, embed_size],
data_type='float32',
param_attr=embed_param_attr_1,
program=program,
init_program=init_program)
embed_second = layers.embedding(
input=second_word,
Ids=second_word,
name="embed_table",
size=[dict_size, embed_size],
data_type='float32',
param_attr=embed_param_attr_2,
program=program,
init_program=init_program)

embed_third = layers.embedding(
input=third_word,
Ids=third_word,
name="embed_table",
size=[dict_size, embed_size],
data_type='float32',
param_attr=embed_param_attr_2,
program=program,
init_program=init_program)
embed_forth = layers.embedding(
input=forth_word,
Ids=forth_word,
name="embed_table",
size=[dict_size, embed_size],
data_type='float32',
param_attr=embed_param_attr_2,
program=program,
init_program=init_program)

Expand Down Expand Up @@ -160,6 +150,7 @@
},
fetch_list=[avg_cost])
out = np.array(outs[0])
print out
if out[0] < 10.0:
exit(0) # if avg cost less than 10.0, we think our code is good.
exit(1)