From dcb5a1ed6747a9168ecf55c8b5a39afc90a1caf0 Mon Sep 17 00:00:00 2001 From: ying Date: Tue, 23 Jan 2018 08:52:47 +0800 Subject: [PATCH] fix ci. --- python/paddle/v2/dataset/wmt16.py | 17 +++++++++-------- python/paddle/v2/fluid/layers/nn.py | 10 +++++----- python/paddle/v2/fluid/layers/ops.py | 18 ++++++++++++++---- .../book/test_understand_sentiment_lstm.py | 4 ++-- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/python/paddle/v2/dataset/wmt16.py b/python/paddle/v2/dataset/wmt16.py index bbc28a2da99..e2f463be2f7 100644 --- a/python/paddle/v2/dataset/wmt16.py +++ b/python/paddle/v2/dataset/wmt16.py @@ -171,8 +171,9 @@ def train(src_dict_size, trg_dict_size, src_lang="en"): callable: The train reader. """ - assert (src_lang in ["en", "de"], ("An error language type. Only support: " - "en (for English); de(for Germany)")) + if src_lang not in ["en", "de"]: + 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_lang) @@ -218,9 +219,9 @@ def test(src_dict_size, trg_dict_size, src_lang="en"): callable: The test reader. """ - assert (src_lang in ["en", "de"], - ("An error language type. " - "Only support: en (for English); de(for Germany)")) + if src_lang not in ["en", "de"]: + 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_lang) @@ -266,9 +267,9 @@ def validation(src_dict_size, trg_dict_size, src_lang="en"): Returns: callable: The validation reader. """ - assert (src_lang in ["en", "de"], - ("An error language type. " - "Only support: en (for English); de(for Germany)")) + if src_lang not in ["en", "de"]: + 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_lang) diff --git a/python/paddle/v2/fluid/layers/nn.py b/python/paddle/v2/fluid/layers/nn.py index 7b3ad707cc6..a01ccfa6353 100644 --- a/python/paddle/v2/fluid/layers/nn.py +++ b/python/paddle/v2/fluid/layers/nn.py @@ -2141,7 +2141,7 @@ def sequence_reshape(input, new_dim): return out -def transpose(input, perm, name=None): +def transpose(x, perm, name=None): """ **transpose Layer** @@ -2161,19 +2161,19 @@ def transpose(input, perm, name=None): .. code-block:: python 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( "Input(perm) is the permutation of dimensions of Input(input). " "It's length shoud be equal to Input(input)'s rank.") helper = LayerHelper('transpose', **locals()) - out = helper.create_tmp_variable(helper.input_dtype()) + out = helper.create_tmp_variable(x.dtype) helper.append_op( type='transpose', - inputs={'X': [input]}, + inputs={'X': [x]}, outputs={'Out': [out]}, attrs={'axis': perm}) return out diff --git a/python/paddle/v2/fluid/layers/ops.py b/python/paddle/v2/fluid/layers/ops.py index b517f8be6a3..022a94cad44 100644 --- a/python/paddle/v2/fluid/layers/ops.py +++ b/python/paddle/v2/fluid/layers/ops.py @@ -45,10 +45,20 @@ __activations__ = [ ] __all__ = [ - 'mean', 'mul', 'reshape', 'scale', 'transpose', - 'sigmoid_cross_entropy_with_logits', 'elementwise_add', 'elementwise_div', - 'elementwise_sub', 'elementwise_mul', 'elementwise_max', 'elementwise_min', - 'clip', 'clip_by_norm', 'sequence_softmax' + 'mean', + 'mul', + 'reshape', + '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__ for _OP in set(__all__): diff --git a/python/paddle/v2/fluid/tests/book/test_understand_sentiment_lstm.py b/python/paddle/v2/fluid/tests/book/test_understand_sentiment_lstm.py index 61819142415..117f74c59ad 100644 --- a/python/paddle/v2/fluid/tests/book/test_understand_sentiment_lstm.py +++ b/python/paddle/v2/fluid/tests/book/test_understand_sentiment_lstm.py @@ -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.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( dtype=emb.dtype, shape=[batch_size, emb_dim], value=0.0) c_pre_init.stop_gradient = False 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, size=class_dim, -- GitLab