diff --git a/.gitignore b/.gitignore index 35bed0accdaa274f5966ca5b4b7180106325449b..1c9730a5ad57cd70613c0692529bcb1ccf056d59 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ build/ .pydevproject Makefile .test_env/ + +*~ +bazel-* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 942669c41ff154c91e88c937739b0f604f21d545..b9902a863d864b28f0fad0fefe64248e356010e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,8 @@ - repo: https://github.com/reyoung/mirrors-yapf.git sha: v0.13.2 hooks: - - id: yapf + - id: yapf + files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$ # Bazel BUILD files follow Python syntax. - repo: https://github.com/pre-commit/pre-commit-hooks sha: 7539d8bd1a00a3c1bfd34cdb606d3a6372e83469 hooks: diff --git a/.travis.yml b/.travis.yml index 9fc518b0cc79e5bac19e81e4ec1dbb386b119d71..7de4ec7fc511832998cd0dc053645e52136042b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,16 +46,19 @@ addons: before_install: - | if [ ${JOB} == "BUILD_AND_TEST" ]; then - if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(\.md$)|(\.rst$)|(\.jpg$)|(\.png$)' - then - echo "Only markdown docs were updated, stopping build process." - exit + local change_list=`git diff --name-only $TRAVIS_COMMIT_RANGE` + if [ $? -eq 0 ]; then # if git diff return no zero, then rerun unit test. + if ! echo ${change_list} | grep -qvE '(\.md$)|(\.rst$)|(\.jpg$)|(\.png$)' + then + echo "Only markdown docs were updated, stopping build process." + exit + fi fi fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo paddle/scripts/travis/before_install.linux.sh; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then paddle/scripts/travis/before_install.osx.sh; fi - if [[ "$JOB" == "PRE_COMMIT" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi - - pip install wheel protobuf sphinx breathe recommonmark virtualenv numpy sphinx_rtd_theme pre-commit + - pip install wheel protobuf sphinx recommonmark virtualenv numpy sphinx_rtd_theme pre-commit script: - paddle/scripts/travis/main.sh notifications: diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000000000000000000000000000000000..d6ae2af8eb678a2e399220abefe825ab3975ff69 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,17 @@ +# External dependency to Google protobuf. +http_archive( + name = "protobuf", + url = "http://github.com/google/protobuf/archive/v3.1.0.tar.gz", + sha256 = "0a0ae63cbffc274efb573bdde9a253e3f32e458c41261df51c5dbc5ad541e8f7", + strip_prefix = "protobuf-3.1.0", +) + +# External dependency to gtest 1.7.0. This method comes from +# https://www.bazel.io/versions/master/docs/tutorial/cpp.html. +new_http_archive( + name = "gtest", + url = "https://github.com/google/googletest/archive/release-1.7.0.zip", + sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0", + build_file = "third_party/gtest.BUILD", + strip_prefix = "googletest-release-1.7.0", +) diff --git a/cmake/check_packages.cmake b/cmake/check_packages.cmake index 3bc0c1fd18448e3c2f0799295ac77d57cdc1bee7..06887455418797f7162a5970669a0483e42a2db8 100644 --- a/cmake/check_packages.cmake +++ b/cmake/check_packages.cmake @@ -30,7 +30,6 @@ if(WITH_DOC) find_package(Sphinx REQUIRED) find_package(Doxygen REQUIRED) find_python_module(recommonmark REQUIRED) - find_python_module(breathe REQUIRED) endif() if(WITH_SWIG_PY) diff --git a/demo/sentiment/predict.py b/demo/sentiment/predict.py index 00239c6009b8503cf445d9847abde92db12db2fe..0095c6f7272a2191ea39e042a836f7d6038032aa 100755 --- a/demo/sentiment/predict.py +++ b/demo/sentiment/predict.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os +import os, sys import numpy as np from optparse import OptionParser from py_paddle import swig_paddle, DataProviderConverter @@ -66,35 +66,27 @@ class SentimentPrediction(): for v in open(label_file, 'r'): self.label[int(v.split('\t')[1])] = v.split('\t')[0] - def get_data(self, data_file): + def get_index(self, data): """ - Get input data of paddle format. + transform word into integer index according to the dictionary. """ - with open(data_file, 'r') as fdata: - for line in fdata: - words = line.strip().split() - word_slot = [ - self.word_dict[w] for w in words if w in self.word_dict - ] - if not word_slot: - print "all words are not in dictionary: %s", line - continue - yield [word_slot] + words = data.strip().split() + word_slot = [ + self.word_dict[w] for w in words if w in self.word_dict + ] + return word_slot - def predict(self, data_file): - """ - data_file: file name of input data. - """ - input = self.converter(self.get_data(data_file)) + def batch_predict(self, data_batch): + input = self.converter(data_batch) output = self.network.forwardTest(input) prob = output[0]["value"] - lab = np.argsort(-prob) - if self.label is None: - print("%s: predicting label is %d" % (data_file, lab[0][0])) - else: - print("%s: predicting label is %s" % - (data_file, self.label[lab[0][0]])) - + labs = np.argsort(-prob) + for idx, lab in enumerate(labs): + if self.label is None: + print("predicting label is %d" % (lab[0])) + else: + print("predicting label is %s" % + (self.label[lab[0]])) def option_parser(): usage = "python predict.py -n config -w model_dir -d dictionary -i input_file " @@ -119,11 +111,13 @@ def option_parser(): default=None, help="dictionary file") parser.add_option( - "-i", - "--data", + "-c", + "--batch_size", + type="int", action="store", - dest="data", - help="data file to predict") + dest="batch_size", + default=1, + help="the batch size for prediction") parser.add_option( "-w", "--model", @@ -137,14 +131,21 @@ def option_parser(): def main(): options, args = option_parser() train_conf = options.train_conf - data = options.data + batch_size = options.batch_size dict_file = options.dict_file model_path = options.model_path label = options.label swig_paddle.initPaddle("--use_gpu=0") predict = SentimentPrediction(train_conf, dict_file, model_path, label) - predict.predict(data) + batch = [] + for line in sys.stdin: + batch.append([predict.get_index(line)]) + if len(batch) == batch_size: + predict.batch_predict(batch) + batch=[] + if len(batch) > 0: + predict.batch_predict(batch) if __name__ == '__main__': main() diff --git a/demo/sentiment/predict.sh b/demo/sentiment/predict.sh index a889dfe3ec6635bd1ab2b60ae7207815cd205416..c72a8e8641516543ef267fcb4b448630246d1e8d 100755 --- a/demo/sentiment/predict.sh +++ b/demo/sentiment/predict.sh @@ -19,9 +19,9 @@ set -e model=model_output/pass-00002/ config=trainer_config.py label=data/pre-imdb/labels.list -python predict.py \ - -n $config\ - -w $model \ - -b $label \ - -d ./data/pre-imdb/dict.txt \ - -i ./data/aclImdb/test/pos/10007_10.txt +cat ./data/aclImdb/test/pos/10007_10.txt | python predict.py \ + --tconf=$config\ + --model=$model \ + --label=$label \ + --dict=./data/pre-imdb/dict.txt \ + --batch_size=1 diff --git a/doc/api/data_provider/pydataprovider2_en.rst b/doc/api/data_provider/pydataprovider2_en.rst index b42cbca576e4b5d67d50d0156939a01faae4533d..083436e2710b4582e11741aaeaf5932d59869473 100644 --- a/doc/api/data_provider/pydataprovider2_en.rst +++ b/doc/api/data_provider/pydataprovider2_en.rst @@ -1,5 +1,7 @@ +.. _api_pydataprovider: + PyDataProvider2 -================= +=============== We highly recommand users to use PyDataProvider2 to provide training or testing data to PaddlePaddle. The user only needs to focus on how to read a single diff --git a/doc/api/index_en.rst b/doc/api/index_en.rst index 9930f93e10e64d1e2306d34bb32aedc858bfcb68..6fdee9f928dd7057cec58f740bf7520af54a24fb 100644 --- a/doc/api/index_en.rst +++ b/doc/api/index_en.rst @@ -1,35 +1,37 @@ API -==== +=== DataProvider API ---------------- .. toctree:: - :maxdepth: 1 + :maxdepth: 1 - data_provider/index_en.rst - data_provider/pydataprovider2_en.rst + data_provider/index_en.rst + data_provider/pydataprovider2_en.rst + +.. _api_trainer_config: Model Config API ---------------- .. toctree:: - :maxdepth: 1 + :maxdepth: 1 - trainer_config_helpers/optimizers.rst - trainer_config_helpers/data_sources.rst - trainer_config_helpers/layers.rst - trainer_config_helpers/activations.rst - trainer_config_helpers/poolings.rst - trainer_config_helpers/networks.rst - trainer_config_helpers/evaluators.rst - trainer_config_helpers/attrs.rst + trainer_config_helpers/optimizers.rst + trainer_config_helpers/data_sources.rst + trainer_config_helpers/layers.rst + trainer_config_helpers/activations.rst + trainer_config_helpers/poolings.rst + trainer_config_helpers/networks.rst + trainer_config_helpers/evaluators.rst + trainer_config_helpers/attrs.rst Applications API ---------------- .. toctree:: - :maxdepth: 1 + :maxdepth: 1 - predict/swig_py_paddle_en.rst + predict/swig_py_paddle_en.rst diff --git a/doc/api/trainer_config_helpers/data_sources.rst b/doc/api/trainer_config_helpers/data_sources.rst index 44ea59df43762508e86c7b867fcf136d84c8351e..b9dd4dda01ae59d1260356aff50ddf298d02c87f 100644 --- a/doc/api/trainer_config_helpers/data_sources.rst +++ b/doc/api/trainer_config_helpers/data_sources.rst @@ -1,3 +1,5 @@ +.. _api_trainer_config_helpers_data_sources: + DataSources =========== diff --git a/doc/api/trainer_config_helpers/layers.rst b/doc/api/trainer_config_helpers/layers.rst index b487b739a719e9f7118efcc143301da36f7a978e..12a75080d0deab1ecce6b2579b059ba56abf6711 100644 --- a/doc/api/trainer_config_helpers/layers.rst +++ b/doc/api/trainer_config_helpers/layers.rst @@ -20,6 +20,8 @@ LayerOutput Data layer =========== +.. _api_trainer_config_helpers_layers_data_layer: + data_layer ---------- .. automodule:: paddle.trainer_config_helpers.layers @@ -29,6 +31,8 @@ data_layer Fully Connected Layers ====================== +.. _api_trainer_config_helpers_layers_fc_layer: + fc_layer -------- .. automodule:: paddle.trainer_config_helpers.layers @@ -68,6 +72,8 @@ img_conv_layer :members: img_conv_layer :noindex: +.. _api_trainer_config_helpers_layers_context_projection: + context_projection ------------------ .. automodule:: paddle.trainer_config_helpers.layers @@ -185,6 +191,8 @@ mixed_layer :members: mixed_layer :noindex: +.. _api_trainer_config_helpers_layers_embedding_layer: + embedding_layer --------------- .. automodule:: paddle.trainer_config_helpers.layers @@ -237,6 +245,8 @@ trans_full_matrix_projection Aggregate Layers ================ +.. _api_trainer_config_helpers_layers_pooling_layer: + pooling_layer ------------- .. automodule:: paddle.trainer_config_helpers.layers @@ -333,6 +343,8 @@ tensor_layer :members: tensor_layer :noindex: +.. _api_trainer_config_helpers_layers_cos_sim: + cos_sim ------- .. automodule:: paddle.trainer_config_helpers.layers diff --git a/doc/api/trainer_config_helpers/networks.rst b/doc/api/trainer_config_helpers/networks.rst index 29c52c5ce3078f1755162dbbdd65a059d8ba9fa4..e13c368051abe3c50036c3baab988f170df4c641 100644 --- a/doc/api/trainer_config_helpers/networks.rst +++ b/doc/api/trainer_config_helpers/networks.rst @@ -13,6 +13,8 @@ sequence_conv_pool :members: sequence_conv_pool :noindex: +.. _api_trainer_config_helpers_network_text_conv_pool: + text_conv_pool -------------- .. automodule:: paddle.trainer_config_helpers.networks diff --git a/doc/conf.py.in b/doc/conf.py.in index 5fb307e3a9b572f14789dec3707611f336a5d44f..01d156e887b623898df09044a800fd067ee116db 100644 --- a/doc/conf.py.in +++ b/doc/conf.py.in @@ -144,5 +144,6 @@ def setup(app): # no c++ API for now app.add_config_value('recommonmark_config', { 'url_resolver': lambda url: github_doc_root + url, + 'enable_eval_rst': True, }, True) app.add_transform(AutoStructify) diff --git a/doc/getstarted/build_and_install/build_from_source_en.md b/doc/getstarted/build_and_install/build_from_source_en.md index 150d7fc43720314462ac5c5b72f6a93b18e6d735..3771d316a1b520b9f29b30babd663b4dd27fd650 100644 --- a/doc/getstarted/build_and_install/build_from_source_en.md +++ b/doc/getstarted/build_and_install/build_from_source_en.md @@ -79,7 +79,7 @@ As a simple example, consider the following: ```bash pip install 'sphinx>=1.4.0' - pip install sphinx_rtd_theme breathe recommonmark + pip install sphinx_rtd_theme recommonmark # install doxygen on Ubuntu sudo apt-get install doxygen diff --git a/doc/getstarted/build_and_install/docker_install_en.rst b/doc/getstarted/build_and_install/docker_install_en.rst index 1ab6fc6a728f68b16d798a577da2896481eb17d1..feb027ccbbcdb68766e3462f0b8180e3734ef9c7 100644 --- a/doc/getstarted/build_and_install/docker_install_en.rst +++ b/doc/getstarted/build_and_install/docker_install_en.rst @@ -104,3 +104,70 @@ container: Then we can direct our Web browser to the HTML version of source code at http://localhost:8088/paddle/ + + +Development Using Docker +------------------------ + +Develpers can work on PaddlePaddle using Docker. This allows +developers to work on different platforms -- Linux, Mac OS X, and +Windows -- in a consistent way. + +The general development workflow with Docker and Bazel is as follows: + +1. Get the source code of Paddle: + + .. code-block:: bash + + git clone --recursive https://github.com/paddlepaddle/paddle + + +2. Build a development Docker image `paddle:dev` from the source code. + This image contains all the development tools and dependencies of + PaddlePaddle. + + + .. code-block:: bash + + cd paddle + docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile . + + +3. Run the image as a container and mounting local source code + directory into the container. This allows us to change the code on + the host and build it within the container. + + .. code-block:: bash + + docker run \ + -d # run the container in background mode \ + --name paddle # we can run a nginx container to serve documents \ + -p 2022:22 # so we can SSH into this container \ + -v $PWD:/paddle # mount the source code \ + -v $HOME/.cache/bazel:/root/.cache/bazel # mount Bazel cache \ + paddle:dev + +4. SSH into the container: + + .. code-block:: bash + + ssh root@localhost -p 2022 + +5. We can edit the source code in the container or on this host. Then + we can build using cmake + + .. code-block:: bash + + cd /paddle # where paddle source code has been mounted into the container + mkdir -p build + cd build + cmake -DWITH_TESTING=ON .. + make -j `nproc` + CTEST_OUTPUT_ON_FAILURE=1 ctest + + or Bazel in the container: + + .. code-block:: bash + + cd /paddle + bazel test ... diff --git a/doc/howto/cmd_parameter/index_en.md b/doc/howto/cmd_parameter/index_en.md index bd16affdd8ceaf72250acb7c1411c315334f07ba..fb658f2aa5bc0edef7b5dcb24a582d2c4182caa7 100644 --- a/doc/howto/cmd_parameter/index_en.md +++ b/doc/howto/cmd_parameter/index_en.md @@ -1,3 +1,6 @@ +```eval_rst +.. _cmd_line_index_en: +``` # How to Set Command-line Parameters * [Use Case](use_case_en.md) diff --git a/doc/howto/source/api.rst b/doc/howto/source/api.rst deleted file mode 100644 index 30396c26b61827847cc5acc29cee1c3c8e7b226e..0000000000000000000000000000000000000000 --- a/doc/howto/source/api.rst +++ /dev/null @@ -1,5 +0,0 @@ -API -=== - -.. doxygenfile:: paddle/api/PaddleAPI.h -.. doxygenfile:: paddle/api/Internal.h diff --git a/doc/howto/source/cuda/index.rst b/doc/howto/source/cuda/index.rst deleted file mode 100644 index b0fed2e7f72c9a9671e56e114edfc88d72504dbe..0000000000000000000000000000000000000000 --- a/doc/howto/source/cuda/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -CUDA -==== - -.. toctree:: - :maxdepth: 2 - - matrix.rst - nn.rst - utils.rst diff --git a/doc/howto/source/cuda/matrix.rst b/doc/howto/source/cuda/matrix.rst deleted file mode 100644 index b7699c83eda15d9003506f5fc57b51d52e7af823..0000000000000000000000000000000000000000 --- a/doc/howto/source/cuda/matrix.rst +++ /dev/null @@ -1,59 +0,0 @@ -Matrix -====== - -Base ----- - -hl_matrix.h -``````````` -.. doxygenfile:: paddle/cuda/include/hl_matrix.h - -hl_matrix_base.h -```````````````` -.. doxygenfile:: paddle/cuda/include/hl_matrix_base.cuh - -hl_matrix_apply.cuh -``````````````````` -.. doxygenfile:: paddle/cuda/include/hl_matrix_apply.cuh - -hl_matrix_ops.cuh -````````````````` -.. doxygenfile:: paddle/cuda/include/hl_matrix_ops.cuh - -hl_matrix_type.cuh -`````````````````` -.. doxygenfile:: paddle/cuda/include/hl_matrix_type.cuh - -hl_sse_matrix_kernel.cuh -```````````````````````` -.. doxygenfile:: paddle/cuda/include/hl_sse_matrix_kernel.cuh - -Matrix Function ---------------- - -hl_batch_transpose.h -```````````````````` -.. doxygenfile:: paddle/cuda/include/hl_batch_transpose.h - -hl_aggregate.h -`````````````` -.. doxygenfile:: paddle/cuda/include/hl_aggregate.h - -hl_top_k.h -`````````` -.. doxygenfile:: paddle/cuda/include/hl_top_k.h - -hl_table_apply.h -```````````````` -.. doxygenfile:: paddle/cuda/include/hl_table_apply.h - -Sparse Matrix -------------- - -hl_sparse.h -``````````` -.. doxygenfile:: paddle/cuda/include/hl_sparse.h - -hl_sparse.ph -```````````` -.. doxygenfile:: paddle/cuda/include/hl_sparse.ph diff --git a/doc/howto/source/cuda/nn.rst b/doc/howto/source/cuda/nn.rst deleted file mode 100644 index 5577d01e72a5b22847bda40528c46a28cacc1490..0000000000000000000000000000000000000000 --- a/doc/howto/source/cuda/nn.rst +++ /dev/null @@ -1,39 +0,0 @@ -Neural Network -============== - -Base ----- - -.. doxygenfile:: paddle/cuda/include/hl_gpu.h -.. doxygenfile:: paddle/cuda/include/hl_functions.h -.. doxygenfile:: paddle/cuda/include/hl_avx_functions.h -.. doxygenfile:: paddle/cuda/include/hl_gpu_functions.cuh -.. doxygenfile:: paddle/cuda/include/hl_activation_functions.h - - -CNN Related APIs ----------------- -.. doxygenfile:: paddle/cuda/include/hl_cnn.h -.. doxygenfile:: paddle/cuda/include/hl_cuda_cudnn.h -.. doxygenfile:: paddle/cuda/include/hl_cuda_cudnn.ph - -RNN Related APIs ----------------- - -.. doxygenfile:: paddle/cuda/include/hl_recurrent_apply.cuh -.. doxygenfile:: paddle/cuda/include/hl_sequence.h - -LSTM Model -`````````` - -.. doxygenfile:: paddle/cuda/include/hl_lstm.h -.. dpxygenfile:: paddle/cuda/include/hl_cpu_lstm.cuh -.. doxygenfile:: paddle/cuda/include/hl_gpu_lstm.cuh -.. doxygenfile:: paddle/cuda/include/hl_lstm_ops.cuh - -GRU Model -````````` - -.. doxygenfile:: paddle/cuda/include/hl_gru_ops.cuh -.. doxygenfile:: paddle/cuda/include/hl_cpu_gru.cuh -.. doxygenfile:: paddle/cuda/include/hl_gpu_gru.cuh diff --git a/doc/howto/source/cuda/utils.rst b/doc/howto/source/cuda/utils.rst deleted file mode 100644 index 850e8bd1c6670947e2a5f1b6f9b0d5b252117cbf..0000000000000000000000000000000000000000 --- a/doc/howto/source/cuda/utils.rst +++ /dev/null @@ -1,37 +0,0 @@ -Utils -===== - -Dynamic Link Libs ------------------ -.. doxygenfile:: paddle/cuda/include/hl_dso_loader.h - -GPU Resources -------------- - -hl_cuda.ph -`````````` -.. doxygenfile:: paddle/cuda/include/hl_cuda.ph - -hl_cuda.h -````````` -.. doxygenfile:: paddle/cuda/include/hl_cuda.h - -HPPL Base ---------- -.. doxygenfile:: paddle/cuda/include/hl_base.h - -CUBLAS Wrapper --------------- -.. doxygenfile:: paddle/cuda/include/hl_cuda_cublas.h - -Timer ------ -.. doxygenfile:: paddle/cuda/include/hl_time.h - -Thread Resource ---------------- -.. doxygenfile:: paddle/cuda/include/hl_thread.ph - -Device Function ---------------- -.. doxygenfile:: paddle/cuda/include/hl_device_functions.cuh diff --git a/doc/howto/source/gserver/activations.rst b/doc/howto/source/gserver/activations.rst deleted file mode 100644 index 55b9d3be383c07842d7066280cc0e174788db1fb..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/activations.rst +++ /dev/null @@ -1,5 +0,0 @@ -Activations -=========== - -.. doxygenclass:: paddle::ActivationFunction - :members: diff --git a/doc/howto/source/gserver/dataproviders.rst b/doc/howto/source/gserver/dataproviders.rst deleted file mode 100644 index c30d9d6a36a6fbb664ae001274b6a7b0e721070f..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/dataproviders.rst +++ /dev/null @@ -1,87 +0,0 @@ -============== -Data Providers -============== - -DataProviders -============= - -Base ----- -.. doxygenclass:: paddle::DataProvider - :members: - -DataProviderGroup ------------------ -.. doxygenclass:: paddle::DataProviderGroup - :members: - -MultiDataProvider ------------------ -.. doxygenclass:: paddle::MultiDataProvider - :members: - -PyDataProvider -============== - -IFieldScanner -------------- -.. doxygenclass:: paddle::IFieldScanner - :members: - -DenseScanner -------------- -.. doxygenclass:: paddle::DenseScanner - :members: - -IndexScanner -------------- -.. doxygenclass:: paddle::IndexScanner - :members: - -SparseNonValueScanner ---------------------- -.. doxygenclass:: paddle::SparseNonValueScanner - :members: - -SparseValueScanner ------------------- -.. doxygenclass:: paddle::SparseValueScanner - :members: - -SequenceScanner ---------------- -.. doxygenclass:: paddle::SparseValueScanner - :members: - -IPyDataProviderCache --------------------- -.. doxygenclass:: paddle::IPyDataProviderCache - :members: - -NoCacheStrategy ---------------- -.. doxygenclass:: paddle::NoCacheStrategy - :members: - -CacheOnePassInMemory --------------------- -.. doxygenclass:: paddle::CacheOnePassInMemory - :members: - -IPyDataProvider ---------------- -.. doxygenclass:: paddle::PyDataProvider2 - :members: - -ProtoDataProvider -================= - -ProtoDataProvider ----------------- -.. doxygenclass:: paddle::ProtoDataProvider - :members: - -ProtoSequenceDataProvider -------------------------- -.. doxygenclass:: paddle::ProtoSequenceDataProvider - :members: diff --git a/doc/howto/source/gserver/evaluators.rst b/doc/howto/source/gserver/evaluators.rst deleted file mode 100644 index f5361f76cd2b1c9c004221c03ea05b2c1f3a652e..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/evaluators.rst +++ /dev/null @@ -1,103 +0,0 @@ -========== -Evaluators -========== - -Base -==== - -.. doxygenclass:: paddle::Evaluator - :members: - -Sum -=== - -SumEvaluator ------------- -.. doxygenclass:: paddle::SumEvaluator - :members: - -ColumnSumEvaluator ------------------- -.. doxygenclass:: paddle::ColumnSumEvaluator - :members: - -Classification -============== - -ClassificationErrorEvaluator ---------------------------- -.. doxygenclass:: paddle::ClassificationErrorEvaluator - :members: - -SequenceClassificationErrorEvaluator ------------------------------------- -.. doxygenclass:: paddle::SequenceClassificationErrorEvaluator - :members: - -AucEvaluator -------------- -.. doxygenclass:: paddle::AucEvaluator - :members: - -PrecisionRecallEvaluator ------------------------- -.. doxygenclass:: paddle::PrecisionRecallEvaluator - :members: - -ChunkEvaluator --------------- -.. doxygenclass:: paddle::ChunkEvaluator - :members: - -CTCEvaluator ------------- -.. doxygenclass:: paddle::CTCErrorEvaluator - :members: - - -Rank -==== - -PnpairEvaluator -------------- -.. doxygenclass:: paddle::PnpairEvaluator - :members: - -AucEvaluator -------------- -.. doxygenclass:: paddle::RankAucEvaluator - :members: - - -Printer -======= - -ValuePrinter -------------- -.. doxygenclass:: paddle::ValuePrinter - :members: - -GradientPrinter ---------------- -.. doxygenclass:: paddle::GradientPrinter - :members: - -MaxIdPrinter ------------- -.. doxygenclass:: paddle::MaxIdPrinter - :members: - -MaxFramePrinter ---------------- -.. doxygenclass:: paddle::MaxFramePrinter - :members: - -SequenceTextPrinter ------------------- -.. doxygenclass:: paddle::SequenceTextPrinter - :members: - -ClassificationErrorPrinter --------------------------- -.. doxygenclass:: paddle::ClassificationErrorPrinter - :members: diff --git a/doc/howto/source/gserver/gradientmachines.rst b/doc/howto/source/gserver/gradientmachines.rst deleted file mode 100644 index 04c8e91d0316a45ad10b0ed0513d3e8916b7c3d9..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/gradientmachines.rst +++ /dev/null @@ -1,27 +0,0 @@ -Gradient Machines -================= - -GradientMachine ---------------- -.. doxygenclass:: paddle::GradientMachine - :members: - -GradientMachineMode -------------------- -.. doxygenclass:: paddle::IGradientMachineMode - :members: - -MultiGradientMachine --------------------- -.. doxygenclass:: paddle::MultiGradientMachine - :members: - -TrainerThread -````````````` -.. doxygenclass:: paddle::TrainerThread - :members: - -RecurrentGradientMachine ------------------------- -.. doxygenclass:: paddle::RecurrentGradientMachine - :members: diff --git a/doc/howto/source/gserver/index.rst b/doc/howto/source/gserver/index.rst deleted file mode 100644 index 223b00b9a9dbf1db40ce702cf0e154e5e53a8644..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/index.rst +++ /dev/null @@ -1,12 +0,0 @@ -GServer -======= - -.. toctree:: - :maxdepth: 2 - - activations.rst - dataproviders.rst - evaluators.rst - gradientmachines.rst - layers.rst - neworks.rst diff --git a/doc/howto/source/gserver/layers.rst b/doc/howto/source/gserver/layers.rst deleted file mode 100644 index 191b2bdff26ed17437370a12036f9dbb174dae15..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/layers.rst +++ /dev/null @@ -1,566 +0,0 @@ -====== -Layers -====== - -Base -==== - -Layer ------ -.. doxygenclass:: paddle::Layer - :members: - -Projection ----------- -.. doxygenclass:: paddle::Projection - :members: - -Operator --------- -.. doxygenclass:: paddle::Operator - :members: - -Data Layer -========== - -.. doxygenclass:: paddle::DataLayer - :members: - -Fully Connected Layers -====================== - -FullyConnectedLayer -------------------- -.. doxygenclass:: paddle::FullyConnectedLayer - :members: - -SelectiveFullyConnectedLayer ----------------------------- -.. doxygenclass:: paddle::SelectiveFullyConnectedLayer - :members: - -Conv Layers -=========== - -ConvBaseLayer -------------- -.. doxygenclass:: paddle::ConvBaseLayer - :members: - -ConvOperator ------------- -.. doxygenclass:: paddle::ConvOperator - :members: - -ConvShiftLayer --------------- -.. doxygenclass:: paddle::ConvShiftLayer - :members: - -CudnnConvLayer --------------- -.. doxygenclass:: paddle::CudnnConvLayer - :members: - -ExpandConvBaseLayer -------------------- -.. doxygenclass:: paddle::ExpandConvBaseLayer - :members: - -ExpandConvLayer ---------------- -.. doxygenclass:: paddle::ExpandConvLayer - :members: - -ContextProjection ------------------ -.. doxygenclass:: paddle::ContextProjection - :members: - -Pooling Layers -============== - -PoolLayer ---------- -.. doxygenclass:: paddle::PoolLayer - :members: - -PoolProjectionLayer -------------------- -.. doxygenclass:: paddle::PoolProjectionLayer - :members: - -CudnnPoolLayer --------------- -.. doxygenclass:: paddle::CudnnPoolLayer - :members: - -SpatialPyramidPoolLayer ------------------------ -.. doxygenclass:: paddle::SpatialPyramidPoolLayer - :members: - -MaxOutLayer ------------ -.. doxygenclass:: paddle::MaxOutLayer - :members: - -Norm Layers -=========== - -NormLayer ---------- -.. doxygenclass:: paddle::NormLayer - :members: - -CMRProjectionNormLayer ----------------------- -.. doxygenclass:: paddle::CMRProjectionNormLayer - :members: - -DataNormLayer -------------- -.. doxygenclass:: paddle::DataNormLayer - :members: - -ResponseNormLayer ------------------ -.. doxygenclass:: paddle::ResponseNormLayer - :members: - -BatchNormBaseLayer ------------------- -.. doxygenclass:: paddle::BatchNormBaseLayer - :members: - -BatchNormalizationLayer ------------------------ -.. doxygenclass:: paddle::BatchNormalizationLayer - :members: - -CudnnBatchNormLayer ------------------------ -.. doxygenclass:: paddle::CudnnBatchNormLayer - :members: - -SumToOneNormLayer ------------------ -.. doxygenclass:: paddle::SumToOneNormLayer - :members: - -Activation Layer -================ - -ParameterReluLayer ------------------- -.. doxygenclass:: paddle::ParameterReluLayer - :members: - -Recurrent Layers -================ - -RecurrentLayer --------------- -.. doxygenclass:: paddle::RecurrentLayer - :members: - -SequenceToBatch ---------------- -.. doxygenclass:: paddle::SequenceToBatch - :members: - -LSTM ----- -LstmLayer -````````` -.. doxygenclass:: paddle::LstmLayer - :members: - -LstmStepLayer -````````````` -.. doxygenclass:: paddle::LstmStepLayer - :members: - -LstmCompute -``````````` -.. doxygenclass:: paddle::LstmCompute - :members: - -MDLSTM ------- -MDLstmLayer -``````````` -.. doxygenclass:: paddle::MDLstmLayer - :members: - -CoordIterator -````````````` -.. doxygenclass:: paddle::CoordIterator - :members: - -GRU ---- -GatedRecurrentLayer -``````````````````` -.. doxygenclass:: paddle::GatedRecurrentLayer - :members: - -GruStepLayer -```````````` -.. doxygenclass:: paddle::GruStepLayer - :members: - -GruCompute -`````````` -.. doxygenclass:: paddle::GruCompute - :members: - -Recurrent Layer Group -===================== - -AgentLayer ----------- -.. doxygenclass:: paddle::AgentLayer - :members: - -SequenceAgentLayer ------------------- -.. doxygenclass:: paddle::SequenceAgentLayer - :members: - -GatherAgentLayer ----------------- -.. doxygenclass:: paddle::GatherAgentLayer - :members: - -SequenceGatherAgentLayer ------------------------- -.. doxygenclass:: paddle::SequenceGatherAgentLayer - :members: - -ScatterAgentLayer ------------------ -.. doxygenclass:: paddle::ScatterAgentLayer - :members: - -SequenceScatterAgentLayer -------------------------- -.. doxygenclass:: paddle::SequenceScatterAgentLayer - :members: - -GetOutputLayer --------------- -.. doxygenclass:: paddle::GetOutputLayer - :members: - -Mixed Layer -=========== -.. doxygenclass:: paddle::MixedLayer - :members: - -DotMulProjection ----------------- -.. doxygenclass:: paddle::DotMulProjection - :members: - -DotMulOperator --------------- -.. doxygenclass:: paddle::DotMulOperator - :members: - -FullMatrixProjection --------------------- -.. doxygenclass:: paddle::FullMatrixProjection - :members: - -IdentityProjection ------------------- -.. doxygenclass:: paddle::IdentityProjection - :members: - -IdentityOffsetProjection ------------------------- -.. doxygenclass:: paddle::IdentityOffsetProjection - :members: - -TableProjection ---------------- -.. doxygenclass:: paddle::TableProjection - :members: - -TransposedFullMatrixProjection ------------------------------- -.. doxygenclass:: paddle::TransposedFullMatrixProjection - :members: - -Aggregate Layers -================ - -Aggregate ---------- -AverageLayer -```````````` -.. doxygenclass:: paddle::AverageLayer - :members: - -MaxLayer -```````` -.. doxygenclass:: paddle::MaxLayer - :members: - -SequenceLastInstanceLayer -````````````````````````` -.. doxygenclass:: paddle::SequenceLastInstanceLayer - :members: - -Concat ------- -ConcatenateLayer -```````````````` -.. doxygenclass:: paddle::ConcatenateLayer - :members: - -ConcatenateLayer2 -````````````````` -.. doxygenclass:: paddle::ConcatenateLayer2 - :members: - -SequenceConcatLayer -``````````````````` -.. doxygenclass:: paddle::SequenceConcatLayer - :members: - -Subset ------- -SubSequenceLayer -```````````````` -.. doxygenclass:: paddle::SubSequenceLayer - :members: - -Reshaping Layers -================ - -BlockExpandLayer ----------------- -.. doxygenclass:: paddle::BlockExpandLayer - :members: - -ExpandLayer ------------ -.. doxygenclass:: paddle::ExpandLayer - :members: - -FeatureMapExpandLayer ---------------------- -.. doxygenclass:: paddle::FeatureMapExpandLayer - :members: - -ResizeLayer ------------ -.. doxygenclass:: paddle::ResizeLayer - :members: - -SequenceReshapeLayer --------------------- -.. doxygenclass:: paddle::SequenceReshapeLayer - :members: - -Math Layers -=========== - -AddtoLayer ----------- -.. doxygenclass:: paddle::AddtoLayer - :members: - -ConvexCombinationLayer ----------------------- -.. doxygenclass:: paddle::ConvexCombinationLayer - :members: - -InterpolationLayer ------------------- -.. doxygenclass:: paddle::InterpolationLayer - :members: - -MultiplexLayer --------------- -.. doxygenclass:: paddle::MultiplexLayer - :members: - -OuterProdLayer --------------- -.. doxygenclass:: paddle::OuterProdLayer - :members: - -PowerLayer ----------- -.. doxygenclass:: paddle::PowerLayer - :members: - -ScalingLayer ------------- -.. doxygenclass:: paddle::ScalingLayer - :members: - -SlopeInterceptLayer -------------------- -.. doxygenclass:: paddle::SlopeInterceptLayer - :members: - -TensorLayer ------------- -.. doxygenclass:: paddle::TensorLayer - :members: - -TransLayer ----------- -.. doxygenclass:: paddle::TransLayer - :members: - -Sampling Layers -=============== - -BilinearInterpLayer -------------------- -.. doxygenclass:: paddle::BilinearInterpLayer - :members: - -MultinomialSampler ------------------- -.. doxygenclass:: paddle::MultinomialSampler - :members: - -MaxIdLayer ----------- -.. doxygenclass:: paddle::MaxIdLayer - :members: - -SamplingIdLayer ---------------- -.. doxygenclass:: paddle::SamplingIdLayer - :members: - -Cost Layers -=========== - -CostLayer ------------ -.. doxygenclass:: paddle::CostLayer - :members: - -HuberTwoClass -````````````` -.. doxygenclass:: paddle::HuberTwoClass - :members: - -LambdaCost -``````````` -.. doxygenclass:: paddle::LambdaCost - :members: - -MultiBinaryLabelCrossEntropy -```````````````````````````` -.. doxygenclass:: paddle::MultiBinaryLabelCrossEntropy - :members: - -MultiClassCrossEntropy -``````````````````````` -.. doxygenclass:: paddle::MultiClassCrossEntropy - :members: - -MultiClassCrossEntropyWithSelfNorm -`````````````````````````````````` -.. doxygenclass:: paddle::MultiClassCrossEntropyWithSelfNorm - :members: - -RankingCost -``````````` -.. doxygenclass:: paddle::RankingCost - :members: - -SoftBinaryClassCrossEntropy -``````````````````````````` -.. doxygenclass:: paddle::SoftBinaryClassCrossEntropy - :members: - -SumOfSquaresCostLayer -````````````````````` -.. doxygenclass:: paddle::SumOfSquaresCostLayer - :members: - -SumCostLayer -````````````````````` -.. doxygenclass:: paddle::SumCostLayer - :members: - -CosSimLayer ------------ -.. doxygenclass:: paddle::CosSimLayer - :members: - -CosSimVecMatLayer ------------------ -.. doxygenclass:: paddle::CosSimVecMatLayer - :members: - -CRFDecodingLayer ----------------- -.. doxygenclass:: paddle::CRFDecodingLayer - :members: - -CRFLayer --------- -.. doxygenclass:: paddle::CRFLayer - :members: - -CTCLayer --------- -.. doxygenclass:: paddle::CTCLayer - :members: - -HierarchicalSigmoidLayer ------------------------- -.. doxygenclass:: paddle::HierarchicalSigmoidLayer - :members: - -LinearChainCRF --------------- -.. doxygenclass:: paddle::LinearChainCRF - :members: - -LinearChainCTC --------------- -.. doxygenclass:: paddle::LinearChainCTC - :members: - -NCELayer --------- -.. doxygenclass:: paddle::NCELayer - :members: - -Validation Layers ------------------ - -ValidationLayer -``````````````` -.. doxygenclass:: paddle::ValidationLayer - :members: - -AucValidation -````````````` -.. doxygenclass:: paddle::AucValidation - :members: - -PnpairValidation -```````````````` -.. doxygenclass:: paddle::PnpairValidation - :members: - -Check Layers -============ - -EosIdCheckLayer ---------------- -.. doxygenclass:: paddle::EosIdCheckLayer - :members: diff --git a/doc/howto/source/gserver/neworks.rst b/doc/howto/source/gserver/neworks.rst deleted file mode 100644 index 73fb60d549cc88f61d2e2d18c9ec31c37cf4fa9a..0000000000000000000000000000000000000000 --- a/doc/howto/source/gserver/neworks.rst +++ /dev/null @@ -1,12 +0,0 @@ -Networks -======== - -NeuralNetwork -------------- -.. doxygenclass:: paddle::NeuralNetwork - :members: - -ParallelNeuralNetwork ---------------------- -.. doxygenclass:: paddle::ParallelNeuralNetwork - :members: diff --git a/doc/howto/source/index.rst b/doc/howto/source/index.rst deleted file mode 100644 index 36323c888ee65147f59f28160dc26ca29235ba63..0000000000000000000000000000000000000000 --- a/doc/howto/source/index.rst +++ /dev/null @@ -1,14 +0,0 @@ -Source Code Documents -===================== - -.. toctree:: - :maxdepth: 1 - - gserver/index.rst - trainer.rst - parameter/index.rst - pserver/index.rst - api.rst - cuda/index.rst - math/index.rst - utils/index.rst diff --git a/doc/howto/source/math/functions.rst b/doc/howto/source/math/functions.rst deleted file mode 100644 index aef12e0f005226c6d40d74d0e858a11585339758..0000000000000000000000000000000000000000 --- a/doc/howto/source/math/functions.rst +++ /dev/null @@ -1,10 +0,0 @@ -Functions -========= - -MathFunctions -------------- -.. doxygenfile:: paddle/math/MathFunctions.h - -SIMDFunctions -------------- -.. doxygenfile:: paddle/math/SIMDFunctions.h diff --git a/doc/howto/source/math/index.rst b/doc/howto/source/math/index.rst deleted file mode 100644 index 2ec16f2b4450c870f9590aea4ad4ca7dc415b75d..0000000000000000000000000000000000000000 --- a/doc/howto/source/math/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -Math -==== - -.. toctree:: - :maxdepth: 2 - - vector.rst - matrix.rst - functions.rst - utils.rst diff --git a/doc/howto/source/math/matrix.rst b/doc/howto/source/math/matrix.rst deleted file mode 100644 index 9bb20f618d229e1baea15e26378bf40d7c6e1783..0000000000000000000000000000000000000000 --- a/doc/howto/source/math/matrix.rst +++ /dev/null @@ -1,76 +0,0 @@ -Matrix -====== - -Base ----- - -BaseMatrix Template -``````````````````` -.. doxygenclass:: paddle::BaseMatrixT - :members: - -Matrix -`````` -.. doxygenclass:: paddle::Matrix - :members: - -MatrixOffset -```````````` -.. doxygenclass:: paddle::MatrixOffset - :members: - -CpuMatrix ---------- - -CpuMatrix -````````` -.. doxygenclass:: paddle::CpuMatrix - :members: - -SharedCpuMatrix -``````````````` -.. doxygenclass:: paddle::SharedCpuMatrix - :members: - -GpuMatrix ---------- -.. doxygenclass:: paddle::GpuMatrix - :members: - -CpuSparseMatrix ---------------- - -CpuSparseMatrix -``````````````` -.. doxygenclass:: paddle::CpuSparseMatrix - :members: - -SparseRowCpuMatrix -`````````````````` -.. doxygenclass:: paddle::SparseRowCpuMatrix - :members: - -SparseAutoGrowRowCpuMatrix -`````````````````````````` -.. doxygenclass:: paddle::SparseAutoGrowRowCpuMatrix - :members: - -SparsePrefetchRowCpuMatrix -`````````````````````````` -.. doxygenclass:: paddle::SparsePrefetchRowCpuMatrix - :members: - -SparseRowIdsCpuMatrix -````````````````````` -.. doxygenclass:: paddle::SparseRowIdsCpuMatrix - :members: - -CacheRowCpuMatrix -````````````````` -.. doxygenclass:: paddle::CacheRowCpuMatrix - :members: - -GpuSparseMatrix ---------------- -.. doxygenclass:: paddle::GpuSparseMatrix - :members: diff --git a/doc/howto/source/math/utils.rst b/doc/howto/source/math/utils.rst deleted file mode 100644 index 55d9961a390c205563a9ae4fbd87ac4ae90fc314..0000000000000000000000000000000000000000 --- a/doc/howto/source/math/utils.rst +++ /dev/null @@ -1,18 +0,0 @@ -Memory Manager -============== - -Memory Handle -------------- -.. doxygenfile:: paddle/math/MemoryHandle.h - -Allocator ---------- -.. doxygenfile:: paddle/math/Allocator.h - -PoolAllocator -````````````` -.. doxygenfile:: paddle/math/PoolAllocator.h - -Storage -------- -.. doxygenfile:: paddle/math/Storage.h diff --git a/doc/howto/source/math/vector.rst b/doc/howto/source/math/vector.rst deleted file mode 100644 index 07f7062abaf4f30b8967b594f4e16ab881f5414f..0000000000000000000000000000000000000000 --- a/doc/howto/source/math/vector.rst +++ /dev/null @@ -1,37 +0,0 @@ -Vector -====== - -BaseVector -`````````` -.. doxygenclass:: paddle::BaseVector - :members: - -Vector Template -``````````````` -.. doxygenclass:: paddle::VectorT - :members: - -CpuVector Template -`````````````````` -.. doxygenclass:: paddle::CpuVectorT - :members: - -GpuVector Template -`````````````````` -.. doxygenclass:: paddle::GpuVectorT - :members: - -ParallelCpuVector Template -`````````````````````````` -.. doxygenclass:: paddle::ParallelCpuVectorT - :members: - -ParallelGpuVector Template -`````````````````````````` -.. doxygenclass:: paddle::ParallelGpuVectorT - :members: - -CpuGpuVector Template -````````````````````` -.. doxygenclass:: paddle::CpuGpuVectorT - :members: diff --git a/doc/howto/source/parameter/index.rst b/doc/howto/source/parameter/index.rst deleted file mode 100644 index 3bf6948dc3478574d8d125d8461235f8827e4e42..0000000000000000000000000000000000000000 --- a/doc/howto/source/parameter/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Parameter -========= - -.. toctree:: - :maxdepth: 2 - - parameter.rst - optimizer.rst - updater.rst diff --git a/doc/howto/source/parameter/optimizer.rst b/doc/howto/source/parameter/optimizer.rst deleted file mode 100644 index b5b8b850b349d547c9e5508d3ebec3d7e00ea310..0000000000000000000000000000000000000000 --- a/doc/howto/source/parameter/optimizer.rst +++ /dev/null @@ -1,22 +0,0 @@ -Optimizer -========= - -ParameterOptimizer ------------------- -.. doxygenfile:: paddle/parameter/ParameterOptimizer.h - -Regularizer ------------ -.. doxygenfile:: paddle/parameter/Regularizer.h - -FirstOrderOptimizer -------------------- -.. doxygenfile:: paddle/parameter/FirstOrderOptimizer.h - -AverageOptimizer ----------------- -.. doxygenfile:: paddle/parameter/AverageOptimizer.h - -OptimizerWithRegularizer ------------------------- -.. doxygenfile:: paddle/parameter/OptimizerWithRegularizer.h diff --git a/doc/howto/source/parameter/parameter.rst b/doc/howto/source/parameter/parameter.rst deleted file mode 100644 index 2daa62d4e63b952cd93bba35ee32ce35ce768a0d..0000000000000000000000000000000000000000 --- a/doc/howto/source/parameter/parameter.rst +++ /dev/null @@ -1,12 +0,0 @@ -Parameter -========= - -Parameter ---------- -.. doxygenfile:: paddle/parameter/Argument.h -.. doxygenfile:: paddle/parameter/Parameter.h -.. doxygenfile:: paddle/parameter/ParallelParameter.h - -Weight ------- -.. doxygenfile:: paddle/parameter/Weight.h diff --git a/doc/howto/source/parameter/updater.rst b/doc/howto/source/parameter/updater.rst deleted file mode 100644 index dfa22e8e7d1d6f0713974835de93194d2cc58e6f..0000000000000000000000000000000000000000 --- a/doc/howto/source/parameter/updater.rst +++ /dev/null @@ -1,14 +0,0 @@ -Updater -======= - -Base ----- -.. doxygenfile:: paddle/parameter/ParameterUpdaterBase.h - -Hook ----- -.. doxygenfile:: paddle/parameter/ParameterUpdaterHook.h - -Functions ---------- -.. doxygenfile:: paddle/parameter/ParameterUpdateFunctions.h diff --git a/doc/howto/source/pserver/client.rst b/doc/howto/source/pserver/client.rst deleted file mode 100644 index e5bba0706a1d919104b85e23861ba490a2c828db..0000000000000000000000000000000000000000 --- a/doc/howto/source/pserver/client.rst +++ /dev/null @@ -1,12 +0,0 @@ -Client -====== - -BaseClient ----------- -.. doxygenclass:: paddle::BaseClient - :members: - -ParameterClient2 ----------------- -.. doxygenclass:: paddle::ParameterClient2 - :members: diff --git a/doc/howto/source/pserver/index.rst b/doc/howto/source/pserver/index.rst deleted file mode 100644 index 0031e9476bd063511cc2f0a8c209f35627cf44ba..0000000000000000000000000000000000000000 --- a/doc/howto/source/pserver/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -PServer -======= - -.. toctree:: - :maxdepth: 2 - - client.rst - network.rst - server.rst - utils.rst diff --git a/doc/howto/source/pserver/network.rst b/doc/howto/source/pserver/network.rst deleted file mode 100644 index 7004c9d91fa9f2af11e15791ef682c108761027e..0000000000000000000000000000000000000000 --- a/doc/howto/source/pserver/network.rst +++ /dev/null @@ -1,27 +0,0 @@ -Network -======= - -SocketServer ------------- -.. doxygenclass:: paddle::SocketServer - :members: - -SocketWorker ------------- -.. doxygenclass:: paddle::SocketWorker - :members: - -SocketClient ------------- -.. doxygenclass:: paddle::SocketClient - :members: - -SocketChannel -------------- -.. doxygenclass:: paddle::SocketChannel - :members: - -MessageReader -------------- -.. doxygenclass:: paddle::MsgReader - :members: diff --git a/doc/howto/source/pserver/server.rst b/doc/howto/source/pserver/server.rst deleted file mode 100644 index 35301acf8ffe3d97e6124c37cf8fe1b43071e14e..0000000000000000000000000000000000000000 --- a/doc/howto/source/pserver/server.rst +++ /dev/null @@ -1,12 +0,0 @@ -Server -====== - -ProtoServer ------------ -.. doxygenclass:: paddle::ProtoServer - :members: - -ParameterServer2 ----------------- -.. doxygenclass:: paddle::ParameterServer2 - :members: diff --git a/doc/howto/source/trainer.rst b/doc/howto/source/trainer.rst deleted file mode 100644 index 85f1feb4fc941f94e65a6b1d037445d2367f65ec..0000000000000000000000000000000000000000 --- a/doc/howto/source/trainer.rst +++ /dev/null @@ -1,32 +0,0 @@ -Trainer -======= - -TrainerStats ------------- - -.. doxygenclass:: paddle::TrainerStats - :members: - -RemoteParameterUpdater ------------------------ - -.. doxygenclass:: paddle::RemoteParameterUpdater - :members: - -ConcurrentRemoteParameterUpdater --------------------------------- - -.. doxygenclass:: paddle::ConcurrentRemoteParameterUpdater - :members: - -SparseRemoteParameterUpdater ----------------------------- - -.. doxygenclass:: paddle::SparseRemoteParameterUpdater - :members: - -SparseRemoteParameterUpdaterComposite -------------------------------------- - -.. doxygenclass:: paddle::SparseRemoteParameterUpdaterComposite - :members: diff --git a/doc/howto/source/utils/customStackTrace.rst b/doc/howto/source/utils/customStackTrace.rst deleted file mode 100644 index cdc8930739eb4b4d6308ff1fbce170d2977d42e8..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/customStackTrace.rst +++ /dev/null @@ -1,4 +0,0 @@ -CustomStackTrace -================ -.. doxygenclass:: paddle::CustomStackTrace - :members: diff --git a/doc/howto/source/utils/enum.rst b/doc/howto/source/utils/enum.rst deleted file mode 100644 index e0da75afe164f9dab59b862faa7230fc57423e50..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/enum.rst +++ /dev/null @@ -1,3 +0,0 @@ -Enumeration wrapper -=================== -.. doxygennamespace:: paddle::enumeration_wrapper diff --git a/doc/howto/source/utils/index.rst b/doc/howto/source/utils/index.rst deleted file mode 100644 index 7ddc47d1726f7627852be922d2b769d0752aa799..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -Utils -===== - -.. toctree:: - :maxdepth: 2 - - lock.rst - queue.rst - thread.rst - customStackTrace.rst - enum.rst diff --git a/doc/howto/source/utils/lock.rst b/doc/howto/source/utils/lock.rst deleted file mode 100644 index f011acb9431f0f3dc3b2ba27fcfe71fe6eb07ae9..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/lock.rst +++ /dev/null @@ -1,32 +0,0 @@ -Lock -==== - -RWLock ------- -.. doxygenclass:: paddle::RWLock - :members: - -ReadLockGuard -------------- -.. doxygenclass:: paddle::ReadLockGuard - :members: - -SpinLock --------- -.. doxygenclass:: paddle::SpinLock - :members: - -Semaphore ---------- -.. doxygenclass:: paddle::Semaphore - :members: - -ThreadBarrier -------------- -.. doxygenclass:: paddle::ThreadBarrier - :members: - -LockedCondition ---------------- -.. doxygenclass:: paddle::LockedCondition - :members: diff --git a/doc/howto/source/utils/queue.rst b/doc/howto/source/utils/queue.rst deleted file mode 100644 index 98192648e2d61e622c2337d10ba024dd676ee685..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/queue.rst +++ /dev/null @@ -1,12 +0,0 @@ -Queue -===== - -Queue ------ -.. doxygenclass:: paddle::Queue - :members: - -BlockingQueue -------------- -.. doxygenclass:: paddle::BlockingQueue - :members: diff --git a/doc/howto/source/utils/thread.rst b/doc/howto/source/utils/thread.rst deleted file mode 100644 index 23d379a9894e5fc22bc6795a480a53d768e608e6..0000000000000000000000000000000000000000 --- a/doc/howto/source/utils/thread.rst +++ /dev/null @@ -1,27 +0,0 @@ -Thread -====== - -Thread ------- -.. doxygenclass:: paddle::Thread - :members: - -ThreadWorker ------------- -.. doxygenclass:: paddle::ThreadWorker - :members: - -SyncThreadPool --------------- -.. doxygenclass:: paddle::SyncThreadPool - :members: - -MultiThreadWorker ------------------ -.. doxygenclass:: paddle::MultiThreadWorker - :members: - -AsyncThreadPool ---------------- -.. doxygenclass:: paddle::AsyncThreadPool - :members: diff --git a/doc/tutorials/quick_start/index_en.md b/doc/tutorials/quick_start/index_en.md index ec548b5393d7b210d6409328c00917aeb679a451..29637293fad79f3c3b9aabe83b71758b471b9338 100644 --- a/doc/tutorials/quick_start/index_en.md +++ b/doc/tutorials/quick_start/index_en.md @@ -12,7 +12,7 @@ This tutorial will teach the basics of deep learning (DL), including how to impl To get started, please install PaddlePaddle on your computer. Throughout this tutorial, you will learn by implementing different DL models for text classification. -To install PaddlePaddle, please follow the instructions here: Build and Install. +To install PaddlePaddle, please follow the instructions here: Build and Install. ## Overview For the first step, you will use PaddlePaddle to build a **text classification** system. For example, suppose you run an e-commence website, and you want to analyze the sentiment of user reviews to evaluate product quality. @@ -156,14 +156,14 @@ define_py_data_sources2(train_list='data/train.list', obj="process", args={"dictionary": word_dict}) ``` -You can refer to the following link for more detailed examples and data formats: PyDataProvider2. +You can refer to the following link for more detailed examples and data formats: PyDataProvider2. ## Network Architecture You will describe four kinds of network architectures in this section.
![](./PipelineNetwork_en.jpg)
First, you will build a logistic regression model. Later, you will also get chance to build other more powerful network architectures. -For more detailed documentation, you could refer to: Layer documentation。All configuration files are in `demo/quick_start` directory. +For more detailed documentation, you could refer to: layer documentation. All configuration files are in `demo/quick_start` directory. ### Logistic Regression The architecture is illustrated in the following picture: @@ -366,7 +366,7 @@ You can use single layer LSTM model with Dropout for our text classification pro
## Optimization Algorithm -Optimization algorithms include Momentum, RMSProp, AdaDelta, AdaGrad, Adam, and Adamax. You can use Adam optimization method here, with L2 regularization and gradient clipping, because Adam has been proved to work very well for training recurrent neural network. +Optimization algorithms include Momentum, RMSProp, AdaDelta, AdaGrad, Adam, and Adamax. You can use Adam optimization method here, with L2 regularization and gradient clipping, because Adam has been proved to work very well for training recurrent neural network. ```python settings(batch_size=128, @@ -391,7 +391,8 @@ paddle train \ --use_gpu=false ``` -If you want to install the remote training platform, which enables distributed training on clusters, follow the instructions here: Platform documentation. We do not provide examples on how to train on clusters. Please refer to other demos or platform training documentation for mode details on training on clusters. +We do not provide examples on how to train on clusters here. If you want to train on clusters, please follow the distributed training documentation or other demos for more details. + ## Inference You can use the trained model to perform prediction on the dataset with no labels. You can also evaluate the model on dataset with labels to obtain its test accuracy.
![](./PipelineTest_en.png)
@@ -406,7 +407,7 @@ paddle train \ --init_model_path=./output/pass-0000x ``` -We will give an example of performing prediction using Recurrent model on a dataset with no labels. You can refer to: Python Prediction API tutorial,or other demo for the prediction process using Python. You can also use the following script for inference or evaluation. +We will give an example of performing prediction using Recurrent model on a dataset with no labels. You can refer to Python Prediction API tutorial,or other demo for the prediction process using Python. You can also use the following script for inference or evaluation. inference script (predict.sh): @@ -508,7 +509,7 @@ The scripts of data downloading, network configurations, and training scrips are * \--config_args:Other configuration arguments. * \--init_model_path:The path of the initial model parameter. -By default, the trainer will save model every pass. You can also specify `saving_period_by_batches` to set the frequency of batch saving. You can use `show_parameter_stats_period` to print the statistics of the parameters, which are very useful for tuning parameters. Other command line arguments can be found in command line argument documentation。 +By default, the trainer will save model every pass. You can also specify `saving_period_by_batches` to set the frequency of batch saving. You can use `show_parameter_stats_period` to print the statistics of the parameters, which are very useful for tuning parameters. Other command line arguments can be found in command line argument documentation。 ### Log diff --git a/doc/tutorials/rec/ml_dataset_en.md b/doc/tutorials/rec/ml_dataset_en.md index c93a4585e4027b1912da8a77c2562d1ee69c5366..dc11a5e06031b62d9f86e4dd83a14b2f1a72afc3 100644 --- a/doc/tutorials/rec/ml_dataset_en.md +++ b/doc/tutorials/rec/ml_dataset_en.md @@ -1,3 +1,8 @@ +```eval_rst +.. _demo_ml_dataset_en: + +``` + # MovieLens Dataset The [MovieLens Dataset](http://grouplens.org/datasets/movielens/) was collected by GroupLens Research. diff --git a/doc/tutorials/rec/ml_regression_en.rst b/doc/tutorials/rec/ml_regression_en.rst index 0c14e4f5bb7f815a06c0c756b1a6e6ef9099fd66..ddc00dc706535e1204b033b505ee8bd579f8dea3 100644 --- a/doc/tutorials/rec/ml_regression_en.rst +++ b/doc/tutorials/rec/ml_regression_en.rst @@ -16,7 +16,7 @@ Data Preparation ```````````````` Download and extract dataset '''''''''''''''''''''''''''' -We use `movielens 1m dataset `_ here. +We use :ref:`demo_ml_dataset_en` here. To download and unzip the dataset, simply run the following commands. .. code-block:: bash @@ -239,26 +239,16 @@ Then we combine each features of movie into one movie feature by a get one user feature. Then we calculate the cosine similarity of these two features. -In these network, we use several api in `trainer_config_helpers -<../../ui/api/trainer_config_helpers/index.html>`_. There are - -* Data Layer, `data_layer - <../../ui/api/trainer_config_helpers/layers.html#id1>`_ -* Fully Connected Layer, `fc_layer - <../../ui/api/trainer_config_helpers/layers.html#fc-layer>`_ -* Embedding Layer, `embedding_layer - <../../ui/api/trainer_config_helpers/layers.html#embedding-layer>`_ -* Context Projection Layer, `context_projection - <../../ui/api/trainer_config_helpers/layers.html#context-projection>`_ -* Pooling Layer, `pooling_layer - <../../ui/api/trainer_config_helpers/layers.html#pooling-layer>`_ -* Cosine Similarity Layer, `cos_sim - <../../ui/api/trainer_config_helpers/layers.html#cos-sim>`_ -* Text Convolution Pooling Layer, `text_conv_pool - <../../ui/api/trainer_config_helpers/networks.html - #trainer_config_helpers.networks.text_conv_pool>`_ -* Declare Python Data Sources, `define_py_data_sources2 - <../../ui/api/trainer_config_helpers/data_sources.html>`_ +In these network, we use several api in :ref:`api_trainer_config` . There are + +* Data Layer, :ref:`api_trainer_config_helpers_layers_data_layer` +* Fully Connected Layer, :ref:`api_trainer_config_helpers_layers_fc_layer` +* Embedding Layer, :ref:`api_trainer_config_helpers_layers_embedding_layer` +* Context Projection Layer, :ref:`api_trainer_config_helpers_layers_context_projection` +* Pooling Layer, :ref:`api_trainer_config_helpers_layers_pooling_layer` +* Cosine Similarity Layer, :ref:`api_trainer_config_helpers_layers_cos_sim` +* Text Convolution Pooling Layer, :ref:`api_trainer_config_helpers_network_text_conv_pool` +* Declare Python Data Sources :ref:`api_trainer_config_helpers_data_sources`. Data Provider ''''''''''''' @@ -274,7 +264,7 @@ In this :code:`dataprovider.py`, we should set\: * use_seq\: Whether this :code:`dataprovider.py` in sequence mode or not. * process\: Return each sample of data to :code:`paddle`. -The data provider details document see `there <../../ui/data_provider/pydataprovider2.html>`_. +The data provider details document see :ref:`api_pydataprovider`. Train ````` @@ -290,8 +280,7 @@ The run.sh is shown as follow: It just start a paddle training process, write the log to `log.txt`, then print it on screen. -Each command line argument in :code:`run.sh`, please refer to the `command line -arguments <../../ui/index.html#command-line-argument>`_ page. The short description of these arguments is shown as follow. +Each command line argument in :code:`run.sh`, please refer to the :ref:`cmd_line_index_en` page. The short description of these arguments is shown as follow. * config\: Tell paddle which file is neural network configuration. * save_dir\: Tell paddle save model into './output' diff --git a/doc/tutorials/semantic_role_labeling/index_cn.md b/doc/tutorials/semantic_role_labeling/index_cn.md new file mode 100644 index 0000000000000000000000000000000000000000..c7e0a78f5071ed0d1702036f4ee0af3881096c68 --- /dev/null +++ b/doc/tutorials/semantic_role_labeling/index_cn.md @@ -0,0 +1,201 @@ +# 语义角色标注教程 # + +语义角色标注(Semantic role labeling, SRL)是浅层语义解析的一种形式,其目的是在给定的输入句子中发现每个谓词的谓词论元结构。 SRL作为很多自然语言处理任务中的中间步骤是很有用的,如信息提取、文档自动分类和问答。 实例如下 [1]: + + [ A0 He ] [ AM-MOD would ][ AM-NEG n’t ] [ V accept] [ A1 anything of value ] from [A2 those he was writing about ]. + +- V: 动词 +- A0: 接受者 +- A1: 接受的东西 +- A2: 从……接受 +- A3: 属性 +- AM-MOD: 情态动词 +- AM-NEG: 否定 + +给定动词“accept”,句子中的组块将会扮演某些语义角色。这里,标签方案来自 Penn Proposition Bank。 + +到目前为止,大多数成功的SRL系统是建立在某种形式的句法分析结果之上的,使用了基于句法结构的预定义特征模板。 本教程将介绍使用深度双向长短期记忆(DB-LSTM)模型[2]的端到端系统来解决SRL任务,这在很大程度上优于先前的最先进的系统。 这个系统将SRL任务视为序列标注问题。 + +## 数据描述 +相关论文[2]采用 CoNLL-2005&2012 共享任务中设置的数据进行训练和测试。由于数据许可的原因,演示采用 CoNLL-2005 的测试数据集,可以在网站上找到。 + +用户只需执行以下命令就可以下载并处理原始数据: + +```bash +cd data +./get_data.sh +``` +`data `目录会出现如下几个新的文件: +```bash +conll05st-release:the test data set of CoNll-2005 shared task +test.wsj.words:the Wall Street Journal data sentences +test.wsj.props: the propositional arguments +feature: the extracted features from data set +``` + +## 训练 +### DB-LSTM +请参阅情感分析的演示以了解有关长期短期记忆单元的更多信息。 + +与在 Sentiment Analysis 演示中使用的 Bidirectional-LSTM 不同,DB-LSTM 采用另一种方法来堆叠LSTM层。首先,标准LSTM以正向处理该序列。该 LSTM 层的输入和输出作为下一个 LSTM 层的输入,并被反向处理。这两个标准 LSTM 层组成一对 LSTM。然后我们堆叠一对对的 LSTM 层后得到深度 LSTM 模型。 + +下图展示了时间扩展的2层 DB-LSTM 网络。 +
+![pic](./network_arch.png) +
+ +### 特征 +两个输入特征在这个流程中起着至关重要的作用:predicate(pred)和argument(arguments)。 还采用了两个其他特征:谓词上下文(ctx-p)和区域标记(mr)。 因为单个谓词不能精确地描述谓词信息,特别是当相同的词在句子中出现多于一次时。 使用谓词上下文,可以在很大程度上消除歧义。类似地,如果它位于谓词上下文区域中,则使用区域标记 mr = 1 来表示参数位置,反之则 mr = 0。这四个简单的特征是我们的SRL系统所需要的。上下文大小设置为1的一个样本的特征如下[2]所示: +
+![pic](./feature.jpg) +
+ +在这个示例中,相应的标记句子是: + +[ A1 A record date ] has [ AM-NEG n't ] been [ V set ] . + +在演示中, 我们采用上面的特征模板, 包括: `argument`, `predicate`, `ctx-p (p=-1,0,1)`, `mark` 并使用 `B/I/O` 方案来标记每个参数。这些特征和标签存储在 `feature` 文件中, 用`\t`分割。 + +### 数据提供 + +`dataprovider.py` 是一个包装数据的 Python 文件。 函数 `hook()` 定义了网络的数据槽。六个特征和标签都是索引槽。 +``` +def hook(settings, word_dict, label_dict, **kwargs): + settings.word_dict = word_dict + settings.label_dict = label_dict + #all inputs are integral and sequential type + settings.slots = [ + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(predicate_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(2), + integer_value_sequence(len(label_dict))] +``` +相应的数据迭代器如下: +``` +@provider(init_hook=hook, should_shuffle=True, calc_batch_size=get_batch_size, + can_over_batch_size=False, cache=CacheType.CACHE_PASS_IN_MEM) +def process(settings, file_name): + with open(file_name, 'r') as fdata: + for line in fdata: + sentence, predicate, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, mark, label = \ + line.strip().split('\t') + + words = sentence.split() + sen_len = len(words) + word_slot = [settings.word_dict.get(w, UNK_IDX) for w in words] + + predicate_slot = [settings.predicate_dict.get(predicate)] * sen_len + ctx_n2_slot = [settings.word_dict.get(ctx_n2, UNK_IDX)] * sen_len + ctx_n1_slot = [settings.word_dict.get(ctx_n1, UNK_IDX)] * sen_len + ctx_0_slot = [settings.word_dict.get(ctx_0, UNK_IDX)] * sen_len + ctx_p1_slot = [settings.word_dict.get(ctx_p1, UNK_IDX)] * sen_len + ctx_p2_slot = [settings.word_dict.get(ctx_p2, UNK_IDX)] * sen_len + + marks = mark.split() + mark_slot = [int(w) for w in marks] + + label_list = label.split() + label_slot = [settings.label_dict.get(w) for w in label_list] + yield word_slot, predicate_slot, ctx_n2_slot, ctx_n1_slot, \ + ctx_0_slot, ctx_p1_slot, ctx_p2_slot, mark_slot, label_slot +``` +函数 `process` 返回8个特征list和1个标签list。 + +### 神经网络配置 + +`db_lstm.py` 是在训练过程中加载字典并定义数据提供程序模块和网络架构的神经网络配置文件。 + +九个 `data_layer` 从数据提供程序加载实例。八个特征分别转换为向量,并由`mixed_layer`混合。 深度双向LSTM层提取softmax层的特征。目标函数是标签的交叉熵。 + +### 训练 +训练的脚本是 `train.sh`,用户只需执行: +```bash + ./train.sh +``` +`train.sh` 中的内容: +``` +paddle train \ + --config=./db_lstm.py \ + --use_gpu=0 \ + --log_period=5000 \ + --trainer_count=1 \ + --show_parameter_stats_period=5000 \ + --save_dir=./output \ + --num_passes=10000 \ + --average_test_period=10000000 \ + --init_model_path=./data \ + --load_missing_parameter_strategy=rand \ + --test_all_data_in_one_period=1 \ +2>&1 | tee 'train.log' +``` + +- \--config=./db_lstm.py : 网络配置文件 +- \--use_gpu=false: 使用 CPU 训练(如果已安装 PaddlePaddle GPU版本并想使用 GPU 训练可以设置为true,目前 crf_layer 不支持 GPU) +- \--log_period=500: 每20个batch输出日志 +- \--trainer_count=1: 设置线程数(或 GPU 数) +- \--show_parameter_stats_period=5000: 每100个batch显示参数统计 +- \--save_dir=./output: 模型输出路径 +- \--num_passes=10000: 设置数据遍历次数,一个pass意味着PaddlePaddle训练数据集中的所有样本被遍历一次 +- \--average_test_period=10000000: 每个 average_test_period 批次对平均参数进行测试 +- \--init_model_path=./data: 参数初始化路径 +- \--load_missing_parameter_strategy=rand: 随机初始不存在的参数 +- \--test_all_data_in_one_period=1: 在一个周期内测试所有数据 + + +训练后,模型将保存在目录`output`中。 我们的训练曲线如下: +
+![pic](./curve.jpg) +
+ +### 测试 +测试脚本是 `test.sh`, 执行: +```bash + ./test.sh +``` +`tesh.sh` 的主要部分: +``` +paddle train \ + --config=./db_lstm.py \ + --model_list=$model_list \ + --job=test \ + --config_args=is_test=1 \ +``` + + - \--config=./db_lstm.py: 网络配置文件 + - \--model_list=$model_list.list: 模型列表文件 + - \--job=test: 指示测试任务 + - \--config_args=is_test=1: 指示测试任务的标记 + - \--test_all_data_in_one_period=1: 在一个周期内测试所有数据 + + +### 预测 +预测脚本是 `predict.sh`,用户只需执行: +```bash + ./predict.sh + +``` +在`predict.sh`中,用户应该提供网络配置文件,模型路径,标签文件,字典文件,特征文件。 +``` +python predict.py + -c $config_file \ + -w $best_model_path \ + -l $label_file \ + -p $predicate_dict_file \ + -d $dict_file \ + -i $input_file \ + -o $output_file +``` + +`predict.py` 是主要的可执行python脚本,其中包括函数:加载模型,加载数据,数据预测。网络模型将输出标签的概率分布。 在演示中,我们使用最大概率的标签作为结果。用户还可以根据概率分布矩阵实现柱搜索或维特比解码。 + +预测后,结果保存在 `predict.res` 中。 + +## 引用 +[1] Martha Palmer, Dan Gildea, and Paul Kingsbury. The Proposition Bank: An Annotated Corpus of Semantic Roles , Computational Linguistics, 31(1), 2005. + +[2] Zhou, Jie, and Wei Xu. "End-to-end learning of semantic role labeling using recurrent neural networks." Proceedings of the Annual Meeting of the Association for Computational Linguistics. 2015. diff --git a/doc/tutorials/semantic_role_labeling/semantic_role_labeling_cn.md b/doc/tutorials/semantic_role_labeling/semantic_role_labeling_cn.md new file mode 100644 index 0000000000000000000000000000000000000000..f3c855a9fd72b894ab69050b08c750fe9e4aa1a2 --- /dev/null +++ b/doc/tutorials/semantic_role_labeling/semantic_role_labeling_cn.md @@ -0,0 +1,201 @@ +# 语义角色标注教程 # + +语义角色标注(Semantic role labeling, SRL)是浅语义解析的一种形式,其目的是在给定的输入句子中发现每个谓词的谓词参数结构。 SRL作为很多自然语言处理任务中的中间步骤是很有用的,如信息提取、文档自动分类和问答。 实例如下 [1]: + + [ A0 他 ] [ AM-MOD 将 ][ AM-NEG 不会 ] [ V 接受] [ A1 任何东西 ] 从 [A2 那些他写的东西中 ]。 + +- V: 动词 +- A0: 接受者 +- A1: 接受的东西 +- A2: 从……接受 +- A3: 属性 +- AM-MOD: 情态动词 +- AM-NEG: 否定 + +给定动词“接受”,句子中的大部分将会扮演某些语义角色。这里,标签方案来自 Penn Proposition Bank。 + +到目前为止,大多数成功的SRL系统是建立在某种形式的解析结果之上的,其中在语法结构上使用了预先定义的特征模板。 本教程将介绍使用深度双向长短期记忆(DB-LSTM)模型[2]的端到端系统来解决SRL任务,这在很大程度上优于先前的最先进的系统。 这个系统将SRL任务视为序列标记问题。 + +## 数据描述 +相关论文[2]采用 CoNLL-2005&2012 共享任务中设置的数据进行训练和测试。根据数据许可证,演示采用 CoNLL-2005 的测试数据集,可以在网站上找到。 + +用户只需执行以下命令就可以下载并处理原始数据: + +```bash +cd data +./get_data.sh +``` +`data `目录会出现如下几个新的文件: +```bash +conll05st-release:the test data set of CoNll-2005 shared task +test.wsj.words:the Wall Street Journal data sentences +test.wsj.props: the propositional arguments +feature: the extracted features from data set +``` + +## 训练 +### DB-LSTM +请参阅情绪分析的演示以了解有关长期短期记忆单元的更多信息。 + +与在 Sentiment Analysis 演示中使用的 Bidirectional-LSTM 不同,DB-LSTM 采用另一种方法来堆叠LSTM层。首先,标准LSTM以正向处理该序列。该 LSTM 层的输入和输出作为下一个 LSTM 层的输入,并被反向处理。这两个标准 LSTM 层组成一对 LSTM。然后我们堆叠一对对的 LSTM 层后得到深度 LSTM 模型。 + +下图展示了时间扩展的2层 DB-LSTM 网络。 +
+![pic](./network_arch.png) +
+ +### 特征 +两个输入特性在这个管道中起着至关重要的作用:predicate(pred)和argument(arguments)。 还采用了两个其他特征:谓词上下文(ctx-p)和区域标记(mr)。 因为单个谓词不能精确地描述谓词信息,特别是当相同的词在句子中出现多于一次时。 使用谓词上下文,可以在很大程度上消除歧义。类似地,如果它位于谓词上下文区域中,则使用区域标记 mr = 1 来表示参数位置,反之则 mr = 0。这四个简单的特征是我们的SRL系统所需要的。上下文大小设置为1的一个样本的特征如下[2]所示: +
+![pic](./feature.jpg) +
+ +在这个示例中,相应的标记句子是: + +[ A1 A record date ] has [ AM-NEG n't ] been [ V set ] . + +在演示中, 我们采用上面的特征模板, 包括: `argument`, `predicate`, `ctx-p (p=-1,0,1)`, `mark` 并使用 `B/I/O` 方案来标记每个参数。这些特征和标签存储在 `feature` 文件中, 用`\t`分割。 + +### 数据提供 + +`dataprovider.py` 是一个包装数据的 Python 文件。 函数 `hook()` 定义了网络的数据槽。六个特征和标签都是索引槽。 +``` +def hook(settings, word_dict, label_dict, **kwargs): + settings.word_dict = word_dict + settings.label_dict = label_dict + #all inputs are integral and sequential type + settings.slots = [ + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(predicate_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(len(word_dict)), + integer_value_sequence(2), + integer_value_sequence(len(label_dict))] +``` +相应的数据迭代器如下: +``` +@provider(init_hook=hook, should_shuffle=True, calc_batch_size=get_batch_size, + can_over_batch_size=False, cache=CacheType.CACHE_PASS_IN_MEM) +def process(settings, file_name): + with open(file_name, 'r') as fdata: + for line in fdata: + sentence, predicate, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, mark, label = \ + line.strip().split('\t') + + words = sentence.split() + sen_len = len(words) + word_slot = [settings.word_dict.get(w, UNK_IDX) for w in words] + + predicate_slot = [settings.predicate_dict.get(predicate)] * sen_len + ctx_n2_slot = [settings.word_dict.get(ctx_n2, UNK_IDX)] * sen_len + ctx_n1_slot = [settings.word_dict.get(ctx_n1, UNK_IDX)] * sen_len + ctx_0_slot = [settings.word_dict.get(ctx_0, UNK_IDX)] * sen_len + ctx_p1_slot = [settings.word_dict.get(ctx_p1, UNK_IDX)] * sen_len + ctx_p2_slot = [settings.word_dict.get(ctx_p2, UNK_IDX)] * sen_len + + marks = mark.split() + mark_slot = [int(w) for w in marks] + + label_list = label.split() + label_slot = [settings.label_dict.get(w) for w in label_list] + yield word_slot, predicate_slot, ctx_n2_slot, ctx_n1_slot, \ + ctx_0_slot, ctx_p1_slot, ctx_p2_slot, mark_slot, label_slot +``` +函数 `process` 产出有8个特征和标签的9个表。 + +### 神经网络配置 + +`db_lstm.py` 是在训练过程中加载字典并定义数据提供程序模块和网络架构的神经网络配置文件。 + +九个 `data_layer` 从数据提供程序加载实例。八个特征分别转换为嵌入,并由`mixed_layer`混合。 深度双向LSTM层提取softmax层的特征。目标函数是标签的交叉熵。 + +### 训练 +训练的脚本是 `train.sh`,用户只需执行: +```bash + ./train.sh +``` +`train.sh` 中的内容: +``` +paddle train \ + --config=./db_lstm.py \ + --use_gpu=0 \ + --log_period=5000 \ + --trainer_count=1 \ + --show_parameter_stats_period=5000 \ + --save_dir=./output \ + --num_passes=10000 \ + --average_test_period=10000000 \ + --init_model_path=./data \ + --load_missing_parameter_strategy=rand \ + --test_all_data_in_one_period=1 \ +2>&1 | tee 'train.log' +``` + +- \--config=./db_lstm.py : 网络配置文件 +- \--use_gpu=false: 使用 CPU 训练(如果已安装 PaddlePaddle GPU版本并想使用 GPU 训练可以设置为true,目前 crf_layer 不支持 GPU) +- \--log_period=500: 每20批(batch)输出日志 +- \--trainer_count=1: 设置线程数(或 GPU 数) +- \--show_parameter_stats_period=5000: 每100批显示参数统计 +- \--save_dir=./output: 模型输出路径 +- \--num_passes=10000: 设置通过数,一次通过意味着PaddlePaddle训练数据集中的所有样本一次 +- \--average_test_period=10000000: 每个 average_test_period 批次对平均参数进行测试 +- \--init_model_path=./data: 参数初始化路径 +- \--load_missing_parameter_strategy=rand: 随机初始不存在的参数 +- \--test_all_data_in_one_period=1: 在一个周期内测试所有数据 + + +训练后,模型将保存在目录`output`中。 我们的训练曲线如下: +
+![pic](./curve.jpg) +
+ +### 测试 +测试脚本是 `test.sh`, 执行: +```bash + ./test.sh +``` +`tesh.sh` 的主要部分: +``` +paddle train \ + --config=./db_lstm.py \ + --model_list=$model_list \ + --job=test \ + --config_args=is_test=1 \ +``` + + - \--config=./db_lstm.py: 网络配置文件 + - \--model_list=$model_list.list: 模型列表文件 + - \--job=test: 指示测试任务 + - \--config_args=is_test=1: 指示测试任务的标记 + - \--test_all_data_in_one_period=1: 在一个周期内测试所有数据 + + +### 预测 +预测脚本是 `predict.sh`,用户只需执行: +```bash + ./predict.sh + +``` +在`predict.sh`中,用户应该提供网络配置文件,模型路径,标签文件,字典文件,特征文件。 +``` +python predict.py + -c $config_file \ + -w $best_model_path \ + -l $label_file \ + -p $predicate_dict_file \ + -d $dict_file \ + -i $input_file \ + -o $output_file +``` + +`predict.py` 是主要的可执行python脚本,其中包括函数:加载模型,加载数据,数据预测。网络模型将输出标签的概率分布。 在演示中,我们使用最大概率的标签作为结果。用户还可以根据概率分布矩阵实现集束搜索或维特比解码。 + +预测后,结果保存在 `predict.res` 中。 + +## 引用 +[1] Martha Palmer, Dan Gildea, and Paul Kingsbury. The Proposition Bank: An Annotated Corpus of Semantic Roles , Computational Linguistics, 31(1), 2005. + +[2] Zhou, Jie, and Wei Xu. "End-to-end learning of semantic role labeling using recurrent neural networks." Proceedings of the Annual Meeting of the Association for Computational Linguistics. 2015. diff --git a/doc/tutorials/sentiment_analysis/index_en.md b/doc/tutorials/sentiment_analysis/index_en.md index c53952c544de9fa88a6318432e34b0d05b149445..bb7681db44ca6f286ad6935ddfecb9becb429192 100644 --- a/doc/tutorials/sentiment_analysis/index_en.md +++ b/doc/tutorials/sentiment_analysis/index_en.md @@ -293,20 +293,21 @@ predict.sh: model=model_output/pass-00002/ config=trainer_config.py label=data/pre-imdb/labels.list -python predict.py \ - -n $config\ - -w $model \ - -b $label \ - -d data/pre-imdb/dict.txt \ - -i data/aclImdb/test/pos/10007_10.txt -``` - -* `predict.py`: predicting interface. -* -n $config : set network configure. -* -w $model: set model path. -* -b $label: set dictionary about corresponding relation between integer label and string label. -* -d data/pre-imdb/dict.txt: set dictionary. -* -i data/aclImdb/test/pos/10014_7.txt: set one example file to predict. +cat ./data/aclImdb/test/pos/10007_10.txt | python predict.py \ + --tconf=$config\ + --model=$model \ + --label=$label \ + --dict=./data/pre-imdb/dict.txt \ + --batch_size=1 +``` + +* `cat ./data/aclImdb/test/pos/10007_10.txt` : the input sample. +* `predict.py` : predicting interface. +* `--tconf=$config` : set network configure. +* ` --model=$model` : set model path. +* `--label=$label` : set dictionary about corresponding relation between integer label and string label. +* `--dict=data/pre-imdb/dict.txt` : set dictionary. +* `--batch_size=1` : set batch size. Note you should make sure the default model path `model_output/pass-00002` exists or change the model path. diff --git a/doc_cn/demo/sentiment_analysis/sentiment_analysis.md b/doc_cn/demo/sentiment_analysis/sentiment_analysis.md index b70f2d59675615c26b29932cdf99d728bb206148..ba307e97e3010629548460e25e894d082a6ddd4e 100644 --- a/doc_cn/demo/sentiment_analysis/sentiment_analysis.md +++ b/doc_cn/demo/sentiment_analysis/sentiment_analysis.md @@ -291,20 +291,21 @@ predict.sh: model=model_output/pass-00002/ config=trainer_config.py label=data/pre-imdb/labels.list -python predict.py \ - -n $config\ - -w $model \ - -b $label \ - -d data/pre-imdb/dict.txt \ - -i data/aclImdb/test/pos/10007_10.txt -``` - -* `predict.py`: 预测接口脚本。 -* -n $config : 设置网络配置。 -* -w $model: 设置模型路径。 -* -b $label: 设置标签类别字典,这个字典是整数标签和字符串标签的一个对应。 -* -d data/pre-imdb/dict.txt: 设置字典文件。 -* -i data/aclImdb/test/pos/10014_7.txt: 设置一个要预测的示例文件。 +cat ./data/aclImdb/test/pos/10007_10.txt | python predict.py \ + --tconf=$config\ + --model=$model \ + --label=$label \ + --dict=./data/pre-imdb/dict.txt \ + --batch_size=1 +``` + +* `cat ./data/aclImdb/test/pos/10007_10.txt` : 输入预测样本。 +* `predict.py` : 预测接口脚本。 +* `--tconf=$config` : 设置网络配置。 +* `--model=$model` : 设置模型路径。 +* `--label=$label` : 设置标签类别字典,这个字典是整数标签和字符串标签的一个对应。 +* `--dict=data/pre-imdb/dict.txt` : 设置字典文件。 +* `--batch_size=1` : 设置batch size。 注意应该确保默认模型路径`model_output / pass-00002`存在或更改为其它模型路径。 diff --git a/paddle/scripts/docker/Dockerfile b/paddle/scripts/docker/Dockerfile index 2a1a842336aa0409bba1315c77279ba2b018a4cd..207f97c4a69e6681702d3fe73475885d9b867ce9 100644 --- a/paddle/scripts/docker/Dockerfile +++ b/paddle/scripts/docker/Dockerfile @@ -1,16 +1,31 @@ FROM ubuntu:14.04 MAINTAINER PaddlePaddle Authors +ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y cmake libprotobuf-dev protobuf-compiler git \ - libgoogle-glog-dev libgflags-dev libatlas-dev libatlas3-base g++ m4 python-pip \ + libgoogle-glog-dev libgflags-dev libgtest-dev \ + libatlas-dev libatlas3-base g++ m4 python-pip \ python-protobuf python-numpy python-dev swig openssh-server \ wget unzip python-matplotlib tar xz-utils bzip2 gzip coreutils \ sed grep graphviz libjpeg-dev zlib1g-dev doxygen \ clang-3.8 llvm-3.8 libclang-3.8-dev \ && apt-get clean -y +RUN cd /usr/src/gtest && cmake . && make && cp *.a /usr/lib RUN pip install -U BeautifulSoup docopt PyYAML pillow \ - sphinx sphinx_rtd_theme breathe recommonmark + sphinx sphinx_rtd_theme recommonmark + +# cmake tends to hide and blur the dependencies between code modules, as +# noted here https://github.com/PaddlePaddle/Paddle/issues/763. We are +# thinking about using Bazel to fix this problem, e.g., +# https://github.com/PaddlePaddle/Paddle/issues/681#issuecomment-263996102. To +# start the trail of fixing, we add Bazel to our Dockerfiles. +RUN apt-get update && apt-get install -y curl software-properties-common \ + && add-apt-repository ppa:webupd8team/java \ + && echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections \ + && echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \ + && curl https://bazel.build/bazel-release.pub.gpg | apt-key add - \ + && apt-get update && apt-get install -y oracle-java8-installer bazel ARG WITH_AVX ARG WITH_DOC diff --git a/paddle/scripts/docker/Dockerfile.gpu b/paddle/scripts/docker/Dockerfile.gpu index b3253d23c35811a68adc665df3d35998c09f9def..33f6adfea2a602c53beb4685e0bf3f87452e2d53 100644 --- a/paddle/scripts/docker/Dockerfile.gpu +++ b/paddle/scripts/docker/Dockerfile.gpu @@ -1,16 +1,31 @@ FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04 MAINTAINER PaddlePaddle Authors +ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y cmake libprotobuf-dev protobuf-compiler git \ - libgoogle-glog-dev libgflags-dev libatlas-dev libatlas3-base g++ m4 python-pip \ + libgoogle-glog-dev libgflags-dev libgtest-dev \ + libatlas-dev libatlas3-base g++ m4 python-pip \ python-protobuf python-numpy python-dev swig openssh-server \ wget unzip python-matplotlib tar xz-utils bzip2 gzip coreutils \ sed grep graphviz libjpeg-dev zlib1g-dev doxygen \ clang-3.8 llvm-3.8 libclang-3.8-dev \ && apt-get clean -y +RUN cd /usr/src/gtest && cmake . && make && cp *.a /usr/lib RUN pip install -U BeautifulSoup docopt PyYAML pillow \ - sphinx sphinx_rtd_theme breathe recommonmark + sphinx sphinx_rtd_theme recommonmark + +# cmake tends to hide and blur the dependencies between code modules, as +# noted here https://github.com/PaddlePaddle/Paddle/issues/763. We are +# thinking about using Bazel to fix this problem, e.g., +# https://github.com/PaddlePaddle/Paddle/issues/681#issuecomment-263996102. To +# start the trail of fixing, we add Bazel to our Dockerfiles. +RUN apt-get update && apt-get install -y curl software-properties-common \ + && add-apt-repository ppa:webupd8team/java \ + && echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections \ + && echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \ + && curl https://bazel.build/bazel-release.pub.gpg | apt-key add - \ + && apt-get update && apt-get install -y oracle-java8-installer bazel ARG WITH_AVX ARG WITH_DOC diff --git a/paddle/scripts/tools/build_docs/Dockerfile b/paddle/scripts/tools/build_docs/Dockerfile index 506b13210ba1ee7277e2671870d79750cf63e900..78dc756bd1175019d90fc852635497fea1eb55e2 100644 --- a/paddle/scripts/tools/build_docs/Dockerfile +++ b/paddle/scripts/tools/build_docs/Dockerfile @@ -3,5 +3,5 @@ COPY build.sh / RUN pip install sphinx &&\ pip install sphinx_rtd_theme &&\ apt install -y doxygen graphviz &&\ - pip install breathe recommonmark numpy protobuf==2.6.1 + pip install recommonmark numpy protobuf==2.6.1 CMD /build.sh diff --git a/paddle/scripts/travis/docs.sh b/paddle/scripts/travis/docs.sh index c2a4809d75b97a9d8d8b83cf197e90bd62b48603..0bbb76a8a3caa27da0911af0fe87df7fbff617b4 100755 --- a/paddle/scripts/travis/docs.sh +++ b/paddle/scripts/travis/docs.sh @@ -47,17 +47,20 @@ if [ $? -eq 0 ]; then fi set -e -# Commit -git add . -git config user.name "Travis CI" -git config user.email "paddle-dev@baidu.com" -git commit -m "Deploy to GitHub Pages: ${SHA}" - -# Set ssh private key -openssl aes-256-cbc -K $SSL_KEY -iv $SSL_IV -in ../../paddle/scripts/travis/deploy_key.enc -out deploy_key -d -chmod 600 deploy_key -eval `ssh-agent -s` -ssh-add deploy_key - -# Push -git push $SSH_REPO $TARGET_BRANCH +if [ -n $SSL_KEY ]; then # Only push updated docs for github.com/PaddlePaddle/Paddle. + # Commit + git add . + git config user.name "Travis CI" + git config user.email "paddle-dev@baidu.com" + git commit -m "Deploy to GitHub Pages: ${SHA}" + + # Set ssh private key + openssl aes-256-cbc -K $SSL_KEY -iv $SSL_IV -in ../../paddle/scripts/travis/deploy_key.enc -out deploy_key -d + chmod 600 deploy_key + eval `ssh-agent -s` + ssh-add deploy_key + + # Push + git push $SSH_REPO $TARGET_BRANCH + +fi diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index fd7fb40822cdfc84e5a6b62559ab18fba7b2824c..42a7a29403f7dde2c3d1d1f090a1885104e15e64 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -141,9 +141,9 @@ def init_config_environment( g_add_submodel_suffix=False, # Whether current layer needs to pass the image height and width. - # Default value is true, but if it encounters recurrent_layer_group, - # it will be false. The reason is that image is converted to be sequence, - # image height will be sequence length, and image width will be feature + # Default value is true, but if it encounters recurrent_layer_group, + # it will be false. The reason is that image is converted to be sequence, + # image height will be sequence length, and image width will be feature # length of each timestep. g_pass_height_width=True, ): @@ -1067,7 +1067,7 @@ def cnn_output_size(img_size, filter_size, padding, stride, caffe_mode): return 1 + int(math.ceil(output)) -#calcualte image_size based on output_size for de-convolution (ConvTransLayer). +#calcualte image_size based on output_size for de-convolution (ConvTransLayer). #It is the reverse function of cnn_output_size def cnn_image_size(output_size, filter_size, padding, stride, caffe_mode): img_size = (output_size - 1) * stride + filter_size - 2 * padding @@ -3364,6 +3364,14 @@ def my_fatal(s): logger.critical(s) raise Exception() +_parse_config_hooks = set() +def register_parse_config_hook(f): + """ + Register a hook function for parse_config. parse_config will invoke the hook + at the beginning of parse. This make it possible to reset global state for + for constructing the model. + """ + _parse_config_hooks.add(f) def parse_config(config_file, config_arg_str): ''' @@ -3371,6 +3379,8 @@ def parse_config(config_file, config_arg_str): passed to config script as a dictionary CONFIG_ARGS ''' init_config_environment() + for hook in _parse_config_hooks: + hook() config_args = {} diff --git a/python/paddle/trainer_config_helpers/default_decorators.py b/python/paddle/trainer_config_helpers/default_decorators.py index 1caad193496cc62bca881d23d1d6ff2bebcc8f98..13712aad7b03e561f86101070a3140324b51a4e3 100644 --- a/python/paddle/trainer_config_helpers/default_decorators.py +++ b/python/paddle/trainer_config_helpers/default_decorators.py @@ -78,6 +78,17 @@ class DefaultNameFactory(object): """ pass + def reset(self): + self.__counter__ = 0 + + +_name_factories = [] + +def reset_hook(): + for factory in _name_factories: + factory.reset() + +register_parse_config_hook(reset_hook) def wrap_name_default(name_prefix=None): """ @@ -95,7 +106,9 @@ def wrap_name_default(name_prefix=None): :return: a decorator to set default name :rtype: callable """ - return wrap_param_default(["name"], DefaultNameFactory(name_prefix)) + factory = DefaultNameFactory(name_prefix) + _name_factories.append(factory) + return wrap_param_default(["name"], factory) def wrap_param_attr_default(param_names=None, default_factory=None): diff --git a/python/paddle/trainer_config_helpers/tests/CMakeLists.txt b/python/paddle/trainer_config_helpers/tests/CMakeLists.txt index 6180b2efbcad87e511a4b981d533f204f45fb5dc..d1a9843d326669711bf3d0769df1b804cfcfa673 100644 --- a/python/paddle/trainer_config_helpers/tests/CMakeLists.txt +++ b/python/paddle/trainer_config_helpers/tests/CMakeLists.txt @@ -4,6 +4,11 @@ add_test(NAME layers_test python ${PROJ_ROOT}/python/paddle/trainer_config_helpers/tests/layers_test.py WORKING_DIRECTORY ${PROJ_ROOT}/python/paddle) +add_test(NAME test_reset_hook + COMMAND ${PROJ_ROOT}/paddle/.set_python_path.sh -d ${PROJ_ROOT}/python/ + python ${PROJ_ROOT}/python/paddle/trainer_config_helpers/tests/test_reset_hook.py + WORKING_DIRECTORY ${PROJ_ROOT}/python/paddle) + if (PROTOBUF_3) add_paddle_exe(protobuf_equal ProtobufEqualMain.cpp) diff --git a/python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh b/python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh index e55f9bd3884a907dcc17a882e3c1dfd71fef79bb..a54af94ce3db4ed300dee697b30516c3b6448d7c 100755 --- a/python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh +++ b/python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh @@ -11,10 +11,12 @@ for conf in ${configs[*]} do echo "Generating " $conf python -m paddle.utils.dump_config $conf.py > $protostr/$conf.protostr.unittest + cat ${conf}.py |python test_config_parser_for_non_file_config.py > $protostr/$conf.protostr.non_file_config.unittest done for conf in ${whole_configs[*]} do echo "Generating " $conf python -m paddle.utils.dump_config $conf.py "" --whole > $protostr/$conf.protostr.unittest + cat ${conf}.py |python test_config_parser_for_non_file_config.py --whole > $protostr/$conf.protostr.non_file_config.unittest done diff --git a/python/paddle/trainer_config_helpers/tests/configs/run_tests.sh b/python/paddle/trainer_config_helpers/tests/configs/run_tests.sh index 73f8b333b236a8850e4c2dfa8fc75addeb143e9d..e984ee70625456241b3cfe6202fdadaa3807d33c 100755 --- a/python/paddle/trainer_config_helpers/tests/configs/run_tests.sh +++ b/python/paddle/trainer_config_helpers/tests/configs/run_tests.sh @@ -17,6 +17,7 @@ if [ -z $1 ]; then base_protostr=$protostr/$file new_protostr=$protostr/$file.unittest diff $base_protostr $new_protostr -u + diff $protostr/$file $protostr/$file.non_file_config.unittest -u done else for file in ${configs[*]} @@ -24,6 +25,9 @@ else if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest; then diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u fi + if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest; then + diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u + fi done for file in ${whole_configs[*]} @@ -31,5 +35,8 @@ else if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest --whole; then diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u fi + if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest --whole; then + diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u + fi done fi diff --git a/python/paddle/trainer_config_helpers/tests/configs/test_config_parser_for_non_file_config.py b/python/paddle/trainer_config_helpers/tests/configs/test_config_parser_for_non_file_config.py new file mode 100644 index 0000000000000000000000000000000000000000..87a607acf4219945b602411cd689afba3298696f --- /dev/null +++ b/python/paddle/trainer_config_helpers/tests/configs/test_config_parser_for_non_file_config.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import re +import getopt + +def main(print_whole_config, globals, locals): + ''' + this test will all test_config.py + ''' + cmdstr = """from paddle.trainer.config_parser import parse_config\n""" + importstr = "" + functionstr = "" + + for line in sys.stdin: + if re.match("^import", line) or re.match("^from.*import", line): + importstr = importstr + line + else: + functionstr = functionstr + " " + line + + cmdstr = cmdstr + importstr + """def configs():\n""" + functionstr + #cmdstr = cmdstr + """def configs():\n""" + importstr + functionstr + if print_whole_config: + cmdstr = cmdstr + """print parse_config(configs, "")""" + else: + cmdstr = cmdstr + """print parse_config(configs, "").model_config""" + + exec(cmdstr, globals, locals) + +if __name__ == '__main__': + whole = False + opts, args = getopt.getopt(sys.argv[1:], "", ["whole"]) + for op, value in opts: + if op == "--whole": + whole = True + main(whole, globals(), locals()) diff --git a/python/paddle/trainer_config_helpers/tests/test_reset_hook.py b/python/paddle/trainer_config_helpers/tests/test_reset_hook.py new file mode 100644 index 0000000000000000000000000000000000000000..dc494d0eef22c927fe8afea5af2f8c36ff405173 --- /dev/null +++ b/python/paddle/trainer_config_helpers/tests/test_reset_hook.py @@ -0,0 +1,28 @@ +# Copyright PaddlePaddle contributors. All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest +from paddle.trainer.config_parser import parse_config + +class TestParse(unittest.TestCase): + + def test_parse(self): + a = parse_config( + 'trainer_config_helpers/tests/layers_test_config.py', '') + b = parse_config( + 'trainer_config_helpers/tests/layers_test_config.py', '') + self.assertEqual(a, b) + + +if __name__ == '__main__': + unittest.main() diff --git a/third_party/gtest.BUILD b/third_party/gtest.BUILD new file mode 100644 index 0000000000000000000000000000000000000000..3e68a1d879311de905fab2f4cd3486a4c72a3532 --- /dev/null +++ b/third_party/gtest.BUILD @@ -0,0 +1,14 @@ +cc_library( + name = "main", + srcs = glob( + ["src/*.cc"], + exclude = ["src/gtest-all.cc"] + ), + hdrs = glob([ + "include/**/*.h", + "src/*.h" + ]), + copts = ["-Iexternal/gtest/include"], + linkopts = ["-pthread"], + visibility = ["//visibility:public"], +) diff --git a/third_party/protobuf_test/BUILD b/third_party/protobuf_test/BUILD new file mode 100644 index 0000000000000000000000000000000000000000..46f769da5f5004ef2c5f6ecee43bc8965c1d811d --- /dev/null +++ b/third_party/protobuf_test/BUILD @@ -0,0 +1,27 @@ +licenses(["notice"]) # Apache 2.0 + +load("@protobuf//:protobuf.bzl", "cc_proto_library") + +cc_proto_library( + name = "example_proto", + srcs = ["example.proto"], + protoc = "@protobuf//:protoc", + default_runtime = "@protobuf//:protobuf", +) + +cc_library( + name = "example_lib", + srcs = ["example_lib.cc"], + hdrs = ["example_lib.h"], + deps = [":example_proto"], +) + +cc_test( + name = "example_lib_test", + srcs = ["example_lib_test.cc"], + copts = ["-Iexternal/gtest/include"], + deps =[ + "@gtest//:main", + ":example_lib", + ], +) diff --git a/third_party/protobuf_test/README.md b/third_party/protobuf_test/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e8bdeee6fee66ef79d0b813b4d8dfa4c180754c6 --- /dev/null +++ b/third_party/protobuf_test/README.md @@ -0,0 +1 @@ +This package tests that Bazel can build protobuf related rules. diff --git a/third_party/protobuf_test/example.proto b/third_party/protobuf_test/example.proto new file mode 100644 index 0000000000000000000000000000000000000000..6a7eada9c14a9df5d3ef8971b636c14a11da3d11 --- /dev/null +++ b/third_party/protobuf_test/example.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package third_party.protobuf_test; + +message Greeting { + string name = 1; +} diff --git a/third_party/protobuf_test/example_lib.cc b/third_party/protobuf_test/example_lib.cc new file mode 100644 index 0000000000000000000000000000000000000000..56341a0124c0c22897aad8f5e1b85f9e28567a22 --- /dev/null +++ b/third_party/protobuf_test/example_lib.cc @@ -0,0 +1,11 @@ +#include "third_party/protobuf_test/example_lib.h" + +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting& who) { + return "Hello " + who.name(); +} + +} // namespace protobuf_test +} // namespace thrid_party diff --git a/third_party/protobuf_test/example_lib.h b/third_party/protobuf_test/example_lib.h new file mode 100644 index 0000000000000000000000000000000000000000..516326e812e19eb162f5392b519904a65c66c660 --- /dev/null +++ b/third_party/protobuf_test/example_lib.h @@ -0,0 +1,13 @@ +#pragma once + +#include "third_party/protobuf_test/example.pb.h" + +#include + +namespace third_party { +namespace protobuf_test { + +std::string get_greet(const Greeting &who); + +} // namespace protobuf_test +} // namespace third_party diff --git a/third_party/protobuf_test/example_lib_test.cc b/third_party/protobuf_test/example_lib_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..6229f56e6026908fff991765bd6bdaff6f8236ac --- /dev/null +++ b/third_party/protobuf_test/example_lib_test.cc @@ -0,0 +1,15 @@ +#include "third_party/protobuf_test/example_lib.h" + +#include "gtest/gtest.h" + +namespace third_party { +namespace protobuf_test { + +TEST(ProtobufTest, GetGreet) { + Greeting g; + g.set_name("Paddle"); + EXPECT_EQ("Hello Paddle", get_greet(g)); +} + +} // namespace protobuf_test +} // namespace third_party