提交 dcb5a1ed 编写于 作者: Y ying

fix ci.

上级 64606eaf
...@@ -171,8 +171,9 @@ def train(src_dict_size, trg_dict_size, src_lang="en"): ...@@ -171,8 +171,9 @@ def train(src_dict_size, trg_dict_size, src_lang="en"):
callable: The train reader. callable: The train reader.
""" """
assert (src_lang in ["en", "de"], ("An error language type. Only support: " if src_lang not in ["en", "de"]:
"en (for English); de(for Germany)")) raise ValueError("An error language type. Only support: "
"en (for English); de(for Germany).")
src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size, src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size,
src_lang) src_lang)
...@@ -218,9 +219,9 @@ def test(src_dict_size, trg_dict_size, src_lang="en"): ...@@ -218,9 +219,9 @@ def test(src_dict_size, trg_dict_size, src_lang="en"):
callable: The test reader. callable: The test reader.
""" """
assert (src_lang in ["en", "de"], if src_lang not in ["en", "de"]:
("An error language type. " raise ValueError("An error language type. "
"Only support: en (for English); de(for Germany)")) "Only support: en (for English); de(for Germany).")
src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size, src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size,
src_lang) src_lang)
...@@ -266,9 +267,9 @@ def validation(src_dict_size, trg_dict_size, src_lang="en"): ...@@ -266,9 +267,9 @@ def validation(src_dict_size, trg_dict_size, src_lang="en"):
Returns: Returns:
callable: The validation reader. callable: The validation reader.
""" """
assert (src_lang in ["en", "de"], if src_lang not in ["en", "de"]:
("An error language type. " raise ValueError("An error language type. "
"Only support: en (for English); de(for Germany)")) "Only support: en (for English); de(for Germany).")
src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size, src_dict_size, trg_dict_size = __get_dict_size(src_dict_size, trg_dict_size,
src_lang) src_lang)
......
...@@ -2141,7 +2141,7 @@ def sequence_reshape(input, new_dim): ...@@ -2141,7 +2141,7 @@ def sequence_reshape(input, new_dim):
return out return out
def transpose(input, perm, name=None): def transpose(x, perm, name=None):
""" """
**transpose Layer** **transpose Layer**
...@@ -2161,19 +2161,19 @@ def transpose(input, perm, name=None): ...@@ -2161,19 +2161,19 @@ def transpose(input, perm, name=None):
.. code-block:: python .. code-block:: python
x = fluid.layers.data(name='x', shape=[5, 10, 15], dtype='float32') x = fluid.layers.data(name='x', shape=[5, 10, 15], dtype='float32')
x_transposed = layers.transpose(input=x, perm=[1, 0, 2]) x_transposed = layers.transpose(x, perm=[1, 0, 2])
""" """
if len(perm) != len(input.shape): if len(perm) != len(x.shape):
raise ValueError( raise ValueError(
"Input(perm) is the permutation of dimensions of Input(input). " "Input(perm) is the permutation of dimensions of Input(input). "
"It's length shoud be equal to Input(input)'s rank.") "It's length shoud be equal to Input(input)'s rank.")
helper = LayerHelper('transpose', **locals()) helper = LayerHelper('transpose', **locals())
out = helper.create_tmp_variable(helper.input_dtype()) out = helper.create_tmp_variable(x.dtype)
helper.append_op( helper.append_op(
type='transpose', type='transpose',
inputs={'X': [input]}, inputs={'X': [x]},
outputs={'Out': [out]}, outputs={'Out': [out]},
attrs={'axis': perm}) attrs={'axis': perm})
return out return out
...@@ -45,10 +45,20 @@ __activations__ = [ ...@@ -45,10 +45,20 @@ __activations__ = [
] ]
__all__ = [ __all__ = [
'mean', 'mul', 'reshape', 'scale', 'transpose', 'mean',
'sigmoid_cross_entropy_with_logits', 'elementwise_add', 'elementwise_div', 'mul',
'elementwise_sub', 'elementwise_mul', 'elementwise_max', 'elementwise_min', 'reshape',
'clip', 'clip_by_norm', 'sequence_softmax' 'scale',
'sigmoid_cross_entropy_with_logits',
'elementwise_add',
'elementwise_div',
'elementwise_sub',
'elementwise_mul',
'elementwise_max',
'elementwise_min',
'clip',
'clip_by_norm',
'sequence_softmax',
] + __activations__ ] + __activations__
for _OP in set(__all__): for _OP in set(__all__):
......
...@@ -65,13 +65,13 @@ def lstm_net(dict_dim, class_dim=2, emb_dim=32, seq_len=80, batch_size=50): ...@@ -65,13 +65,13 @@ def lstm_net(dict_dim, class_dim=2, emb_dim=32, seq_len=80, batch_size=50):
emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim]) emb = fluid.layers.embedding(input=data, size=[dict_dim, emb_dim])
emb = fluid.layers.reshape(x=emb, shape=[batch_size, seq_len, emb_dim]) emb = fluid.layers.reshape(x=emb, shape=[batch_size, seq_len, emb_dim])
emb = fluid.layers.transpose(x=emb, axis=[1, 0, 2]) emb = fluid.layers.transpose(x=emb, perm=[1, 0, 2])
c_pre_init = fluid.layers.fill_constant( c_pre_init = fluid.layers.fill_constant(
dtype=emb.dtype, shape=[batch_size, emb_dim], value=0.0) dtype=emb.dtype, shape=[batch_size, emb_dim], value=0.0)
c_pre_init.stop_gradient = False c_pre_init.stop_gradient = False
layer_1_out = lstm(emb, c_pre_init=c_pre_init, hidden_dim=emb_dim) layer_1_out = lstm(emb, c_pre_init=c_pre_init, hidden_dim=emb_dim)
layer_1_out = fluid.layers.transpose(x=layer_1_out, axis=[1, 0, 2]) layer_1_out = fluid.layers.transpose(x=layer_1_out, perm=[1, 0, 2])
prediction = fluid.layers.fc(input=layer_1_out, prediction = fluid.layers.fc(input=layer_1_out,
size=class_dim, size=class_dim,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册