diff --git a/doc/.buildinfo b/doc/.buildinfo index fc2ad92e9f6e2e04e778695c81e30b318e6208ee..765cc9cc2194d8c057838a7f05829970145b0b80 100644 --- a/doc/.buildinfo +++ b/doc/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 70a318b9e7a63a79aedc16f559247671 +config: abb235454c522821afda02c2aa921d6f tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/doc/_images/parameters.png b/doc/_images/parameters.png new file mode 100644 index 0000000000000000000000000000000000000000..2ec67480951e21f0400bce1c34b3108dcd65c18c Binary files /dev/null and b/doc/_images/parameters.png differ diff --git a/doc/_sources/build/build_from_source.txt b/doc/_sources/build/build_from_source.txt index c671f483863c7466a13fac3943e8d58eb74866fc..b8f26f431eb7a04147fe791a8c805427c827fe09 100644 --- a/doc/_sources/build/build_from_source.txt +++ b/doc/_sources/build/build_from_source.txt @@ -1,10 +1,9 @@ Installing from Sources -================= +========================== * [1. Download and Setup](#download) * [2. Requirements](#requirements) * [3. Build on Ubuntu](#ubuntu) -* [4. Build on Mac OS X](#mac) ## Download and Setup You can download PaddlePaddle from the [github source](https://github.com/gangliao/Paddle). @@ -28,51 +27,26 @@ To compile the source code, your computer must be equipped with GCC >=4.6 or Cla PaddlePaddle supports some build options. To enable it, first you need to install the related libraries. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
OptionalDescription
WITH_GPUCompile with GPU mode.
WITH_DOUBLECompile with double precision floating-point, default: single precision.
WITH_GLOGCompile with glog. If not found, default: an internal log implementation.
WITH_GFLAGSCompile with gflags. If not found, default: an internal flag implementation.
WITH_TESTINGCompile with gtest for PaddlePaddle's unit testing.
WITH_DOCCompile to generate PaddlePaddle's docs, default: disabled (OFF)
WITH_SWIG_PYCompile with python predict API, default: disabled (OFF).
WITH_STYLE_CHECKCompile with code style check, default: enabled (ON).
+ + + + + + + + + + + + + + + +
OptionalDescription
WITH_GPUCompile with GPU mode.
WITH_DOUBLECompile with double precision floating-point, default: single precision.
WITH_GLOGCompile with glog. If not found, default: an internal log implementation.
WITH_GFLAGSCompile with gflags. If not found, default: an internal flag implementation.
WITH_TESTINGCompile with gtest for PaddlePaddle's unit testing.
WITH_DOC Compile to generate PaddlePaddle's docs, default: disabled (OFF).
WITH_SWIG_PYCompile with python predict API, default: disabled (OFF).
WITH_STYLE_CHECKCompile with code style check, default: enabled (ON).
+ **Note:** - The GPU version works best with Cuda Toolkit 7.5 and cuDNN v5. @@ -178,12 +152,12 @@ As a simple example, consider the following: - **Only CPU** ```bash - cmake .. -DWITH_GPU=OFF -DWITH_DOC=OFF + cmake .. -DWITH_GPU=OFF ``` - **GPU** ```bash - cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF + cmake .. -DWITH_GPU=ON ``` - **GPU with doc and swig** @@ -196,7 +170,7 @@ Finally, you can build PaddlePaddle: ```bash # you can add build option here, such as: -cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX= +cmake .. -DWITH_GPU=ON -DCMAKE_INSTALL_PREFIX= # please use sudo make install, if you want to install PaddlePaddle into the system make -j `nproc` && make install # set PaddlePaddle installation path in ~/.bashrc @@ -216,122 +190,3 @@ sudo pip install /opt/paddle/share/wheels/*.whl # or just run sudo paddle version ``` - -## Building on Mac OS X - -### Prerequisites -This guide is based on Mac OS X 10.11 (El Capitan). Note that if you are running an up to date version of OS X, -you will already have Python 2.7.10 and Numpy 1.8 installed. - -The best option is to use the package manager homebrew to handle installations and upgrades for you. -To install [homebrew](http://brew.sh/), first open a terminal window (you can find Terminal in the Utilities folder in Applications), and issue the command: - -```bash -# install brew -/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -# install pip -easy_install pip -``` - -### Install Dependencies - -- **CPU Dependencies** - - ```bash - # Install fundamental dependents - brew install glog gflags cmake protobuf openblas - - # Install google test on Mac OS X - # Download gtest 1.7.0 - wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz - tar -xvf googletest-release-1.7.0.tar.gz && cd googletest-release-1.7.0 - # Build gtest - mkdir build && cmake .. - make - # Install gtest library - sudo cp -r ../include/gtest /usr/local/include/ - sudo cp lib*.a /usr/local/lib - ``` - -- **GPU Dependencies(optional)** - - To build GPU version, you will need the following installed: - - 1. a CUDA-capable GPU - 2. Mac OS X 10.11 or later - 2. the Clang compiler and toolchain installed using Xcode - 3. NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-downloads) - 4. NVIDIA cuDNN Library (availabel at https://developer.nvidia.com/cudnn) - - The CUDA development environment relies on tight integration with the host development environment, - including the host compiler and C runtime libraries, and is therefore only supported on - distribution versions that have been qualified for this CUDA Toolkit release. - - 1. After downloading cuDNN library, issue the following commands: - - ```bash - sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C /usr/local - sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* - ``` - 2. Then you need to set DYLD\_LIBRARY\_PATH, PATH environment variables in ~/.bashrc. - - ```bash - export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH - export PATH=/usr/local/cuda/bin:$PATH - ``` - -### Build and Install - -As usual, the best option is to create build folder under paddle project directory. - -```bash -mkdir build && cd build -cmake .. -``` - -CMake first check PaddlePaddle's dependencies in system default path. After installing some optional -libraries, corresponding build option will be set automatically (for instance, glog, gtest and gflags). -If still not found, you can manually set it based on CMake error information from your screen. - -As a simple example, consider the following: - -- **Only CPU** - - ```bash - cmake .. -DWITH_GPU=OFF -DWITH_DOC=OFF - ``` -- **GPU** - - ```bash - cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF - ``` - -- **GPU with doc and swig** - - ```bash - cmake .. -DWITH_GPU=ON -DWITH_DOC=ON -DWITH_SWIG_PY=ON - ``` - -Finally, you can build PaddlePaddle: - -```bash -# you can add build option here, such as: -cmake .. -DWITH_GPU=ON -DWITH_DOC=OFF -DCMAKE_INSTALL_PREFIX= -# please use sudo make install, if you want to install PaddlePaddle into the system -make -j `nproc` && make install -# set PaddlePaddle installation path in ~/.bashrc -export PATH=/bin:$PATH -``` -**Note:** - -If you set `WITH_SWIG_PY=ON`, related python dependencies also need to be installed. -Otherwise, PaddlePaddle will automatically install python dependencies -at first time when user run paddle commands, such as `paddle version`, `paddle train`. -It may require sudo privileges: - -```bash -# you can run -sudo pip install /opt/paddle/share/wheels/*.whl -# or just run -sudo paddle version -``` \ No newline at end of file diff --git a/doc/_sources/build/contribute_to_paddle.txt b/doc/_sources/build/contribute_to_paddle.txt index 06fcff61720755432c5618500ac509c5b3f867df..a9ab69c5f42b8d341dca87479a642e28ca58fbf4 100644 --- a/doc/_sources/build/contribute_to_paddle.txt +++ b/doc/_sources/build/contribute_to_paddle.txt @@ -4,7 +4,7 @@ We sincerely appreciate your contributions. You can use fork and pull request workflow to merge your code. ## Code Requirements -- Your code mush be fully documented by +- Your code must be fully documented by [doxygen](http://www.stack.nl/~dimitri/doxygen/) style. - Make sure the compiler option WITH\_STYLE\_CHECK is on and the compiler passes the code style check. @@ -20,16 +20,30 @@ It's just that simple. ## Clone +Paddle is currently using [git-flow branching model](http://nvie.com/posts/a-successful-git-branching-model/). +The **develop** is the main branch, and other user's branches are feature branches. + Once you've created a fork, you can use your favorite git client to clone your repo or just head straight to the command line: ```shell # Clone your fork to your local machine -git clone https://github.com/USERNAME/Paddle.git +git clone --branch develop https://github.com/USERNAME/Paddle.git +``` +If your repository doesn't contain **develop** branch, just create it by your own. + +```shell +git clone https://github.com/USERNAME/Paddle.git Paddle +cd Paddle +git checkout -b develop # create develop branch. +git remote add upstream https://github.com/baidu/Paddle.git # add upstream to baidu/Paddle +git pull upstream develop # update to upstream ``` + Then you can start to develop by making a local developement branch + ```shell -git checkout -b MY_COOL_STUFF_BRANCH origin/master +git checkout -b MY_COOL_STUFF_BRANCH ``` ## Commit @@ -41,7 +55,7 @@ Commit your changes by following command lines: git status # add modified files git add xx -git commit -m "commit info" +env EDITOR=vim git commit # You can write your comments by vim/nano/emacs. ``` The first line of commit infomation is the title. The second and later lines are the details if any. @@ -63,7 +77,7 @@ git remote -v Update your fork with the latest upstream changes: ```shell -git pull --rebase upstream HEAD +git pull --rebase upstream develop ``` If there are no unique commits locally, git will simply perform a fast-forward. @@ -76,7 +90,7 @@ Now, your local master branch is up-to-date with everything modified upstream. ```shell # push to your repository in Github -git push origin HEAD +git push -u origin MY_COOL_STUFF_BRANCH # create remote branch MY_COOL_STUFF_BRANCH to origin. ``` ## Pull Request @@ -93,9 +107,24 @@ of conflict, you need to do the update manually. You need to do the following on your local repository: ```shell git checkout MY_COOL_STUFF_BRANCH -git pull --rebase upstream HEAD +git pull upstream develop # You may need to resolve the conflict according to the git prompt. # Make and test your code. -git push -f origin HEAD +git push origin MY_COOL_STUFF_BRANCH ``` Now your Pull Request is updated with the latest version. + +## Revise your pull request + +When you revise your pull request according to reviewer's comments, please use 'git commit' instead of 'git commit --amend' to commit your changes so that the reviewers can see the difference between the new pull requrest and the old pull request. + +The possible commands are + +```shell +git checkout MY_COOL_STUFF_BRANCH +git pull upstream develop # update local to newest code base. +# May be some conflicts will occured. +# And develop your cool stuff +env EDITOR=vim git commit # add your revise log +git push origin MY_COOL_STUFF_BRANCH +``` diff --git a/doc/_sources/build/docker_install.txt b/doc/_sources/build/docker_install.txt index 3cd9d1730a22b97c208233ad4c6f9bad8038c1bf..e95de35f4da35fee511551f13bc6026532cce5c3 100644 --- a/doc/_sources/build/docker_install.txt +++ b/doc/_sources/build/docker_install.txt @@ -1,42 +1,84 @@ Docker installation guide -==================== -PaddlePaddle provides some pre-compiled binary, including Docker images, ubuntu deb packages. It is welcomed to contributed more installation package of different linux distribution (such as ubuntu, centos, debian, gentoo and so on). We recommend to use Docker images to deploy PaddlePaddle. -## Docker installation +========================== -Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. +PaddlePaddle provide the `Docker `_ image. `Docker`_ is a lightweight container utilities. The performance of PaddlePaddle in `Docker`_ container is basically as same as run it in a normal linux. The `Docker`_ is a very convenient way to deliver the binary release for linux programs. -### PaddlePaddle Docker images -There are six Docker images: +.. note:: -- paddledev/paddle:cpu-latest: PaddlePaddle CPU binary image. -- paddledev/paddle:gpu-latest: PaddlePaddle GPU binary image. -- paddledev/paddle:cpu-devel-latest: PaddlePaddle CPU binary image plus source code. -- paddledev/paddle:gpu-devel-latest: PaddlePaddle GPU binary image plus source code. -- paddledev/paddle:cpu-demo-latest: PaddlePaddle CPU binary image plus source code and demo -- paddledev/paddle:gpu-demo-latest: PaddlePaddle GPU binary image plus source code and demo + The `Docker`_ image is the recommended way to run PaddlePaddle -Tags with latest will be replaced by a released version. +PaddlePaddle Docker images +-------------------------- -### Download and Run Docker images +There are 12 `images `_ for PaddlePaddle, and the name is :code:`paddle-dev/paddle`, tags are\: + + ++-----------------+------------------+------------------------+-----------------------+ +| | normal | devel | demo | ++=================+==================+========================+=======================+ +| CPU | cpu-latest | cpu-devel-latest | cpu-demo-latest | ++-----------------+------------------+------------------------+-----------------------+ +| GPU | gpu-latest | gpu-devel-latest | gpu-demo-latest | ++-----------------+------------------+------------------------+-----------------------+ +| CPU WITHOUT AVX | cpu-noavx-latest | cpu-devel-noavx-latest | cpu-demo-noavx-latest | ++-----------------+------------------+------------------------+-----------------------+ +| GPU WITHOUT AVX | gpu-noavx-latest | gpu-devel-noavx-latest | gpu-demo-noavx-latest | ++-----------------+------------------+------------------------+-----------------------+ + +And the three columns are: + +* normal\: The docker image only contains binary of PaddlePaddle. +* devel\: The docker image contains PaddlePaddle binary, source code and essential build environment. +* demo\: The docker image contains the dependencies to run PaddlePaddle demo. + +And the four rows are: + +* CPU\: CPU Version. Support CPU which has :code:`AVX` instructions. +* GPU\: GPU Version. Support GPU, and cpu has :code:`AVX` instructions. +* CPU WITHOUT AVX\: CPU Version, which support most CPU even doesn't have :code:`AVX` instructions. +* GPU WITHOUT AVX\: GPU Version, which support most CPU even doesn't have :code:`AVX` instructions. + +User can choose any version depends on machine. The following script can help you to detect your CPU support :code:`AVX` or not. + +.. code-block:: bash + + if cat /proc/cpuinfo | grep -q avx ; then echo "Support AVX"; else echo "Not support AVX"; fi + +If the output is :code:`Support AVX`, then you can choose the AVX version of PaddlePaddle, otherwise, you need select :code:`noavx` version of PaddlePaddle. For example, the CPU develop version of PaddlePaddle is :code:`paddle-dev/paddle:cpu-devel-latest`. + +The PaddlePaddle images don't contain any entry command. You need to write your entry command to use this image. See :code:`Remote Access` part or just use following command to run a :code:`bash` + +.. code-block:: bash + + docker run -it paddledev/paddle:cpu-latest /bin/bash + + +Download and Run Docker images +------------------------------ You have to install Docker in your machine which has linux kernel version 3.10+ first. You can refer to the official guide https://docs.docker.com/engine/installation/ for further information. -You can use ```docker pull ```to download images first, or just launch a container with ```docker run```: -```bash -docker run -it paddledev/paddle:cpu-latest -``` +You can use :code:`docker pull ` to download images first, or just launch a container with :code:`docker run` \: + +.. code-block:: bash + + docker run -it paddledev/paddle:cpu-latest + If you want to launch container with GPU support, you need to set some environment variables at the same time: -```bash -export CUDA_SO="$(\ls /usr/lib64/libcuda* | xargs -I{} echo '-v {}:{}') $(\ls /usr/lib64/libnvidia* | xargs -I{} echo '-v {}:{}" -export DEVICES=$(\ls /dev/nvidia* | xargs -I{} echo '--device {}:{}') -docker run -it paddledev/paddle:gpu-latest -``` +.. code-block:: bash + + export CUDA_SO="$(\ls /usr/lib64/libcuda* | xargs -I{} echo '-v {}:{}') $(\ls /usr/lib64/libnvidia* | xargs -I{} echo '-v {}:{}')" + export DEVICES=$(\ls /dev/nvidia* | xargs -I{} echo '--device {}:{}') + docker run ${CUDA_SO} ${DEVICES} -it paddledev/paddle:gpu-latest -### Notice -#### Performance +Some notes for docker +--------------------- + +Performance ++++++++++++ Since Docker is based on the lightweight virtual containers, the CPU computing performance maintains well. And GPU driver and equipments are all mapped to the container, so the GPU computing performance would not be seriously affected. @@ -45,47 +87,36 @@ If you use high performance nic, such as RDMA(RoCE 40GbE or IB 56GbE), Ethernet( -#### Remote access -If you want to enable ssh access background, you need to build an image by yourself. Please refer to official guide https://docs.docker.com/engine/reference/builder/ for further information. +Remote access ++++++++++++++ -Following is a simple Dockerfile with ssh: -```bash -FROM paddledev/paddle -MAINTAINER PaddlePaddle dev team +If you want to enable ssh access background, you need to build an image by yourself. Please refer to official guide https://docs.docker.com/engine/reference/builder/ for further information. -RUN apt-get update -RUN apt-get install -y openssh-server -RUN mkdir /var/run/sshd -RUN echo 'root:root' | chpasswd +Following is a simple Dockerfile with ssh: -RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config -RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config +.. literalinclude:: ../../doc_cn/build_and_install/install/paddle_ssh.Dockerfile -EXPOSE 22 +Then you can build an image with Dockerfile and launch a container: -CMD ["/usr/sbin/sshd", "-D"] -``` +.. code-block:: bash -Then you can build an image with Dockerfile and launch a container: + # cd into Dockerfile directory + docker build . -t paddle_ssh + # run container, and map host machine port 8022 to container port 22 + docker run -d -p 8022:22 --name paddle_ssh_machine paddle_ssh -```bash -# cd into Dockerfile directory -docker build . -t paddle_ssh -# run container, and map host machine port 8022 to container port 22 -docker run -d -p 8022:22 --name paddle_ssh_machine paddle_ssh -``` Now, you can ssh on port 8022 to access the container, username is root, password is also root: -```bash -ssh -p 8022 root@YOUR_HOST_MACHINE -``` +.. code-block:: bash + ssh -p 8022 root@YOUR_HOST_MACHINE You can stop and delete the container as following: -```bash -# stop -docker stop paddle_ssh_machine -# delete -docker rm paddle_ssh_machine -``` + +.. code-block:: bash + + # stop + docker stop paddle_ssh_machine + # delete + docker rm paddle_ssh_machine diff --git a/doc/_sources/build/index.txt b/doc/_sources/build/index.txt index d6d0d19e110fc35faec87da90d784a6775b9c91f..511cdea145c7fd0e41566d0a85115dbb06f84058 100644 --- a/doc/_sources/build/index.txt +++ b/doc/_sources/build/index.txt @@ -10,31 +10,24 @@ Install PaddlePaddle install_* internal/install_from_jumbo.md + docker_install.rst + ubuntu_install.rst Build from Source ----------------- -If you want to hack and contribute PaddlePaddle source code, following guides can help you\: +.. warning:: -.. toctree:: - :maxdepth: 1 - :glob: + Please use :code:`deb` package or :code:`docker` image to install paddle. The building guide is used for hacking or contributing to PaddlePaddle. + - build_from_source.md - contribute_to_paddle.md - -Docker and Debian Package installation --------------------------------------- - -Note: The installation packages are still in pre-release -state and your experience of installation may not be smooth. +If you want to hack and contribute PaddlePaddle source code, following guides can help you\: -If you want to pack docker image, the following guide can help you\: .. toctree:: :maxdepth: 1 :glob: - docker_install.md - ubuntu_install.md + build_from_source.md + contribute_to_paddle.md diff --git a/doc/_sources/build/ubuntu_install.txt b/doc/_sources/build/ubuntu_install.txt index c30a8f6db5d9eb83390d9374d27aba46fa42a462..ea8042085bf458be96e71017d229d88ad867695b 100644 --- a/doc/_sources/build/ubuntu_install.txt +++ b/doc/_sources/build/ubuntu_install.txt @@ -1,21 +1,25 @@ Debian Package installation guide ================================= -## Debian Package installation -Currently , PaddlePaddle only provides ubuntu14.04 debian packages. -There are two versions package, including CPU and GPU. The download address is: +PaddlePaddle supports :code:`deb` pacakge. The installation of this :code:`deb` package is tested in ubuntu 14.04, but it should be support other debian based linux, too. -https://github.com/baidu/Paddle/releases/tag/V0.8.0b0 +There are four versions of debian package, :code:`cpu`, :code:`gpu`, :code:`cpu-noavx`, :code:`gpu-noavx`. And :code:`noavx` version is used to support CPU which does not contain :code:`AVX` instructions. The download url of :code:`deb` package is \: https://github.com/baidu/Paddle/releases/ -After downloading PaddlePaddle deb packages, you can run: +After downloading PaddlePaddle deb packages, you can use :code:`gdebi` install. -```bash -dpkg -i paddle-0.8.0b-cpu.deb -apt-get install -f -``` -And if you use GPU version deb package, you need to install CUDA toolkit and cuDNN, and set related environment variables(such as LD_LIBRARY_PATH) first. It is normal when `dpkg -i` get errors. `apt-get install -f` will continue install paddle, and install dependences. +.. code-block:: bash + + gdebi paddle-*.deb + +If :code:`gdebi` is not installed, you can use :code:`sudo apt-get install gdebi` to install it. + +Or you can use following commands to install PaddlePaddle. -**Note** +.. code-block:: bash + + dpkg -i paddle-*.deb + apt-get install -f + +And if you use GPU version deb package, you need to install CUDA toolkit and cuDNN, and set related environment variables(such as LD_LIBRARY_PATH) first. It is normal when `dpkg -i` get errors. `apt-get install -f` will continue install paddle, and install dependences. -PaddlePaddle package only supports x86 CPU with AVX instructions. If not, you have to download and build from source code. diff --git a/doc/_sources/cluster/opensource/cluster_train.txt b/doc/_sources/cluster/opensource/cluster_train.txt index 4763ede39b049b6c49225dc9ae7add77325d704e..cb493a88f031850cb6a5eeed0ebe9e41bb7e01c3 100644 --- a/doc/_sources/cluster/opensource/cluster_train.txt +++ b/doc/_sources/cluster/opensource/cluster_train.txt @@ -1,26 +1,24 @@ -# Cluster Training +# Distributed Training -We provide some simple scripts ```paddle/scripts/cluster_train``` to help you to launch cluster training Job to harness PaddlePaddle's distributed trainning. For MPI and other cluster scheduler refer this naive script to implement more robust cluster training platform by yourself. +In this article, we explain how to run distributed Paddle training jobs on clusters. We will create the distributed version of the single-process training example, [recommendation](https://github.com/baidu/Paddle/tree/develop/demo/recommendation). -The following cluster demo is based on RECOMMENDATION local training demo in PaddlePaddle ```demo/recommendation``` directory. Assuming you enter the ```paddle/scripts/cluster_train/``` directory. +[Scripts](https://github.com/baidu/Paddle/tree/develop/paddle/scripts/cluster_train) used in this article launch distributed jobs via SSH. They also work as a reference for users running more sophisticated cluster management systems like MPI and Kubernetes. -## Pre-requirements +## Prerequisite -Firstly, +1. Aforementioned scripts use a Python library [fabric](http://www.fabfile.org/) to run SSH commands. We can use `pip` to install fabric: -```bash + ```bash pip install fabric -``` - -Secondly, go through installing scripts to install PaddlePaddle at all nodes to make sure demo can run as local mode. For CUDA enabled training, we assume that CUDA is installed in ```/usr/local/cuda```, otherwise missed cuda runtime libraries error could be reported at cluster runtime. In one word, the local training environment should be well prepared for the simple scripts. + ``` -Then you should prepare same ROOT_DIR directory in all nodes. ROOT_DIR is from in cluster_train/conf.py. Assuming that the ROOT_DIR = /home/paddle, you can create ```paddle``` user account as well, at last ```paddle.py``` can ssh connections to all nodes with ```paddle``` user automatically. +1. We need to install PaddlePaddle on all nodes in the cluster. To enable GPUs, we need to install CUDA in `/usr/local/cuda`; otherwise Paddle would report errors at runtime. -At last you can create ssh mutual trust relationship between all nodes for easy ssh login, otherwise ```password``` should be provided at runtime from ```paddle.py```. +1. Set the `ROOT_DIR` variable in [`cluster_train/conf.py`] on all nodes. For convenience, we often create a Unix user `paddle` on all nodes and set `ROOT_DIR=/home/paddle`. In this way, we can write public SSH keys into `/home/paddle/.ssh/authorized_keys` so that user `paddle` can SSH to all nodes without password. ## Prepare Job Workspace -```Job workspace``` is defined as one package directory which contains dependency libraries, train data, test data, model config file and all other related file dependencies. +We refer to the directory where we put dependent libraries, config files, etc., as *workspace*. These ```train/test``` data should be prepared before launching cluster job. To satisfy the requirement that train/test data are placed in different directory from workspace, PADDLE refers train/test data according to index file named as ```train.list/test.list``` which are used in model config file. So the train/test data also contains train.list/test.list two list file. All local training demo already provides scripts to help you create these two files, and all nodes in cluster job will handle files with same logical code in normal condition. diff --git a/doc/_sources/demo/quick_start/index_en.txt b/doc/_sources/demo/quick_start/index_en.txt index ee3fa2a2166f497524663574270b239a6170ab19..659485d9be1b6a3e9759a2fd040cb09d1f2a3005 100644 --- a/doc/_sources/demo/quick_start/index_en.txt +++ b/doc/_sources/demo/quick_start/index_en.txt @@ -1,4 +1,4 @@ -# Quick Start Tutorial +# Quick Start This tutorial will teach the basics of deep learning (DL), including how to implement many different models in PaddlePaddle. You will learn how to: - Prepare data into the standardized format that PaddlePaddle accepts. @@ -134,7 +134,7 @@ def process(settings, file_name): You need to add a data provider definition `define_py_data_sources2` in our network configuration. This definition specifies: - The path of the training and testing data (`data/train.list`, `data/test.list`). -- The location of the data provider file (`dataprovider_pow`). +- The location of the data provider file (`dataprovider_bow`). - The function to call to get data. (`process`). - Additional arguments or data. Here it passes the path of word dictionary. @@ -477,7 +477,7 @@ The scripts of data downloading, network configurations, and training scrips are Word embedding 15MB 8.484% -trainer_config.bow.py +trainer_config.emb.py diff --git a/doc/_sources/demo/semantic_role_labeling/semantic_role_labeling.txt b/doc/_sources/demo/semantic_role_labeling/semantic_role_labeling.txt index 05fbc8278daf204df60ad19b742c920e47128c27..890f7314582c65e9add50664006b57aa4e0709eb 100644 --- a/doc/_sources/demo/semantic_role_labeling/semantic_role_labeling.txt +++ b/doc/_sources/demo/semantic_role_labeling/semantic_role_labeling.txt @@ -1,183 +1,183 @@ -# Semantic Role labeling Tutorial # - -Semantic role labeling (SRL) is a form of shallow semantic parsing whose goal is to discover the predicate-argument structure of each predicate in a given input sentence. SRL is useful as an intermediate step in a wide range of natural language processing tasks, such as information extraction. automatic document categorization and question answering. An instance is as following [1]: - - [ A0 He ] [ AM-MOD would ][ AM-NEG n’t ] [ V accept] [ A1 anything of value ] from [A2 those he was writing about ]. - -- V: verb -- A0: acceptor -- A1: thing accepted -- A2: accepted-from -- A3: Attribute -- AM-MOD: modal -- AM-NEG: negation - -Given the verb "accept", the chunks in sentence would play certain semantic roles. Here, the label scheme is from Penn Proposition Bank. - -To this date, most of the successful SRL systems are built on top of some form of parsing results where pre-defined feature templates over the syntactic structure are used. This tutorial will present an end-to-end system using deep bidirectional long short-term memory (DB-LSTM)[2] for solving the SRL task, which largely outperforms the previous state-of-the-art systems. The system regards SRL task as the sequence labelling problem. - -## Data Description -The relevant paper[2] takes the data set in CoNLL-2005&2012 Shared Task for training and testing. Accordingto data license, the demo adopts the test data set of CoNLL-2005, which can be reached on website. - -To download and process the original data, user just need to execute the following command: - -```bash -cd data -./get_data.sh -``` -Several new files appear in the `data `directory as follows. -```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 -src.dict:the dictionary of words in sentences -tgt.dict:the labels dictionary -feature: the extracted features from data set -``` - -## Training -### DB-LSTM -Please refer to the Sentiment Analysis demo to learn more about the long short-term memory unit. - -Unlike Bidirectional-LSTM that used in Sentiment Analysis demo, the DB-LSTM adopts another way to stack LSTM layer. First a standard LSTM processes the sequence in forward direction. The input and output of this LSTM layer are taken by the next LSTM layer as input, processed in reversed direction. These two standard LSTM layers compose a pair of LSTM. Then we stack LSTM layers pair after pair to obtain the deep LSTM model. - -The following figure shows a temporal expanded 2-layer DB-LSTM network. -
-![pic](./network_arch.png) -
- -### Features -Two input features play an essential role in this pipeline: predicate (pred) and argument (argu). Two other features: predicate context (ctx-p) and region mark (mr) are also adopted. Because a single predicate word can not exactly describe the predicate information, especially when the same words appear more than one times in a sentence. With the predicate context, the ambiguity can be largely eliminated. Similarly, we use region mark mr = 1 to denote the argument position if it locates in the predicate context region, or mr = 0 if does not. These four simple features are all we need for our SRL system. Features of one sample with context size set to 1 is showed as following[2]: -
-![pic](./feature.jpg) -
- -In this sample, the coresponding labelled sentence is: - -[ A1 A record date ] has [ AM-NEG n't ] been [ V set ] . - -In the demo, we adopt the feature template as above, consists of : `argument`, `predicate`, `ctx-p (p=-1,0,1)`, `mark` and use `B/I/O` scheme to label each argument. These features and labels are stored in `feature` file, and separated by `\t`. - -### Data Provider - -`dataprovider.py` is the python file to wrap data. `hook()` function is to define the data slots for network. The Six features and label are all IndexSlots. -``` -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(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))] -``` -The corresponding data iterator is as following: -``` -@provider(use_seq=True, init_hook=hook) -def process(obj, file_name): - with open(file_name, 'r') as fdata: - for line in fdata: - sentence, predicate, ctx_n1, ctx_0, ctx_p1, mark, label = line.strip().split('\t') - words = sentence.split() - sen_len = len(words) - word_slot = [obj.word_dict.get(w, UNK_IDX) for w in words] - - predicate_slot = [obj.word_dict.get(predicate, UNK_IDX)] * sen_len - ctx_n1_slot = [obj.word_dict.get(ctx_n1, UNK_IDX) ] * sen_len - ctx_0_slot = [obj.word_dict.get(ctx_0, UNK_IDX) ] * sen_len - ctx_p1_slot = [obj.word_dict.get(ctx_p1, UNK_IDX) ] * sen_len - - marks = mark.split() - mark_slot = [int(w) for w in marks] - - label_list = label.split() - label_slot = [obj.label_dict.get(w) for w in label_list] - - yield word_slot, predicate_slot, ctx_n1_slot, ctx_0_slot, ctx_p1_slot, mark_slot, label_slot -``` -The `process`function yield 7 lists which are six features and labels. - -### Neural Network Config -`db_lstm.py` is the neural network config file to load the dictionaries and define the data provider module and network architecture during the training procedure. - -Seven `data_layer` load instances from data provider. Six features are transformed into embedddings respectively, and mixed by `mixed_layer` . Deep bidirectional LSTM layers extract features for the softmax layer. The objective function is cross entropy of labels. - -### Run Training -The script for training is `train.sh`, user just need to execute: -```bash - ./train.sh -``` -The content in `train.sh`: -``` -paddle train \ - --config=./db_lstm.py \ - --save_dir=./output \ - --trainer_count=4 \ - --log_period=10 \ - --num_passes=500 \ - --use_gpu=false \ - --show_parameter_stats_period=10 \ - --test_all_data_in_one_period=1 \ -2>&1 | tee 'train.log' -``` - -- \--config=./db_lstm.py : network config file. -- \--save_di=./output: output path to save models. -- \--trainer_count=4 : set thread number (or GPU count). -- \--log_period=10 : print log every 20 batches. -- \--num_passes=500: set pass number, one pass in PaddlePaddle means training all samples in dataset one time. -- \--use_gpu=false: use CPU to train, set true, if you install GPU version of PaddlePaddle and want to use GPU to train. -- \--show_parameter_stats_period=10: show parameter statistic every 100 batches. -- \--test_all_data_in_one_period=1: test all data in every testing. - - -After training, the models will be saved in directory `output`. - -### Run testing -The script for testing is `test.sh`, user just need to execute: -```bash - ./test.sh -``` -The main part in `tesh.sh` -``` -paddle train \ - --config=./db_lstm.py \ - --model_list=$model_list \ - --job=test \ - --config_args=is_test=1 \ -``` - - - \--config=./db_lstm.py: network config file - - \--model_list=$model_list.list: model list file - - \--job=test: indicate the test job - - \--config_args=is_test=1: flag to indicate test - - -### Run prediction -The script for prediction is `predict.sh`, user just need to execute: -```bash - ./predict.sh - -``` -In `predict.sh`, user should offer the network config file, model path, label file, word dictionary file, feature file -``` -python predict.py - -c $config_file - -w $model_path - -l $label_file - -d $dict_file - -i $input_file -``` - -`predict.py` is the main executable python script, which includes functions: load model, load data, data prediction. The network model will output the probability distribution of labels. In the demo, we take the label with maximum probability as result. User can also implement the beam search or viterbi decoding upon the probability distribution matrix. - -After prediction, the result is saved in `predict.res`. - -## Reference -[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. +# Semantic Role labeling Tutorial # + +Semantic role labeling (SRL) is a form of shallow semantic parsing whose goal is to discover the predicate-argument structure of each predicate in a given input sentence. SRL is useful as an intermediate step in a wide range of natural language processing tasks, such as information extraction. automatic document categorization and question answering. An instance is as following [1]: + + [ A0 He ] [ AM-MOD would ][ AM-NEG n’t ] [ V accept] [ A1 anything of value ] from [A2 those he was writing about ]. + +- V: verb +- A0: acceptor +- A1: thing accepted +- A2: accepted-from +- A3: Attribute +- AM-MOD: modal +- AM-NEG: negation + +Given the verb "accept", the chunks in sentence would play certain semantic roles. Here, the label scheme is from Penn Proposition Bank. + +To this date, most of the successful SRL systems are built on top of some form of parsing results where pre-defined feature templates over the syntactic structure are used. This tutorial will present an end-to-end system using deep bidirectional long short-term memory (DB-LSTM)[2] for solving the SRL task, which largely outperforms the previous state-of-the-art systems. The system regards SRL task as the sequence labelling problem. + +## Data Description +The relevant paper[2] takes the data set in CoNLL-2005&2012 Shared Task for training and testing. Accordingto data license, the demo adopts the test data set of CoNLL-2005, which can be reached on website. + +To download and process the original data, user just need to execute the following command: + +```bash +cd data +./get_data.sh +``` +Several new files appear in the `data `directory as follows. +```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 +src.dict:the dictionary of words in sentences +tgt.dict:the labels dictionary +feature: the extracted features from data set +``` + +## Training +### DB-LSTM +Please refer to the Sentiment Analysis demo to learn more about the long short-term memory unit. + +Unlike Bidirectional-LSTM that used in Sentiment Analysis demo, the DB-LSTM adopts another way to stack LSTM layer. First a standard LSTM processes the sequence in forward direction. The input and output of this LSTM layer are taken by the next LSTM layer as input, processed in reversed direction. These two standard LSTM layers compose a pair of LSTM. Then we stack LSTM layers pair after pair to obtain the deep LSTM model. + +The following figure shows a temporal expanded 2-layer DB-LSTM network. +
+![pic](./network_arch.png) +
+ +### Features +Two input features play an essential role in this pipeline: predicate (pred) and argument (argu). Two other features: predicate context (ctx-p) and region mark (mr) are also adopted. Because a single predicate word can not exactly describe the predicate information, especially when the same words appear more than one times in a sentence. With the predicate context, the ambiguity can be largely eliminated. Similarly, we use region mark mr = 1 to denote the argument position if it locates in the predicate context region, or mr = 0 if does not. These four simple features are all we need for our SRL system. Features of one sample with context size set to 1 is showed as following[2]: +
+![pic](./feature.jpg) +
+ +In this sample, the coresponding labelled sentence is: + +[ A1 A record date ] has [ AM-NEG n't ] been [ V set ] . + +In the demo, we adopt the feature template as above, consists of : `argument`, `predicate`, `ctx-p (p=-1,0,1)`, `mark` and use `B/I/O` scheme to label each argument. These features and labels are stored in `feature` file, and separated by `\t`. + +### Data Provider + +`dataprovider.py` is the python file to wrap data. `hook()` function is to define the data slots for network. The Six features and label are all IndexSlots. +``` +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(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))] +``` +The corresponding data iterator is as following: +``` +@provider(use_seq=True, init_hook=hook) +def process(obj, file_name): + with open(file_name, 'r') as fdata: + for line in fdata: + sentence, predicate, ctx_n1, ctx_0, ctx_p1, mark, label = line.strip().split('\t') + words = sentence.split() + sen_len = len(words) + word_slot = [obj.word_dict.get(w, UNK_IDX) for w in words] + + predicate_slot = [obj.word_dict.get(predicate, UNK_IDX)] * sen_len + ctx_n1_slot = [obj.word_dict.get(ctx_n1, UNK_IDX) ] * sen_len + ctx_0_slot = [obj.word_dict.get(ctx_0, UNK_IDX) ] * sen_len + ctx_p1_slot = [obj.word_dict.get(ctx_p1, UNK_IDX) ] * sen_len + + marks = mark.split() + mark_slot = [int(w) for w in marks] + + label_list = label.split() + label_slot = [obj.label_dict.get(w) for w in label_list] + + yield word_slot, predicate_slot, ctx_n1_slot, ctx_0_slot, ctx_p1_slot, mark_slot, label_slot +``` +The `process`function yield 7 lists which are six features and labels. + +### Neural Network Config +`db_lstm.py` is the neural network config file to load the dictionaries and define the data provider module and network architecture during the training procedure. + +Seven `data_layer` load instances from data provider. Six features are transformed into embedddings respectively, and mixed by `mixed_layer` . Deep bidirectional LSTM layers extract features for the softmax layer. The objective function is cross entropy of labels. + +### Run Training +The script for training is `train.sh`, user just need to execute: +```bash + ./train.sh +``` +The content in `train.sh`: +``` +paddle train \ + --config=./db_lstm.py \ + --save_dir=./output \ + --trainer_count=4 \ + --log_period=10 \ + --num_passes=500 \ + --use_gpu=false \ + --show_parameter_stats_period=10 \ + --test_all_data_in_one_period=1 \ +2>&1 | tee 'train.log' +``` + +- \--config=./db_lstm.py : network config file. +- \--save_di=./output: output path to save models. +- \--trainer_count=4 : set thread number (or GPU count). +- \--log_period=10 : print log every 20 batches. +- \--num_passes=500: set pass number, one pass in PaddlePaddle means training all samples in dataset one time. +- \--use_gpu=false: use CPU to train, set true, if you install GPU version of PaddlePaddle and want to use GPU to train. +- \--show_parameter_stats_period=10: show parameter statistic every 100 batches. +- \--test_all_data_in_one_period=1: test all data in every testing. + + +After training, the models will be saved in directory `output`. + +### Run testing +The script for testing is `test.sh`, user just need to execute: +```bash + ./test.sh +``` +The main part in `tesh.sh` +``` +paddle train \ + --config=./db_lstm.py \ + --model_list=$model_list \ + --job=test \ + --config_args=is_test=1 \ +``` + + - \--config=./db_lstm.py: network config file + - \--model_list=$model_list.list: model list file + - \--job=test: indicate the test job + - \--config_args=is_test=1: flag to indicate test + + +### Run prediction +The script for prediction is `predict.sh`, user just need to execute: +```bash + ./predict.sh + +``` +In `predict.sh`, user should offer the network config file, model path, label file, word dictionary file, feature file +``` +python predict.py + -c $config_file + -w $model_path + -l $label_file + -d $dict_file + -i $input_file +``` + +`predict.py` is the main executable python script, which includes functions: load model, load data, data prediction. The network model will output the probability distribution of labels. In the demo, we take the label with maximum probability as result. User can also implement the beam search or viterbi decoding upon the probability distribution matrix. + +After prediction, the result is saved in `predict.res`. + +## Reference +[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/_sources/index.txt b/doc/_sources/index.txt index df03a33fac98c46635eef05d88639235ac72cf8f..cbd08ba52abe529aec84f6b1c2e35300496878a5 100644 --- a/doc/_sources/index.txt +++ b/doc/_sources/index.txt @@ -3,11 +3,12 @@ PaddlePaddle Documentation User Guide ---------- +* [Introduction](introduction/index.md) * [Quick Start](demo/quick_start/index_en.md) * [Build and Installation](build/index.rst) * [Contribute Code](build/contribute_to_paddle.md) * [User Interface](ui/index.md) -* [Model Config Interface](ui/api/trainer_config_helpers/index.md) +* [Model Config Interface](ui/api/trainer_config_helpers/index.rst) * [Example and Demo](demo/index.md) * [Cluster Train](cluster/index.md) diff --git a/doc/_sources/introduction/index.txt b/doc/_sources/introduction/index.txt new file mode 100644 index 0000000000000000000000000000000000000000..01f52031a1d0247cd0b885218c17001f23685239 --- /dev/null +++ b/doc/_sources/introduction/index.txt @@ -0,0 +1,100 @@ +# Introduction + +PaddlePaddle is a deep learning platform open-sourced by Baidu. With PaddlePaddle, you can easily train a classic neural network within a couple lines of configuration, or you can build sophisticated models that provide state-of-the-art performance on difficult learning tasks like sentiment analysis, machine translation, image caption and so on. + +## 1. A Classic Problem + +Now, to give you a hint of what using PaddlePaddle looks like, let's start with a fundamental learning problem - **simple linear regression** : you have observed a set of two-dimensional data points of `X` and `Y`, where `X` is an explanatory variable and `Y` is corresponding dependent variable, and you want to recover the underlying correlation between `X` and `Y`. Linear regression can be used in many practical scenarios. For example, `X` can be a variable about house size, and `Y` a variable about house price. You can build a model that captures relationship between them by observing real estate markets. + +## 2. Prepare the Data + +Suppose the true relationship can be characterized as `Y = 2X + 0.3`, let's see how to recover this pattern only from observed data. Here is a piece of python code that feeds synthetic data to PaddlePaddle. The code is pretty self-explanatory, the only extra thing you need to add for PaddlePaddle is a definition of input data types. + +```python +# dataprovider.py +from paddle.trainer.PyDataProvider2 import * +import random + +# define data types of input: 2 real numbers +@provider(input_types=[dense_vector(1), dense_vector(1)],use_seq=False) +def process(settings, input_file): + for i in xrange(2000): + x = random.random() + yield [x], [2*x+0.3] +``` + +## 3. Train a NeuralNetwork in PaddlePaddle + +To recover this relationship between `X` and `Y`, we use a neural network with one layer of linear activation units and a square error cost layer. Don't worry if you are not familiar with these terminologies, it's just saying that we are starting from a random line `Y' = wX + b` , then we gradually adapt `w` and `b` to minimize the difference between `Y'` and `Y`. Here is what it looks like in PaddlePaddle: + +```python +# trainer_config.py +from paddle.trainer_config_helpers import * + +# 1. read data. Suppose you saved above python code as dataprovider.py +data_file = 'empty.list' +with open(data_file, 'w') as f: f.writelines(' ') +define_py_data_sources2(train_list=data_file, test_list=None, + module='dataprovider', obj='process',args={}) + +# 2. learning algorithm +settings(batch_size=12, learning_rate=1e-3, learning_method=MomentumOptimizer()) + +# 3. Network configuration +x = data_layer(name='x', size=1) +y = data_layer(name='y', size=1) +y_predict = fc_layer(input=x, param_attr=ParamAttr(name='w'), size=1, act=LinearActivation(), bias_attr=ParamAttr(name='b')) +cost = regression_cost(input=y_predict, label=y) +outputs(cost) +``` + +Some of the most fundamental usages of PaddlePaddle are demonstrated: + +- The first part shows how to feed data into PaddlePaddle. In general cases, PaddlePaddle reads raw data from a list of files, and then do some user-defined process to get real input. In this case, we only need to create a placeholder file since we are generating synthetic data on the fly. + +- The second part describes learning algorithm. It defines in what ways adjustments are made to model parameters. PaddlePaddle provides a rich set of optimizers, but a simple momentum based optimizer will suffice here, and it processes 12 data points each time. + +- Finally, the network configuration. It usually is as simple as "stacking" layers. Three kinds of layers are used in this configuration: + - **Data Layer**: a network always starts with one or more data layers. They provide input data to the rest of the network. In this problem, two data layers are used respectively for `X` and `Y`. + - **FC Layer**: FC layer is short for Fully Connected Layer, which connects all the input units to current layer and does the actual computation specified as activation function. Computation layers like this are the fundamental building blocks of a deeper model. + - **Cost Layer**: in training phase, cost layers are usually the last layers of the network. They measure the performance of current model, and provide guidence to adjust parameters. + +Now that everything is ready, you can train the network with a simple command line call: + ``` + paddle train --config=trainer_config.py --save_dir=./output --num_passes=30 + ``` + +This means that PaddlePaddle will train this network on the synthectic dataset for 30 passes, and save all the models under path `./output`. You will see from the messages printed out during training phase that the model cost is decreasing as time goes by, which indicates we are getting a closer guess. + + +## 4. Evaluate the Model + +Usually, a different dataset that left out during training phase should be used to evalute the models. However, we are lucky enough to know the real answer: `w=2, b=0.3`, thus a better option is to check out model parameters directly. + +In PaddlePaddle, training is just to get a collection of model parameters, which are `w` and `b` in this case. Each parameter is saved in an individual file in the popular `numpy` array format. Here is the code that reads parameters from last pass. + +```python +import numpy as np +import os + +def load(file_name): + with open(file_name, 'rb') as f: + f.read(16) # skip header for float type. + return np.fromfile(f, dtype=np.float32) + +print 'w=%.6f, b=%.6f' % (load('output/pass-00029/w'), load('output/pass-00029/b')) +# w=1.999743, b=0.300137 +``` + +
![](./parameters.png)
+ +Although starts from a random guess, you can see that value of `w` changes quickly towards 2 and `b` changes quickly towards 0.3. In the end, the predicted line is almost identical with real answer. + +There, you have recovered the underlying pattern between `X` and `Y` only from observed data. + + +## 5. Where to Go from Here + +- Build and Installation +- Quick Start +- Example and Demo diff --git a/doc/_sources/source/gserver/layers/layer.txt b/doc/_sources/source/gserver/layers/layer.txt index 807b22ca140ee71208a96e2877b9c5636620b165..4b8e149505f0695ad2fa4be967a50d1a0ac48b43 100644 --- a/doc/_sources/source/gserver/layers/layer.txt +++ b/doc/_sources/source/gserver/layers/layer.txt @@ -465,6 +465,11 @@ SumOfSquaresCostLayer .. doxygenclass:: paddle::SumOfSquaresCostLayer :members: +SumCostLayer +````````````````````` +.. doxygenclass:: paddle::SumCostLayer + :members: + CosSimLayer ----------- .. doxygenclass:: paddle::CosSimLayer diff --git a/doc/_sources/ui/api/trainer_config_helpers/activations.txt b/doc/_sources/ui/api/trainer_config_helpers/activations.txt index c4e14ed779efb6f6601d2c5fa41764f318c82848..269e6491e7ebe3899c3fb24fca756a393043473b 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/activations.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/activations.txt @@ -1,3 +1,7 @@ +=========== +Activations +=========== + BaseActivation ============== @@ -32,6 +36,13 @@ LinearActivation .. automodule:: paddle.trainer_config_helpers.activations :members: LinearActivation :noindex: + +LogActivation +================== + +.. automodule:: paddle.trainer_config_helpers.activations + :members: LogActivation + :noindex: SquareActivation ================ @@ -95,4 +106,3 @@ STanhActivation .. automodule:: paddle.trainer_config_helpers.activations :members: STanhActivation :noindex: - diff --git a/doc/_sources/ui/api/trainer_config_helpers/activations_index.txt b/doc/_sources/ui/api/trainer_config_helpers/activations_index.txt deleted file mode 100644 index 1c0b71ab77eec62859c1d7615f6ebe637f3108ac..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/activations_index.txt +++ /dev/null @@ -1,7 +0,0 @@ -Activations -=========== - -.. toctree:: - :maxdepth: 3 - - activations.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/evaluators.txt b/doc/_sources/ui/api/trainer_config_helpers/evaluators.txt index 0586c9907e472dd98c5f7e9098251f3bc6b88bab..d6a79c13e2316b0fd3d53eb47960a767bcf8abdb 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/evaluators.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/evaluators.txt @@ -1,3 +1,7 @@ +========== +Evaluators +========== + Base ==== .. automodule:: paddle.trainer_config_helpers.evaluators diff --git a/doc/_sources/ui/api/trainer_config_helpers/evaluators_index.txt b/doc/_sources/ui/api/trainer_config_helpers/evaluators_index.txt deleted file mode 100644 index 298de3e1a32d36b9102f5ad64cc1b968f418041b..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/evaluators_index.txt +++ /dev/null @@ -1,7 +0,0 @@ -Evaluators -========== - -.. toctree:: - :maxdepth: 3 - - evaluators.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/index.txt b/doc/_sources/ui/api/trainer_config_helpers/index.txt index 00fa99bb3fa4c407dc867f91f4c7c495dc4061a1..8395eb75710b3e67ec0c5442f79c999bdacdff42 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/index.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/index.txt @@ -1,10 +1,14 @@ -# Model Config Interface +Model Config Interface +====================== -* [Optimizer](optimizers_index.rst) -* [Data Source](data_sources.rst) -* [Layers](layers_index.rst) -* [Activations](activations_index.rst) -* [Poolings](poolings_index.rst) -* [Networks](networks_index.rst) -* [Evaluators](evaluators_index.rst) -* [Parameter and Extra Layer Attribute](attrs.rst) +.. toctree:: + :maxdepth: 1 + + optimizers.rst + data_sources.rst + layers.rst + activations.rst + poolings.rst + networks.rst + evaluators.rst + attrs.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/layers.txt b/doc/_sources/ui/api/trainer_config_helpers/layers.txt index c1d7a7ce815301be7d4193560fc6c27d90cf6e69..4a02af396993207d305be488c993ce94cf20fe1d 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/layers.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/layers.txt @@ -1,3 +1,7 @@ +====== +Layers +====== + Base ====== @@ -46,6 +50,12 @@ conv_operator :members: conv_operator :noindex: +conv_projection +--------------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: conv_projection + :noindex: + conv_shift_layer ------------------ .. automodule:: paddle.trainer_config_helpers.layers @@ -71,6 +81,18 @@ img_pool_layer -------------- .. automodule:: paddle.trainer_config_helpers.layers :members: img_pool_layer + :noindex: + +spp_layer +-------------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: spp_layer + :noindex: + +maxout_layer +------------ +.. automodule:: paddle.trainer_config_helpers.layers + :members: maxout_layer :noindex: Norm Layer @@ -130,6 +152,12 @@ gru_step_layer Recurrent Layer Group ===================== +memory +------ +.. automodule:: paddle.trainer_config_helpers.layers + :members: memory + :noindex: + recurrent_group --------------- .. automodule:: paddle.trainer_config_helpers.layers @@ -163,6 +191,12 @@ embedding_layer :members: embedding_layer :noindex: +scaling_projection +----------------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: scaling_projection + :noindex: + dotmul_projection ----------------- .. automodule:: paddle.trainer_config_helpers.layers @@ -242,6 +276,12 @@ expand_layer :members: expand_layer :noindex: +repeat_layer +------------ +.. automodule:: paddle.trainer_config_helpers.layers + :members: repeat_layer + :noindex: + Math Layers =========== @@ -263,6 +303,12 @@ interpolation_layer :members: interpolation_layer :noindex: +bilinear_interp_layer +---------------------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: bilinear_interp_layer + :noindex: + power_layer ----------- .. automodule:: paddle.trainer_config_helpers.layers @@ -371,12 +417,24 @@ ctc_layer :members: ctc_layer :noindex: +nce_layer +----------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: nce_layer + :noindex: + hsigmoid --------- .. automodule:: paddle.trainer_config_helpers.layers :members: hsigmoid :noindex: +sum_cost +--------- +.. automodule:: paddle.trainer_config_helpers.layers + :members: sum_cost + :noindex: + Check Layer ============ diff --git a/doc/_sources/ui/api/trainer_config_helpers/layers_index.txt b/doc/_sources/ui/api/trainer_config_helpers/layers_index.txt deleted file mode 100644 index c0daab152148ce769948f600c3101bd79f5a1013..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/layers_index.txt +++ /dev/null @@ -1,7 +0,0 @@ -Layers -====== - -.. toctree:: - :maxdepth: 3 - - layers.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/networks.txt b/doc/_sources/ui/api/trainer_config_helpers/networks.txt index 2a15b34eaea0b763f992a7225550e6af747f303c..29c52c5ce3078f1755162dbbdd65a059d8ba9fa4 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/networks.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/networks.txt @@ -1,3 +1,9 @@ +======== +Networks +======== + +The networks module contains pieces of neural network that combine multiple layers. + NLP === @@ -111,4 +117,3 @@ outputs .. automodule:: paddle.trainer_config_helpers.networks :members: outputs :noindex: - diff --git a/doc/_sources/ui/api/trainer_config_helpers/networks_index.txt b/doc/_sources/ui/api/trainer_config_helpers/networks_index.txt deleted file mode 100644 index 17bc4dfaa6c4ed3cd5daf0476d0d4c15a2067a22..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/networks_index.txt +++ /dev/null @@ -1,9 +0,0 @@ -Networks -======== - -The networks module contains pieces of neural network that combine multiple layers. - -.. toctree:: - :maxdepth: 3 - - networks.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/optimizers.txt b/doc/_sources/ui/api/trainer_config_helpers/optimizers.txt index b487fec64c4ebb5cfbdff1aa101d9b3675776a2c..7ca4e34156e273caf66cc71e6927bfb23bb5235e 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/optimizers.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/optimizers.txt @@ -1,3 +1,7 @@ +========== +Optimizers +========== + BaseSGDOptimizer ================ .. automodule:: paddle.trainer_config_helpers.optimizers @@ -51,4 +55,3 @@ settings .. automodule:: paddle.trainer_config_helpers.optimizers :members: settings :noindex: - diff --git a/doc/_sources/ui/api/trainer_config_helpers/optimizers_index.txt b/doc/_sources/ui/api/trainer_config_helpers/optimizers_index.txt deleted file mode 100644 index f39f94f0cd6e1a6c3c25eeceb7820a7fbc070570..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/optimizers_index.txt +++ /dev/null @@ -1,7 +0,0 @@ -Optimizers -========== - -.. toctree:: - :maxdepth: 3 - - optimizers.rst diff --git a/doc/_sources/ui/api/trainer_config_helpers/poolings.txt b/doc/_sources/ui/api/trainer_config_helpers/poolings.txt index caadec639383aad24ed477d8bdaeaa31c0026bb5..66566809d26f59263597b5286c5b27e0bbc9415a 100644 --- a/doc/_sources/ui/api/trainer_config_helpers/poolings.txt +++ b/doc/_sources/ui/api/trainer_config_helpers/poolings.txt @@ -1,3 +1,7 @@ +======== +Poolings +======== + BasePoolingType =============== .. automodule:: paddle.trainer_config_helpers.poolings @@ -27,4 +31,3 @@ SquareRootNPooling .. automodule:: paddle.trainer_config_helpers.poolings :members: SquareRootNPooling :noindex: - diff --git a/doc/_sources/ui/api/trainer_config_helpers/poolings_index.txt b/doc/_sources/ui/api/trainer_config_helpers/poolings_index.txt deleted file mode 100644 index 250d3fa69c0dcedfd689b685fe7b47ec71d02fee..0000000000000000000000000000000000000000 --- a/doc/_sources/ui/api/trainer_config_helpers/poolings_index.txt +++ /dev/null @@ -1,9 +0,0 @@ -Poolings -======== - -These pooling types are used for sequence input, not for images. - -.. toctree:: - :maxdepth: 3 - - poolings.rst diff --git a/doc/_sources/ui/cmd_argument/argument_outline.txt b/doc/_sources/ui/cmd_argument/argument_outline.txt index 98dadc270dcac8cb5c05f3065c98bac78671d7fa..d6cc2c6ed7cc1b9209d56b4348497427efe40ac3 100644 --- a/doc/_sources/ui/cmd_argument/argument_outline.txt +++ b/doc/_sources/ui/cmd_argument/argument_outline.txt @@ -183,7 +183,7 @@ It looks like there are a lot of arguments. However, most of them are for develo -GPUgpu_id +GPUgpu_id √√√√ @@ -207,6 +207,11 @@ It looks like there are a lot of arguments. However, most of them are for develo √√√√ + +cudnn_conv_workspace_limit_in_mb +√√√√ + + RNN beam_size diff --git a/doc/_sources/ui/cmd_argument/detail_introduction.txt b/doc/_sources/ui/cmd_argument/detail_introduction.txt index 0d0362d022a72b597e78e760893c91df449e5745..07608e5edf740bd3e1242913f1d2d7589ad313aa 100644 --- a/doc/_sources/ui/cmd_argument/detail_introduction.txt +++ b/doc/_sources/ui/cmd_argument/detail_introduction.txt @@ -163,6 +163,10 @@ - Choose path to dynamic load NVIDIA CUDA library, for instance, /usr/local/cuda/lib64. [Default]: LD_LIBRARY_PATH - type: string (default: "", null) +* `--cudnn_conv_workspace_limit_in_mb` + - Specify cuDNN max workspace limit, in units MB, 4096MB=4GB by default. + - type: int32 (default: 4096MB=4GB) + ## NLP: RNN/LSTM/GRU * `--rnn_use_batch` - Whether to use batch method for calculation in simple RecurrentLayer. diff --git a/doc/_static/searchtools.js b/doc/_static/searchtools.js index a51e0dc5b6ab26465274ba8810118382bc597652..ba82ad4877ca5803883434a08f1aea6afb43f3b6 100644 --- a/doc/_static/searchtools.js +++ b/doc/_static/searchtools.js @@ -226,6 +226,106 @@ var Scorer = { }; + + + +var splitChars = (function() { + var result = {}; + var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, + 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, + 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, + 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, + 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, + 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, + 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, + 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, + 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, + 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; + var i, j, start, end; + for (i = 0; i < singles.length; i++) { + result[singles[i]] = true; + } + var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], + [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], + [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], + [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], + [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], + [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], + [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], + [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], + [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], + [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], + [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], + [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], + [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], + [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], + [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], + [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], + [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], + [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], + [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], + [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], + [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], + [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], + [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], + [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], + [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], + [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], + [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], + [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], + [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], + [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], + [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], + [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], + [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], + [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], + [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], + [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], + [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], + [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], + [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], + [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], + [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], + [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], + [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], + [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], + [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], + [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], + [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], + [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], + [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; + for (i = 0; i < ranges.length; i++) { + start = ranges[i][0]; + end = ranges[i][1]; + for (j = start; j <= end; j++) { + result[j] = true; + } + } + return result; +})(); + +function splitQuery(query) { + var result = []; + var start = -1; + for (var i = 0; i < query.length; i++) { + if (splitChars[query.charCodeAt(i)]) { + if (start !== -1) { + result.push(query.slice(start, i)); + start = -1; + } + } else if (start === -1) { + start = i; + } + } + if (start !== -1) { + result.push(query.slice(start)); + } + return result; +} + + + + /** * Search Module */ @@ -324,7 +424,7 @@ var Search = { var searchterms = []; var excluded = []; var hlterms = []; - var tmp = query.split(/\W+/); + var tmp = splitQuery(query); var objectterms = []; for (i = 0; i < tmp.length; i++) { if (tmp[i] !== "") { diff --git a/doc/algorithm/rnn/rnn.html b/doc/algorithm/rnn/rnn.html index c969e63e5cddcf7975211b0a2d1a782a689ea8f6..f87122a4824f4f23150b06fcc2b0ec793b9fa152 100644 --- a/doc/algorithm/rnn/rnn.html +++ b/doc/algorithm/rnn/rnn.html @@ -330,7 +330,7 @@ Its output function simply takes \(x_t\) \ No newline at end of file diff --git a/doc/build/build_from_source.html b/doc/build/build_from_source.html index 66ac23d7155f6a3f7d72e1ec1c35aac5778e72ce..a89ea0f4e24908f1bbfa3a7dd49ac984f557b3bb 100644 --- a/doc/build/build_from_source.html +++ b/doc/build/build_from_source.html @@ -31,7 +31,7 @@ - + + + + + + + + + + + + + + + + +
+
+
+
+ +
+

Introduction

+

PaddlePaddle is a deep learning platform open-sourced by Baidu. With PaddlePaddle, you can easily train a classic neural network within a couple lines of configuration, or you can build sophisticated models that provide state-of-the-art performance on difficult learning tasks like sentiment analysis, machine translation, image caption and so on.

+
+

1. A Classic Problem

+

Now, to give you a hint of what using PaddlePaddle looks like, let’s start with a fundamental learning problem - simple linear regression : you have observed a set of two-dimensional data points of X and Y, where X is an explanatory variable and Y is corresponding dependent variable, and you want to recover the underlying correlation between X and Y. Linear regression can be used in many practical scenarios. For example, X can be a variable about house size, and Y a variable about house price. You can build a model that captures relationship between them by observing real estate markets.

+
+
+

2. Prepare the Data

+

Suppose the true relationship can be characterized as Y = 2X + 0.3, let’s see how to recover this pattern only from observed data. Here is a piece of python code that feeds synthetic data to PaddlePaddle. The code is pretty self-explanatory, the only extra thing you need to add for PaddlePaddle is a definition of input data types.

+
# dataprovider.py
+from paddle.trainer.PyDataProvider2 import *
+import random
+
+# define data types of input: 2 real numbers
+@provider(input_types=[dense_vector(1), dense_vector(1)],use_seq=False)
+def process(settings, input_file):
+    for i in xrange(2000):
+        x = random.random()
+        yield [x], [2*x+0.3]
+
+
+
+
+

3. Train a NeuralNetwork in PaddlePaddle

+

To recover this relationship between X and Y, we use a neural network with one layer of linear activation units and a square error cost layer. Don’t worry if you are not familiar with these terminologies, it’s just saying that we are starting from a random line Y' = wX + b , then we gradually adapt w and b to minimize the difference between Y' and Y. Here is what it looks like in PaddlePaddle:

+
# trainer_config.py
+from paddle.trainer_config_helpers import *
+
+# 1. read data. Suppose you saved above python code as dataprovider.py
+data_file = 'empty.list'
+with open(data_file, 'w') as f: f.writelines(' ')
+define_py_data_sources2(train_list=data_file, test_list=None, 
+        module='dataprovider', obj='process',args={})
+
+# 2. learning algorithm
+settings(batch_size=12, learning_rate=1e-3, learning_method=MomentumOptimizer())
+
+# 3. Network configuration
+x = data_layer(name='x', size=1)
+y = data_layer(name='y', size=1)
+y_predict = fc_layer(input=x, param_attr=ParamAttr(name='w'), size=1, act=LinearActivation(), bias_attr=ParamAttr(name='b'))
+cost = regression_cost(input=y_predict, label=y)
+outputs(cost)
+
+
+

Some of the most fundamental usages of PaddlePaddle are demonstrated:

+
    +
  • The first part shows how to feed data into PaddlePaddle. In general cases, PaddlePaddle reads raw data from a list of files, and then do some user-defined process to get real input. In this case, we only need to create a placeholder file since we are generating synthetic data on the fly.
  • +
  • The second part describes learning algorithm. It defines in what ways adjustments are made to model parameters. PaddlePaddle provides a rich set of optimizers, but a simple momentum based optimizer will suffice here, and it processes 12 data points each time.
  • +
  • Finally, the network configuration. It usually is as simple as “stacking” layers. Three kinds of layers are used in this configuration:
      +
    • Data Layer: a network always starts with one or more data layers. They provide input data to the rest of the network. In this problem, two data layers are used respectively for X and Y.
    • +
    • FC Layer: FC layer is short for Fully Connected Layer, which connects all the input units to current layer and does the actual computation specified as activation function. Computation layers like this are the fundamental building blocks of a deeper model.
    • +
    • Cost Layer: in training phase, cost layers are usually the last layers of the network. They measure the performance of current model, and provide guidence to adjust parameters.
    • +
    +
  • +
+

Now that everything is ready, you can train the network with a simple command line call:

+
paddle train --config=trainer_config.py --save_dir=./output --num_passes=30
+
+
+

This means that PaddlePaddle will train this network on the synthectic dataset for 30 passes, and save all the models under path ./output. You will see from the messages printed out during training phase that the model cost is decreasing as time goes by, which indicates we are getting a closer guess.

+
+
+

4. Evaluate the Model

+

Usually, a different dataset that left out during training phase should be used to evalute the models. However, we are lucky enough to know the real answer: w=2, b=0.3, thus a better option is to check out model parameters directly.

+

In PaddlePaddle, training is just to get a collection of model parameters, which are w and b in this case. Each parameter is saved in an individual file in the popular numpy array format. Here is the code that reads parameters from last pass.

+
import numpy as np
+import os
+
+def load(file_name):
+    with open(file_name, 'rb') as f:
+        f.read(16) # skip header for float type.
+        return np.fromfile(f, dtype=np.float32)
+        
+print 'w=%.6f, b=%.6f' % (load('output/pass-00029/w'), load('output/pass-00029/b'))
+# w=1.999743, b=0.300137
+
+
+

+

Although starts from a random guess, you can see that value of w changes quickly towards 2 and b changes quickly towards 0.3. In the end, the predicted line is almost identical with real answer.

+

There, you have recovered the underlying pattern between X and Y only from observed data.

+
+
+

5. Where to Go from Here

+ +
+
+ + +
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/doc/layer.html b/doc/layer.html index a5b082c3875646dbd16d4966a157bf22db38556e..d0ec6166ba358ca066842f0f449128a5175b378a 100644 --- a/doc/layer.html +++ b/doc/layer.html @@ -30,7 +30,7 @@ - + - - - - - - - - - - - - - - - - -
- - -
-
- - - - \ No newline at end of file diff --git a/doc/ui/api/trainer_config_helpers/attrs.html b/doc/ui/api/trainer_config_helpers/attrs.html index 132cca0e00c597e62cf43a85cad921de43f96e52..a1b57f3158db6255603be5f43c340894b29ebf36 100644 --- a/doc/ui/api/trainer_config_helpers/attrs.html +++ b/doc/ui/api/trainer_config_helpers/attrs.html @@ -30,8 +30,8 @@ - - + + - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/doc/ui/api/trainer_config_helpers/index.html b/doc/ui/api/trainer_config_helpers/index.html index f0e959204d164b66f8c4972cd9d49ad012dd152f..9745a94c23ed8e50e4de71deb5776911622f24f9 100644 --- a/doc/ui/api/trainer_config_helpers/index.html +++ b/doc/ui/api/trainer_config_helpers/index.html @@ -29,9 +29,8 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/doc/ui/api/trainer_config_helpers/networks.html b/doc/ui/api/trainer_config_helpers/networks.html index 93e67d832934c5f356ba37f92c13843bc111a061..1f1c99342b4abf352cefc7a0839153b0693f6fe7 100644 --- a/doc/ui/api/trainer_config_helpers/networks.html +++ b/doc/ui/api/trainer_config_helpers/networks.html @@ -8,7 +8,7 @@ - NLP — PaddlePaddle documentation + Networks — PaddlePaddle documentation @@ -29,9 +29,9 @@ - - - + + + - - - - - - - - - - - - - - - - -
-
-
-
- -
-

Networks

-

The networks module contains pieces of neural network that combine multiple layers.

- -
- - -
-
-
- -
-
- - - - \ No newline at end of file diff --git a/doc/ui/api/trainer_config_helpers/optimizers.html b/doc/ui/api/trainer_config_helpers/optimizers.html index de240ec5beaf92117a2cecd360b0d346cdb1bc3c..3383169e50d4a920665a9f87d138064470207bdd 100644 --- a/doc/ui/api/trainer_config_helpers/optimizers.html +++ b/doc/ui/api/trainer_config_helpers/optimizers.html @@ -8,7 +8,7 @@ - BaseSGDOptimizer — PaddlePaddle documentation + Optimizers — PaddlePaddle documentation @@ -29,9 +29,9 @@ - + - + - - - - - - - - - - - - - - - - -
- - -
-
- - - - \ No newline at end of file diff --git a/doc/ui/api/trainer_config_helpers/poolings.html b/doc/ui/api/trainer_config_helpers/poolings.html index cd07c4e1a335adbe52c1bb0c8845a45536edfb2e..0e8feffe81c6c7521cb6748e8c3a0279631262f2 100644 --- a/doc/ui/api/trainer_config_helpers/poolings.html +++ b/doc/ui/api/trainer_config_helpers/poolings.html @@ -8,7 +8,7 @@ - BasePoolingType — PaddlePaddle documentation + Poolings — PaddlePaddle documentation @@ -29,9 +29,9 @@ - - - + + + - - - - - - - - - - - - - - - - -
-
-
-
- -
-

Poolings

-

These pooling types are used for sequence input, not for images.

- -
- - -
-
-
- -
-
- - - - \ No newline at end of file diff --git a/doc/ui/cmd_argument/argument_outline.html b/doc/ui/cmd_argument/argument_outline.html index fdbf52c1247b464feac50a986c8cdff0d907d023..2049b42b59d57aace5c16b1123f07c4728fc0f71 100644 --- a/doc/ui/cmd_argument/argument_outline.html +++ b/doc/ui/cmd_argument/argument_outline.html @@ -185,7 +185,7 @@ var _hmt = _hmt || []; Auc/PnpairValidationpredict_file √√ -GPUgpu_id +GPUgpu_id √√√√ parallel_nn @@ -200,6 +200,9 @@ var _hmt = _hmt || []; cuda_dir √√√√ +cudnn_conv_workspace_limit_in_mb +√√√√ + RNN beam_size √√ @@ -371,7 +374,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc/ui/cmd_argument/detail_introduction.html b/doc/ui/cmd_argument/detail_introduction.html index 27caecf65a568defdf5de09a9d5fe1a42d4b941c..eab04b85aef8d46b199da356fbff8d844f2938c2 100644 --- a/doc/ui/cmd_argument/detail_introduction.html +++ b/doc/ui/cmd_argument/detail_introduction.html @@ -284,6 +284,11 @@ var _hmt = _hmt || [];
  • type: string (default: “”, null)
  • +
  • --cudnn_conv_workspace_limit_in_mb
      +
    • Specify cuDNN max workspace limit, in units MB, 4096MB=4GB by default.
    • +
    • type: int32 (default: 4096MB=4GB)
    • +
    +
  • @@ -601,7 +606,7 @@ var _hmt = _hmt || [];
    \ No newline at end of file diff --git a/doc/ui/cmd_argument/use_case.html b/doc/ui/cmd_argument/use_case.html index b6b140c5af1e988242587f3b4e9869845bcc8c00..06f3f162f05eabaa341e9651a653b6643e60889e 100644 --- a/doc/ui/cmd_argument/use_case.html +++ b/doc/ui/cmd_argument/use_case.html @@ -31,7 +31,7 @@ - + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +

    支持双层序列作为输入的Layer

    +
    +

    概述

    +

    在自然语言处理任务中,序列是一种常见的数据类型。一个独立的词语,可以看作是一个非序列输入,或者,我们称之为一个0层的序列;由词语构成的句子,是一个单层序列;若干个句子构成一个段落,是一个双层的序列。

    +

    双层序列是一个嵌套的序列,它的每一个元素,又是一个单层的序列。这是一种非常灵活的数据组织方式,帮助我们构造一些复杂的输入信息。

    +

    我们可以按照如下层次定义非序列,单层序列,以及双层序列。

    +
      +
    • 0层序列:一个独立的元素,类型可以是PaddlePaddle支持的任意输入数据类型
    • +
    • 单层序列:排成一列的多个元素,每个元素是一个0层序列,元素之间的顺序是重要的输入信息
    • +
    • 双层序列:排成一列的多个元素,每个元素是一个单层序列,称之为双层序列的一个子序列(subseq),subseq的每个元素是一个0层序列
    • +
    +

    在 PaddlePaddle中,下面这些Layer能够接受双层序列作为输入,完成相应的计算。

    +
    +
    +

    pooling_layer

    +

    pooling_layer的使用示例如下,详细见配置API

    +
    seq_pool = pooling_layer(input=layer,
    +                         pooling_type=AvgPooling(),
    +                         agg_level=AggregateLevel.EACH_SEQUENCE)
    +
    +
    +
      +
    • pooling_type 目前支持两种,分别是:MaxPooling()和AvgPooling()。
    • +
    • agg_level=AggregateLevel.TIMESTEP时(默认值):
        +
      • 作用:双层序列经过运算变成一个0层序列,或单层序列经过运算变成一个0层序列
      • +
      • 输入:一个双层序列,或一个单层序列
      • +
      • 输出:一个0层序列,即整个输入序列(单层或双层)的平均值(或最大值)
      • +
      +
    • +
    • agg_level=AggregateLevel.EACH_SEQUENCE时:
        +
      • 作用:一个双层序列经过运算变成一个单层序列
      • +
      • 输入:必须是一个双层序列
      • +
      • 输出:一个单层序列,序列的每个元素是原来双层序列每个subseq元素的平均值(或最大值)
      • +
      +
    • +
    +
    +
    +

    last_seq 和 first_seq

    +

    last_seq的使用示例如下(first_seq类似),详细见配置API

    +
    last = last_seq(input=layer,
    +                agg_level=AggregateLevel.EACH_SEQUENCE)
    +
    +
    +
      +
    • agg_level=AggregateLevel.TIMESTEP时(默认值):
        +
      • 作用:一个双层序列经过运算变成一个0层序列,或一个单层序列经过运算变成一个0层序列
      • +
      • 输入:一个双层序列或一个单层序列
      • +
      • 输出:一个0层序列,即整个输入序列(双层或者单层)最后一个,或第一个元素。
      • +
      +
    • +
    • agg_level=AggregateLevel.EACH_SEQUENCE时:
        +
      • 作用:一个双层序列经过运算变成一个单层序列
      • +
      • 输入:必须是一个双层序列
      • +
      • 输出:一个单层序列,其中每个元素是双层序列中每个subseq最后一个(或第一个)元素。
      • +
      +
    • +
    +
    +
    +

    expand_layer

    +

    expand_layer的使用示例如下,详细见配置API

    +
    expand = expand_layer(input=layer1,
    +                      expand_as=layer2,
    +                      expand_level=ExpandLevel.FROM_TIMESTEP)
    +
    +
    +
      +
    • expand_level=ExpandLevel.FROM_TIMESTEP时(默认值):
        +
      • 作用:一个0层序列经过运算扩展成一个单层序列,或者一个双层序列
      • +
      • 输入:layer1必须是一个0层序列,是待扩展的数据;layer2可以是一个单层序列,或者是一个双层序列,提供扩展的长度信息
      • +
      • 输出:一个单层序列,或一个双层序列,输出序列的类型(双层序列,或单层序列)和序列中含有元素的数目同 layer2一致。若输出是单层序列,单层序列的每个元素(0层序列),都是对layer1元素的拷贝;若输出是双层序列,双层序列每个subseq中每个元素(0层序列),都是对layer1元素的拷贝
      • +
      +
    • +
    • expand_level=ExpandLevel.FROM_SEQUENCE时:
        +
      • 作用:一个单层序列经过运算扩展成一个双层序列
      • +
      • 输入:layer1必须是一个单层序列,是待扩展的数据;layer2必须是一个双层序列,提供扩展的长度信息
      • +
      • 输出:一个双层序列,序列中含有元素的数目同layer2一致。要求单层序列含有元素的数目(0层序列),和双层序列含有subseq 的数目一致。单层序列第i个元素(0层序列),被扩展为一个单层序列,构成了输出双层序列的第i个subseq。
      • +
      +
    • +
    +
    +
    + + +
    +
    +
    + +
    +
    + + + + \ No newline at end of file diff --git a/doc_cn/algorithm/rnn/hierarchical-rnn.html b/doc_cn/algorithm/rnn/hierarchical-rnn.html new file mode 100644 index 0000000000000000000000000000000000000000..e3e5ad1206c0c4909090aee2f99494e0bc8f928c --- /dev/null +++ b/doc_cn/algorithm/rnn/hierarchical-rnn.html @@ -0,0 +1,551 @@ + + + + + + + + + + 双层RNN配置与示例 — PaddlePaddle documentation + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +

    双层RNN配置与示例

    +

    我们在paddle/gserver/tests/test_RecurrentGradientMachine单测中,通过多组语义相同的单双层RNN配置,讲解如何使用双层RNN。

    +
    +

    示例1:双进双出,subseq间无memory

    +

    配置:单层RNN(sequence_layer_group)和双层RNN(sequence_nest_layer_group),语义完全相同。

    +
    +

    读取双层序列的方法

    +

    首先,我们看一下单双层序列的不同数据组织形式(您也可以采用别的组织形式):

    +
      +
    • 单层序列的数据(Sequence/tour_train_wdseg)如下,一共有10个样本。每个样本由两部分组成,一个label(此处都为2)和一个已经分词后的句子。
    • +
    +
    2   酒店 有 很 舒适 的 床垫 子 , 床上用品 也 应该 是 一人 一 换 , 感觉 很 利落 对 卫生 很 放心 呀 。
    +2   很 温馨 , 也 挺 干净 的 * 地段 不错 , 出来 就 有 全家 , 离 地铁站 也 近 , 交通 很方便 * 就是 都 不 给 刷牙 的 杯子 啊 , 就 第一天 给 了 一次性杯子 *
    +2   位置 方便 , 强烈推荐 , 十一 出去玩 的 时候 选 的 , 对面 就是 华润万家 , 周围 吃饭 的 也 不少 。
    +2   交通便利 , 吃 很 便利 , 乾 浄 、 安静 , 商务 房 有 电脑 、 上网 快 , 价格 可以 , 就 早餐 不 好吃 。 整体 是 不错 的 。 適 合 出差 來 住 。
    +2   本来 准备 住 两 晚 , 第 2 天 一早 居然 停电 , 且 无 通知 , 只有 口头 道歉 。 总体来说 性价比 尚可 , 房间 较 新 , 还是 推荐 .
    +2   这个 酒店 去过 很多 次 了 , 选择 的 主要原因 是 离 客户 最 便宜 相对 又 近 的 酒店
    +2   挺好 的 汉庭 , 前台 服务 很 热情 , 卫生 很 整洁 , 房间 安静 , 水温 适中 , 挺好 !
    +2   HowardJohnson 的 品质 , 服务 相当 好 的 一 家 五星级 。 房间 不错 、 泳池 不错 、 楼层 安排 很 合理 。 还有 就是 地理位置 , 简直 一 流 。 就 在 天一阁 、 月湖 旁边 , 离 天一广场 也 不远 。 下次 来 宁波 还会 住 。
    +2   酒店 很干净 , 很安静 , 很 温馨 , 服务员 服务 好 , 各方面 都 不错 *
    +2   挺好 的 , 就是 没 窗户 , 不过 对 得 起 这 价格
    +
    +
    +
      +
    • 双层序列的数据(Sequence/tour_train_wdseg.nest)如下,一共有4个样本。样本间用空行分开,代表不同的双层序列,序列数据和上面的完全一样。每个样本的子句数分别为2,3,2,3。
    • +
    +
    2   酒店 有 很 舒适 的 床垫 子 , 床上用品 也 应该 是 一人 一 换 , 感觉 很 利落 对 卫生 很 放心 呀 。
    +2   很 温馨 , 也 挺 干净 的 * 地段 不错 , 出来 就 有 全家 , 离 地铁站 也 近 , 交通 很方便 * 就是 都 不 给 刷牙 的 杯子 啊 , 就 第一天 给 了 一次性杯子 *
    +
    +2   位置 方便 , 强烈推荐 , 十一 出去玩 的 时候 选 的 , 对面 就是 华润万家 , 周围 吃饭 的 也 不少 。
    +2   交通便利 , 吃 很 便利 , 乾 浄 、 安静 , 商务 房 有 电脑 、 上网 快 , 价格 可以 , 就 早餐 不 好吃 。 整体 是 不错 的 。 適 合 出差 來 住 。
    +2   本来 准备 住 两 晚 , 第 2 天 一早 居然 停电 , 且 无 通知 , 只有 口头 道歉 。 总体来说 性价比 尚可 , 房间 较 新 , 还是 推荐 .
    +
    +2   这个 酒店 去过 很多 次 了 , 选择 的 主要原因 是 离 客户 最 便宜 相对 又 近 的 酒店
    +2   挺好 的 汉庭 , 前台 服务 很 热情 , 卫生 很 整洁 , 房间 安静 , 水温 适中 , 挺好 !
    +
    +2   HowardJohnson 的 品质 , 服务 相当 好 的 一 家 五星级 。 房间 不错 、 泳池 不错 、 楼层 安排 很 合理 。 还有 就是 地理位置 , 简直 一 流 。 就 在 天一阁 、 月湖 旁边 , 离 天一广场 也 不远 。 下次 来 宁波 还会 住 。
    +2   酒店 很干净 , 很安静 , 很 温馨 , 服务员 服务 好 , 各方面 都 不错 *
    +2   挺好 的 , 就是 没 窗户 , 不过 对 得 起 这 价格
    +
    +
    +

    其次,我们看一下单双层序列的不同dataprovider(见sequenceGen.py):

    +
      +
    • 单层序列的dataprovider如下:
        +
      • word_slot是integer_value_sequence类型,代表单层序列。
      • +
      • label是integer_value类型,代表一个向量。
      • +
      +
    • +
    +
    def hook(settings, dict_file, **kwargs):
    +    settings.word_dict = dict_file
    +    settings.input_types = [integer_value_sequence(len(settings.word_dict)), 
    +                            integer_value(3)]
    +
    +@provider(init_hook=hook)
    +def process(settings, file_name):
    +    with open(file_name, 'r') as fdata:
    +        for line in fdata:
    +            label, comment = line.strip().split('\t')
    +            label = int(''.join(label.split()))
    +            words = comment.split()
    +            word_slot = [settings.word_dict[w] for w in words if w in settings.word_dict]
    +            yield word_slot, label
    +
    +
    +
      +
    • 双层序列的dataprovider如下:
        +
      • word_slot是integer_value_sub_sequence类型,代表双层序列。
      • +
      • label是integer_value_sequence类型,代表单层序列,即一个子句一个label。注意:也可以为integer_value类型,代表一个向量,即一个句子一个label。通常根据任务需求进行不同设置。
      • +
      • 关于dataprovider中input_types的详细用法,参见PyDataProvider2。
      • +
      +
    • +
    +
    def hook2(settings, dict_file, **kwargs):
    +    settings.word_dict = dict_file
    +    settings.input_types = [integer_value_sub_sequence(len(settings.word_dict)),
    +                            integer_value_sequence(3)]
    +
    +@provider(init_hook=hook2)
    +def process2(settings, file_name):
    +    with open(file_name) as fdata:
    +        label_list = []
    +        word_slot_list = []
    +        for line in fdata:
    +            if (len(line)) > 1:
    +                label,comment = line.strip().split('\t')
    +                label = int(''.join(label.split()))
    +                words = comment.split()
    +                word_slot = [settings.word_dict[w] for w in words if w in settings.word_dict]
    +                label_list.append(label)
    +                word_slot_list.append(word_slot)
    +            else:
    +                yield word_slot_list, label_list
    +                label_list = []
    +                word_slot_list = []
    +
    +
    +
    +
    +

    模型中的配置

    +

    首先,我们看一下单层序列的配置(见sequence_layer_group.conf)。注意:batchsize=5表示一次过5句单层序列,因此2个batch就可以完成1个pass。

    +
    settings(batch_size=5)
    +
    +data = data_layer(name="word", size=dict_dim)
    +
    +emb = embedding_layer(input=data, size=word_dim)
    +
    +# (lstm_input + lstm) is equal to lstmemory 
    +with mixed_layer(size=hidden_dim*4) as lstm_input:
    +    lstm_input += full_matrix_projection(input=emb)
    +
    +lstm = lstmemory_group(input=lstm_input,
    +                       size=hidden_dim,
    +                       act=TanhActivation(),
    +                       gate_act=SigmoidActivation(),
    +                       state_act=TanhActivation(),
    +                       lstm_layer_attr=ExtraLayerAttribute(error_clipping_threshold=50))
    +
    +lstm_last = last_seq(input=lstm)
    +
    +with mixed_layer(size=label_dim, 
    +                 act=SoftmaxActivation(), 
    +                 bias_attr=True) as output:
    +    output += full_matrix_projection(input=lstm_last)
    +
    +outputs(classification_cost(input=output, label=data_layer(name="label", size=1)))
    +
    +
    +
    +

    其次,我们看一下语义相同的双层序列配置(见sequence_nest_layer_group.conf),并对其详细分析:

    +
      +
    • batchsize=2表示一次过2句双层序列。但从上面的数据格式可知,2句双层序列和5句单层序列的数据完全一样。
    • +
    • data_layer和embedding_layer不关心数据是否是序列格式,因此两个配置在这两层上的输出是一样的。
    • +
    • lstmemory:
        +
      • 单层序列过了一个mixed_layer和lstmemory_group。
      • +
      • 双层序列在同样的mixed_layer和lstmemory_group外,直接加了一层group。由于这个外层group里面没有memory,表示subseq间不存在联系,即起到的作用仅仅是把双层seq拆成单层,因此双层序列过完lstmemory的输出和单层的一样。
      • +
      +
    • +
    • last_seq:
        +
      • 单层序列直接取了最后一个元素
      • +
      • 双层序列首先(last_seq层)取了每个subseq的最后一个元素,将其拼接成一个新的单层序列;接着(expand_layer层)将其扩展成一个新的双层序列,其中第i个subseq中的所有向量均为输入的单层序列中的第i个向量;最后(average_layer层)取了每个subseq的平均值。
      • +
      • 分析得出:第一个last_seq后,每个subseq的最后一个元素就等于单层序列的最后一个元素,而expand_layer和average_layer后,依然保持每个subseq最后一个元素的值不变(这两层仅是为了展示它们的用法,实际中并不需要)。因此单双层序列的输出是一样旳。
      • +
      +
    • +
    +
    settings(batch_size=2)
    +
    +data = data_layer(name="word", size=dict_dim)
    +
    +emb_group = embedding_layer(input=data, size=word_dim)
    +
    +# (lstm_input + lstm) is equal to lstmemory 
    +def lstm_group(lstm_group_input):
    +    with mixed_layer(size=hidden_dim*4) as group_input:
    +      group_input += full_matrix_projection(input=lstm_group_input)
    +
    +    lstm_output = lstmemory_group(input=group_input,
    +                                  name="lstm_group",
    +                                  size=hidden_dim,
    +                                  act=TanhActivation(),
    +                                  gate_act=SigmoidActivation(),
    +                                  state_act=TanhActivation(),
    +                                  lstm_layer_attr=ExtraLayerAttribute(error_clipping_threshold=50))
    +    return lstm_output
    +
    +lstm_nest_group = recurrent_group(input=SubsequenceInput(emb_group),
    +                                  step=lstm_group,
    +                                  name="lstm_nest_group")
    +# hasSubseq ->(seqlastins) seq
    +lstm_last = last_seq(input=lstm_nest_group, agg_level=AggregateLevel.EACH_SEQUENCE)
    +
    +# seq ->(expand) hasSubseq
    +lstm_expand = expand_layer(input=lstm_last, expand_as=emb_group, expand_level=ExpandLevel.FROM_SEQUENCE)
    +
    +# hasSubseq ->(average) seq
    +lstm_average = pooling_layer(input=lstm_expand,
    +                             pooling_type=AvgPooling(),
    +                             agg_level=AggregateLevel.EACH_SEQUENCE)
    +
    +with mixed_layer(size=label_dim, 
    +                 act=SoftmaxActivation(), 
    +                 bias_attr=True) as output:
    +    output += full_matrix_projection(input=lstm_average)
    +
    +outputs(classification_cost(input=output, label=data_layer(name="label", size=1)))
    +
    +
    +
    +
    +
    +

    示例2:双进双出,subseq间有memory

    +

    配置:单层RNN(sequence_rnn.conf),双层RNN(sequence_nest_rnn.confsequence_nest_rnn_readonly_memory.conf),语义完全相同。

    +
    +

    读取双层序列的方法

    +

    我们看一下单双层序列的不同数据组织形式和dataprovider(见rnn_data_provider.py

    +
    data = [
    +    [[[1, 3, 2], [4, 5, 2]], 0],
    +    [[[0, 2], [2, 5], [0, 1, 2]], 1],
    +]
    +
    +@provider(input_types=[integer_value_sub_sequence(10),
    +                       integer_value(3)])
    +def process_subseq(settings, file_name):
    +    for d in data:
    +        yield d
    +
    +@provider(input_types=[integer_value_sequence(10),
    +                       integer_value(3)])
    +def process_seq(settings, file_name):
    +    for d in data:
    +        seq = []
    +
    +
    +
      +
    • 单层序列:有两句,分别为[1,3,2,4,5,2]和[0,2,2,5,0,1,2]。
    • +
    • 双层序列:有两句,分别为[[1,3,2],[4,5,2]](2个子句)和[[0,2],[2,5],[0,1,2]](3个子句)。
    • +
    • 单双层序列的label都分别是0和1
    • +
    +
    +
    +

    模型中的配置

    +

    我们选取单双层序列配置中的不同部分,来对比分析两者语义相同的原因。

    +
      +
    • 单层序列:过了一个很简单的recurrent_group。每一个时间步,当前的输入y和上一个时间步的输出rnn_state做了一个全链接。
    • +
    +
    def step(y):
    +    mem = memory(name="rnn_state", size=hidden_dim)
    +    return fc_layer(input=[y, mem],
    +                    size=hidden_dim,
    +                    act=TanhActivation(),
    +                    bias_attr=True,
    +                    name="rnn_state")
    +
    +out = recurrent_group(step=step, input=emb)
    +
    +
    +
      +
    • 双层序列,外层memory是一个元素:
        +
      • 内层inner_step的recurrent_group和单层序列的几乎一样。除了boot_layer=outer_mem,表示将外层的outer_mem作为内层memory的初始状态。外层outer_step中,outer_mem是一个子句的最后一个向量,即整个双层group是将前一个子句的最后一个向量,作为下一个子句memory的初始状态。
      • +
      • 从输入数据上看,单双层序列的句子是一样的,只是双层序列将其又做了子序列划分。因此双层序列的配置中,必须将前一个子句的最后一个元素,作为boot_layer传给下一个子句的memory,才能保证和单层序列的配置中“每一个时间步都用了上一个时间步的输出结果”一致。
      • +
      +
    • +
    +
    def outer_step(x):
    +    outer_mem = memory(name="outer_rnn_state", size=hidden_dim)
    +    def inner_step(y):
    +        inner_mem = memory(name="inner_rnn_state",
    +                           size=hidden_dim,
    +                           boot_layer=outer_mem)
    +        return fc_layer(input=[y, inner_mem],
    +                        size=hidden_dim,
    +                        act=TanhActivation(),
    +                        bias_attr=True,
    +                        name="inner_rnn_state")
    +
    +    inner_rnn_output = recurrent_group(
    +        step=inner_step,
    +        input=x)
    +    last = last_seq(input=inner_rnn_output, name="outer_rnn_state")
    +
    +    return inner_rnn_output
    +
    +out = recurrent_group(step=outer_step, input=SubsequenceInput(emb))
    +
    +
    +
      +
    • 双层序列,外层memory是单层序列:
        +
      • 由于外层每个时间步返回的是一个子句,这些子句的长度往往不等长。因此当外层有is_seq=True的memory时,内层是无法直接使用它的,即内层memory的boot_layer不能链接外层的这个memory。
      • +
      • 如果内层memory想间接使用这个外层memory,只能通过pooling_layerlast_seqfirst_seq这三个layer将它先变成一个元素。但这种情况下,外层memory必须有boot_layer,否则在第0个时间步时,由于外层memory没有任何seq信息,因此上述三个layer的前向会报出“Check failed: input.sequenceStartPositions”的错误。
      • +
      +
    • +
    +
    +
    +
    +

    示例3:双进双出,输入不等长

    +

    输入不等长是指recurrent_group的多个输入在各时刻的长度可以不相等, 但需要指定一个和输出长度一致的input,用targetInlink表示。参考配置:单层RNN(sequence_rnn_multi_unequalength_inputs.conf),双层RNN(sequence_nest_rnn_multi_unequalength_inputs.conf

    +
    +

    读取双层序列的方法

    +

    我们看一下单双层序列的数据组织形式和dataprovider(见rnn_data_provider.py

    +
    data2 = [
    +    [[[1, 2], [4, 5, 2]], [[5, 4, 1], [3, 1]] ,0],
    +    [[[0, 2], [2, 5], [0, 1, 2]],[[1, 5], [4], [2, 3, 6, 1]], 1],
    +]
    +
    +@provider(input_types=[integer_value_sub_sequence(10),
    +                       integer_value_sub_sequence(10),
    +                       integer_value(2)],
    +          should_shuffle=False)
    +def process_unequalength_subseq(settings, file_name): #双层RNN的dataprovider
    +    for d in data2:
    +        yield d
    +
    +
    +@provider(input_types=[integer_value_sequence(10),
    +                       integer_value_sequence(10),
    +                       integer_value(2)],
    +          should_shuffle=False)
    +def process_unequalength_seq(settings, file_name): #单层RNN的dataprovider
    +    for d in data2:
    +        words1=reduce(lambda x,y: x+y, d[0])
    +        words2=reduce(lambda x,y: x+y, d[1])
    +        yield words1, words2, d[2]
    +
    +
    +

    data2 中有两个样本,每个样本有两个特征, 记fea1, fea2。

    +
      +
    • 单层序列:两个样本分别为[[1, 2, 4, 5, 2], [5, 4, 1, 3, 1]] 和 [[0, 2, 2, 5, 0, 1, 2], [1, 5, 4, 2, 3, 6, 1]]
    • +
    • 双层序列:两个样本分别为
        +
      • 样本1:[[[1, 2], [4, 5, 2]], [[5, 4, 1], [3, 1]]]。fea1和fea2都分别有2个子句,fea1=[[1, 2], [4, 5, 2]], fea2=[[5, 4, 1], [3, 1]]
      • +
      • 样本2:[[[0, 2], [2, 5], [0, 1, 2]],[[1, 5], [4], [2, 3, 6, 1]]]。fea1和fea2都分别有3个子句, fea1=[[0, 2], [2, 5], [0, 1, 2]], fea2=[[1, 5], [4], [2, 3, 6, 1]]。
      • +
      • 注意:每个样本中,各特征的子句数目需要相等。这里说的“双进双出,输入不等长”是指fea1在i时刻的输入的长度可以不等于fea2在i时刻的输入的长度。如对于第1个样本,时刻i=2, fea1[2]=[4, 5, 2],fea2[2]=[3, 1],3≠2。
      • +
      +
    • +
    • 单双层序列中,两个样本的label都分别是0和1
    • +
    +
    +
    +

    模型中的配置

    +

    单层RNN(sequence_rnn_multi_unequalength_inputs.conf)和双层RNN(sequence_nest_rnn_multi_unequalength_inputs.conf)两个模型配置达到的效果完全一样,区别只在于输入为单层还是双层序列,现在我们来看它们内部分别是如何实现的。

    +
      +
    • 单层序列:
        +
      • 过了一个简单的recurrent_group。每一个时间步,当前的输入y和上一个时间步的输出rnn_state做了一个全连接,功能与示例2中sequence_rnn.confstep函数完全相同。这里,两个输入x1,x2分别通过calrnn返回最后时刻的状态。结果得到的encoder1_rep和encoder2_rep分别是单层序列,最后取encoder1_rep的最后一个时刻和encoder2_rep的所有时刻分别相加得到context。
      • +
      • 注意到这里recurrent_group输入的每个样本中,fea1和fea2的长度都分别相等,这并非偶然,而是因为recurrent_group要求输入为单层序列时,所有输入的长度都必须相等。
      • +
      +
    • +
    +
    def step(x1, x2):
    +    def calrnn(y):
    +        mem = memory(name = 'rnn_state_' + y.name, size = hidden_dim)
    +        out = fc_layer(input = [y, mem],
    +            size = hidden_dim,
    +            act = TanhActivation(),
    +            bias_attr = True,
    +            name = 'rnn_state_' + y.name)
    +        return out
    +
    +    encoder1 = calrnn(x1)
    +    encoder2 = calrnn(x2)
    +    return [encoder1, encoder2]
    +    
    +encoder1_rep, encoder2_rep = recurrent_group(
    +    name="stepout",                           
    +    step=step,
    +    input=[emb1, emb2])
    +
    +encoder1_last = last_seq(input = encoder1_rep)                           
    +encoder1_expandlast = expand_layer(input = encoder1_last,
    +                                   expand_as = encoder2_rep)
    +context = mixed_layer(input = [identity_projection(encoder1_expandlast),
    +                               identity_projection(encoder2_rep)],
    +                      size = hidden_dim)
    +
    +
    +
      +
    • 双层序列:
        +
      • 双层RNN中,对输入的两个特征分别求时序上的连续全连接(inner_step1inner_step2分别处理fea1和fea2),其功能与示例2中sequence_nest_rnn.confouter_step函数完全相同。不同之处是,此时输入[SubsequenceInput(emb1), SubsequenceInput(emb2)]在各时刻并不等长。
      • +
      • 函数outer_step中可以分别处理这两个特征,但我们需要用targetInlink指定recurrent_group的输出的格式(各子句长度)只能和其中一个保持一致,如这里选择了和emb2的长度一致。
      • +
      • 最后,依然是取encoder1_rep的最后一个时刻和encoder2_rep的所有时刻分别相加得到context。
      • +
      +
    • +
    +
    def outer_step(x1, x2):
    +    outer_mem1 = memory(name = "outer_rnn_state1", size = hidden_dim)
    +    outer_mem2 = memory(name = "outer_rnn_state2", size = hidden_dim)
    +    def inner_step1(y):
    +        inner_mem = memory(name = 'inner_rnn_state_' + y.name,
    +                           size = hidden_dim,
    +                           boot_layer = outer_mem1)
    +        out = fc_layer(input = [y, inner_mem],
    +                       size = hidden_dim,
    +                       act = TanhActivation(),
    +                       bias_attr = True,
    +                       name = 'inner_rnn_state_' + y.name)
    +        return out
    +
    +    def inner_step2(y):
    +        inner_mem = memory(name = 'inner_rnn_state_' + y.name,
    +                           size = hidden_dim,
    +                           boot_layer = outer_mem2)
    +        out = fc_layer(input = [y, inner_mem],
    +                       size = hidden_dim,
    +                       act = TanhActivation(),
    +                       bias_attr = True,
    +                       name = 'inner_rnn_state_' + y.name)
    +        return out
    +
    +    encoder1 = recurrent_group(
    +        step = inner_step1,
    +        name = 'inner1',
    +        input = x1)
    +
    +    encoder2 = recurrent_group(
    +        step = inner_step2,
    +        name = 'inner2',
    +        input = x2)
    +
    +    sentence_last_state1 = last_seq(input = encoder1, name = 'outer_rnn_state1')
    +    sentence_last_state2_ = last_seq(input = encoder2, name = 'outer_rnn_state2')
    +
    +    encoder1_expand = expand_layer(input = sentence_last_state1,
    +                                   expand_as = encoder2)
    +
    +    return [encoder1_expand, encoder2]
    +
    +encoder1_rep, encoder2_rep = recurrent_group(
    +    name="outer",
    +    step=outer_step,
    +    input=[SubsequenceInput(emb1), SubsequenceInput(emb2)],
    +    targetInlink=emb2)
    +
    +encoder1_last = last_seq(input = encoder1_rep)
    +encoder1_expandlast = expand_layer(input = encoder1_last,
    +                                   expand_as = encoder2_rep)
    +context = mixed_layer(input = [identity_projection(encoder1_expandlast),
    +                               identity_projection(encoder2_rep)],
    +                      size = hidden_dim)
    +
    +
    +
    +
    + +
    + + +
    +
    +
    + +
    +
    + + + + \ No newline at end of file diff --git a/doc_cn/algorithm/rnn/rnn-tutorial.html b/doc_cn/algorithm/rnn/rnn-tutorial.html new file mode 100644 index 0000000000000000000000000000000000000000..b49147e5237bb35b449ed4057f58d3b94a5e7407 --- /dev/null +++ b/doc_cn/algorithm/rnn/rnn-tutorial.html @@ -0,0 +1,222 @@ + + + + + + + + + + Recurrent Group教程 — PaddlePaddle documentation + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    +

    Recurrent Group教程

    +
    +

    概述

    +

    序列数据是自然语言处理任务面对的一种主要输入数据类型。

    +

    一句话是由词语构成的序列,多句话进一步构成了段落。因此,段落可以看作是一个嵌套的双层的序列,这个序列的每个元素又是一个序列。

    +

    双层序列是PaddlePaddle支持的一种非常灵活的数据组织方式,帮助我们更好地描述段落、多轮对话等更为复杂的语言数据。基于双层序列输入,我们可以设计搭建一个灵活的、层次化的RNN,分别从词语和句子级别编码输入数据,同时也能够引入更加复杂的记忆机制,更好地完成一些复杂的语言理解任务。

    +

    在PaddlePaddle中,recurrent_group是一种任意复杂的RNN单元,用户只需定义RNN在一个时间步内完成的计算,PaddlePaddle负责完成信息和误差在时间序列上的传播。

    +

    更进一步,recurrent_group同样可以扩展到双层序列的处理上。通过两个嵌套的recurrent_group分别定义子句级别和词语级别上需要完成的运算,最终实现一个层次化的复杂RNN。

    +

    目前,在PaddlePaddle中,能够对双向序列进行处理的有recurrent_group和部分Layer,具体可参考文档:支持双层序列作为输入的Layer

    +
    +
    +

    相关概念

    +
    +

    基本原理

    +

    recurrent_group 是PaddlePaddle支持的一种任意复杂的RNN单元。使用者只需要关注于设计RNN在一个时间步之内完成的计算,PaddlePaddle负责完成信息和梯度在时间序列上的传播。

    +

    PaddlePaddle中,recurrent_group的一个简单调用如下:

    +
    recurrent_group(step, input, reverse)
    +
    +
    +
      +
    • step:一个可调用的函数,定义一个时间步之内RNN单元完成的计算
    • +
    • input:输入,必须是一个单层序列,或者一个双层序列
    • +
    • reverse:是否以逆序处理输入序列
    • +
    +

    使用recurrent_group的核心是设计step函数的计算逻辑。step函数内部可以自由组合PaddlePaddle支持的各种layer,完成任意的运算逻辑。recurrent_group 的输入(即input)会成为step函数的输入,由于step 函数只关注于RNN一个时间步之内的计算,在这里recurrent_group替我们完成了原始输入数据的拆分。

    +
    +
    +

    输入

    +

    recurrent_group处理的输入序列主要分为以下三种类型:

    +
      +
    • 数据输入:一个双层序列进入recurrent_group会被拆解为一个单层序列,一个单层序列进入recurrent_group会被拆解为非序列,然后交给step函数,这一过程对用户是完全透明的。可以有以下两种:1)通过data_layer拿到的用户输入;2)其它layer的输出。
    • +
    • 只读Memory输入StaticInput 定义了一个只读的Memory,由StaticInput指定的输入不会被recurrent_group拆解,recurrent_group 循环展开的每个时间步总是能够引用所有输入,可以是一个非序列,或者一个单层序列。
    • +
    • 序列生成任务的输入GeneratedInput只用于在序列生成任务中指定输入数据。
    • +
    +
    +
    +

    输入示例

    +

    序列生成任务大多遵循encoder-decoer架构,encoder和decoder可以是能够处理序列的任意神经网络单元,而RNN是最流行的选择。

    +

    给定encoder输出和当前词,decoder每次预测产生下一个最可能的词语。在这种结构中,decoder接受两个输入:

    +
      +
    • 要生成的目标序列:是decoder的数据输入,也是decoder循环展开的依据,recurrent_group会对这类输入进行拆解。
    • +
    • encoder输出,可以是一个非序列,或者一个单层序列:是一个unbounded memory,decoder循环展开的每一个时间步会引用全部结果,不应该被拆解,这种类型的输入必须通过StaticInput指定。关于Unbounded Memory的更多讨论请参考论文 Neural Turning Machine
    • +
    +

    在序列生成任务中,decoder RNN总是引用上一时刻预测出的词的词向量,作为当前时刻输入。GeneratedInput自动完成这一过程。

    +
    +
    +

    输出

    +

    step函数必须返回一个或多个Layer的输出,这个Layer的输出会作为整个recurrent_group 最终的输出结果。在输出的过程中,recurrent_group 会将每个时间步的输出拼接,这个过程对用户也是透明的。

    +
    +
    +

    memory

    +

    memory只能在recurrent_group中定义和使用。memory不能独立存在,必须指向一个PaddlePaddle定义的Layer。引用memory得到这layer上一时刻输出,因此,可以将memory理解为一个时延操作。

    +

    可以显示地指定一个layer的输出用于初始化memory。不指定时,memory默认初始化为0。

    +
    +
    +
    +

    双层RNN介绍

    +

    recurrent_group帮助我们完成对输入序列的拆分,对输出的合并,以及计算逻辑在序列上的循环展开。

    +

    利用这种特性,两个嵌套的recurrent_group能够处理双层序列,实现词语和句子两个级别的双层RNN结构。

    +
      +
    • 单层(word-level)RNN:每个状态(state)对应一个词(word)。
    • +
    • 双层(sequence-level)RNN:一个双层RNN由多个单层RNN组成,每个单层RNN(即双层RNN的每个状态)对应一个子句(subseq)。
    • +
    +

    为了描述方便,下文以NLP任务为例,将含有子句(subseq)的段落定义为一个双层序列,将含有词语的句子定义为一个单层序列,那么0层序列即为一个词语。

    +
    +
    +

    双层RNN的使用

    +
    +

    训练流程的使用方法

    +

    使用 recurrent_group需要遵循以下约定:

    +
      +
    • 单进单出:输入和输出都是单层序列。
        +
      • 如果有多个输入,不同输入序列含有的词语数必须严格相等。
      • +
      • 输出一个单层序列,输出序列的词语数和输入序列一致。
      • +
      • memory:在step函数中定义 memory指向一个layer,通过引用memory得到这个layer上一个时刻输出,形成recurrent 连接。memory的is_seq参数必须为false。如果没有定义memory,每个时间步之内的运算是独立的。
      • +
      • boot_layer:memory的初始状态,默认初始状为0,memory的is_seq参数必须为false。
      • +
      +
    • +
    • 双进双出:输入和输出都是双层序列。
        +
      • 如果有多个输入序列,不同输入含有的子句(subseq)数必须严格相等,但子句含有的词语数可以不相等。
      • +
      • 输出一个双层序列,子句(subseq)数、子句的单词数和指定的一个输入序列一致,默认为第一个输入。
      • +
      • memory:在step函数中定义memory,指向一个layer,通过引用memory得到这个layer上一个时刻的输出,形成recurrent连接。定义在外层recurrent_group step函数中的memory,能够记录上一个subseq 的状态,可以是一个单层序列(只作为read-only memory),也可以是一个词语。如果没有定义memory,那么 subseq 之间的运算是独立的。
      • +
      • boot_layer:memory 初始状态,可以是一个单层序列(只作为read-only memory)或一个向量。默认不设置,即初始状态为0。
      • +
      +
    • +
    • 双进单出:目前还未支持,会报错”In hierachical RNN, all out links should be from sequences now”。
    • +
    +
    +
    +

    生成流程的使用方法

    +

    使用beam_search需要遵循以下约定:

    +
      +
    • 单层RNN:从一个word生成下一个word。
    • +
    • 双层RNN:即把单层RNN生成后的subseq给拼接成一个新的双层seq。从语义上看,也不存在一个subseq直接生成下一个subseq的情况。
    • +
    +
    +
    +
    + + +
    +
    +
    + +
    +
    + + + + \ No newline at end of file diff --git a/doc_cn/build/docker/build_docker_image.html b/doc_cn/build/docker/build_docker_image.html index ae6fade3d8505d76dc4c3ba51cadef8e4e902376..0e3b695d1eb2b69715732bc77bae99d0b68e41b7 100644 --- a/doc_cn/build/docker/build_docker_image.html +++ b/doc_cn/build/docker/build_docker_image.html @@ -139,7 +139,7 @@ docker build --build-arg LOWEST_DL_SPEED \ No newline at end of file diff --git a/doc_cn/build_and_install/cmake/compile_options.html b/doc_cn/build_and_install/cmake/compile_options.html index b51c36246355f01f6f920f0f82a7872860c72ca9..890f0b96b2c2b06e5d20b62574daf81f320ff5bb 100644 --- a/doc_cn/build_and_install/cmake/compile_options.html +++ b/doc_cn/build_and_install/cmake/compile_options.html @@ -247,7 +247,7 @@ cmake \ No newline at end of file diff --git a/doc_cn/build_and_install/cmake/index.html b/doc_cn/build_and_install/cmake/index.html index 0b07ce9913506cc5a6d4cc0bc12e9d05d1544e9a..496ae61238a1c7855b2fd62ece67355f2e687bcb 100644 --- a/doc_cn/build_and_install/cmake/index.html +++ b/doc_cn/build_and_install/cmake/index.html @@ -113,7 +113,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/build_and_install/cmake/install_deps.html b/doc_cn/build_and_install/cmake/install_deps.html index b8d83b1f6959f17b35e3eda6dd89a1234c49e81c..da36e4d5784209e64ad338f5e63e94f10c3d70b0 100644 --- a/doc_cn/build_and_install/cmake/install_deps.html +++ b/doc_cn/build_and_install/cmake/install_deps.html @@ -99,7 +99,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/build_and_install/cmake/make_and_install.html b/doc_cn/build_and_install/cmake/make_and_install.html index 4effe1c33647f16ee0afee78a1dd3ef9bb5779d5..091ff1d129056daa80beebebc365999938f2b710 100644 --- a/doc_cn/build_and_install/cmake/make_and_install.html +++ b/doc_cn/build_and_install/cmake/make_and_install.html @@ -99,7 +99,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/build_and_install/index.html b/doc_cn/build_and_install/index.html index 23d66944b1fcd18c85c25575ff34c3bf1aa73c61..a25a32b335ff1d441eba7a7256372f2693cfde9c 100644 --- a/doc_cn/build_and_install/index.html +++ b/doc_cn/build_and_install/index.html @@ -58,16 +58,28 @@ var _hmt = _hmt || [];

    编译与安装

    +
    +

    安装

    PaddlePaddle提供数个预编译的二进制来进行安装,包括Docker镜像,ubuntu的deb安装包等。我们推荐使用Docker镜像来部署环境,同时欢迎贡献更多的安装包。

    -

    Note: The intallation packages are still in pre-release state and your experience of installation may not be smooth.

    -

    注意:目前PaddlePaddle的安装包还处在pre-release的状态,使用起来或许会不是很顺畅。

    +
    +
    +

    编译

    +
    +

    Warning

    +

    编译选项主要推荐高级用户查看,普通用户请走安装流程。

    +
    + +
    @@ -76,6 +88,15 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/cmd/merge_model.html b/doc_cn/ui/cmd/merge_model.html index c5ee440fe4154e88b75eb2c284804e60c946005f..2a0affffe0c7db5f6d25de09c1904478ee7f6d79 100644 --- a/doc_cn/ui/cmd/merge_model.html +++ b/doc_cn/ui/cmd/merge_model.html @@ -95,7 +95,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/cmd/paddle_pserver.html b/doc_cn/ui/cmd/paddle_pserver.html index 05e1a1d4177a147504cd82c00467b907ae3f8d74..a225bf3eec0f5747a03097b1d1981f70edc2b510 100644 --- a/doc_cn/ui/cmd/paddle_pserver.html +++ b/doc_cn/ui/cmd/paddle_pserver.html @@ -98,7 +98,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/cmd/paddle_train.html b/doc_cn/ui/cmd/paddle_train.html index ad87820ba819dbe39421b257146fb49ad8b493bf..8a575dbdcada7db686776e687d7d839c5d26b46e 100644 --- a/doc_cn/ui/cmd/paddle_train.html +++ b/doc_cn/ui/cmd/paddle_train.html @@ -98,7 +98,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/cmd/paddle_version.html b/doc_cn/ui/cmd/paddle_version.html index b1e38980dfb7b917001aa9cb5c95c042e7efc473..8e3d613e9b59ded1bb5771640c90d57753017d5e 100644 --- a/doc_cn/ui/cmd/paddle_version.html +++ b/doc_cn/ui/cmd/paddle_version.html @@ -114,7 +114,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/data_provider/index.html b/doc_cn/ui/data_provider/index.html index c49184676d372e2a564f3b025f038634df4b556a..216b20d887db8766282ea18c26905cd7cac35e03 100644 --- a/doc_cn/ui/data_provider/index.html +++ b/doc_cn/ui/data_provider/index.html @@ -125,7 +125,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/data_provider/pydataprovider2.html b/doc_cn/ui/data_provider/pydataprovider2.html index bfae21080c05da9061bc71eface1af14448e6dd6..c03ec088c78a1aa639b7e0db0f0dd66710521fdf 100644 --- a/doc_cn/ui/data_provider/pydataprovider2.html +++ b/doc_cn/ui/data_provider/pydataprovider2.html @@ -99,17 +99,11 @@ train.list即为

    19 20 21 -22 -23 -24 -25
    from paddle.trainer.PyDataProvider2 import *
    +22
    from paddle.trainer.PyDataProvider2 import *
     
     
     # Define a py data provider
    -@provider(input_types=[
    -    dense_vector(28 * 28),
    -    integer_value(10)
    -])
    +@provider(input_types=[dense_vector(28 * 28), integer_value(10)])
     def process(settings, filename):  # settings is not used currently.
         f = open(filename, 'r')  # open one of training file
     
    @@ -150,10 +144,11 @@ process函数调用多次 
     

    在训练配置里,只需要使用一行代码即可以设置训练引用这个DataProvider。这个设置为

    from paddle.trainer_config_helpers import *
     
    -define_py_data_sources2(train_list='train.list',
    -                        test_list=None,
    -                        module='mnist_provider',
    -                        obj='process')
    +define_py_data_sources2(
    +    train_list='train.list',
    +    test_list=None,
    +    module='mnist_provider',
    +    obj='process')
     img = data_layer(name='pixel', size=784)
     label = data_layer(name='label', size=10)
     
    @@ -184,15 +179,13 @@ process函数调用多次 21 22 23 -24 -25
    from paddle.trainer.PyDataProvider2 import *
    +24
    from paddle.trainer.PyDataProvider2 import *
     
     
     # Define a py data provider
    -@provider(input_types=[
    -    dense_vector(28 * 28),
    -    integer_value(10)
    -])
    +@provider(
    +    input_types={'pixel': dense_vector(28 * 28),
    +                 'label': integer_value(10)})
     def process(settings, filename):  # settings is not used currently.
         f = open(filename, 'r')  # open one of training file
     
    @@ -207,7 +200,7 @@ process函数调用多次 
                 pixels_float.append(float(each_pixel_str))
     
             # give data to paddle.
    -        yield { "pixel": pixels_float, 'label': int(label) }
    +        yield {"pixel": pixels_float, 'label': int(label)}
     
         f.close()  # close file
     
    @@ -252,7 +245,8 @@ process函数调用多次 # The text is a sequence of integer values, and each value is a word id. # The whole sequence is the sentences that we want to predict its # sentimental. - integer_value(len(dictionary), seq_type=SequenceType), # text input + integer_value( + len(dictionary), seq_type=SequenceType), # text input # label positive/negative integer_value(2) @@ -300,12 +294,15 @@ DataProvider创建的时候执行。这个初始化函数具有如下参数:

    dictionary = dict() ... # read dictionary from outside -define_py_data_sources2(train_list='train.list', test_list=None, - module='sentimental_provider', obj='process', - # above codes same as mnist sample. - args={ # pass to provider. - 'dictionary': dictionary - }) +define_py_data_sources2( + train_list='train.list', + test_list=None, + module='sentimental_provider', + obj='process', + # above codes same as mnist sample. + args={ # pass to provider. + 'dictionary': dictionary + })

    这个声明基本上和mnist的样例一致。除了

    @@ -340,8 +337,6 @@ DataProvider创建的时候执行。这个初始化函数具有如下参数:

    是一个batch size,但是有时为了计算均衡性,可以将一条数据设置成多个batch size
  • cache 是数据缓存的策略,参考 cache
  • init_hook 是初始化时调用的函数,参考 init_hook
  • -
  • use_dynamic_order 如果是true的话,可以返回一个dict,key是data_layer的名字,value是特征值。同时,也可以 -返回一个list或者tuple。如果是false的话,只能够返回list或者tuple
  • check 设置成true的话,会根据input_types检查数据的合法性。
  • check_fail_continue 如果设置成true的话,即使在check中数据不合法,也会扔到这条数据,继续训练。 如果 check是false的话,没有作用。
  • @@ -550,7 +545,7 @@ DataProvider \ No newline at end of file diff --git a/doc_cn/ui/data_provider/write_new_dataprovider.html b/doc_cn/ui/data_provider/write_new_dataprovider.html index f68366ce32458bf36385fb22c390707326ccc2a3..07567c077e0d2b7132c727439d3861301a65fda3 100644 --- a/doc_cn/ui/data_provider/write_new_dataprovider.html +++ b/doc_cn/ui/data_provider/write_new_dataprovider.html @@ -99,7 +99,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/index.html b/doc_cn/ui/index.html index 21af749dfafd7338d8e507822b4cf5eeabc1ed40..e76d79bf4ad5c77d87f7afe7c6ee2223945c3dfc 100644 --- a/doc_cn/ui/index.html +++ b/doc_cn/ui/index.html @@ -132,7 +132,7 @@ var _hmt = _hmt || []; \ No newline at end of file diff --git a/doc_cn/ui/predict/swig_py_paddle.html b/doc_cn/ui/predict/swig_py_paddle.html index a10a0d9ecc3c02798aa335b30506538a08acbb1a..4d02cfd0d65416a370f184c784ee30858dfe143d 100644 --- a/doc_cn/ui/predict/swig_py_paddle.html +++ b/doc_cn/ui/predict/swig_py_paddle.html @@ -72,21 +72,21 @@ var _hmt = _hmt || []; from paddle.trainer.PyDataProvider2 import dense_vector from paddle.trainer.config_parser import parse_config - -def main(): - conf = parse_config("./mnist_model/trainer_config.py", "") - print conf.data_config.load_data_args - network = swig_paddle.GradientMachine.createFromConfigProto(conf.model_config) - assert isinstance(network, swig_paddle.GradientMachine) # For code hint. - network.loadParameters("./mnist_model/") - converter = DataProviderConverter([dense_vector(784)]) - inArg = converter(TEST_DATA) - print network.forwardTest(inArg) - - -if __name__ == '__main__': - swig_paddle.initPaddle("--use_gpu=0") - main() + 0.988235, 0.988235, 0.552941, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.211765, + 0.878431, 0.988235, 0.992157, 0.701961, 0.329412, 0.109804, 0, 0, 0, 0, 0, + 0, 0, 0.698039, 0.988235, 0.913725, 0.145098, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0.188235, 0.890196, 0.988235, 0.988235, 0.745098, 0.047059, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0.882353, 0.988235, 0.568627, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.2, + 0.933333, 0.992157, 0.992157, 0.992157, 0.447059, 0.294118, 0, 0, 0, 0, 0, + 0, 0, 0, 0.447059, 0.992157, 0.768627, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0.623529, 0.988235, 0.988235, 0.988235, 0.988235, 0.992157, 0.47451, 0, 0, + 0, 0, 0, 0, 0, 0.188235, 0.933333, 0.87451, 0.509804, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0.992157, 0.988235, 0.937255, 0.792157, 0.988235, 0.894118, + 0.082353, 0, 0, 0, 0, 0, 0, 0.027451, 0.647059, 0.992157, 0.654902, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0.623529, 0.988235, 0.913725, 0.329412, 0.376471, + 0.184314, 0, 0, 0, 0, 0, 0, 0.027451, 0.513725, 0.988235, 0.635294, + 0.219608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.196078, 0.929412, 0.988235, + 0.988235, 0.741176, 0.309804, 0, 0, 0, 0, 0, 0, 0.529412, 0.988235,

    主要的软件包为py_paddle.swig_paddle,这个软件包文档相对完善。可以使用python的 @@ -168,7 +168,7 @@ layer作为输出,所以用于预测的配置文件要做相应的修改。

    \ No newline at end of file