diff --git a/.tools/build_docker.sh b/.tools/build_docker.sh new file mode 100755 index 0000000000000000000000000000000000000000..55faa715a4fbbda97d8ff6422fb2e3d7fe8668fc --- /dev/null +++ b/.tools/build_docker.sh @@ -0,0 +1,40 @@ +#!/bin/bash +cur_path="$(cd "$(dirname "$0")" && pwd -P)" +cd $cur_path/../ + +#convert md to ipynb +.tools/convert-markdown-into-ipynb-and-test.sh + +paddle_version=0.10.0rc2 + +#generate docker file +if [ ${USE_UBUNTU_REPO_MIRROR} ]; then + UPDATE_MIRROR_CMD="sed 's@http:\/\/archive.ubuntu.com\/ubuntu\/@mirror:\/\/mirrors.ubuntu.com\/mirrors.txt@' -i /etc/apt/sources.list && \\" +else + UPDATE_MIRROR_CMD="\\" +fi + +mkdir -p build +cat > build/Dockerfile < + +RUN ${UPDATE_MIRROR_CMD} + apt-get install locales +RUN localedef -f UTF-8 -i en_US en_US.UTF-8 + +RUN apt-get -y install gcc && \ + apt-get -y clean + +RUN pip install -U matplotlib jupyter numpy requests scipy + +COPY . /book +RUN rm -rf /book/build + +EXPOSE 8888 +CMD ["sh", "-c", "jupyter notebook --ip=0.0.0.0 --no-browser --NotebookApp.token='' --NotebookApp.disable_check_xsrf=True /book/"] +EOF + +#build docker image +echo "paddle_version:"$paddle_version +docker build --no-cache -t paddlepaddle/book:${paddle_version} -t paddlepaddle/book:latest -f ./build/Dockerfile . diff --git a/.tools/convert-markdown-into-ipynb-and-test.sh b/.tools/convert-markdown-into-ipynb-and-test.sh index ef47387dc46d96e096095189c96122be5c370741..710b61957a82c033531d267aaccafcc616e6e46d 100755 --- a/.tools/convert-markdown-into-ipynb-and-test.sh +++ b/.tools/convert-markdown-into-ipynb-and-test.sh @@ -5,9 +5,9 @@ if [ $? -ne 0 ]; then exit 1 fi -GOPATH=/tmp/go go get -u github.com/wangkuiyi/ipynb/markdown-to-ipynb +GOPATH=~/.go go get -u github.com/wangkuiyi/ipynb/markdown-to-ipynb -cur_path=$(dirname $(readlink -f $0)) +cur_path="$(cd "$(dirname "$0")" && pwd -P)" cd $cur_path/../ #convert md to ipynb diff --git a/fit_a_line/.gitignore b/01.fit_a_line/.gitignore similarity index 100% rename from fit_a_line/.gitignore rename to 01.fit_a_line/.gitignore diff --git a/fit_a_line/README.en.ipynb b/01.fit_a_line/README.en.ipynb similarity index 100% rename from fit_a_line/README.en.ipynb rename to 01.fit_a_line/README.en.ipynb diff --git a/fit_a_line/README.en.md b/01.fit_a_line/README.en.md similarity index 100% rename from fit_a_line/README.en.md rename to 01.fit_a_line/README.en.md diff --git a/fit_a_line/README.ipynb b/01.fit_a_line/README.ipynb similarity index 100% rename from fit_a_line/README.ipynb rename to 01.fit_a_line/README.ipynb diff --git a/fit_a_line/README.md b/01.fit_a_line/README.md similarity index 100% rename from fit_a_line/README.md rename to 01.fit_a_line/README.md diff --git a/fit_a_line/image/predictions.png b/01.fit_a_line/image/predictions.png similarity index 100% rename from fit_a_line/image/predictions.png rename to 01.fit_a_line/image/predictions.png diff --git a/fit_a_line/image/predictions_en.png b/01.fit_a_line/image/predictions_en.png similarity index 100% rename from fit_a_line/image/predictions_en.png rename to 01.fit_a_line/image/predictions_en.png diff --git a/fit_a_line/image/ranges.png b/01.fit_a_line/image/ranges.png similarity index 100% rename from fit_a_line/image/ranges.png rename to 01.fit_a_line/image/ranges.png diff --git a/fit_a_line/image/ranges_en.png b/01.fit_a_line/image/ranges_en.png similarity index 100% rename from fit_a_line/image/ranges_en.png rename to 01.fit_a_line/image/ranges_en.png diff --git a/fit_a_line/index.en.html b/01.fit_a_line/index.en.html similarity index 100% rename from fit_a_line/index.en.html rename to 01.fit_a_line/index.en.html diff --git a/fit_a_line/index.html b/01.fit_a_line/index.html similarity index 100% rename from fit_a_line/index.html rename to 01.fit_a_line/index.html diff --git a/fit_a_line/train.py b/01.fit_a_line/train.py similarity index 100% rename from fit_a_line/train.py rename to 01.fit_a_line/train.py diff --git a/recognize_digits/.gitignore b/02.recognize_digits/.gitignore similarity index 100% rename from recognize_digits/.gitignore rename to 02.recognize_digits/.gitignore diff --git a/recognize_digits/README.en.md b/02.recognize_digits/README.en.md similarity index 100% rename from recognize_digits/README.en.md rename to 02.recognize_digits/README.en.md diff --git a/recognize_digits/README.md b/02.recognize_digits/README.md similarity index 100% rename from recognize_digits/README.md rename to 02.recognize_digits/README.md diff --git a/recognize_digits/image/cnn.png b/02.recognize_digits/image/cnn.png similarity index 100% rename from recognize_digits/image/cnn.png rename to 02.recognize_digits/image/cnn.png diff --git a/recognize_digits/image/cnn_en.png b/02.recognize_digits/image/cnn_en.png similarity index 100% rename from recognize_digits/image/cnn_en.png rename to 02.recognize_digits/image/cnn_en.png diff --git a/recognize_digits/image/cnn_train_log.png b/02.recognize_digits/image/cnn_train_log.png similarity index 100% rename from recognize_digits/image/cnn_train_log.png rename to 02.recognize_digits/image/cnn_train_log.png diff --git a/recognize_digits/image/cnn_train_log_en.png b/02.recognize_digits/image/cnn_train_log_en.png similarity index 100% rename from recognize_digits/image/cnn_train_log_en.png rename to 02.recognize_digits/image/cnn_train_log_en.png diff --git a/recognize_digits/image/conv_layer.png b/02.recognize_digits/image/conv_layer.png similarity index 100% rename from recognize_digits/image/conv_layer.png rename to 02.recognize_digits/image/conv_layer.png diff --git a/recognize_digits/image/max_pooling.png b/02.recognize_digits/image/max_pooling.png similarity index 100% rename from recognize_digits/image/max_pooling.png rename to 02.recognize_digits/image/max_pooling.png diff --git a/recognize_digits/image/max_pooling_en.png b/02.recognize_digits/image/max_pooling_en.png similarity index 100% rename from recognize_digits/image/max_pooling_en.png rename to 02.recognize_digits/image/max_pooling_en.png diff --git a/recognize_digits/image/mlp.png b/02.recognize_digits/image/mlp.png similarity index 100% rename from recognize_digits/image/mlp.png rename to 02.recognize_digits/image/mlp.png diff --git a/recognize_digits/image/mlp_en.png b/02.recognize_digits/image/mlp_en.png similarity index 100% rename from recognize_digits/image/mlp_en.png rename to 02.recognize_digits/image/mlp_en.png diff --git a/recognize_digits/image/mlp_train_log.png b/02.recognize_digits/image/mlp_train_log.png similarity index 100% rename from recognize_digits/image/mlp_train_log.png rename to 02.recognize_digits/image/mlp_train_log.png diff --git a/recognize_digits/image/mlp_train_log_en.png b/02.recognize_digits/image/mlp_train_log_en.png similarity index 100% rename from recognize_digits/image/mlp_train_log_en.png rename to 02.recognize_digits/image/mlp_train_log_en.png diff --git a/recognize_digits/image/mnist_example_image.png b/02.recognize_digits/image/mnist_example_image.png similarity index 100% rename from recognize_digits/image/mnist_example_image.png rename to 02.recognize_digits/image/mnist_example_image.png diff --git a/recognize_digits/image/softmax_regression.png b/02.recognize_digits/image/softmax_regression.png similarity index 100% rename from recognize_digits/image/softmax_regression.png rename to 02.recognize_digits/image/softmax_regression.png diff --git a/recognize_digits/image/softmax_regression_en.png b/02.recognize_digits/image/softmax_regression_en.png similarity index 100% rename from recognize_digits/image/softmax_regression_en.png rename to 02.recognize_digits/image/softmax_regression_en.png diff --git a/recognize_digits/image/softmax_train_log.png b/02.recognize_digits/image/softmax_train_log.png similarity index 100% rename from recognize_digits/image/softmax_train_log.png rename to 02.recognize_digits/image/softmax_train_log.png diff --git a/recognize_digits/image/softmax_train_log_en.png b/02.recognize_digits/image/softmax_train_log_en.png similarity index 100% rename from recognize_digits/image/softmax_train_log_en.png rename to 02.recognize_digits/image/softmax_train_log_en.png diff --git a/recognize_digits/index.en.html b/02.recognize_digits/index.en.html similarity index 100% rename from recognize_digits/index.en.html rename to 02.recognize_digits/index.en.html diff --git a/recognize_digits/index.html b/02.recognize_digits/index.html similarity index 100% rename from recognize_digits/index.html rename to 02.recognize_digits/index.html diff --git a/recognize_digits/train.py b/02.recognize_digits/train.py similarity index 100% rename from recognize_digits/train.py rename to 02.recognize_digits/train.py diff --git a/image_classification/.gitignore b/03.image_classification/.gitignore similarity index 100% rename from image_classification/.gitignore rename to 03.image_classification/.gitignore diff --git a/image_classification/README.en.md b/03.image_classification/README.en.md similarity index 100% rename from image_classification/README.en.md rename to 03.image_classification/README.en.md diff --git a/image_classification/README.ipynb b/03.image_classification/README.ipynb similarity index 100% rename from image_classification/README.ipynb rename to 03.image_classification/README.ipynb diff --git a/image_classification/README.md b/03.image_classification/README.md similarity index 100% rename from image_classification/README.md rename to 03.image_classification/README.md diff --git a/image_classification/image/cifar.png b/03.image_classification/image/cifar.png similarity index 100% rename from image_classification/image/cifar.png rename to 03.image_classification/image/cifar.png diff --git a/image_classification/image/dog.png b/03.image_classification/image/dog.png similarity index 100% rename from image_classification/image/dog.png rename to 03.image_classification/image/dog.png diff --git a/image_classification/image/dog_cat.png b/03.image_classification/image/dog_cat.png similarity index 100% rename from image_classification/image/dog_cat.png rename to 03.image_classification/image/dog_cat.png diff --git a/image_classification/image/fea_conv0.png b/03.image_classification/image/fea_conv0.png similarity index 100% rename from image_classification/image/fea_conv0.png rename to 03.image_classification/image/fea_conv0.png diff --git a/image_classification/image/flowers.png b/03.image_classification/image/flowers.png similarity index 100% rename from image_classification/image/flowers.png rename to 03.image_classification/image/flowers.png diff --git a/image_classification/image/googlenet.jpeg b/03.image_classification/image/googlenet.jpeg similarity index 100% rename from image_classification/image/googlenet.jpeg rename to 03.image_classification/image/googlenet.jpeg diff --git a/image_classification/image/ilsvrc.png b/03.image_classification/image/ilsvrc.png similarity index 100% rename from image_classification/image/ilsvrc.png rename to 03.image_classification/image/ilsvrc.png diff --git a/image_classification/image/inception.png b/03.image_classification/image/inception.png similarity index 100% rename from image_classification/image/inception.png rename to 03.image_classification/image/inception.png diff --git a/image_classification/image/inception_en.png b/03.image_classification/image/inception_en.png similarity index 100% rename from image_classification/image/inception_en.png rename to 03.image_classification/image/inception_en.png diff --git a/image_classification/image/lenet.png b/03.image_classification/image/lenet.png similarity index 100% rename from image_classification/image/lenet.png rename to 03.image_classification/image/lenet.png diff --git a/image_classification/image/lenet_en.png b/03.image_classification/image/lenet_en.png similarity index 100% rename from image_classification/image/lenet_en.png rename to 03.image_classification/image/lenet_en.png diff --git a/image_classification/image/plot.png b/03.image_classification/image/plot.png similarity index 100% rename from image_classification/image/plot.png rename to 03.image_classification/image/plot.png diff --git a/image_classification/image/plot_en.png b/03.image_classification/image/plot_en.png similarity index 100% rename from image_classification/image/plot_en.png rename to 03.image_classification/image/plot_en.png diff --git a/image_classification/image/resnet.png b/03.image_classification/image/resnet.png similarity index 100% rename from image_classification/image/resnet.png rename to 03.image_classification/image/resnet.png diff --git a/image_classification/image/resnet_block.jpg b/03.image_classification/image/resnet_block.jpg similarity index 100% rename from image_classification/image/resnet_block.jpg rename to 03.image_classification/image/resnet_block.jpg diff --git a/image_classification/image/variations.png b/03.image_classification/image/variations.png similarity index 100% rename from image_classification/image/variations.png rename to 03.image_classification/image/variations.png diff --git a/image_classification/image/variations_en.png b/03.image_classification/image/variations_en.png similarity index 100% rename from image_classification/image/variations_en.png rename to 03.image_classification/image/variations_en.png diff --git a/image_classification/image/vgg16.png b/03.image_classification/image/vgg16.png similarity index 100% rename from image_classification/image/vgg16.png rename to 03.image_classification/image/vgg16.png diff --git a/image_classification/index.en.html b/03.image_classification/index.en.html similarity index 100% rename from image_classification/index.en.html rename to 03.image_classification/index.en.html diff --git a/image_classification/index.html b/03.image_classification/index.html similarity index 100% rename from image_classification/index.html rename to 03.image_classification/index.html diff --git a/image_classification/resnet.py b/03.image_classification/resnet.py similarity index 100% rename from image_classification/resnet.py rename to 03.image_classification/resnet.py diff --git a/image_classification/train.py b/03.image_classification/train.py similarity index 100% rename from image_classification/train.py rename to 03.image_classification/train.py diff --git a/image_classification/vgg.py b/03.image_classification/vgg.py similarity index 100% rename from image_classification/vgg.py rename to 03.image_classification/vgg.py diff --git a/word2vec/.gitignore b/04.word2vec/.gitignore similarity index 100% rename from word2vec/.gitignore rename to 04.word2vec/.gitignore diff --git a/word2vec/README.en.md b/04.word2vec/README.en.md similarity index 100% rename from word2vec/README.en.md rename to 04.word2vec/README.en.md diff --git a/word2vec/README.md b/04.word2vec/README.md similarity index 100% rename from word2vec/README.md rename to 04.word2vec/README.md diff --git a/word2vec/calculate_dis.py b/04.word2vec/calculate_dis.py similarity index 100% rename from word2vec/calculate_dis.py rename to 04.word2vec/calculate_dis.py diff --git a/word2vec/format_convert.py b/04.word2vec/format_convert.py similarity index 100% rename from word2vec/format_convert.py rename to 04.word2vec/format_convert.py diff --git a/word2vec/image/2d_similarity.png b/04.word2vec/image/2d_similarity.png similarity index 100% rename from word2vec/image/2d_similarity.png rename to 04.word2vec/image/2d_similarity.png diff --git a/word2vec/image/cbow.png b/04.word2vec/image/cbow.png similarity index 100% rename from word2vec/image/cbow.png rename to 04.word2vec/image/cbow.png diff --git a/word2vec/image/cbow_en.png b/04.word2vec/image/cbow_en.png similarity index 100% rename from word2vec/image/cbow_en.png rename to 04.word2vec/image/cbow_en.png diff --git a/word2vec/image/ngram.en.png b/04.word2vec/image/ngram.en.png similarity index 100% rename from word2vec/image/ngram.en.png rename to 04.word2vec/image/ngram.en.png diff --git a/word2vec/image/ngram.png b/04.word2vec/image/ngram.png similarity index 100% rename from word2vec/image/ngram.png rename to 04.word2vec/image/ngram.png diff --git a/word2vec/image/nnlm.png b/04.word2vec/image/nnlm.png similarity index 100% rename from word2vec/image/nnlm.png rename to 04.word2vec/image/nnlm.png diff --git a/word2vec/image/nnlm_en.png b/04.word2vec/image/nnlm_en.png similarity index 100% rename from word2vec/image/nnlm_en.png rename to 04.word2vec/image/nnlm_en.png diff --git a/word2vec/image/sentence_emb.png b/04.word2vec/image/sentence_emb.png similarity index 100% rename from word2vec/image/sentence_emb.png rename to 04.word2vec/image/sentence_emb.png diff --git a/word2vec/image/skipgram.png b/04.word2vec/image/skipgram.png similarity index 100% rename from word2vec/image/skipgram.png rename to 04.word2vec/image/skipgram.png diff --git a/word2vec/image/skipgram_en.png b/04.word2vec/image/skipgram_en.png similarity index 100% rename from word2vec/image/skipgram_en.png rename to 04.word2vec/image/skipgram_en.png diff --git a/word2vec/index.en.html b/04.word2vec/index.en.html similarity index 100% rename from word2vec/index.en.html rename to 04.word2vec/index.en.html diff --git a/word2vec/index.html b/04.word2vec/index.html similarity index 100% rename from word2vec/index.html rename to 04.word2vec/index.html diff --git a/word2vec/train.py b/04.word2vec/train.py similarity index 100% rename from word2vec/train.py rename to 04.word2vec/train.py diff --git a/understand_sentiment/.gitignore b/05.understand_sentiment/.gitignore similarity index 100% rename from understand_sentiment/.gitignore rename to 05.understand_sentiment/.gitignore diff --git a/understand_sentiment/README.en.md b/05.understand_sentiment/README.en.md similarity index 99% rename from understand_sentiment/README.en.md rename to 05.understand_sentiment/README.en.md index dfca945c975ed86571a590284116626b52c1d76c..5db0347208729a71986d6dc14e97bc5d8f0bc3a5 100644 --- a/understand_sentiment/README.en.md +++ b/05.understand_sentiment/README.en.md @@ -334,7 +334,7 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): - result = trainer.test(reader=test_reader, reader_dict=reader_dict) + result = trainer.test(reader=test_reader, feeding=feeding) print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics) ``` diff --git a/understand_sentiment/README.md b/05.understand_sentiment/README.md similarity index 100% rename from understand_sentiment/README.md rename to 05.understand_sentiment/README.md diff --git a/understand_sentiment/image/lstm.png b/05.understand_sentiment/image/lstm.png similarity index 100% rename from understand_sentiment/image/lstm.png rename to 05.understand_sentiment/image/lstm.png diff --git a/understand_sentiment/image/lstm_en.png b/05.understand_sentiment/image/lstm_en.png similarity index 100% rename from understand_sentiment/image/lstm_en.png rename to 05.understand_sentiment/image/lstm_en.png diff --git a/understand_sentiment/image/rnn.png b/05.understand_sentiment/image/rnn.png similarity index 100% rename from understand_sentiment/image/rnn.png rename to 05.understand_sentiment/image/rnn.png diff --git a/understand_sentiment/image/stacked_lstm.jpg b/05.understand_sentiment/image/stacked_lstm.jpg similarity index 100% rename from understand_sentiment/image/stacked_lstm.jpg rename to 05.understand_sentiment/image/stacked_lstm.jpg diff --git a/understand_sentiment/image/stacked_lstm_en.png b/05.understand_sentiment/image/stacked_lstm_en.png similarity index 100% rename from understand_sentiment/image/stacked_lstm_en.png rename to 05.understand_sentiment/image/stacked_lstm_en.png diff --git a/understand_sentiment/image/text_cnn.png b/05.understand_sentiment/image/text_cnn.png similarity index 100% rename from understand_sentiment/image/text_cnn.png rename to 05.understand_sentiment/image/text_cnn.png diff --git a/understand_sentiment/image/text_cnn_en.png b/05.understand_sentiment/image/text_cnn_en.png similarity index 100% rename from understand_sentiment/image/text_cnn_en.png rename to 05.understand_sentiment/image/text_cnn_en.png diff --git a/understand_sentiment/index.en.html b/05.understand_sentiment/index.en.html similarity index 99% rename from understand_sentiment/index.en.html rename to 05.understand_sentiment/index.en.html index 14d87b0da2bd0b0c1ed4f12148efbec5c77ca3f5..d64b42bea01afa58e6402d01f4fd457a80c91c84 100644 --- a/understand_sentiment/index.en.html +++ b/05.understand_sentiment/index.en.html @@ -376,7 +376,7 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): - result = trainer.test(reader=test_reader, reader_dict=reader_dict) + result = trainer.test(reader=test_reader, feeding=feeding) print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics) ``` diff --git a/understand_sentiment/index.html b/05.understand_sentiment/index.html similarity index 100% rename from understand_sentiment/index.html rename to 05.understand_sentiment/index.html diff --git a/understand_sentiment/train.py b/05.understand_sentiment/train.py similarity index 100% rename from understand_sentiment/train.py rename to 05.understand_sentiment/train.py diff --git a/label_semantic_roles/.gitignore b/06.label_semantic_roles/.gitignore similarity index 100% rename from label_semantic_roles/.gitignore rename to 06.label_semantic_roles/.gitignore diff --git a/label_semantic_roles/README.en.md b/06.label_semantic_roles/README.en.md similarity index 80% rename from label_semantic_roles/README.en.md rename to 06.label_semantic_roles/README.en.md index 6fd83b71891fbcbc5fc736b47fbaf1be61a22f60..888598c1dc5cc13153b2a450e8b17b33e19e7761 100644 --- a/label_semantic_roles/README.en.md +++ b/06.label_semantic_roles/README.en.md @@ -1,44 +1,50 @@ # Semantic Role Labeling -Source code of this chapter is in [book/label_semantic_roles](https://github.com/PaddlePaddle/book/tree/develop/label_semantic_roles). +The source code of this chapter is live on [book/label_semantic_roles](https://github.com/PaddlePaddle/book/tree/develop/label_semantic_roles). For instructions on getting started with PaddlePaddle, see [PaddlePaddle installation guide](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/getstarted/build_and_install/docker_install_en.rst). ## Background -Natural Language Analysis contains three components: Lexical Analysis, Syntactic Analysis, and Semantic Analysis. Semantic Role Labelling (SRL) is one way for Shallow Semantic Analysis. A predicate of a sentence is a property that a subject possesses or is characterized, such as what it does, what it is or how it is, which mostly corresponds to the core of an event. The noun associated with a predicate is called Argument. Semantic roles express the abstract roles that arguments of a predicate can take in the event, such as Agent, Patient, Theme, Experiencer, Beneficiary, Instrument, Location, Goal and Source, etc. +Natural language analysis techniques consist of lexical, syntactic, and semantic analysis. **Semantic Role Labeling (SRL)** is an instance of **Shallow Semantic Analysis**. -In the following example, “遇到” (encounters) is a Predicate (“Pred”),“小明” (Ming) is an Agent,“小红” (Hong) is a Patient,“昨天” (yesterday) indicates the Time, and “公园” (park) is the Location. +In a sentence, a **predicate** states a property or a characterization of a *subject*, such as what it does and what it is like. The predicate represents the core of an event, whereas the words accompanying the predicate are **arguments**. A **semantic role** refers to the abstract role an argument of a predicate take on in the event, including *agent*, *patient*, *theme*, *experiencer*, *beneficiary*, *instrument*, *location*, *goal*, and *source*. -$$\mbox{[小明]}_{\mbox{Agent}}\mbox{[昨天]}_{\mbox{Time}}\mbox{[晚上]}_\mbox{Time}\mbox{在[公园]}_{\mbox{Location}}\mbox{[遇到]}_{\mbox{Predicate}}\mbox{了[小红]}_{\mbox{Patient}}\mbox{。}$$ +In the following example of a Chinese sentence, "to encounter" is the predicate (*pred*); "Ming" is the *agent*; "Hong" is the *patient*; "yesterday" and "evening" are the *time*; finally, "the park" is the *location*. -Instead of in-depth analysis on semantic information, the goal of Semantic Role Labeling is to identify the relation of predicate and other constituents, e.g., predicate-argument structure, as specific semantic roles, which is an important intermediate step in a wide range of natural language understanding tasks (Information Extraction, Discourse Analysis, DeepQA etc). Predicates are always assumed to be given; the only thing is to identify arguments and their semantic roles. +$$\mbox{[小明 Ming]}_{\mbox{Agent}}\mbox{[昨天 yesterday]}_{\mbox{Time}}\mbox{[晚上 evening]}_\mbox{Time}\mbox{在[公园 a park]}_{\mbox{Location}}\mbox{[遇到 to encounter]}_{\mbox{Predicate}}\mbox{了[小红 Hong]}_{\mbox{Patient}}\mbox{。}$$ -Standard SRL system mostly builds on top of Syntactic Analysis and contains five steps: +Instead of analyzing the semantic information, **Semantic Role Labeling** (**SRL**) identifies the relation between the predicate and the other constituents surrounding it. The predicate-argument structures are labeled as specific semantic roles. A wide range of natural language understanding tasks, including *information extraction*, *discourse analysis*, and *deepQA*. Research usually assumes a predicate of a sentence to be specified; the only task is to identify its arguments and their semantic roles. -1. Construct a syntactic parse tree, as shown in Fig. 1 -2. Identity candidate arguments of given predicate from constructed syntactic parse tree. -3. Prune most unlikely candidate arguments. -4. Identify arguments, often by a binary classifier. -5. Multi-class semantic role labeling. Steps 2-3 usually introduce hand-designed features based on Syntactic Analysis (step 1). +Conventional SRL systems mostly build on top of syntactic analysis, usually consisting of five steps: + +1. Construct a syntax tree, as shown in Fig. 1 +2. Identity the candidate arguments of the given predicate on the tree. +3. Prune the most unlikely candidate arguments. +4. Identify the real arguments, often by a binary classifier. +5. Multi-classify on results from step 4 to label the semantic roles. Steps 2 and 3 usually introduce hand-designed features based on syntactic analysis (step 1).

-Fig 1. Syntactic parse tree +Fig 1. Syntax tree
-However, complete syntactic analysis requires identifying the relation among all constitutes and the performance of SRL is sensitive to the precision of syntactic analysis, which makes SRL a very challenging task. To reduce the complexity and obtain some syntactic structure information, we often use shallow syntactic analysis. Shallow Syntactic Analysis is also called partial parsing or chunking. Unlike complete syntactic analysis which requires the construction of the complete parsing tree, Shallow Syntactic Analysis only need to identify some independent components with relatively simple structure, such as verb phrases (chunk). To avoid difficulties in constructing a syntactic tree with high accuracy, some work\[[1](#Reference)\] proposed semantic chunking based SRL methods, which convert SRL as a sequence tagging problem. Sequence tagging tasks classify syntactic chunks using BIO representation. For syntactic chunks forming a chunk of type A, the first chunk receives the B-A tag (Begin), the remaining ones receive the tag I-A (Inside), and all chunks outside receive the tag O-A. +However, a complete syntactic analysis requires identifying the relation among all constituents. Thus, the accuracy of SRL is sensitive to the preciseness of the syntactic analysis, making SRL challenging. To reduce its complexity and obtain some information on the syntactic structures, we often use *shallow syntactic analysis* a.k.a. partial parsing or chunking. Unlike complete syntactic analysis, which requires the construction of the complete parsing tree, *Shallow Syntactic Analysis* only requires identifying some independent constituents with relatively simple structures, such as verb phrases (chunk). To avoid difficulties in constructing a syntax tree with high accuracy, some work\[[1](#Reference)\] proposed semantic chunking-based SRL methods, which reduces SRL into a sequence tagging problem. Sequence tagging tasks classify syntactic chunks using **BIO representation**. For syntactic chunks forming role A, its first chunk receives the B-A tag (Begin) and the remaining ones receive the tag I-A (Inside); in the end, the chunks left out receive the tag O. The BIO representation of above example is shown in Fig.1.

-Fig 2. BIO represention +Fig 2. BIO representation
-This example illustrates the simplicity of sequence tagging because (1) shallow syntactic analysis reduces the precision requirement of syntactic analysis; (2) pruning candidate arguments is removed; 3) argument identification and tagging are finished at the same time. Such unified methods simplify the procedure, reduce the risk of accumulating errors and boost the performance further. +This example illustrates the simplicity of sequence tagging, since + +1. It only relies on shallow syntactic analysis, reduces the precision requirement of syntactic analysis; +2. Pruning the candidate arguments is no longer necessary; +3. Arguments are identified and tagged at the same time. Simplifying the workflow reduces the risk of accumulating errors; oftentimes, methods that unify multiple steps boost performance. In this tutorial, our SRL system is built as an end-to-end system via a neural network. We take only text sequences, without using any syntactic parsing results or complex hand-designed features. We give public dataset [CoNLL-2004 and CoNLL-2005 Shared Tasks](http://www.cs.upc.edu/~srlconll/) as an example to illustrate: given a sentence with predicates marked, identify the corresponding arguments and their semantic roles by sequence tagging method. @@ -48,15 +54,19 @@ Recurrent Neural Networks are important tools for sequence modeling and have bee ### Stacked Recurrent Neural Network -Deep Neural Networks allows extracting hierarchical representations. Higher layers can form more abstract/complex representations on top of lower layers. LSTMs, when unfolded in time, is a deep feed-forward neural network, because a computational path between the input at time $k < t$ to the output at time $t$ crosses several nonlinear layers. However, the computation carried out at each time-step is only linear transformation, which makes LSTMs a shallow model. Deep LSTMs are typically constructed by stacking multiple LSTM layers on top of each other and taking the output from lower LSTM layer at time $t$ as the input of upper LSTM layer at time $t$. Deep, hierarchical neural networks can be much efficient at representing some functions and modeling varying-length dependencies\[[2](#Reference)\]. +*Deep Neural Networks* can extract hierarchical representations. The higher layers can form relatively abstract/complex representations, based on primitive features discovered through the lower layers. Unfolding LSTMs through time results in a deep feed-forward neural network. This is because any computational path between the input at time $k < t$ to the output at time $t$ crosses several nonlinear layers. On the other hand, due to parameter sharing over time, LSTMs are also *shallow*; the computation carried out at each time-step is just a linear transformation. Deep LSTM networks are typically constructed by stacking multiple LSTM layers on top of each other and taking the output from lower LSTM layer at time $t$ as the input of upper LSTM layer at time $t$. Deep, hierarchical neural networks can be efficient at representing some functions and modeling varying-length dependencies\[[2](#Reference)\]. + +However, a deep LSTM network increases the number of nonlinear steps the gradient has to traverse when propagated back in depth. As a result, while LSTMs of 4 layers can be trained properly, those with 4-8 have much worse performance. Conventional LSTMs prevent backpropagated errors from vanishing and exploding by introducing shortcut connections to skip the intermediate nonlinear layers. Therefore, deep LSTMs can consider shortcut connections in depth as well. -However, deep LSTMs increases the number of nonlinear steps the gradient has to traverse when propagated back in depth. For example, four layer LSTMs can be trained properly, but the performance becomes worse as the number of layers up to 4-8. Conventional LSTMs prevent backpropagated errors from vanishing and exploding by introducing shortcut connections to skip the intermediate nonlinear layers. Therefore, deep LSTMs can consider shortcut connections in depth as well. +A single LSTM cell has three operations: -The operation of a single LSTM cell contain 3 parts: (1) input-to-hidden: map input $x$ to the input of the forget gates, input gates, memory cells and output gates by linear transformation (i.e., matrix mapping); (2) hidden-to-hidden: calculate forget gates, input gates, output gates and update memory cell, this is the main part of LSTMs; (3)hidden-to-output: this part typically involves an activation operation on hidden states. Based on the stacked LSTMs, we add a shortcut connection: take the input-to-hidden from the previous layer as a new input and learn another linear transformation. +1. input-to-hidden: map input $x$ to the input of the forget gates, input gates, memory cells and output gates by linear transformation (i.e., matrix mapping); +2. hidden-to-hidden: calculate forget gates, input gates, output gates and update memory cell, this is the main part of LSTMs; +3. hidden-to-output: this part typically involves an activation operation on hidden states. Based on the stacked LSTMs, we add a shortcut connection: take the input-to-hidden from the previous layer as a new input and learn another linear transformation. -Fig.3 illustrate the final stacked recurrent neural networks. +Fig.3 illustrates the final stacked recurrent neural networks.


diff --git a/label_semantic_roles/README.md b/06.label_semantic_roles/README.md similarity index 100% rename from label_semantic_roles/README.md rename to 06.label_semantic_roles/README.md diff --git a/label_semantic_roles/image/bidirectional_stacked_lstm.png b/06.label_semantic_roles/image/bidirectional_stacked_lstm.png similarity index 100% rename from label_semantic_roles/image/bidirectional_stacked_lstm.png rename to 06.label_semantic_roles/image/bidirectional_stacked_lstm.png diff --git a/label_semantic_roles/image/bidirectional_stacked_lstm_en.png b/06.label_semantic_roles/image/bidirectional_stacked_lstm_en.png similarity index 100% rename from label_semantic_roles/image/bidirectional_stacked_lstm_en.png rename to 06.label_semantic_roles/image/bidirectional_stacked_lstm_en.png diff --git a/label_semantic_roles/image/bio_example.png b/06.label_semantic_roles/image/bio_example.png similarity index 100% rename from label_semantic_roles/image/bio_example.png rename to 06.label_semantic_roles/image/bio_example.png diff --git a/label_semantic_roles/image/bio_example_en.png b/06.label_semantic_roles/image/bio_example_en.png similarity index 100% rename from label_semantic_roles/image/bio_example_en.png rename to 06.label_semantic_roles/image/bio_example_en.png diff --git a/label_semantic_roles/image/db_lstm_network.png b/06.label_semantic_roles/image/db_lstm_network.png similarity index 100% rename from label_semantic_roles/image/db_lstm_network.png rename to 06.label_semantic_roles/image/db_lstm_network.png diff --git a/label_semantic_roles/image/db_lstm_network_en.png b/06.label_semantic_roles/image/db_lstm_network_en.png similarity index 100% rename from label_semantic_roles/image/db_lstm_network_en.png rename to 06.label_semantic_roles/image/db_lstm_network_en.png diff --git a/label_semantic_roles/image/dependency_parsing.png b/06.label_semantic_roles/image/dependency_parsing.png similarity index 100% rename from label_semantic_roles/image/dependency_parsing.png rename to 06.label_semantic_roles/image/dependency_parsing.png diff --git a/label_semantic_roles/image/dependency_parsing_en.png b/06.label_semantic_roles/image/dependency_parsing_en.png similarity index 100% rename from label_semantic_roles/image/dependency_parsing_en.png rename to 06.label_semantic_roles/image/dependency_parsing_en.png diff --git a/label_semantic_roles/image/linear_chain_crf.png b/06.label_semantic_roles/image/linear_chain_crf.png similarity index 100% rename from label_semantic_roles/image/linear_chain_crf.png rename to 06.label_semantic_roles/image/linear_chain_crf.png diff --git a/label_semantic_roles/image/stacked_lstm.png b/06.label_semantic_roles/image/stacked_lstm.png similarity index 100% rename from label_semantic_roles/image/stacked_lstm.png rename to 06.label_semantic_roles/image/stacked_lstm.png diff --git a/label_semantic_roles/image/stacked_lstm_en.png b/06.label_semantic_roles/image/stacked_lstm_en.png similarity index 100% rename from label_semantic_roles/image/stacked_lstm_en.png rename to 06.label_semantic_roles/image/stacked_lstm_en.png diff --git a/label_semantic_roles/index.en.html b/06.label_semantic_roles/index.en.html similarity index 81% rename from label_semantic_roles/index.en.html rename to 06.label_semantic_roles/index.en.html index 9efd5c90de84944762fe7ffdffe59695bf7492b1..7463fda7b62eb2a2fc0138cb0297a2f8e3ddc62d 100644 --- a/label_semantic_roles/index.en.html +++ b/06.label_semantic_roles/index.en.html @@ -42,45 +42,51 @@

diff --git a/index.en.html.json b/index.en.html.json index 354d0d99b929d6b734b3804566137995e977bae7..7dac20ddb75d58b958c58f1bbdeeb4cb8189ab28 100644 --- a/index.en.html.json +++ b/index.en.html.json @@ -3,35 +3,35 @@ "chapters": [ { "name": "Linear Regression", - "link": "./fit_a_line/index.en.html" + "link": "./01.fit_a_line/index.en.html" }, { "name": "Recognize Digits", - "link": "./recognize_digits/index.en.html" + "link": "./02.recognize_digits/index.en.html" }, { "name": "Image Classification", - "link": "./image_classification/index.en.html" + "link": "./03.image_classification/index.en.html" }, { "name": "Word2Vec", - "link": "./word2vec/index.en.html" + "link": "./04.word2vec/index.en.html" }, { "name": "Sentiment Analysis", - "link": "./understand_sentiment/index.en.html" + "link": "./05.understand_sentiment/index.en.html" }, { "name": "Semantic Role Labeling", - "link": "./label_semantic_roles/index.en.html" + "link": "./06.label_semantic_roles/index.en.html" }, { "name": "Machine Translation", - "link": "./machine_translation/index.en.html" + "link": "./07.machine_translation/index.en.html" }, { "name": "Personalized Recommendation", - "link": "./recommender_system/index.en.html" + "link": "./08.recommender_system/index.en.html" } ] } diff --git a/index.html b/index.html index a216d3110262f71774c6bb95aaf46cd3b17c9e99..9cc744529ec35fe5dcb356bd1fcb3a2bd354762c 100644 --- a/index.html +++ b/index.html @@ -107,35 +107,35 @@
-
diff --git a/index.html.json b/index.html.json index 65beb7c422560427c14f6013e0c0c577382edb3a..a678a5a0d0744810bade16f0ae45e762b651a0e8 100644 --- a/index.html.json +++ b/index.html.json @@ -3,35 +3,35 @@ "chapters": [ { "name": "新手入门", - "link": "./fit_a_line/index.html" + "link": "./01.fit_a_line/index.html" }, { "name": "识别数字", - "link": "./recognize_digits/index.html" + "link": "./02.recognize_digits/index.html" }, { "name": "图像分类", - "link": "./image_classification/index.html" + "link": "./03.image_classification/index.html" }, { "name": "词向量", - "link": "./word2vec/index.html" + "link": "./04.word2vec/index.html" }, { "name": "情感分析", - "link": "./understand_sentiment/index.html" + "link": "./05.understand_sentiment/index.html" }, { "name": "语义角色标注", - "link": "./label_semantic_roles/index.html" + "link": "./06.label_semantic_roles/index.html" }, { "name": "机器翻译", - "link": "./machine_translation/index.html" + "link": "./07.machine_translation/index.html" }, { "name": "个性化推荐", - "link": "./recommender_system/index.html" + "link": "./08.recommender_system/index.html" } ] } diff --git a/index.html.tmpl b/index.html.tmpl index 0dcd6342af32de6b515f04f1706eeffd625aabfd..3729ec62426c393c08afb934fcfc2d61832cfcd3 100644 --- a/index.html.tmpl +++ b/index.html.tmpl @@ -118,7 +118,7 @@
-