<!DOCTYPE html> <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Networks — PaddlePaddle documentation</title> <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" /> <link rel="index" title="Index" href="../../../genindex.html"/> <link rel="search" title="Search" href="../../../search.html"/> <link rel="top" title="PaddlePaddle documentation" href="../../../index.html"/> <link rel="up" title="Model Configuration" href="../model_configs.html"/> <link rel="next" title="Parameter Attribute" href="attr.html"/> <link rel="prev" title="Pooling" href="pooling.html"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" /> <link rel="stylesheet" href="../../../_static/css/override.css" type="text/css" /> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script src="../../../_static/js/modernizr.min.js"></script> </head> <body class="wy-body-for-nav" role="document"> <header class="site-header"> <div class="site-logo"> <a href="/"><img src="../../../_static/images/PP_w.png"></a> </div> <div class="site-nav-links"> <div class="site-menu"> <a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Folk me on Github</a> <div class="language-switcher dropdown"> <a type="button" data-toggle="dropdown"> <span>English</span> <i class="fa fa-angle-up"></i> <i class="fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <li><a href="/doc_cn">中文</a></li> <li><a href="/doc">English</a></li> </ul> </div> <ul class="site-page-links"> <li><a href="/">Home</a></li> </ul> </div> <div class="doc-module"> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../../../getstarted/index_en.html">GET STARTED</a></li> <li class="toctree-l1"><a class="reference internal" href="../../../howto/index_en.html">HOW TO</a></li> <li class="toctree-l1 current"><a class="reference internal" href="../../index_en.html">API</a></li> <li class="toctree-l1"><a class="reference internal" href="../../../about/index_en.html">ABOUT</a></li> </ul> <div role="search"> <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get"> <input type="text" name="q" placeholder="Search docs" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> </div> </header> <div class="main-content-wrap"> <nav class="doc-menu-vertical" role="navigation"> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="../../../getstarted/index_en.html">GET STARTED</a><ul> <li class="toctree-l2"><a class="reference internal" href="../../../getstarted/build_and_install/index_en.html">Install and Build</a><ul> <li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/docker_install_en.html">PaddlePaddle in Docker Containers</a></li> <li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/ubuntu_install_en.html">Debian Package installation guide</a></li> <li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/build_from_source_en.html">Installing from Sources</a></li> </ul> </li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../../howto/index_en.html">HOW TO</a><ul> <li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul> <li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/use_case_en.html">Use Case</a></li> <li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/arguments_en.html">Argument Outline</a></li> <li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li> </ul> </li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cluster/cluster_train_en.html">Run Distributed Training</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/k8s/k8s_en.html">Paddle On Kubernetes</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/k8s/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/new_layer_en.html">Write New Layers</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/contribute_to_paddle_en.html">Contribute Code</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/deep_model/rnn/index_en.html">RNN Models</a></li> <li class="toctree-l2"><a class="reference internal" href="../../../howto/optimization/gpu_profiling_en.html">Tune GPU Performance</a></li> </ul> </li> <li class="toctree-l1 current"><a class="reference internal" href="../../index_en.html">API</a><ul class="current"> <li class="toctree-l2 current"><a class="reference internal" href="../model_configs.html">Model Configuration</a><ul class="current"> <li class="toctree-l3"><a class="reference internal" href="activation.html">Activation</a></li> <li class="toctree-l3"><a class="reference internal" href="layer.html">Layers</a></li> <li class="toctree-l3"><a class="reference internal" href="evaluators.html">Evaluators</a></li> <li class="toctree-l3"><a class="reference internal" href="optimizer.html">Optimizer</a></li> <li class="toctree-l3"><a class="reference internal" href="pooling.html">Pooling</a></li> <li class="toctree-l3 current"><a class="current reference internal" href="#">Networks</a></li> <li class="toctree-l3"><a class="reference internal" href="attr.html">Parameter Attribute</a></li> </ul> </li> <li class="toctree-l2"><a class="reference internal" href="../data.html">Data Reader Interface and DataSets</a></li> <li class="toctree-l2"><a class="reference internal" href="../run_logic.html">Training and Inference</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="../../../about/index_en.html">ABOUT</a></li> </ul> </nav> <section class="doc-content-wrap"> <div role="navigation" aria-label="breadcrumbs navigation"> <ul class="wy-breadcrumbs"> <li><a href="../../index_en.html">API</a> > </li> <li><a href="../model_configs.html">Model Configuration</a> > </li> <li>Networks</li> </ul> </div> <div class="wy-nav-content" id="doc-content"> <div class="rst-content"> <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> <div itemprop="articleBody"> <div class="section" id="networks"> <h1>Networks<a class="headerlink" href="#networks" title="Permalink to this headline">¶</a></h1> <p>The v2.networks module contains pieces of neural network that combine multiple layers.</p> <div class="section" id="nlp"> <h2>NLP<a class="headerlink" href="#nlp" title="Permalink to this headline">¶</a></h2> <div class="section" id="sequence-conv-pool"> <h3>sequence_conv_pool<a class="headerlink" href="#sequence-conv-pool" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">sequence_conv_pool</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Text convolution pooling layers helper.</p> <p>Text input => Context Projection => FC Layer => Pooling => Output.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – name of output layer(pooling layer name)</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – name of input layer</li> <li><strong>context_len</strong> (<em>int</em>) – context projection length. See context_projection’s document.</li> <li><strong>hidden_size</strong> (<em>int</em>) – FC Layer size.</li> <li><strong>context_start</strong> (<em>int</em><em> or </em><em>None</em>) – context projection length. See context_projection’s context_start.</li> <li><strong>pool_type</strong> (<em>BasePoolingType.</em>) – pooling layer type. See pooling’s document.</li> <li><strong>context_proj_name</strong> (<em>basestring</em>) – context projection layer name. None if user don’t care.</li> <li><strong>context_proj_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None.</em>) – context projection parameter attribute. None if user don’t care.</li> <li><strong>fc_name</strong> (<em>basestring</em>) – fc layer name. None if user don’t care.</li> <li><strong>fc_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None</em>) – fc layer parameter attribute. None if user don’t care.</li> <li><strong>fc_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None</em>) – fc bias parameter attribute. False if no bias, None if user don’t care.</li> <li><strong>fc_act</strong> (<em>paddle.v2.Activation.Base</em>) – fc layer activation type. None means tanh</li> <li><strong>pool_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None.</em>) – pooling layer bias attr. None if don’t care. False if no bias.</li> <li><strong>fc_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – fc layer extra attribute.</li> <li><strong>context_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – context projection layer extra attribute.</li> <li><strong>pool_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – pooling layer extra attribute.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">output layer name.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="text-conv-pool"> <span id="api-trainer-config-helpers-network-text-conv-pool"></span><h3>text_conv_pool<a class="headerlink" href="#text-conv-pool" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">text_conv_pool</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Text convolution pooling layers helper.</p> <p>Text input => Context Projection => FC Layer => Pooling => Output.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – name of output layer(pooling layer name)</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – name of input layer</li> <li><strong>context_len</strong> (<em>int</em>) – context projection length. See context_projection’s document.</li> <li><strong>hidden_size</strong> (<em>int</em>) – FC Layer size.</li> <li><strong>context_start</strong> (<em>int</em><em> or </em><em>None</em>) – context projection length. See context_projection’s context_start.</li> <li><strong>pool_type</strong> (<em>BasePoolingType.</em>) – pooling layer type. See pooling’s document.</li> <li><strong>context_proj_name</strong> (<em>basestring</em>) – context projection layer name. None if user don’t care.</li> <li><strong>context_proj_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None.</em>) – context projection parameter attribute. None if user don’t care.</li> <li><strong>fc_name</strong> (<em>basestring</em>) – fc layer name. None if user don’t care.</li> <li><strong>fc_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None</em>) – fc layer parameter attribute. None if user don’t care.</li> <li><strong>fc_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None</em>) – fc bias parameter attribute. False if no bias, None if user don’t care.</li> <li><strong>fc_act</strong> (<em>paddle.v2.Activation.Base</em>) – fc layer activation type. None means tanh</li> <li><strong>pool_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em><em> or </em><em>None.</em>) – pooling layer bias attr. None if don’t care. False if no bias.</li> <li><strong>fc_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – fc layer extra attribute.</li> <li><strong>context_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – context projection layer extra attribute.</li> <li><strong>pool_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – pooling layer extra attribute.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">output layer name.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="section" id="images"> <h2>Images<a class="headerlink" href="#images" title="Permalink to this headline">¶</a></h2> <div class="section" id="img-conv-bn-pool"> <h3>img_conv_bn_pool<a class="headerlink" href="#img-conv-bn-pool" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">img_conv_bn_pool</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Convolution, batch normalization, pooling group.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – group name</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – layer’s input</li> <li><strong>filter_size</strong> (<em>int</em>) – see img_conv’s document</li> <li><strong>num_filters</strong> (<em>int</em>) – see img_conv’s document</li> <li><strong>pool_size</strong> (<em>int</em>) – see img_pool’s document.</li> <li><strong>pool_type</strong> (<em>BasePoolingType</em>) – see img_pool’s document.</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – see batch_norm’s document.</li> <li><strong>groups</strong> (<em>int</em>) – see img_conv’s document</li> <li><strong>conv_stride</strong> (<em>int</em>) – see img_conv’s document.</li> <li><strong>conv_padding</strong> (<em>int</em>) – see img_conv’s document.</li> <li><strong>conv_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – see img_conv’s document.</li> <li><strong>num_channel</strong> (<em>int</em>) – see img_conv’s document.</li> <li><strong>conv_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – see img_conv’s document.</li> <li><strong>shared_bias</strong> (<em>bool</em>) – see img_conv’s document.</li> <li><strong>conv_attr</strong> (<em>Extrapaddle.v2.config_base.Layer</em>) – see img_conv’s document.</li> <li><strong>bn_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute.</em>) – see batch_norm’s document.</li> <li><strong>bn_bias_attr</strong> – see batch_norm’s document.</li> <li><strong>bn_attr</strong> – paddle.v2.attr.ParameterAttribute.</li> <li><strong>pool_stride</strong> (<em>int</em>) – see img_pool’s document.</li> <li><strong>pool_padding</strong> (<em>int</em>) – see img_pool’s document.</li> <li><strong>pool_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – see img_pool’s document.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Layer groups output</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="img-conv-group"> <h3>img_conv_group<a class="headerlink" href="#img-conv-group" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">img_conv_group</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Image Convolution Group, Used for vgg net.</p> <p>TODO(yuyang18): Complete docs</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>conv_batchnorm_drop_rate</strong> – </li> <li><strong>input</strong> – </li> <li><strong>conv_num_filter</strong> – </li> <li><strong>pool_size</strong> – </li> <li><strong>num_channels</strong> – </li> <li><strong>conv_padding</strong> – </li> <li><strong>conv_filter_size</strong> – </li> <li><strong>conv_act</strong> – </li> <li><strong>conv_with_batchnorm</strong> – </li> <li><strong>pool_stride</strong> – </li> <li><strong>pool_type</strong> – </li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"></p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="simple-img-conv-pool"> <span id="api-trainer-config-helpers-network-simple-img-conv-pool"></span><h3>simple_img_conv_pool<a class="headerlink" href="#simple-img-conv-pool" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">simple_img_conv_pool</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Simple image convolution and pooling group.</p> <p>Input => conv => pooling</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – group name</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>filter_size</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>num_filters</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>pool_size</strong> (<em>int</em>) – see img_pool for details</li> <li><strong>pool_type</strong> (<em>BasePoolingType</em>) – see img_pool for details</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – see img_conv for details</li> <li><strong>groups</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>conv_stride</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>conv_padding</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – see img_conv for details</li> <li><strong>num_channel</strong> (<em>int</em>) – see img_conv for details</li> <li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – see img_conv for details</li> <li><strong>shared_bias</strong> (<em>bool</em>) – see img_conv for details</li> <li><strong>conv_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – see img_conv for details</li> <li><strong>pool_stride</strong> (<em>int</em>) – see img_pool for details</li> <li><strong>pool_padding</strong> (<em>int</em>) – see img_pool for details</li> <li><strong>pool_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – see img_pool for details</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Layer’s output</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="small-vgg"> <h3>small_vgg<a class="headerlink" href="#small-vgg" title="Permalink to this headline">¶</a></h3> </div> <div class="section" id="vgg-16-network"> <h3>vgg_16_network<a class="headerlink" href="#vgg-16-network" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">vgg_16_network</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Same model from <a class="reference external" href="https://gist.github.com/ksimonyan/211839e770f7b538e2d8">https://gist.github.com/ksimonyan/211839e770f7b538e2d8</a></p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>num_classes</strong> – </li> <li><strong>input_image</strong> (<em>paddle.v2.config_base.Layer</em>) – </li> <li><strong>num_channels</strong> (<em>int</em>) – </li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"></p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="section" id="recurrent"> <h2>Recurrent<a class="headerlink" href="#recurrent" title="Permalink to this headline">¶</a></h2> <div class="section" id="lstm"> <h3>LSTM<a class="headerlink" href="#lstm" title="Permalink to this headline">¶</a></h3> <div class="section" id="lstmemory-unit"> <h4>lstmemory_unit<a class="headerlink" href="#lstmemory-unit" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">lstmemory_unit</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Define calculations that a LSTM unit performs in a single time step. This function itself is not a recurrent layer, so that it can not be directly applied to sequence input. This function is always used in recurrent_group (see layers.py for more details) to implement attention mechanism.</p> <p>Please refer to <strong>Generating Sequences With Recurrent Neural Networks</strong> for more details about LSTM. The link goes as follows: .. _Link: <a class="reference external" href="https://arxiv.org/abs/1308.0850">https://arxiv.org/abs/1308.0850</a></p> <div class="math"> \[ \begin{align}\begin{aligned}i_t & = \sigma(W_{xi}x_{t} + W_{hi}h_{t-1} + W_{ci}c_{t-1} + b_i)\\f_t & = \sigma(W_{xf}x_{t} + W_{hf}h_{t-1} + W_{cf}c_{t-1} + b_f)\\c_t & = f_tc_{t-1} + i_t tanh (W_{xc}x_t+W_{hc}h_{t-1} + b_c)\\o_t & = \sigma(W_{xo}x_{t} + W_{ho}h_{t-1} + W_{co}c_t + b_o)\\h_t & = o_t tanh(c_t)\end{aligned}\end{align} \]</div> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">lstm_step</span> <span class="o">=</span> <span class="n">lstmemory_unit</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Tanh</span><span class="p">(),</span> <span class="n">gate_act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Sigmoid</span><span class="p">(),</span> <span class="n">state_act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Tanh</span><span class="p">())</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – lstmemory unit name.</li> <li><strong>size</strong> (<em>int</em>) – lstmemory unit size.</li> <li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – Parameter config, None if use default.</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm final activiation type</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm gate activiation type</li> <li><strong>state_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm state activiation type.</li> <li><strong>mixed_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias parameter attribute of mixed layer. False means no bias, None means default bias.</li> <li><strong>lstm_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias parameter attribute of lstm layer. False means no bias, None means default bias.</li> <li><strong>mixed_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – mixed layer’s extra attribute.</li> <li><strong>lstm_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – lstm layer’s extra attribute.</li> <li><strong>get_output_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – get output layer’s extra attribute.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">lstmemory unit name.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="lstmemory-group"> <h4>lstmemory_group<a class="headerlink" href="#lstmemory-group" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">lstmemory_group</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>lstm_group is a recurrent layer group version of Long Short Term Memory. It does exactly the same calculation as the lstmemory layer (see lstmemory in layers.py for the maths) does. A promising benefit is that LSTM memory cell states, or hidden states in every time step are accessible to the user. This is especially useful in attention model. If you do not need to access the internal states of the lstm, but merely use its outputs, it is recommended to use the lstmemory, which is relatively faster than lstmemory_group.</p> <p>NOTE: In PaddlePaddle’s implementation, the following input-to-hidden multiplications: <span class="math">\(W_{xi}x_{t}\)</span> , <span class="math">\(W_{xf}x_{t}\)</span>, <span class="math">\(W_{xc}x_t\)</span>, <span class="math">\(W_{xo}x_{t}\)</span> are not done in lstmemory_unit to speed up the calculations. Consequently, an additional mixed with full_matrix_projection must be included before lstmemory_unit is called.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">lstm_step</span> <span class="o">=</span> <span class="n">lstmemory_group</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Tanh</span><span class="p">(),</span> <span class="n">gate_act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Sigmoid</span><span class="p">(),</span> <span class="n">state_act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Tanh</span><span class="p">())</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – lstmemory group name.</li> <li><strong>size</strong> (<em>int</em>) – lstmemory group size.</li> <li><strong>reverse</strong> (<em>bool</em>) – is lstm reversed</li> <li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – Parameter config, None if use default.</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm final activiation type</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm gate activiation type</li> <li><strong>state_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm state activiation type.</li> <li><strong>mixed_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias parameter attribute of mixed layer. False means no bias, None means default bias.</li> <li><strong>lstm_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias parameter attribute of lstm layer. False means no bias, None means default bias.</li> <li><strong>mixed_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – mixed layer’s extra attribute.</li> <li><strong>lstm_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – lstm layer’s extra attribute.</li> <li><strong>get_output_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – get output layer’s extra attribute.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the lstmemory group.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="simple-lstm"> <h4>simple_lstm<a class="headerlink" href="#simple-lstm" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">simple_lstm</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Simple LSTM Cell.</p> <p>It just combine a mixed layer with fully_matrix_projection and a lstmemory layer. The simple lstm cell was implemented as follow equations.</p> <div class="math"> \[ \begin{align}\begin{aligned}i_t & = \sigma(W_{xi}x_{t} + W_{hi}h_{t-1} + W_{ci}c_{t-1} + b_i)\\f_t & = \sigma(W_{xf}x_{t} + W_{hf}h_{t-1} + W_{cf}c_{t-1} + b_f)\\c_t & = f_tc_{t-1} + i_t tanh (W_{xc}x_t+W_{hc}h_{t-1} + b_c)\\o_t & = \sigma(W_{xo}x_{t} + W_{ho}h_{t-1} + W_{co}c_t + b_o)\\h_t & = o_t tanh(c_t)\end{aligned}\end{align} \]</div> <p>Please refer <strong>Generating Sequences With Recurrent Neural Networks</strong> if you want to know what lstm is. <a class="reference external" href="http://arxiv.org/abs/1308.0850">Link</a> is here.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – lstm layer name.</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>size</strong> (<em>int</em>) – lstm layer size.</li> <li><strong>reverse</strong> (<em>bool</em>) – whether to process the input data in a reverse order</li> <li><strong>mat_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – mixed layer’s matrix projection parameter attribute.</li> <li><strong>bias_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias parameter attribute. False means no bias, None means default bias.</li> <li><strong>inner_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – lstm cell parameter attribute.</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm final activiation type</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm gate activiation type</li> <li><strong>state_act</strong> (<em>paddle.v2.Activation.Base</em>) – lstm state activiation type.</li> <li><strong>mixed_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – mixed layer’s extra attribute.</li> <li><strong>lstm_cell_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) – lstm layer’s extra attribute.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">lstm layer name.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="bidirectional-lstm"> <h4>bidirectional_lstm<a class="headerlink" href="#bidirectional-lstm" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">bidirectional_lstm</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>A bidirectional_lstm is a recurrent unit that iterates over the input sequence both in forward and bardward orders, and then concatenate two outputs form a final output. However, concatenation of two outputs is not the only way to form the final output, you can also, for example, just add them together.</p> <p>Please refer to <strong>Neural Machine Translation by Jointly Learning to Align and Translate</strong> for more details about the bidirectional lstm. The link goes as follows: .. _Link: <a class="reference external" href="https://arxiv.org/pdf/1409.0473v3.pdf">https://arxiv.org/pdf/1409.0473v3.pdf</a></p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">bi_lstm</span> <span class="o">=</span> <span class="n">bidirectional_lstm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">input1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – bidirectional lstm layer name.</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer.</li> <li><strong>size</strong> (<em>int</em>) – lstm layer size.</li> <li><strong>return_seq</strong> (<em>bool</em>) – If set False, outputs of the last time step are concatenated and returned. If set True, the entire output sequences that are processed in forward and backward directions are concatenated and returned.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object accroding to the return_seq.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="section" id="gru"> <h3>GRU<a class="headerlink" href="#gru" title="Permalink to this headline">¶</a></h3> <div class="section" id="gru-unit"> <h4>gru_unit<a class="headerlink" href="#gru-unit" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">gru_unit</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Define calculations that a gated recurrent unit performs in a single time step. This function itself is not a recurrent layer, so that it can not be directly applied to sequence input. This function is almost always used in the recurrent_group (see layers.py for more details) to implement attention mechanism.</p> <p>Please see grumemory in layers.py for the details about the maths.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – name of the gru group.</li> <li><strong>size</strong> (<em>int</em>) – hidden size of the gru.</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the activation</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the gate activation</li> <li><strong>gru_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – Extra parameter attribute of the gru layer.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the gru output layer.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="gru-group"> <h4>gru_group<a class="headerlink" href="#gru-group" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">gru_group</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>gru_group is a recurrent layer group version of Gated Recurrent Unit. It does exactly the same calculation as the grumemory layer does. A promising benefit is that gru hidden states are accessible to the user. This is especially useful in attention model. If you do not need to access any internal state, but merely use the outputs of a GRU, it is recommended to use the grumemory, which is relatively faster.</p> <p>Please see grumemory in layers.py for more detail about the maths.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">gru</span> <span class="o">=</span> <span class="n">gur_group</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Tanh</span><span class="p">(),</span> <span class="n">gate_act</span><span class="o">=</span><span class="n">paddle</span><span class="o">.</span><span class="n">v2</span><span class="o">.</span><span class="n">Activation</span><span class="o">.</span><span class="n">Sigmoid</span><span class="p">())</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – name of the gru group.</li> <li><strong>size</strong> (<em>int</em>) – hidden size of the gru.</li> <li><strong>reverse</strong> (<em>bool</em>) – whether to process the input data in a reverse order</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the activiation</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the gate activiation</li> <li><strong>gru_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias. False means no bias, None means default bias.</li> <li><strong>gru_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – Extra parameter attribute of the gru layer.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the gru group.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="simple-gru"> <h4>simple_gru<a class="headerlink" href="#simple-gru" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">simple_gru</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>You maybe see gru_step, grumemory in layers.py, gru_unit, gru_group, simple_gru in network.py. The reason why there are so many interfaces is that we have two ways to implement recurrent neural network. One way is to use one complete layer to implement rnn (including simple rnn, gru and lstm) with multiple time steps, such as recurrent, lstmemory, grumemory. But, the multiplication operation <span class="math">\(W x_t\)</span> is not computed in these layers. See details in their interfaces in layers.py. The other implementation is to use an recurrent group which can ensemble a series of layers to compute rnn step by step. This way is flexible for attenion mechanism or other complex connections.</p> <ul class="simple"> <li>gru_step: only compute rnn by one step. It needs an memory as input and can be used in recurrent group.</li> <li>gru_unit: a wrapper of gru_step with memory.</li> <li>gru_group: a GRU cell implemented by a combination of multiple layers in recurrent group. But <span class="math">\(W x_t\)</span> is not done in group.</li> <li>gru_memory: a GRU cell implemented by one layer, which does same calculation with gru_group and is faster than gru_group.</li> <li>simple_gru: a complete GRU implementation inlcuding <span class="math">\(W x_t\)</span> and gru_group. <span class="math">\(W\)</span> contains <span class="math">\(W_r\)</span>, <span class="math">\(W_z\)</span> and <span class="math">\(W\)</span>, see formula in grumemory.</li> </ul> <p>The computational speed is that, grumemory is relatively better than gru_group, and gru_group is relatively better than simple_gru.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">gru</span> <span class="o">=</span> <span class="n">simple_gru</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – name of the gru group.</li> <li><strong>size</strong> (<em>int</em>) – hidden size of the gru.</li> <li><strong>reverse</strong> (<em>bool</em>) – whether to process the input data in a reverse order</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the activiation</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the gate activiation</li> <li><strong>gru_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias. False means no bias, None means default bias.</li> <li><strong>gru_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – Extra parameter attribute of the gru layer.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the gru group.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="simple-gru2"> <h4>simple_gru2<a class="headerlink" href="#simple-gru2" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">simple_gru2</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>simple_gru2 is the same with simple_gru, but using grumemory instead Please see grumemory in layers.py for more detail about the maths. simple_gru2 is faster than simple_gru.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">gru</span> <span class="o">=</span> <span class="n">simple_gru2</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer name.</li> <li><strong>name</strong> (<em>basestring</em>) – name of the gru group.</li> <li><strong>size</strong> (<em>int</em>) – hidden size of the gru.</li> <li><strong>reverse</strong> (<em>bool</em>) – whether to process the input data in a reverse order</li> <li><strong>act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the activiation</li> <li><strong>gate_act</strong> (<em>paddle.v2.Activation.Base</em>) – type of the gate activiation</li> <li><strong>gru_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – bias. False means no bias, None means default bias.</li> <li><strong>gru_attr</strong> (<em>paddle.v2.attr.ParameterAttribute|False</em>) – Extra parameter attribute of the gru layer.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the gru group.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="bidirectional-gru"> <h4>bidirectional_gru<a class="headerlink" href="#bidirectional-gru" title="Permalink to this headline">¶</a></h4> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">bidirectional_gru</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>A bidirectional_gru is a recurrent unit that iterates over the input sequence both in forward and bardward orders, and then concatenate two outputs to form a final output. However, concatenation of two outputs is not the only way to form the final output, you can also, for example, just add them together.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">bi_gru</span> <span class="o">=</span> <span class="n">bidirectional_gru</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">input1</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – bidirectional gru layer name.</li> <li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) – input layer.</li> <li><strong>size</strong> (<em>int</em>) – gru layer size.</li> <li><strong>return_seq</strong> (<em>bool</em>) – If set False, outputs of the last time step are concatenated and returned. If set True, the entire output sequences that are processed in forward and backward directions are concatenated and returned.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="section" id="simple-attention"> <h3>simple_attention<a class="headerlink" href="#simple-attention" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">simple_attention</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>Calculate and then return a context vector by attention machanism. Size of the context vector equals to size of the encoded_sequence.</p> <div class="math"> \[ \begin{align}\begin{aligned}a(s_{i-1},h_{j}) & = v_{a}f(W_{a}s_{t-1} + U_{a}h_{j})\\e_{i,j} & = a(s_{i-1}, h_{j})\\a_{i,j} & = \frac{exp(e_{i,j})}{\sum_{k=1}^{T_x}{exp(e_{i,k})}}\\c_{i} & = \sum_{j=1}^{T_{x}}a_{i,j}h_{j}\end{aligned}\end{align} \]</div> <p>where <span class="math">\(h_{j}\)</span> is the jth element of encoded_sequence, <span class="math">\(U_{a}h_{j}\)</span> is the jth element of encoded_proj <span class="math">\(s_{i-1}\)</span> is decoder_state <span class="math">\(f\)</span> is weight_act, and is set to tanh by default.</p> <p>Please refer to <strong>Neural Machine Translation by Jointly Learning to Align and Translate</strong> for more details. The link is as follows: <a class="reference external" href="https://arxiv.org/abs/1409.0473">https://arxiv.org/abs/1409.0473</a>.</p> <p>The example usage is:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">context</span> <span class="o">=</span> <span class="n">simple_attention</span><span class="p">(</span><span class="n">encoded_sequence</span><span class="o">=</span><span class="n">enc_seq</span><span class="p">,</span> <span class="n">encoded_proj</span><span class="o">=</span><span class="n">enc_proj</span><span class="p">,</span> <span class="n">decoder_state</span><span class="o">=</span><span class="n">decoder_prev</span><span class="p">,)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> (<em>basestring</em>) – name of the attention model.</li> <li><strong>softmax_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – parameter attribute of sequence softmax that is used to produce attention weight</li> <li><strong>weight_act</strong> (<em>Activation</em>) – activation of the attention model</li> <li><strong>encoded_sequence</strong> (<em>paddle.v2.config_base.Layer</em>) – output of the encoder</li> <li><strong>encoded_proj</strong> (<em>paddle.v2.config_base.Layer</em>) – attention weight is computed by a feed forward neural network which has two inputs : decoder’s hidden state of previous time step and encoder’s output. encoded_proj is output of the feed-forward network for encoder’s output. Here we pre-compute it outside simple_attention for speed consideration.</li> <li><strong>decoder_state</strong> (<em>paddle.v2.config_base.Layer</em>) – hidden state of decoder in previous time step</li> <li><strong>transform_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) – parameter attribute of the feed-forward network that takes decoder_state as inputs to compute attention weight.</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a context vector</p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="section" id="miscs"> <h2>Miscs<a class="headerlink" href="#miscs" title="Permalink to this headline">¶</a></h2> <div class="section" id="dropout-layer"> <h3>dropout_layer<a class="headerlink" href="#dropout-layer" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt> <em class="property">class </em><code class="descclassname">paddle.v2.networks.</code><code class="descname">dropout_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt> <dd><p>@TODO(yuyang18): Add comments.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>name</strong> – </li> <li><strong>input</strong> – </li> <li><strong>dropout_rate</strong> – </li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"></p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> </div> </div> </div> <footer> <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> <a href="attr.html" class="btn btn-neutral float-right" title="Parameter Attribute" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a> <a href="pooling.html" class="btn btn-neutral" title="Pooling" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a> </div> <hr/> <div role="contentinfo"> <p> © Copyright 2016, PaddlePaddle developers. </p> </div> Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT:'../../../', VERSION:'', COLLAPSE_INDEX:false, FILE_SUFFIX:'.html', HAS_SOURCE: true, SOURCELINK_SUFFIX: ".txt", }; </script> <script type="text/javascript" src="../../../_static/jquery.js"></script> <script type="text/javascript" src="../../../_static/underscore.js"></script> <script type="text/javascript" src="../../../_static/doctools.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/javascript" src="../../../_static/js/theme.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script> <script src="../../../_static/js/paddle_doc_init.js"></script> </body> </html>