提交 22d433f1 编写于 作者: J JiabinYang

test to merge longfei

...@@ -79,14 +79,14 @@ def skip_gram_word2vec(dict_size, ...@@ -79,14 +79,14 @@ def skip_gram_word2vec(dict_size,
datas.append(predict_word) datas.append(predict_word)
if with_hsigmoid: if with_hsigmoid:
if max_code_length: ptable = fluid.layers.data(
ptable = fluid.layers.data( name='ptable',
name='ptable', shape=[max_code_length], dtype='int64') shape=[max_code_length if max_code_length else 40],
pcode = fluid.layers.data( dtype='int64')
name='pcode', shape=[max_code_length], dtype='int64') pcode = fluid.layers.data(
else: name='pcode',
ptable = fluid.layers.data(name='ptable', shape=[40], dtype='int64') shape=[max_code_length if max_code_length else 40],
pcode = fluid.layers.data(name='pcode', shape=[40], dtype='int64') dtype='int64')
datas.append(ptable) datas.append(ptable)
datas.append(pcode) datas.append(pcode)
...@@ -95,8 +95,6 @@ def skip_gram_word2vec(dict_size, ...@@ -95,8 +95,6 @@ def skip_gram_word2vec(dict_size,
words = fluid.layers.read_file(py_reader) words = fluid.layers.read_file(py_reader)
cost = None
emb = fluid.layers.embedding( emb = fluid.layers.embedding(
input=words[0], input=words[0],
is_sparse=is_sparse, is_sparse=is_sparse,
...@@ -104,12 +102,17 @@ def skip_gram_word2vec(dict_size, ...@@ -104,12 +102,17 @@ def skip_gram_word2vec(dict_size,
param_attr=fluid.ParamAttr(initializer=fluid.initializer.Normal( param_attr=fluid.ParamAttr(initializer=fluid.initializer.Normal(
scale=1 / math.sqrt(dict_size)))) scale=1 / math.sqrt(dict_size))))
cost, cost_nce, cost_hs = None, None, None
if with_nce: if with_nce:
cost = nce_layer(emb, words[1], embedding_size, dict_size, 5, "uniform", cost_nce = nce_layer(emb, words[1], embedding_size, dict_size, 5,
word_frequencys, None) "uniform", word_frequencys, None)
cost = cost_nce
if with_hsigmoid: if with_hsigmoid:
cost = hsigmoid_layer(emb, words[1], words[2], words[3], dict_size, cost_hs = hsigmoid_layer(emb, words[1], words[2], words[3], dict_size)
is_sparse) cost = cost_hs
if with_nce and with_hsigmoid:
cost = fluid.layers.elementwise_add(cost_nce, cost_hs)
avg_cost = fluid.layers.reduce_mean(cost) avg_cost = fluid.layers.reduce_mean(cost)
......
...@@ -193,6 +193,9 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id): ...@@ -193,6 +193,9 @@ def train_loop(args, train_program, reader, py_reader, loss, trainer_id):
def train(): def train():
args = parse_args() 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): if not os.path.isdir(args.model_output_dir):
os.mkdir(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.
先完成此消息的编辑!
想要评论请 注册