layer.html 277.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36


<!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>Layers &mdash; PaddlePaddle  文档</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  

  
  
        <link rel="index" title="索引"
              href="../../../genindex.html"/>
        <link rel="search" title="搜索" href="../../../search.html"/>
    <link rel="top" title="PaddlePaddle  文档" href="../../../index.html"/>
        <link rel="up" title="Model Configuration" href="../model_configs.html"/>
37
        <link rel="next" title="Evaluators" href="evaluators.html"/>
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
        <link rel="prev" title="Activation" href="activation.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">
68
        <a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
69 70 71 72 73 74 75 76 77 78 79 80
        <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">
81
          <li><a href="/">Home</a></li>
82 83 84 85 86 87 88 89 90
        </ul>
      </div>
      <div class="doc-module">
        
        <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../getstarted/index_cn.html">新手入门</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../howto/index_cn.html">进阶指南</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../index_cn.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../faq/index_cn.html">FAQ</a></li>
91
<li class="toctree-l1"><a class="reference internal" href="../../../mobile/index_cn.html">MOBILE</a></li>
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
</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_cn.html">新手入门</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../getstarted/build_and_install/index_cn.html">安装与编译</a><ul>
115 116
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/pip_install_cn.html">使用pip安装</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/docker_install_cn.html">使用Docker安装运行</a></li>
117
<li class="toctree-l3"><a class="reference internal" href="../../../howto/dev/build_cn.html">用Docker编译和测试PaddlePaddle</a></li>
118
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/build_from_source_cn.html">从源码编译</a></li>
119 120
</ul>
</li>
121
<li class="toctree-l2"><a class="reference internal" href="../../../getstarted/concepts/use_concepts_cn.html">基本使用概念</a></li>
122 123 124 125 126 127 128 129 130
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../howto/index_cn.html">进阶指南</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cmd_parameter/index_cn.html">设置命令行参数</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/use_case_cn.html">使用案例</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/arguments_cn.html">参数概述</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/detail_introduction_cn.html">细节描述</a></li>
</ul>
</li>
131
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cluster/cluster_train_cn.html">PaddlePaddle分布式训练</a></li>
132 133 134
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/k8s/k8s_basis_cn.html">Kubernetes 简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/k8s/k8s_cn.html">Kubernetes单机训练</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/k8s/k8s_distributed_cn.html">Kubernetes分布式训练</a></li>
135
<li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/contribute_to_paddle_cn.html">如何贡献代码</a></li>
136 137
<li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/write_docs_cn.html">如何贡献/修改文档</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/deep_model/rnn/index_cn.html">RNN相关模型</a><ul>
138
<li class="toctree-l3"><a class="reference internal" href="../../../howto/deep_model/rnn/rnn_config_cn.html">RNN配置</a></li>
139 140 141 142 143 144 145 146 147 148 149 150
<li class="toctree-l3"><a class="reference internal" href="../../../howto/deep_model/rnn/recurrent_group_cn.html">Recurrent Group教程</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/deep_model/rnn/hierarchical_layer_cn.html">支持双层序列作为输入的Layer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/deep_model/rnn/hrnn_rnn_api_compare_cn.html">单双层RNN API对比介绍</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/optimization/gpu_profiling_cn.html">GPU性能分析与调优</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../../index_cn.html">API</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="../model_configs.html">模型配置</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="activation.html">Activation</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Layers</a></li>
151
<li class="toctree-l3"><a class="reference internal" href="evaluators.html">Evaluators</a></li>
152 153 154 155 156 157
<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"><a class="reference internal" href="networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="attr.html">Parameter Attribute</a></li>
</ul>
</li>
158 159 160 161 162 163
<li class="toctree-l2"><a class="reference internal" href="../data.html">数据访问</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../data/data_reader.html">Data Reader Interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data/image.html">Image Interface</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data/dataset.html">Dataset</a></li>
</ul>
</li>
164 165 166
<li class="toctree-l2"><a class="reference internal" href="../run_logic.html">训练与应用</a></li>
</ul>
</li>
167 168 169 170 171 172 173 174
<li class="toctree-l1"><a class="reference internal" href="../../../faq/index_cn.html">FAQ</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../faq/build_and_install/index_cn.html">编译安装与单元测试</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../faq/model/index_cn.html">模型配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../faq/parameter/index_cn.html">参数设置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../faq/local/index_cn.html">本地训练与预测</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../faq/cluster/index_cn.html">集群训练与预测</a></li>
</ul>
</li>
175
<li class="toctree-l1"><a class="reference internal" href="../../../mobile/index_cn.html">MOBILE</a><ul>
176 177 178
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_android_cn.html">Android平台编译指南</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_ios_cn.html">iOS平台编译指南</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_raspberry_cn.html">Raspberry Pi平台编译指南</a></li>
179 180
</ul>
</li>
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
</ul>

        
    </nav>
    
    <section class="doc-content-wrap">

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
        <li><a href="../../index_cn.html">API</a> > </li>
      
        <li><a href="../model_configs.html">Model Configuration</a> > </li>
      
    <li>Layers</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="layers">
<span id="api-v2-layer"></span><h1>Layers<a class="headerlink" href="#layers" title="永久链接至标题"></a></h1>
<div class="section" id="data-layer">
<h2>Data layer<a class="headerlink" href="#data-layer" title="永久链接至标题"></a></h2>
<div class="section" id="data">
<span id="api-v2-layer-data"></span><h3>data<a class="headerlink" href="#data" title="永久链接至标题"></a></h3>
220
<dl class="attribute">
221
<dt>
222 223
<code class="descclassname">paddle.v2.layer.</code><code class="descname">data</code></dt>
<dd><p><code class="xref py py-class docutils literal"><span class="pre">name</span></code> 的别名</p>
224 225 226 227 228 229 230 231 232 233
</dd></dl>

</div>
</div>
<div class="section" id="fully-connected-layers">
<h2>Fully Connected Layers<a class="headerlink" href="#fully-connected-layers" title="永久链接至标题"></a></h2>
<div class="section" id="fc">
<span id="api-v2-layer-fc"></span><h3>fc<a class="headerlink" href="#fc" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
234
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">fc</code></dt>
235 236 237 238
<dd><p>Helper for declare fully connected layer.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">fc</span> <span class="o">=</span> <span class="n">fc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
              <span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span>
239
              <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">Linear</span><span class="p">(),</span>
240 241 242 243 244 245 246 247 248 249 250 251 252
              <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
<p>which is equal to:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">)</span> <span class="k">as</span> <span class="n">fc</span><span class="p">:</span>
    <span class="n">fc</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
253
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
254
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | list | tuple</em>) &#8211; The input of this layer.</li>
255
<li><strong>size</strong> (<em>int</em>) &#8211; The layer dimension.</li>
256
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation Type. paddle.v2.activation.Tanh is the default activation.</li>
257
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The Parameter Attribute|list.</li>
258 259 260
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
261
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra Layer config.</li>
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="selective-fc">
<h3>selective_fc<a class="headerlink" href="#selective-fc" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
280
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">selective_fc</code></dt>
281
<dd><p>Selectived fully connected layer. Different from fc, the output
282
of this layer can be sparse. It requires an additional input to indicate
283 284 285
several selected columns for output. If the selected columns is not
specified, selective_fc acts exactly like fc.</p>
<p>The simple usage is:</p>
286
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sel_fc</span> <span class="o">=</span> <span class="n">selective_fc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">128</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>
287 288 289 290 291 292 293
</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">参数:</th><td class="field-body"><ul class="first simple">
294
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
295
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | list | tuple</em>) &#8211; The input of this layer.</li>
296 297 298 299 300 301 302 303 304 305 306 307 308 309
<li><strong>select</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The layer to select columns to output. It should be a sparse
binary matrix, and is treated as the mask of selective fc. If
it is not set or set to None, selective_fc acts exactly
like fc.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer, which should be equal to that of
the layer &#8216;select&#8217;.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Tanh is the default activation.</li>
<li><strong>pass_generation</strong> (<em>bool</em>) &#8211; The flag which indicates whether it is during generation.</li>
<li><strong>has_selected_colums</strong> (<em>bool</em>) &#8211; The flag which indicates whether the parameter &#8216;select&#8217;
has been set. True is the default.</li>
<li><strong>mul_ratio</strong> (<em>float</em>) &#8211; A ratio helps to judge how sparse the output is and determine
the computation method for speed consideration.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
310 311 312 313
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The parameter attribute for bias. If this parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute,
no bias is defined. If this parameter is set to True,
the bias is initialized to zero.</li>
314 315
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="conv-layers">
<h2>Conv Layers<a class="headerlink" href="#conv-layers" title="永久链接至标题"></a></h2>
<div class="section" id="conv-operator">
<h3>conv_operator<a class="headerlink" href="#conv-operator" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
337
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">conv_operator</code></dt>
338 339 340
<dd><p>Different from img_conv, conv_op is an Operator, which can be used
in mixed. And conv_op takes two inputs to perform convolution.
The first input is the image and the second is filter kernel. It only
341
supports GPU mode.</p>
342 343 344 345 346 347 348 349 350 351 352 353 354
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">op</span> <span class="o">=</span> <span class="n">conv_operator</span><span class="p">(</span><span class="n">img</span><span class="o">=</span><span class="n">input1</span><span class="p">,</span>
                   <span class="nb">filter</span><span class="o">=</span><span class="n">input2</span><span class="p">,</span>
                   <span class="n">filter_size</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                   <span class="n">num_filters</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span>
                   <span class="n">num_channels</span><span class="o">=</span><span class="mi">64</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">参数:</th><td class="field-body"><ul class="first simple">
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
<li><strong>img</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input image.</li>
<li><strong>filter</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input filter.</li>
<li><strong>filter_size</strong> (<em>int</em>) &#8211; The dimension of the filter kernel on the x axis.</li>
<li><strong>filter_size_y</strong> (<em>int</em>) &#8211; The dimension of the filter kernel on the y axis.
If the parameter is not set or set to None, it will
set to &#8216;filter_size&#8217; automatically.</li>
<li><strong>num_filters</strong> (<em>int</em>) &#8211; The number of the output channels.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of the input channels. If the parameter is not set
or set to None, it will be automatically set to the channel
number of the &#8216;img&#8217;.</li>
<li><strong>stride</strong> (<em>int</em>) &#8211; The stride on the x axis.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The stride on the y axis. If the parameter is not set or
set to None, it will be set to &#8216;stride&#8217; automatically.</li>
<li><strong>padding</strong> (<em>int</em>) &#8211; The padding size on the x axis.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The padding size on the y axis. If the parameter is not set
or set to None, it will be set to &#8216;padding&#8217; automatically.</li>
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A ConvOperator Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">ConvOperator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="conv-projection">
<h3>conv_projection<a class="headerlink" href="#conv-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
389
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">conv_projection</code></dt>
390 391 392
<dd><p>Different from img_conv and conv_op, conv_projection is a Projection,
which can be used in mixed and concat. It uses cudnn to implement
convolution and only supports GPU mode.</p>
393 394 395 396 397 398 399 400 401 402 403 404
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">conv_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">input1</span><span class="p">,</span>
                       <span class="n">filter_size</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                       <span class="n">num_filters</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span>
                       <span class="n">num_channels</span><span class="o">=</span><span class="mi">64</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">参数:</th><td class="field-body"><ul class="first simple">
405
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
406 407 408 409 410
<li><strong>filter_size</strong> (<em>int | tuple | list</em>) &#8211; The dimensions of the filter kernel. If the parameter is
set to one integer, the two dimensions on x and y axises
will be same when filter_size_y is not set. If it is set
to a list, the first element indicates the dimension on
the x axis, and the second is used to specify the dimension
411
on the y axis when filter_size_y is not provided.</li>
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
<li><strong>filter_size_y</strong> (<em>int</em>) &#8211; The dimension of the filter kernel on the y axis. If the parameter
is not set, it will be set automatically according to filter_size.</li>
<li><strong>num_filters</strong> (<em>int</em>) &#8211; The number of filters.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of the input channels.</li>
<li><strong>stride</strong> (<em>int | tuple | list</em>) &#8211; The strides. If the parameter is set to one integer, the strides
on x and y axises will be same when stride_y is not set. If it is
set to a list, the first element indicates the stride on the x axis,
and the second is used to specify the stride on the y axis when
stride_y is not provided.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The stride on the y axis.</li>
<li><strong>padding</strong> (<em>int | tuple | list</em>) &#8211; The padding sizes. If the parameter is set to one integer, the padding
sizes on x and y axises will be same when padding_y is not set. If it
is set to a list, the first element indicates the padding size on the
x axis, and the second is used to specify the padding size on the y axis
when padding_y is not provided.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The padding size on the y axis.</li>
428
<li><strong>groups</strong> (<em>int</em>) &#8211; The group number.</li>
429 430 431
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute of the convolution. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>trans</strong> (<em>bool</em>) &#8211; Whether it is ConvTransProjection or ConvProjection</li>
432 433 434
</ul>
</td>
</tr>
435
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A Projection Object.</p>
436 437
</td>
</tr>
438
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">ConvTransProjection | ConvProjection</p>
439 440 441 442 443 444 445 446 447 448 449
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="conv-shift">
<h3>conv_shift<a class="headerlink" href="#conv-shift" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
450
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">conv_shift</code></dt>
451
<dd><dl class="docutils">
452
<dt>This layer performs cyclic convolution on two inputs. For example:</dt>
453 454 455 456 457 458 459 460 461 462
<dd><ul class="first last simple">
<li>a[in]: contains M elements.</li>
<li>b[in]: contains N elements (N should be odd).</li>
<li>c[out]: contains M elements.</li>
</ul>
</dd>
</dl>
<div class="math">
\[c[i] = \sum_{j=-(N-1)/2}^{(N-1)/2}a_{i+j} * b_{j}\]</div>
<dl class="docutils">
463
<dt>In this formula:</dt>
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
<dd><ul class="first last simple">
<li>a&#8217;s index is computed modulo M. When it is negative, then get item from
the right side (which is the end of array) to the left.</li>
<li>b&#8217;s index is computed modulo N. When it is negative, then get item from
the right size (which is the end of array) to the left.</li>
</ul>
</dd>
</dl>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">conv_shift</span> <span class="o">=</span> <span class="n">conv_shift</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
481
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
482 483 484 485
<li><strong>a</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input of this layer.</li>
<li><strong>b</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input of this layer.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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">
<h3>img_conv<a class="headerlink" href="#img-conv" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
504
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">img_conv</code></dt>
505 506 507 508 509 510 511 512 513 514 515 516
<dd><p>Convolution layer for image. Paddle can support both square and non-square
input currently.</p>
<p>The details of convolution layer, please refer UFLDL&#8217;s <a class="reference external" href="http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/">convolution</a> .</p>
<p>Convolution Transpose (deconv) layer for image. Paddle can support both square
and non-square input currently.</p>
<p>The details of convolution transpose layer,
please refer to the following explanation and references therein
&lt;<a class="reference external" href="http://datascience.stackexchange.com/questions/6107/">http://datascience.stackexchange.com/questions/6107/</a>
what-are-deconvolutional-layers/&gt;`_ .
The num_channel means input image&#8217;s channel number. It may be 1 or 3 when
input is raw pixels of image(mono or RGB), or it may be the previous layer&#8217;s
num_filters * num_group.</p>
517 518
<p>There are several groups of filters in PaddlePaddle implementation.
Each group will process some channels of the input. For example, if
519
num_channel = 256, group = 4, num_filter=32, the PaddlePaddle will create
520 521 522
32*4 = 128 filters to process the input. The channels will be split into 4
pieces. First 256/4 = 64 channels will be processed by first 32 filters. The
rest channels will be processed by the rest groups of filters.</p>
523 524 525 526 527
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">conv</span> <span class="o">=</span> <span class="n">img_conv</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">filter_size</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">filter_size_y</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                      <span class="n">num_channels</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                      <span class="n">num_filters</span><span class="o">=</span><span class="mi">16</span><span class="p">,</span> <span class="n">stride</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                      <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
528
                      <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">Relu</span><span class="p">())</span>
529 530 531 532 533 534 535
</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">参数:</th><td class="field-body"><ul class="first simple">
536
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
537
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
538 539 540 541 542 543 544 545
<li><strong>filter_size</strong> (<em>int | tuple | list</em>) &#8211; The dimensions of the filter kernel. If the parameter is
set to one integer, the two dimensions on x and y axises
will be same when filter_size_y is not set. If it is set
to a list, the first element indicates the dimension on
the x axis, and the second is used to specify the dimension
on the y axis when filter_size_y is not provided.</li>
<li><strong>filter_size_y</strong> (<em>int</em>) &#8211; The dimension of the filter kernel on the y axis. If the parameter
is not set, it will be set automatically according to filter_size.</li>
546
<li><strong>num_filters</strong> &#8211; Each filter group&#8217;s number of filter</li>
547
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Relu is the default activation.</li>
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
<li><strong>groups</strong> (<em>int</em>) &#8211; The group number. 1 is the default group number.</li>
<li><strong>stride</strong> (<em>int | tuple | list</em>) &#8211; The strides. If the parameter is set to one integer, the strides
on x and y axises will be same when stride_y is not set. If it is
set to a list, the first element indicates the stride on the x axis,
and the second is used to specify the stride on the y axis when
stride_y is not provided. 1 is the default value.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The stride on the y axis.</li>
<li><strong>padding</strong> (<em>int | tuple | list</em>) &#8211; The padding sizes. If the parameter is set to one integer, the padding
sizes on x and y axises will be same when padding_y is not set. If it
is set to a list, the first element indicates the padding size on the
x axis, and the second is used to specify the padding size on the y axis
when padding_y is not provided. 0 is the default padding size.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The padding size on the y axis.</li>
<li><strong>dilation</strong> (<em>int | tuple | list</em>) &#8211; The dimensions of the dilation. If the parameter is set to one integer,
the two dimensions on x and y axises will be same when dilation_y is not
set. If it is set to a list, the first element indicates the dimension
on the x axis, and the second is used to specify the dimension on the y
axis when dilation_y is not provided. 1 is the default dimension.</li>
<li><strong>dilation_y</strong> (<em>int</em>) &#8211; The dimension of the dilation on the y axis.</li>
567 568 569
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
570 571 572 573 574 575 576 577 578 579 580 581 582
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of input channels. If the parameter is not set or
set to None, its actual value will be automatically set to
the channel number of the input.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>shared_biases</strong> (<em>bool</em>) &#8211; Whether biases will be shared between filters or not.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attributes. See paddle.v2.attr.ExtraAttribute for
details.</li>
<li><strong>trans</strong> (<em>bool</em>) &#8211; True if it is a convTransLayer, False if it is a convLayer</li>
<li><strong>layer_type</strong> (<em>basestring</em>) &#8211; Specify the layer type. If the dilation&#8217;s dimension on one axis is
larger than 1, layer_type has to be &#8220;cudnn_conv&#8221; or &#8220;cudnn_convt&#8221;.
If trans=True, layer_type has to be &#8220;exconvt&#8221; or &#8220;cudnn_convt&#8221;,
otherwise layer_type has to be either &#8220;exconv&#8221; or &#8220;cudnn_conv&#8221;.</li>
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="context-projection">
<span id="api-v2-layer-context-projection"></span><h3>context_projection<a class="headerlink" href="#context-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
601
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">context_projection</code></dt>
602 603 604 605 606 607 608 609 610 611 612 613 614 615
<dd><p>Context Projection.</p>
<p>It just simply reorganizes input sequence, combines &#8220;context_len&#8221; sequence
to one context from context_start. &#8220;context_start&#8221; will be set to
-(context_len - 1) / 2 by default. If context position out of sequence
length, padding will be filled as zero if padding_attr = False, otherwise
it is trainable.</p>
<p>For example, origin sequence is [A B C D E F G], context len is 3, then
after context projection and not set padding_attr, sequence will
be [ 0AB ABC BCD CDE DEF EFG FG0 ].</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">参数:</th><td class="field-body"><ul class="first simple">
616
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer, which should be a sequence.</li>
617 618 619
<li><strong>context_len</strong> (<em>int</em>) &#8211; context length.</li>
<li><strong>context_start</strong> (<em>int</em>) &#8211; context start position. Default is
-(context_len - 1)/2</li>
620
<li><strong>padding_attr</strong> (<em>bool | paddle.v2.attr.ParameterAttribute</em>) &#8211; Padding Parameter Attribute. If false, it means padding
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
always be zero. Otherwise Padding is learnable, and
parameter attribute is set by this parameter.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">Projection</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">Projection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

636 637 638 639 640 641 642
</div>
<div class="section" id="row-conv">
<h3>row_conv<a class="headerlink" href="#row-conv" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">row_conv</code></dt>
<dd><p>The row convolution is called lookahead convolution. It is firstly
643
introduced in paper of <a class="reference external" href="https://arxiv.org/pdf/1512.02595v1.pdf">Deep Speech 2: End-to-End Speech Recognition
644 645 646 647 648 649
in English and Mandarin</a> .</p>
<p>The bidirectional RNN that learns representation for a sequence by
performing a forward and a backward pass through the entire sequence.
However, unlike unidirectional RNNs, bidirectional RNNs are challenging
to deploy in an online and low-latency setting. The lookahead convolution
incorporates information from future subsequences in a computationally
650 651
efficient manner to improve unidirectional RNNs.</p>
<p>The connection of row convolution is different from the 1D sequence
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
convolution. Assumed that, the future context-length is k, that is to say,
it can get the output at timestep t by using the the input feature from t-th
timestep to (t+k+1)-th timestep. Assumed that the hidden dim of input
activations are d, the activations r_t for the new layer at time-step t are:</p>
<div class="math">
\[r_{t,r} = \sum_{j=1}^{k + 1} {w_{i,j}h_{t+j-1, i}}
          \quad         ext{for} \quad  (1 \leq i \leq d)\]</div>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p class="last">The <cite>context_len</cite> is <cite>k + 1</cite>. That is to say, the lookahead step
number plus one equals context_len.</p>
</div>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">row_conv</span> <span class="o">=</span> <span class="n">row_conv</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">context_len</span><span class="o">=</span><span class="mi">3</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">参数:</th><td class="field-body"><ul class="first simple">
672
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
673 674
<li><strong>context_len</strong> (<em>int</em>) &#8211; The context length equals the lookahead step number
plus one.</li>
675
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation Type. paddle.v2.activation.Linear is the default activation.</li>
676 677 678 679
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
680 681 682 683 684 685 686 687 688 689 690 691 692
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

693 694 695 696 697 698 699 700
</div>
</div>
<div class="section" id="image-pooling-layer">
<h2>Image Pooling Layer<a class="headerlink" href="#image-pooling-layer" title="永久链接至标题"></a></h2>
<div class="section" id="img-pool">
<h3>img_pool<a class="headerlink" href="#img-pool" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
701
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">img_pool</code></dt>
702 703
<dd><blockquote>
<div><p>Image pooling Layer.</p>
704
<p>The details of pooling layer, please refer to ufldl&#8217;s <a class="reference external" href="http://ufldl.stanford.edu/tutorial/supervised/Pooling/">pooling</a> .</p>
705 706 707 708
<ul class="simple">
<li>ceil_mode=True:</li>
</ul>
<div class="math">
709 710 711 712 713 714 715 716 717
\[w = 1 +\]</div>
</div></blockquote>
<dl class="docutils">
<dt>rac{ceil(input_width + 2 * padding - pool_size)}{stride} \</dt>
<dd>h = 1 +</dd>
</dl>
<p>rac{ceil(input_height + 2 * padding_y - pool_size_y)}{stride_y}</p>
<blockquote>
<div><ul class="simple">
718 719 720
<li>ceil_mode=False:</li>
</ul>
<div class="math">
721 722 723 724 725 726 727 728 729
\[w = 1 +\]</div>
</div></blockquote>
<dl class="docutils">
<dt>rac{floor(input_width + 2 * padding - pool_size)}{stride} \</dt>
<dd>h = 1 +</dd>
</dl>
<p>rac{floor(input_height + 2 * padding_y - pool_size_y)}{stride_y}</p>
<blockquote>
<div><p>The example usage is:</p>
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">maxpool</span> <span class="o">=</span> <span class="n">img_pool</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">conv</span><span class="p">,</span>
                         <span class="n">pool_size</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
                         <span class="n">pool_size_y</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
                         <span class="n">num_channels</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                         <span class="n">stride</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                         <span class="n">stride_y</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                         <span class="n">padding</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                         <span class="n">padding_y</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                         <span class="n">pool_type</span><span class="o">=</span><span class="n">MaxPooling</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">
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
<tr class="field-odd field"><th class="field-name">param padding:</th><td class="field-body">The padding size on the x axis. 0 is the default padding size.</td>
</tr>
<tr class="field-even field"><th class="field-name">type padding:</th><td class="field-body">int</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param padding_y:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The padding size on the y axis. If the parameter is not set
or set to None, it will be set to &#8216;padding&#8217; automatically.</td>
</tr>
<tr class="field-even field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
</tr>
<tr class="field-even field"><th class="field-name">param input:</th><td class="field-body">The input of this layer.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param pool_size:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">The pooling window length on the x axis.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type pool_size:</th><td class="field-body">int</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param pool_size_y:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">The pooling window length on the y axis. If the parameter is
768
not set or set to None, its actual value will be automatically
769 770 771 772 773 774 775
set to pool_size.</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">type pool_size_y:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">int</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param num_channels:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">The number of input channels. If the parameter is not set or
776
set to None, its actual value will be automatically set to
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
the channels number of the input.</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">type num_channels:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">int</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param pool_type:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">Pooling type. MaxPooling is the default pooling.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type pool_type:</th><td class="field-body">BasePoolingType</td>
</tr>
<tr class="field-even field"><th class="field-name">param stride:</th><td class="field-body">The stride on the x axis. 1 is the default value.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type stride:</th><td class="field-body">int</td>
</tr>
<tr class="field-even field"><th class="field-name">param stride_y:</th><td class="field-body">The stride on the y axis. If the parameter is not set or set to
None, its actual value will be automatically set to &#8216;stride&#8217;.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type stride_y:</th><td class="field-body">int</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttribute</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param ceil_mode:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">Whether to use the ceil function to calculate output height and width.
805
True is the default. If it is set to False, the floor function will
806 807 808 809 810 811
be used.</td>
</tr>
<tr class="field-odd field"><th class="field-name">type ceil_mode:</th><td class="field-body">bool</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">param exclude_mode:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">Whether to exclude the padding cells when calculating, but only
812 813
work when pool_type is AvgPooling. If None, also exclude the padding
cells. If use cudnn, use CudnnAvgPooling or CudnnAvgInclPadPooling
814
as pool_type to identify the mode.</td>
815
</tr>
816 817
<tr class="field-odd field"><th class="field-name" colspan="2">type exclude_mode:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">bool</td>
818
</tr>
819 820 821
<tr class="field-even field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-odd field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
822 823 824
</tr>
</tbody>
</table>
825
</div></blockquote>
826 827 828 829 830 831 832
</dd></dl>

</div>
<div class="section" id="spp">
<h3>spp<a class="headerlink" href="#spp" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
833
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">spp</code></dt>
834 835 836
<dd><p>A layer performs spatial pyramid pooling.</p>
<dl class="docutils">
<dt>Reference:</dt>
837 838
<dd><a href="#id12"><span class="problematic" id="id13">`Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition
https://arxiv.org/abs/1406.4729`_</span></a></dd>
839
</dl>
840 841 842 843 844 845 846 847 848 849 850 851
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">spp</span> <span class="o">=</span> <span class="n">spp</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                <span class="n">pyramid_height</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                <span class="n">num_channels</span><span class="o">=</span><span class="mi">16</span><span class="p">,</span>
                <span class="n">pool_type</span><span class="o">=</span><span class="n">MaxPooling</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">参数:</th><td class="field-body"><ul class="first simple">
852
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
853
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
854 855 856 857 858 859 860
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of input channels. If the parameter is not set or
set to None, its actual value will be automatically set to
the channels number of the input.</li>
<li><strong>pool_type</strong> &#8211; Pooling type. MaxPooling is the default pooling.</li>
<li><strong>pyramid_height</strong> (<em>int</em>) &#8211; The pyramid height of this pooling.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="maxout">
<h3>maxout<a class="headerlink" href="#maxout" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
879
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">maxout</code></dt>
880 881
<dd><blockquote>
<div><dl class="docutils">
882
<dt>A layer to do max out on convolutional layer output.</dt>
883
<dd><ul class="first last simple">
884 885 886
<li>Input: the output of a convolutional layer.</li>
<li>Output: feature map size same as the input&#8217;s, and its channel number is
(input channel) / groups.</li>
887 888 889 890
</ul>
</dd>
</dl>
<p>So groups should be larger than 1, and the num of channels should be able
891 892 893
to be devided by groups.</p>
<dl class="docutils">
<dt>Reference:</dt>
894 895 896 897
<dd><a href="#id14"><span class="problematic" id="id15">`Maxout Networks
http://www.jmlr.org/proceedings/papers/v28/goodfellow13.pdf`_</span></a>
<a href="#id16"><span class="problematic" id="id17">`Multi-digit Number Recognition from Street View Imagery using Deep Convolutional Neural Networks
https://arxiv.org/pdf/1312.6082v4.pdf`_</span></a></dd>
898
</dl>
899
<div class="math">
900 901 902 903 904 905 906 907 908 909 910 911
\[\begin{split}out = \max_k (in[n, k, o_c , s])   \\
out_{i * s + j} = \max_k in_{  k * o_{c} * s + i * s + j}  \\
s =\end{split}\]</div>
</div></blockquote>
<dl class="docutils">
<dt>rac{input.size}{ num_channels}       \</dt>
<dd>o_{c} =</dd>
<dt>rac{num_channels}{groups}         \</dt>
<dd><blockquote class="first">
<div>0 le i &lt; o_{c}                             \
0 le j &lt; s                                 \
0 le k &lt; groups                            \</div></blockquote>
912 913 914 915 916 917
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">maxout</span> <span class="o">=</span> <span class="n">maxout</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span>
                      <span class="n">num_channels</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span>
                      <span class="n">groups</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
</pre></div>
</div>
918
<table class="last docutils field-list" frame="void" rules="none">
919 920 921
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
922 923 924 925 926 927
<tr class="field-odd field"><th class="field-name">param input:</th><td class="field-body">The input of this layer.</td>
</tr>
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param num_channels:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The number of input channels. If the parameter is not set or
928
set to None, its actual value will be automatically set to
929
the channels number of the input.</td>
930
</tr>
931 932
<tr class="field-even field"><th class="field-name" colspan="2">type num_channels:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">int</td>
933
</tr>
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
<tr class="field-odd field"><th class="field-name">param groups:</th><td class="field-body">The group number of input layer.</td>
</tr>
<tr class="field-even field"><th class="field-name">type groups:</th><td class="field-body">int</td>
</tr>
<tr class="field-odd field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
</tr>
<tr class="field-even field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttribute</td>
</tr>
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
952 953 954
</tr>
</tbody>
</table>
955 956
</dd>
</dl>
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
</dd></dl>

</div>
<div class="section" id="roi-pool">
<h3>roi_pool<a class="headerlink" href="#roi-pool" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">roi_pool</code></dt>
<dd><p>A layer used by Fast R-CNN to extract feature maps of ROIs from the last
feature map.</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer.</em>) &#8211; The input layer.</li>
<li><strong>rois</strong> (<em>paddle.v2.config_base.Layer.</em>) &#8211; The input ROIs&#8217; data.</li>
<li><strong>pooled_width</strong> (<em>int</em>) &#8211; The width after pooling.</li>
<li><strong>pooled_height</strong> (<em>int</em>) &#8211; The height after pooling.</li>
<li><strong>spatial_scale</strong> (<em>float</em>) &#8211; The spatial scale between the image and feature map.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; number of input channel.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
983 984 985 986 987 988 989 990 991 992 993 994 995 996
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="norm-layer">
<h2>Norm Layer<a class="headerlink" href="#norm-layer" title="永久链接至标题"></a></h2>
<div class="section" id="img-cmrnorm">
<h3>img_cmrnorm<a class="headerlink" href="#img-cmrnorm" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
997
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">img_cmrnorm</code></dt>
998 999 1000
<dd><p>Response normalization across feature maps.</p>
<dl class="docutils">
<dt>Reference:</dt>
1001 1002
<dd><a href="#id18"><span class="problematic" id="id19">`ImageNet Classification with Deep Convolutional Neural Networks
http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf`_</span></a></dd>
1003
</dl>
1004 1005 1006 1007 1008 1009 1010 1011 1012
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">norm</span> <span class="o">=</span> <span class="n">img_cmrnorm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">net</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">5</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">参数:</th><td class="field-body"><ul class="first simple">
1013
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1014
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1015 1016 1017
<li><strong>size</strong> (<em>int</em>) &#8211; Normalize in number of <span class="math">\(size\)</span> feature maps.</li>
<li><strong>scale</strong> (<em>float</em>) &#8211; The hyper-parameter.</li>
<li><strong>power</strong> (<em>float</em>) &#8211; The hyper-parameter.</li>
1018 1019 1020 1021 1022
<li><strong>num_channels</strong> &#8211; The number of input channels. If the parameter is not set or
set to None, its actual value will be automatically set to
the channels number of the input.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attributes. See paddle.v2.attr.ExtraAttribute for
details.</li>
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="batch-norm">
<h3>batch_norm<a class="headerlink" href="#batch-norm" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1041
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">batch_norm</code></dt>
1042
<dd><p>Batch Normalization Layer. The notation of this layer is as follows.</p>
1043 1044 1045 1046 1047 1048 1049 1050 1051
<p><span class="math">\(x\)</span> is the input features over a mini-batch.</p>
<div class="math">
\[\begin{split}\mu_{\beta} &amp;\gets \frac{1}{m} \sum_{i=1}^{m} x_i \qquad &amp;//\
\ mini-batch\ mean \\
\sigma_{\beta}^{2} &amp;\gets \frac{1}{m} \sum_{i=1}^{m}(x_i - \
\mu_{\beta})^2 \qquad &amp;//\ mini-batch\ variance \\
\hat{x_i} &amp;\gets \frac{x_i - \mu_\beta} {\sqrt{\
\sigma_{\beta}^{2} + \epsilon}} \qquad &amp;//\ normalize \\
y_i &amp;\gets \gamma \hat{x_i} + \beta \qquad &amp;//\ scale\ and\ shift\end{split}\]</div>
1052 1053
<dl class="docutils">
<dt>Reference:</dt>
1054
<dd><a href="#id20"><span class="problematic" id="id21">`Batch Normalization: Accelerating Deep Network Training by Reducing
1055
Internal Covariate Shift
1056
http://arxiv.org/abs/1502.03167`_</span></a></dd>
1057
</dl>
1058
<p>The example usage is:</p>
1059
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">norm</span> <span class="o">=</span> <span class="n">batch_norm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">net</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">Relu</span><span class="p">())</span>
1060 1061 1062 1063 1064 1065 1066
</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">参数:</th><td class="field-body"><ul class="first simple">
1067
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1068
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; This layer&#8217;s input which is to be performed batch normalization on.</li>
1069 1070 1071 1072 1073 1074
<li><strong>batch_norm_type</strong> (<em>None | string</em><em>, </em><em>None</em><em> or </em><em>&quot;batch_norm&quot;</em><em> or </em><em>&quot;cudnn_batch_norm&quot;</em><em>
or </em><em>&quot;mkldnn_batch_norm&quot;</em>) &#8211; We have batch_norm, mkldnn_batch_norm and cudnn_batch_norm.
batch_norm supports CPU, MKLDNN and GPU. cudnn_batch_norm
requires cuDNN version greater or equal to v4 (&gt;=v4).
But cudnn_batch_norm is faster and needs less
memory than batch_norm. mkldnn_batch_norm requires
1075 1076
use_mkldnn is enabled. By default (None), we will
automatically select cudnn_batch_norm for GPU,
1077
mkldnn_batch_norm for MKLDNN and batch_norm for CPU.
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
Users can specify the batch norm type. If you use
cudnn_batch_norm, we suggested you use latest version,
such as v5.1.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Relu is the default activation.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of input channels. If the parameter is not set or
set to None, its actual value will be automatically set to
the channels number of the input.</li>
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; <span class="math">\(\beta\)</span>. The bias attribute. If the parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute, no
bias is defined. If the parameter is set to True, the bias is
initialized to zero.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; <span class="math">\(\gamma\)</span>. The parameter attribute. See paddle.v2.attr.ParameterAttribute
for details.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
<li><strong>use_global_stats</strong> (<em>bool | None.</em>) &#8211; Whether use moving mean/variance statistics during
testing peroid. If the parameter is set to None or
True, it will use moving mean/variance statistics
during testing. If the parameter is set to False, it
will use the mean and variance of the current batch
of test data.</li>
1099
<li><strong>epsilon</strong> (<em>float.</em>) &#8211; The small constant added to the variance to improve numeric stability.</li>
1100 1101
<li><strong>moving_average_fraction</strong> (<em>float.</em>) &#8211; Factor used in the moving average computation.
<span class="math">\(runningMean = newMean*(1-factor) + runningMean*factor\)</span></li>
1102
<li><strong>mean_var_names</strong> (<em>string list</em>) &#8211; [mean name, variance name]</li>
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="sum-to-one-norm">
<h3>sum_to_one_norm<a class="headerlink" href="#sum-to-one-norm" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1121
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">sum_to_one_norm</code></dt>
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
<dd><p>A layer for sum-to-one normalization,
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[out[i] = \frac {in[i]} {\sum_{k=1}^N in[k]}\]</div>
<p>where <span class="math">\(in\)</span> is a (batchSize x dataDim) input vector,
and <span class="math">\(out\)</span> is a (batchSize x dataDim) output vector.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sum_to_one_norm</span> <span class="o">=</span> <span class="n">sum_to_one_norm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
1137
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1138
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1139 1140
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute
for details.</li>
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

1154 1155 1156 1157 1158
</div>
<div class="section" id="cross-channel-norm">
<h3>cross_channel_norm<a class="headerlink" href="#cross-channel-norm" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1159
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">cross_channel_norm</code></dt>
1160 1161 1162 1163 1164 1165 1166 1167 1168
<dd><p>Normalize a layer&#8217;s output. This layer is necessary for ssd.
This layer applys normalize across the channels of each sample to
a conv layer&#8217;s output and scale the output by a group of trainable
factors which dimensions equal to the channel&#8217;s number.</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">参数:</th><td class="field-body"><ul class="first simple">
1169
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1170
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The Parameter Attribute|list.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
</div>
<div class="section" id="row-l2-norm">
<h3>row_l2_norm<a class="headerlink" href="#row-l2-norm" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">row_l2_norm</code></dt>
<dd><blockquote>
<div><p>A layer for L2-normalization in each row.</p>
<div class="math">
\[out[i] =\]</div>
</div></blockquote>
<p>rac{in[i]}{sqrt{sum_{k=1}^N in[k]^{2}}}</p>
<blockquote>
<div><p>where the size of <span class="math">\(in\)</span> is (batchSize x dataDim) ,
and the size of <span class="math">\(out\)</span> is a (batchSize x dataDim) .</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">row_l2_norm</span> <span class="o">=</span> <span class="n">row_l2_norm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">
1205
<tr class="field-odd field"><th class="field-name">param input:</th><td class="field-body">The input of this layer.</td>
1206 1207 1208
</tr>
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
1209
<tr class="field-odd field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
1210 1211 1212 1213
</tr>
<tr class="field-even field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
1214 1215
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The extra layer attribute. See paddle.v2.attr.ExtraAttribute
for details.</td>
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttribute</td>
</tr>
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
</tbody>
</table>
</div></blockquote>
</dd></dl>

1229 1230 1231 1232 1233 1234 1235 1236
</div>
</div>
<div class="section" id="recurrent-layers">
<h2>Recurrent Layers<a class="headerlink" href="#recurrent-layers" title="永久链接至标题"></a></h2>
<div class="section" id="recurrent">
<h3>recurrent<a class="headerlink" href="#recurrent" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1237
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">recurrent</code></dt>
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
<dd><p>Simple recurrent unit layer. It is just a fully connect layer through both
time and neural network.</p>
<p>For each sequence [start, end] it performs the following computation:</p>
<div class="math">
\[\begin{split}out_{i} = act(in_{i})     \      \      \text{for} \ i = start \\
out_{i} = act(in_{i} + out_{i-1} * W) \ \ \text{for} \ start &lt; i &lt;= end\end{split}\]</div>
<p>If reversed is true, the order is reversed:</p>
<div class="math">
\[\begin{split}out_{i} = act(in_{i})           \    \   \text{for} \ i = end  \\
out_{i} = act(in_{i} + out_{i+1} * W) \ \ \text{for} \ start &lt;= i &lt; end\end{split}\]</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">参数:</th><td class="field-body"><ul class="first simple">
1253
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1254
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Tanh is the default activation.</li>
1255 1256 1257 1258
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The parameter attribute for bias. If this parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute,
no bias is defined. If the parameter is set to True,
the bias is initialized to zero.</li>
1259 1260
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
1261
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1262 1263
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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">
<h3>lstmemory<a class="headerlink" href="#lstmemory" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1282
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">lstmemory</code></dt>
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
<dd><p>Long Short-term Memory Cell.</p>
<p>The memory cell was implemented as follow equations.</p>
<div class="math">
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{xi}x_{t} + W_{hi}h_{t-1} + W_{ci}c_{t-1} + b_i)\\f_t &amp; = \sigma(W_{xf}x_{t} + W_{hf}h_{t-1} + W_{cf}c_{t-1} + b_f)\\c_t &amp; = f_tc_{t-1} + i_t tanh (W_{xc}x_t+W_{hc}h_{t-1} + b_c)\\o_t &amp; = \sigma(W_{xo}x_{t} + W_{ho}h_{t-1} + W_{co}c_t + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
<p>NOTE: In PaddlePaddle&#8217;s implementation, the 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 the lstmemory layer,
so an additional mixed with full_matrix_projection or a fc must
be included in the configuration file to complete the input-to-hidden
mappings before lstmemory is called.</p>
<p>NOTE: This is a low level user interface. You can use network.simple_lstm
to config a simple plain lstm layer.</p>
<p>Please refer to <strong>Generating Sequences With Recurrent Neural Networks</strong> for
more details about LSTM.</p>
<p><a class="reference external" href="http://arxiv.org/abs/1308.0850">Link</a> goes as below.</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The lstmemory layer name.</li>
1304
<li><strong>size</strong> (<em>int</em>) &#8211; DEPRECATED. size of the lstm cell</li>
1305
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1306
<li><strong>reverse</strong> (<em>bool</em>) &#8211; is sequence process reversed or not.</li>
1307
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Tanh is the default activation.</li>
1308 1309
<li><strong>gate_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; gate activation type, paddle.v2.activation.Sigmoid by default.</li>
<li><strong>state_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; state activation type, paddle.v2.activation.Tanh by default.</li>
1310 1311 1312
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
1313 1314
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | False</em>) &#8211; Parameter Attribute.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra Layer attribute</li>
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="grumemory">
<h3>grumemory<a class="headerlink" href="#grumemory" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1333
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">grumemory</code></dt>
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
<dd><p>Gate Recurrent Unit Layer.</p>
<p>The memory cell was implemented as follow equations.</p>
<p>1. update gate <span class="math">\(z\)</span>: defines how much of the previous memory to
keep around or the unit updates its activations. The update gate
is computed by:</p>
<div class="math">
\[z_t = \sigma(W_{z}x_{t} + U_{z}h_{t-1} + b_z)\]</div>
<p>2. reset gate <span class="math">\(r\)</span>: determines how to combine the new input with the
previous memory. The reset gate is computed similarly to the update gate:</p>
<div class="math">
\[r_t = \sigma(W_{r}x_{t} + U_{r}h_{t-1} + b_r)\]</div>
<p>3. The candidate activation <span class="math">\(\tilde{h_t}\)</span> is computed similarly to
that of the traditional recurrent unit:</p>
<div class="math">
\[{\tilde{h_t}} = tanh(W x_{t} + U (r_{t} \odot h_{t-1}) + b)\]</div>
<p>4. The hidden activation <span class="math">\(h_t\)</span> of the GRU at time t is a linear
interpolation between the previous activation <span class="math">\(h_{t-1}\)</span> and the
candidate activation <span class="math">\(\tilde{h_t}\)</span>:</p>
<div class="math">
\[h_t = (1 - z_t) h_{t-1} + z_t {\tilde{h_t}}\]</div>
<p>NOTE: In PaddlePaddle&#8217;s implementation, the multiplication operations
<span class="math">\(W_{r}x_{t}\)</span>, <span class="math">\(W_{z}x_{t}\)</span> and <span class="math">\(W x_t\)</span> are not computed in
gate_recurrent layer. Consequently, an additional mixed with
full_matrix_projection or a fc must be included before grumemory
is called.</p>
<p>More details can be found by referring to <a class="reference external" href="https://arxiv.org/abs/1412.3555">Empirical Evaluation of Gated
Recurrent Neural Networks on Sequence Modeling.</a></p>
<p>The simple 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">grumemory</span><span class="p">(</span><span class="nb">input</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">参数:</th><td class="field-body"><ul class="first simple">
1370 1371
<li><strong>name</strong> (<em>None | basestring</em>) &#8211; The gru layer name.</li>
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer.</em>) &#8211; The input of this layer.</li>
1372
<li><strong>size</strong> (<em>int</em>) &#8211; DEPRECATED. size of the gru cell</li>
1373
<li><strong>reverse</strong> (<em>bool</em>) &#8211; Whether sequence process is reversed or not.</li>
1374
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type, paddle.v2.activation.Tanh is the default. This activation
1375
affects the <span class="math">\({\tilde{h_t}}\)</span>.</li>
1376
<li><strong>gate_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; gate activation type, paddle.v2.activation.Sigmoid by default.
1377 1378
This activation affects the <span class="math">\(z_t\)</span> and <span class="math">\(r_t\)</span>. It is the
<span class="math">\(\sigma\)</span> in the above formula.</li>
1379 1380 1381
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
1382 1383
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | False</em>) &#8211; Parameter Attribute.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra Layer attribute</li>
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="recurrent-layer-group">
<h2>Recurrent Layer Group<a class="headerlink" href="#recurrent-layer-group" title="永久链接至标题"></a></h2>
<div class="section" id="memory">
<h3>memory<a class="headerlink" href="#memory" title="永久链接至标题"></a></h3>
1403
<dl class="class">
1404
<dt>
1405
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">memory</code></dt>
1406 1407 1408 1409 1410 1411 1412
<dd><p>The memory takes a layer&#8217;s output at previous time step as its own output.</p>
<p>If boot_bias, the activation of the bias is the initial value of the memory.</p>
<p>If boot_with_const_id is set, then the memory&#8217;s output at the first time step
is a IndexSlot, the Arguments.ids()[0] is this <code class="code docutils literal"><span class="pre">cost_id</span></code>.</p>
<p>If boot is specified, the memory&#8217;s output at the first time step will
be the boot&#8217;s output.</p>
<p>In other case, the default memory&#8217;s output at the first time step is zero.</p>
1413
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">mem</span> <span class="o">=</span> <span class="n">memory</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">name</span><span class="o">=</span><span class="s1">&#39;state&#39;</span><span class="p">)</span>
1414
<span class="n">state</span> <span class="o">=</span> <span class="n">fc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">mem</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">name</span><span class="o">=</span><span class="s1">&#39;state&#39;</span><span class="p">)</span>
1415 1416
</pre></div>
</div>
1417 1418
<p>If you do not want to specify the name, you can also use set_input()
to specify the layer to be remembered as the following:</p>
1419 1420 1421 1422 1423
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">mem</span> <span class="o">=</span> <span class="n">memory</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">state</span> <span class="o">=</span> <span class="n">fc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">mem</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">mem</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="n">mem</span><span class="p">)</span>
</pre></div>
</div>
1424 1425 1426 1427 1428
<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">参数:</th><td class="field-body"><ul class="first simple">
1429
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of the layer which this memory remembers.
1430 1431
If name is None, user should call set_input() to specify the
name of the layer which this memory remembers.</li>
1432 1433
<li><strong>size</strong> (<em>int</em>) &#8211; The dimensionality of memory.</li>
<li><strong>memory_name</strong> (<em>basestring</em>) &#8211; The name of the memory. It is ignored when name is provided.</li>
1434
<li><strong>is_seq</strong> (<em>bool</em>) &#8211; DEPRECATED. is sequence for boot</li>
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
<li><strong>boot</strong> (<em>paddle.v2.config_base.Layer | None</em>) &#8211; This parameter specifies memory&#8217;s output at the first time
step and the output is boot&#8217;s output.</li>
<li><strong>boot_bias</strong> (<em>paddle.v2.attr.ParameterAttribute | None</em>) &#8211; The bias attribute of memory&#8217;s output at the first time step.
If the parameter is set to False or an object whose type is not
paddle.v2.attr.ParameterAttribute, no bias is defined. If the parameter is set
to True, the bias is initialized to zero.</li>
<li><strong>boot_bias_active_type</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type for memory&#8217;s bias at the first time
step. paddle.v2.activation.Linear is the default activation.</li>
<li><strong>boot_with_const_id</strong> (<em>int</em>) &#8211; This parameter specifies memory&#8217;s output at the first
time step and the output is an index.</li>
1445 1446 1447
</ul>
</td>
</tr>
1448
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
1449 1450
</td>
</tr>
1451
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
1452 1453 1454 1455
</td>
</tr>
</tbody>
</table>
1456
</dd></dl>
1457 1458 1459 1460

</div>
<div class="section" id="recurrent-group">
<h3>recurrent_group<a class="headerlink" href="#recurrent-group" title="永久链接至标题"></a></h3>
1461 1462 1463
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">recurrent_group</code></dt>
1464 1465 1466
<dd><p>Recurrent layer group is an extremely flexible recurrent unit in
PaddlePaddle. As long as the user defines the calculation done within a
time step, PaddlePaddle will iterate such a recurrent calculation over
1467 1468
sequence input. This is useful for attention-based models, or Neural
Turning Machine like models.</p>
1469 1470
<p>The basic usage (time steps) is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="nb">input</span><span class="p">):</span>
1471
    <span class="n">output</span> <span class="o">=</span> <span class="n">fc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
1472
                      <span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span>
1473
                      <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">Linear</span><span class="p">(),</span>
1474 1475 1476 1477 1478 1479 1480 1481 1482
                      <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">output</span>

<span class="n">group</span> <span class="o">=</span> <span class="n">recurrent_group</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                        <span class="n">step</span><span class="o">=</span><span class="n">step</span><span class="p">)</span>
</pre></div>
</div>
<p>You can see following configs for further usages:</p>
<ul class="simple">
1483 1484
<li>time steps: lstmemory_group, paddle/gserver/tests/sequence_group.conf,                   demo/seqToseq/seqToseq_net.py</li>
<li>sequence steps: paddle/gserver/tests/sequence_nest_group.conf</li>
1485 1486 1487 1488 1489
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
1490
<tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple">
1491 1492 1493 1494 1495
<li><strong>step</strong> (<em>callable</em>) &#8211; <p>A step function which takes the input of recurrent_group as its own
input and returns values as recurrent_group&#8217;s output every time step.</p>
<p>The recurrent group scatters a sequence into time steps. And
for each time step, it will invoke step function, and return
a time step result. Then gather outputs of each time step into
1496 1497
layer group&#8217;s output.</p>
</li>
1498
<li><strong>name</strong> (<em>basestring</em>) &#8211; The recurrent_group&#8217;s name. It is optional.</li>
1499
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | StaticInput | SubsequenceInput | list | tuple</em>) &#8211; <p>Input links array.</p>
1500
<p>paddle.v2.config_base.Layer will be scattered into time steps.
1501 1502
SubsequenceInput will be scattered into sequence steps.
StaticInput will be imported to each time step, and doesn&#8217;t change
1503
over time. It&#8217;s a mechanism to access layer outside step function.</p>
1504
</li>
1505
<li><strong>reverse</strong> (<em>bool</em>) &#8211; If reverse is set to True, the recurrent unit will process the
1506
input sequence in a reverse order.</li>
1507
<li><strong>targetInlink</strong> (<em>paddle.v2.config_base.Layer | SubsequenceInput</em>) &#8211; <p>DEPRECATED.
1508
The input layer which share info with layer group&#8217;s output</p>
1509 1510 1511 1512 1513 1514 1515 1516 1517
<p>Param input specifies multiple input layers. For
SubsequenceInput inputs, config should assign one input
layer that share info(the number of sentences and the number
of words in each sentence) with all layer group&#8217;s outputs.
targetInlink should be one of the layer group&#8217;s input.</p>
</li>
</ul>
</td>
</tr>
1518 1519
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
</td>
1520
</tr>
1521 1522
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
1523 1524 1525 1526
</tr>
</tbody>
</table>
</dd></dl>
1527 1528 1529 1530 1531 1532

</div>
<div class="section" id="lstm-step">
<h3>lstm_step<a class="headerlink" href="#lstm-step" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1533
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">lstm_step</code></dt>
1534 1535
<dd><p>LSTM Step Layer. This function is used only in recurrent_group.
The lstm equations are shown as follows.</p>
1536
<div class="math">
1537
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{x_i}x_{t} + W_{h_i}h_{t-1} + W_{c_i}c_{t-1} + b_i)\\f_t &amp; = \sigma(W_{x_f}x_{t} + W_{h_f}h_{t-1} + W_{c_f}c_{t-1} + b_f)\\c_t &amp; = f_tc_{t-1} + i_t tanh (W_{x_c}x_t+W_{h_c}h_{t-1} + b_c)\\o_t &amp; = \sigma(W_{x_o}x_{t} + W_{h_o}h_{t-1} + W_{c_o}c_t + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
1538 1539
<p>The input of lstm step is <span class="math">\(Wx_t + Wh_{t-1}\)</span>, and user should use
<code class="code docutils literal"><span class="pre">mixed</span></code> and <code class="code docutils literal"><span class="pre">full_matrix_projection</span></code> to calculate these
1540
input vectors.</p>
1541 1542 1543
<p>The state of lstm step is <span class="math">\(c_{t-1}\)</span>. And lstm step layer will do</p>
<div class="math">
\[ \begin{align}\begin{aligned}i_t = \sigma(input + W_{ci}c_{t-1} + b_i)\\...\end{aligned}\end{align} \]</div>
1544 1545
<p>This layer has two outputs. The default output is <span class="math">\(h_t\)</span>. The other
output is <span class="math">\(o_t\)</span>, whose name is &#8216;state&#8217; and users can use
1546 1547 1548 1549 1550 1551
<code class="code docutils literal"><span class="pre">get_output</span></code> to extract this 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">参数:</th><td class="field-body"><ul class="first simple">
1552
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer&#8217;s output, which must be
equal to the dimension of the state.</li>
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
<li><strong>state</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The state of the LSTM unit.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Tanh is the default activation.</li>
<li><strong>gate_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type of the gate. paddle.v2.activation.Sigmoid is the
default activation.</li>
<li><strong>state_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type of the state. paddle.v2.activation.Tanh is the
default activation.</li>
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for details.</li>
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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-step">
<h3>gru_step<a class="headerlink" href="#gru-step" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1584
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">gru_step</code></dt>
1585 1586 1587 1588 1589
<dd><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">参数:</th><td class="field-body"><ul class="first simple">
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer, whose dimension can be divided by 3.</li>
<li><strong>output_mem</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; A memory which memorizes the output of this layer at previous
time step.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer&#8217;s output. If it is not set or set to None,
it will be set to one-third of the dimension of the input automatically.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type of this layer&#8217;s output. paddle.v2.activation.Tanh
is the default activation.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>gate_act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type of this layer&#8217;s two gates. paddle.v2.activation.Sigmoid is
the default activation.</li>
1600 1601 1602 1603
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The parameter attribute for bias. If this parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute, no bias
is defined. If this parameter is set to True,
the bias is initialized to zero.</li>
1604 1605
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for details.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for details.</li>
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="beam-search">
<h3>beam_search<a class="headerlink" href="#beam-search" title="永久链接至标题"></a></h3>
1622 1623 1624
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">beam_search</code></dt>
1625 1626 1627 1628 1629 1630
<dd><p>Beam search is a heuristic search algorithm used in sequence generation.
It explores a graph by expanding the most promising nodes in a limited set
to maintain tractability.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">rnn_step</span><span class="p">(</span><span class="nb">input</span><span class="p">):</span>
    <span class="n">last_time_step_output</span> <span class="o">=</span> <span class="n">memory</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;rnn&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">)</span>
1631
    <span class="k">with</span> <span class="n">mixed</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;rnn&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">simple_rnn</span><span class="p">:</span>
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
        <span class="n">simple_rnn</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
        <span class="n">simple_rnn</span> <span class="o">+=</span> <span class="n">last_time_step_output</span>
    <span class="k">return</span> <span class="n">simple_rnn</span>

<span class="n">generated_word_embedding</span> <span class="o">=</span> <span class="n">GeneratedInput</span><span class="p">(</span>
                       <span class="n">size</span><span class="o">=</span><span class="n">target_dictionary_dim</span><span class="p">,</span>
                       <span class="n">embedding_name</span><span class="o">=</span><span class="s2">&quot;target_language_embedding&quot;</span><span class="p">,</span>
                       <span class="n">embedding_size</span><span class="o">=</span><span class="n">word_vector_dim</span><span class="p">)</span>

<span class="n">beam_gen</span> <span class="o">=</span> <span class="n">beam_search</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;decoder&quot;</span><span class="p">,</span>
                       <span class="n">step</span><span class="o">=</span><span class="n">rnn_step</span><span class="p">,</span>
                       <span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">StaticInput</span><span class="p">(</span><span class="n">encoder_last</span><span class="p">),</span>
                              <span class="n">generated_word_embedding</span><span class="p">],</span>
                       <span class="n">bos_id</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                       <span class="n">eos_id</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                       <span class="n">beam_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<p>Please see the following demo for more details:</p>
<ul class="simple">
<li>machine translation : demo/seqToseq/translation/gen.conf                             demo/seqToseq/seqToseq_net.py</li>
</ul>
<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">参数:</th><td class="field-body"><ul class="first simple">
1659 1660
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of the recurrent unit that is responsible for
generating sequences. It is optional.</li>
1661 1662 1663 1664 1665 1666 1667
<li><strong>step</strong> (<em>callable</em>) &#8211; <p>A callable function that defines the calculation in a time
step, and it is applied to sequences with arbitrary length by
sharing a same set of weights.</p>
<p>You can refer to the first parameter of recurrent_group, or
demo/seqToseq/seqToseq_net.py for more details.</p>
</li>
<li><strong>input</strong> (<em>list</em>) &#8211; Input data for the recurrent unit, which should include the
1668 1669
previously generated words as a GeneratedInput object.
In beam_search, none of the input&#8217;s type should be paddle.v2.config_base.Layer.</li>
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
<li><strong>bos_id</strong> (<em>int</em>) &#8211; Index of the start symbol in the dictionary. The start symbol
is a special token for NLP task, which indicates the
beginning of a sequence. In the generation task, the start
symbol is essential, since it is used to initialize the RNN
internal state.</li>
<li><strong>eos_id</strong> (<em>int</em>) &#8211; Index of the end symbol in the dictionary. The end symbol is
a special token for NLP task, which indicates the end of a
sequence. The generation process will stop once the end
symbol is generated, or a pre-defined max iteration number
is exceeded.</li>
<li><strong>max_length</strong> (<em>int</em>) &#8211; Max generated sequence length.</li>
<li><strong>beam_size</strong> (<em>int</em>) &#8211; Beam search for sequence generation is an iterative search
algorithm. To maintain tractability, every iteration only
only stores a predetermined number, called the beam_size,
of the most promising next words. The greater the beam
size, the fewer candidate words are pruned.</li>
<li><strong>num_results_per_sample</strong> (<em>int</em>) &#8211; Number of the generated results per input
sequence. This number must always be less than
beam size.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">The generated word index.</p>
</td>
</tr>
1695
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
1696 1697 1698 1699 1700
</td>
</tr>
</tbody>
</table>
</dd></dl>
1701 1702 1703 1704 1705 1706

</div>
<div class="section" id="get-output">
<h3>get_output<a class="headerlink" href="#get-output" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1707
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">get_output</code></dt>
1708 1709 1710 1711 1712 1713 1714 1715 1716
<dd><p>Get layer&#8217;s output by name. In PaddlePaddle, a layer might return multiple
values, but returns one layer&#8217;s output. If the user wants to use another
output besides the default one, please use get_output first to get
the output from input.</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">参数:</th><td class="field-body"><ul class="first simple">
1717
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1718
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input layer. And this layer should contain
1719
multiple outputs.</li>
1720 1721 1722
<li><strong>arg_name</strong> (<em>basestring</em>) &#8211; The name of the output to be extracted from the input layer.</li>
<li><strong>layer_attr</strong> &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="mixed-layer">
<h2>Mixed Layer<a class="headerlink" href="#mixed-layer" title="永久链接至标题"></a></h2>
<div class="section" id="mixed">
<span id="api-v2-layer-mixed"></span><h3>mixed<a class="headerlink" href="#mixed" title="永久链接至标题"></a></h3>
1742 1743 1744
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">mixed</code></dt>
1745 1746 1747 1748
<dd><p>Mixed Layer. A mixed layer will add all inputs together, then activate.
Each inputs is a projection or operator.</p>
<p>There are two styles of usages.</p>
<ol class="arabic simple">
1749
<li>When not set inputs parameter, use mixed like this:</li>
1750
</ol>
1751
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed</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="k">as</span> <span class="n">m</span><span class="p">:</span>
1752 1753 1754 1755 1756
    <span class="n">m</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">)</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer2</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
1757
<li>You can also set all inputs when invoke mixed as follows:</li>
1758
</ol>
1759
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">mixed</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">,</span>
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
                <span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">),</span>
                       <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; mixed layer name. Can be referenced by other layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; layer size.</li>
1771
<li><strong>input</strong> &#8211; The input of this layer. It is an optional parameter. If set,
1772
then this function will just return layer&#8217;s name.</li>
1773
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation Type. paddle.v2.activation.Linear is the default activation.</li>
1774 1775 1776
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
1777
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer config. Default is None.</li>
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">MixedLayerType object can add inputs or layer name.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">MixedLayerType</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
1790 1791 1792 1793 1794 1795

</div>
<div class="section" id="embedding">
<span id="api-v2-layer-embedding"></span><h3>embedding<a class="headerlink" href="#embedding" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1796
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">embedding</code></dt>
1797 1798 1799 1800 1801 1802
<dd><p>Define a embedding Layer.</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">参数:</th><td class="field-body"><ul class="first simple">
1803
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
1804
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer, which must be Index Data.</li>
1805
<li><strong>size</strong> (<em>int</em>) &#8211; The embedding dimension.</li>
1806
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None</em>) &#8211; The embedding parameter attribute. See paddle.v2.attr.ParameterAttribute
1807
for details.</li>
1808
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra layer Config. Default is None.</li>
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="scaling-projection">
<h3>scaling_projection<a class="headerlink" href="#scaling-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1827
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">scaling_projection</code></dt>
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
<dd><p>scaling_projection multiplies the input with a scalar parameter and add to
the output.</p>
<div class="math">
\[out += w * in\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">scaling_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
1841
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A ScalingProjection object</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">ScalingProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="dotmul-projection">
<h3>dotmul_projection<a class="headerlink" href="#dotmul-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1861
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">dotmul_projection</code></dt>
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
<dd><p>DotMulProjection with a layer as input.
It performs element-wise multiplication with weight.</p>
<div class="math">
\[out.row[i] += in.row[i] .* weight\]</div>
<p>where <span class="math">\(.*\)</span> means element-wise multiplication.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">dotmul_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
1876
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A DotMulProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">DotMulProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="dotmul-operator">
<h3>dotmul_operator<a class="headerlink" href="#dotmul-operator" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1896
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">dotmul_operator</code></dt>
1897 1898
<dd><p>DotMulOperator takes two inputs and performs element-wise multiplication:</p>
<div class="math">
1899
\[out.row[i] += scale * (a.row[i] .* b.row[i])\]</div>
1900 1901 1902
<p>where <span class="math">\(.*\)</span> means element-wise multiplication, and
scale is a config scalar, its default value is one.</p>
<p>The example usage is:</p>
1903
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">op</span> <span class="o">=</span> <span class="n">dotmul_operator</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931
</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>a</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; Input layer1</li>
<li><strong>b</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; Input layer2</li>
<li><strong>scale</strong> (<em>float</em>) &#8211; config scalar, default value is one.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A DotMulOperator Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">DotMulOperator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="full-matrix-projection">
<h3>full_matrix_projection<a class="headerlink" href="#full-matrix-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1932
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">full_matrix_projection</code></dt>
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
<dd><p>Full Matrix Projection. It performs full matrix multiplication.</p>
<div class="math">
\[out.row[i] += in.row[i] * weight\]</div>
<p>There are two styles of usage.</p>
<ol class="arabic simple">
<li>When used in mixed like this, you can only set the input:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="k">as</span> <span class="n">m</span><span class="p">:</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>When used as an independant object like this, you must set the size:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                              <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                              <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</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">参数:</th><td class="field-body"><ul class="first simple">
1957
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A FullMatrixProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">FullMatrixProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="identity-projection">
<h3>identity_projection<a class="headerlink" href="#identity-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
1978
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">identity_projection</code></dt>
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
<dd><ol class="arabic simple">
<li>IdentityProjection if offset=None. It performs:</li>
</ol>
<div class="math">
\[out.row[i] += in.row[i]\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<p>2. IdentityOffsetProjection if offset!=None. It likes IdentityProjection,
but layer size may be smaller than input size.
It select dimesions [offset, offset+layer_size) from input:</p>
<div class="math">
\[out.row[i] += in.row[i + \textrm{offset}]\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                           <span class="n">offset</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that both of two projections should not have any parameter.</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">参数:</th><td class="field-body"><ul class="first simple">
2004
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
<li><strong>offset</strong> (<em>int</em>) &#8211; Offset, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A IdentityProjection or IdentityOffsetProjection object</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">IdentityProjection or IdentityOffsetProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
</div>
<div class="section" id="slice-projection">
<h3>slice_projection<a class="headerlink" href="#slice-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">slice_projection</code></dt>
<dd><p>slice_projection can slice the input value into multiple parts,
and then select some of them to merge into a new output.</p>
<div class="math">
\[output = [input.slices()]\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">slice_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span> <span class="n">slices</span><span class="o">=</span><span class="p">[(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">)])</span>
</pre></div>
</div>
<p>Note that slice_projection should not have any parameter.</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">参数:</th><td class="field-body"><ul class="first simple">
2039
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
<li><strong>slices</strong> (<em>pair of int</em>) &#8211; An array of slice parameters.
Each slice contains the start and end offsets based
on the input.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A SliceProjection object</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">SliceProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2056 2057 2058 2059 2060
</div>
<div class="section" id="table-projection">
<h3>table_projection<a class="headerlink" href="#table-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2061
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">table_projection</code></dt>
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
<dd><p>Table Projection. It selects rows from parameter where row_id
is in input_ids.</p>
<div class="math">
\[out.row[i] += table.row[ids[i]]\]</div>
<p>where <span class="math">\(out\)</span> is output, <span class="math">\(table\)</span> is parameter, <span class="math">\(ids\)</span> is input_ids,
and <span class="math">\(i\)</span> is row_id.</p>
<p>There are two styles of usage.</p>
<ol class="arabic simple">
<li>When used in mixed like this, you can only set the input:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="k">as</span> <span class="n">m</span><span class="p">:</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">table_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>When used as an independant object like this, you must set the size:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">table_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                        <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                        <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</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">参数:</th><td class="field-body"><ul class="first simple">
2089
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer, which must contains id fields.</li>
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A TableProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">TableProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="trans-full-matrix-projection">
<h3>trans_full_matrix_projection<a class="headerlink" href="#trans-full-matrix-projection" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2110
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">trans_full_matrix_projection</code></dt>
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129
<dd><p>Different from full_matrix_projection, this projection performs matrix
multiplication, using transpose of weight.</p>
<div class="math">
\[out.row[i] += in.row[i] * w^\mathrm{T}\]</div>
<p><span class="math">\(w^\mathrm{T}\)</span> means transpose of weight.
The simply usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">trans_full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                                    <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                    <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span>
                                         <span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</span><span class="p">,</span>
                                         <span class="n">initial_mean</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span>
                                         <span class="n">initial_std</span><span class="o">=</span><span class="mf">0.01</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">参数:</th><td class="field-body"><ul class="first simple">
2130
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A TransposedFullMatrixProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">TransposedFullMatrixProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="aggregate-layers">
<h2>Aggregate Layers<a class="headerlink" href="#aggregate-layers" title="永久链接至标题"></a></h2>
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
<div class="section" id="aggregatelevel">
<h3>AggregateLevel<a class="headerlink" href="#aggregatelevel" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">AggregateLevel</code></dt>
<dd><p>PaddlePaddle supports three sequence types:</p>
<ul class="simple">
<li><code class="code docutils literal"><span class="pre">SequenceType.NO_SEQUENCE</span></code> means the sample is not a sequence.</li>
<li><code class="code docutils literal"><span class="pre">SequenceType.SEQUENCE</span></code> means the sample is a sequence.</li>
<li><code class="code docutils literal"><span class="pre">SequenceType.SUB_SEQUENCE</span></code> means the sample is a nested sequence,
each timestep of which is also a sequence.</li>
</ul>
<p>Accordingly, AggregateLevel supports two modes:</p>
<ul class="simple">
2164
<li><code class="code docutils literal"><span class="pre">AggregateLevel.TO_NO_SEQUENCE</span></code> means the aggregation acts on each
2165 2166
timestep of a sequence, both <code class="code docutils literal"><span class="pre">SUB_SEQUENCE</span></code> and <code class="code docutils literal"><span class="pre">SEQUENCE</span></code> will
be aggregated to <code class="code docutils literal"><span class="pre">NO_SEQUENCE</span></code>.</li>
2167
<li><code class="code docutils literal"><span class="pre">AggregateLevel.TO_SEQUENCE</span></code> means the aggregation acts on each
2168 2169 2170 2171 2172 2173
sequence of a nested sequence, <code class="code docutils literal"><span class="pre">SUB_SEQUENCE</span></code> will be aggregated to
<code class="code docutils literal"><span class="pre">SEQUENCE</span></code>.</li>
</ul>
</dd></dl>

</div>
2174 2175 2176 2177
<div class="section" id="api-v2-layer-pooling">
<span id="id1"></span><h3>pooling<a class="headerlink" href="#api-v2-layer-pooling" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2178
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">pooling</code></dt>
2179
<dd><p>Pooling layer for sequence inputs, not used for Image.</p>
2180 2181 2182 2183 2184 2185
<p>If stride &gt; 0, this layer slides a window whose size is determined by stride,
and return the pooling value of the window as the output. Thus, a long sequence
will be shorten.</p>
<p>The parameter stride specifies the intervals at which to apply the pooling
operation. Note that for sequence with sub-sequence, the default value
of stride is -1.</p>
2186 2187 2188
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">seq_pool</span> <span class="o">=</span> <span class="n">pooling</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                         <span class="n">pooling_type</span><span class="o">=</span><span class="n">AvgPooling</span><span class="p">(),</span>
2189
                         <span class="n">agg_level</span><span class="o">=</span><span class="n">AggregateLevel</span><span class="o">.</span><span class="n">TO_NO_SEQUENCE</span><span class="p">)</span>
2190 2191 2192 2193 2194 2195 2196
</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">参数:</th><td class="field-body"><ul class="first simple">
2197 2198
<li><strong>agg_level</strong> (<em>AggregateLevel</em>) &#8211; AggregateLevel.TO_NO_SEQUENCE or
AggregateLevel.TO_SEQUENCE</li>
2199
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2200 2201
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
<li><strong>pooling_type</strong> (<em>BasePoolingType | None</em>) &#8211; Type of pooling, MaxPooling(default), AvgPooling,
2202
SumPooling, SquareRootNPooling.</li>
2203
<li><strong>stride</strong> (<em>Int</em>) &#8211; The step size between successive pooling regions.</li>
2204 2205 2206
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
2207
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The Extra Attributes for layer, such as dropout.</li>
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="last-seq">
<span id="api-v2-layer-last-seq"></span><h3>last_seq<a class="headerlink" href="#last-seq" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2226
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">last_seq</code></dt>
2227
<dd><p>Get Last Timestamp Activation of a sequence.</p>
2228 2229 2230 2231
<p>If stride &gt; 0, this layer slides a window whose size is determined by stride,
and return the last value of the window as the output. Thus, a long sequence
will be shorten. Note that for sequence with sub-sequence, the default value
of stride is -1.</p>
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">seq</span> <span class="o">=</span> <span class="n">last_seq</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>agg_level</strong> &#8211; Aggregated level</li>
2242
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2243
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2244
<li><strong>stride</strong> (<em>Int</em>) &#8211; The step size between successive pooling regions.</li>
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="first-seq">
<span id="api-v2-layer-first-seq"></span><h3>first_seq<a class="headerlink" href="#first-seq" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2264
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">first_seq</code></dt>
2265
<dd><p>Get First Timestamp Activation of a sequence.</p>
2266 2267 2268 2269
<p>If stride &gt; 0, this layer slides a window whose size is determined by stride,
and return the first value of the window as the output. Thus, a long sequence
will be shorten. Note that for sequence with sub-sequence, the default value
of stride is -1.</p>
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">seq</span> <span class="o">=</span> <span class="n">first_seq</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>agg_level</strong> &#8211; aggregation level</li>
2280
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2281
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2282
<li><strong>stride</strong> (<em>Int</em>) &#8211; The step size between successive pooling regions.</li>
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="concat">
<h3>concat<a class="headerlink" href="#concat" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2302
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">concat</code></dt>
2303 2304
<dd><p>Concatenate all input vectors to one vector.
Inputs can be a list of paddle.v2.config_base.Layer or a list of projection.</p>
2305 2306 2307 2308 2309 2310 2311 2312 2313
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">concat</span> <span class="o">=</span> <span class="n">concat</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">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
2314
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2315
<li><strong>input</strong> (<em>list | tuple | collections.Sequence</em>) &#8211; The input layers or projections</li>
2316
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Identity is the default activation.</li>
2317 2318
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="seq-concat">
<h3>seq_concat<a class="headerlink" href="#seq-concat" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2337
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">seq_concat</code></dt>
2338
<dd><p>Concatenate sequence a and sequence b.</p>
2339 2340 2341
<dl class="docutils">
<dt>Inputs:</dt>
<dd><ul class="first last simple">
2342
<li>a = [a1, a2, ..., am]</li>
2343 2344 2345 2346
<li>b = [b1, b2, ..., bn]</li>
</ul>
</dd>
</dl>
2347 2348 2349
<p>Output: [a1, ..., am, b1, ..., bn]</p>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
2350 2351 2352 2353 2354 2355 2356 2357 2358
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">concat</span> <span class="o">=</span> <span class="n">seq_concat</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
2359
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2360 2361
<li><strong>a</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input sequence layer</li>
<li><strong>b</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input sequence layer</li>
2362
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Identity is the default activation.</li>
2363 2364
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2365 2366 2367
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
2368 2369 2370 2371
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</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="seq-slice">
<h3>seq_slice<a class="headerlink" href="#seq-slice" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">seq_slice</code></dt>
<dd><p>seq_slice will return one or several sub-sequences from the
input sequence layer given start and end indices.</p>
<blockquote>
<div><ul class="simple">
<li>If only start indices are given, and end indices are set to None,
this layer slices the input sequence from the given start indices
to its end.</li>
<li>If only end indices are given, and start indices are set to None,
this layer slices the input sequence from its beginning to the
given end indices.</li>
<li>If start and end indices are both given, they should have the same
number of elements.</li>
</ul>
</div></blockquote>
<p>If start or end indices contains more than one elements, the input sequence
will be sliced for multiple times.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">seq_silce</span> <span class="o">=</span> <span class="n">seq_slice</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">input_seq</span><span class="p">,</span>
                            <span class="n">starts</span><span class="o">=</span><span class="n">start_pos</span><span class="p">,</span> <span class="n">ends</span><span class="o">=</span><span class="n">end_pos</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">参数:</th><td class="field-body"><ul class="first simple">
2412
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2413
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer, which should be a sequence.</li>
2414 2415
<li><strong>starts</strong> (<em>paddle.v2.config_base.Layer | None</em>) &#8211; The start indices to slice the input sequence.</li>
<li><strong>ends</strong> (<em>paddle.v2.config_base.Layer | None</em>) &#8211; The end indices to slice the input sequence.</li>
2416 2417 2418 2419
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
2420 2421
</td>
</tr>
2422 2423 2424 2425 2426 2427 2428
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2429 2430 2431
</div>
<div class="section" id="kmax-sequence-score">
<h3>kmax_sequence_score<a class="headerlink" href="#kmax-sequence-score" title="永久链接至标题"></a></h3>
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443
</div>
<div class="section" id="sub-nested-seq">
<h3>sub_nested_seq<a class="headerlink" href="#sub-nested-seq" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">sub_nested_seq</code></dt>
<dd><p>The sub_nested_seq accepts two inputs: the first one is a nested
sequence; the second one is a set of selceted indices in the nested sequence.</p>
<p>Then sub_nest_seq trims the first nested sequence input according
to the selected indices to form a new output. This layer is useful in
beam training.</p>
<p>The example usage is:</p>
2444
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sub_nest_seq</span> <span class="o">=</span> <span class="n">sub_nested_seq</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">selected_indices</span><span class="o">=</span><span class="n">selected_ids</span><span class="p">)</span>
2445 2446 2447 2448 2449 2450 2451
</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">参数:</th><td class="field-body"><ul class="first simple">
2452 2453
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer. It is a nested sequence.</li>
<li><strong>selected_indices</strong> &#8211; A set of sequence indices in the nested sequence.</li>
2454
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2455 2456 2457 2458 2459 2460
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
</td>
</tr>
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
<tr class="field-odd field"><th class="field-name">返回类型:</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="reshaping-layers">
<h2>Reshaping Layers<a class="headerlink" href="#reshaping-layers" title="永久链接至标题"></a></h2>
<div class="section" id="block-expand">
<h3>block_expand<a class="headerlink" href="#block-expand" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2476
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">block_expand</code></dt>
2477 2478 2479 2480 2481 2482 2483 2484 2485 2486
<dd><dl class="docutils">
<dt>Expand feature map to minibatch matrix.</dt>
<dd><ul class="first last simple">
<li>matrix width is: block_y * block_x * num_channels</li>
<li>matirx height is: outputH * outputW</li>
</ul>
</dd>
</dl>
<div class="math">
\[ \begin{align}\begin{aligned}outputH = 1 + (2 * padding_y + imgSizeH - block_y + stride_y - 1) / stride_y\\outputW = 1 + (2 * padding_x + imgSizeW - block_x + stride_x - 1) / stride_x\end{aligned}\end{align} \]</div>
2487
<p>The expanding method is the same with ExpandConvLayer, but saved the transposed
2488
value. After expanding, output.sequenceStartPositions will store timeline.
2489
The number of time steps is outputH * outputW and the dimension of each
2490
time step is block_y * block_x * num_channels. This layer can be used after
2491
convolutional neural network, and before recurrent neural network.</p>
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">block_expand</span> <span class="o">=</span> <span class="n">block_expand</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                                  <span class="n">num_channels</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span>
                                  <span class="n">stride_x</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">stride_y</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">block_x</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">block_x</span><span class="o">=</span><span class="mi">3</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">参数:</th><td class="field-body"><ul class="first simple">
2506
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2507 2508 2509
<li><strong>num_channels</strong> (<em>int</em>) &#8211; The number of input channels. If the parameter is not set or
set to None, its actual value will be automatically set to
the channels number of the input.</li>
2510 2511 2512 2513 2514 2515
<li><strong>block_x</strong> (<em>int</em>) &#8211; The width of sub block.</li>
<li><strong>block_y</strong> (<em>int</em>) &#8211; The width of sub block.</li>
<li><strong>stride_x</strong> (<em>int</em>) &#8211; The stride size in horizontal direction.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The stride size in vertical direction.</li>
<li><strong>padding_x</strong> (<em>int</em>) &#8211; The padding size in horizontal direction.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The padding size in vertical direction.</li>
2516 2517 2518
<li><strong>name</strong> (<em>basestring.</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2532 2533 2534 2535 2536 2537 2538 2539 2540
</div>
<div class="section" id="expandlevel">
<span id="api-v2-layer-expand"></span><h3>ExpandLevel<a class="headerlink" href="#expandlevel" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">ExpandLevel</code></dt>
<dd><p>Please refer to AggregateLevel first.</p>
<p>ExpandLevel supports two modes:</p>
<ul class="simple">
2541 2542
<li><code class="code docutils literal"><span class="pre">ExpandLevel.FROM_NO_SEQUENCE</span></code> means the expansion acts on
<code class="code docutils literal"><span class="pre">NO_SEQUENCE</span></code>, which will be expanded to
2543
<code class="code docutils literal"><span class="pre">SEQUENCE</span></code> or <code class="code docutils literal"><span class="pre">SUB_SEQUENCE</span></code>.</li>
2544 2545
<li><code class="code docutils literal"><span class="pre">ExpandLevel.FROM_SEQUENCE</span></code> means the expansion acts on
<code class="code docutils literal"><span class="pre">SEQUENCE</span></code>, which will be expanded to
2546 2547 2548 2549
<code class="code docutils literal"><span class="pre">SUB_SEQUENCE</span></code>.</li>
</ul>
</dd></dl>

2550 2551
</div>
<div class="section" id="expand">
2552
<h3>expand<a class="headerlink" href="#expand" title="永久链接至标题"></a></h3>
2553 2554
<dl class="class">
<dt>
2555
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">expand</code></dt>
2556 2557 2558 2559 2560
<dd><p>A layer for &#8220;Expand Dense data or (sequence data where the length of each
sequence is one) to sequence data.&#8221;</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">expand</span> <span class="o">=</span> <span class="n">expand</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span>
                      <span class="n">expand_as</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span>
2561
                      <span class="n">expand_level</span><span class="o">=</span><span class="n">ExpandLevel</span><span class="o">.</span><span class="n">FROM_NO_SEQUENCE</span><span class="p">)</span>
2562 2563 2564 2565 2566 2567 2568
</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">参数:</th><td class="field-body"><ul class="first simple">
2569
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2570
<li><strong>expand_as</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; Expand as this layer&#8217;s sequence info.</li>
2571
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2572 2573 2574
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594
<li><strong>expand_level</strong> (<em>ExpandLevel</em>) &#8211; whether input layer is timestep(default) or sequence.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="repeat">
<h3>repeat<a class="headerlink" href="#repeat" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2595
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">repeat</code></dt>
2596
<dd><p>A layer for repeating the input for num_repeats times.</p>
2597 2598 2599 2600 2601 2602
<p>If as_row_vector:</p>
<div class="math">
\[y  = [x_1,\cdots, x_n, \cdots, x_1, \cdots, x_n]\]</div>
<p>If not as_row_vector:</p>
<div class="math">
\[y  = [x_1,\cdots, x_1, \cdots, x_n, \cdots, x_n]\]</div>
2603 2604 2605 2606 2607 2608 2609 2610 2611
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">expand</span> <span class="o">=</span> <span class="n">repeat</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span> <span class="n">num_repeats</span><span class="o">=</span><span class="mi">4</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">参数:</th><td class="field-body"><ul class="first simple">
2612
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2613
<li><strong>num_repeats</strong> (<em>int</em>) &#8211; The times of repeating the input.</li>
2614
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2615 2616 2617 2618
<li><strong>as_row_vector</strong> (<em>bool</em>) &#8211; Whether to treat the input as row vectors or not. If
the parameter is set to True, the repeating operation
will be performed in the column direction. Otherwise,
it will be performed in the row direction.</li>
2619
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Identity is the default activation.</li>
2620 2621
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="rotate">
<h3>rotate<a class="headerlink" href="#rotate" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2640
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">rotate</code></dt>
2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656
<dd><p>A layer for rotating 90 degrees (clock-wise) for each feature channel,
usually used when the input sample is some image or feature map.</p>
<div class="math">
\[y(j,i,:) = x(M-i-1,j,:)\]</div>
<p>where <span class="math">\(x\)</span> is (M x N x C) input, and <span class="math">\(y\)</span> is (N x M x C) output.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">rot</span> <span class="o">=</span> <span class="n">rotate</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                   <span class="n">height</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                   <span class="n">width</span><span class="o">=</span><span class="mi">100</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">参数:</th><td class="field-body"><ul class="first simple">
2657
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2658 2659
<li><strong>height</strong> (<em>int</em>) &#8211; The height of the sample matrix.</li>
<li><strong>width</strong> (<em>int</em>) &#8211; The width of the sample matrix.</li>
2660
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2661 2662
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="seq-reshape">
<h3>seq_reshape<a class="headerlink" href="#seq-reshape" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2681
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">seq_reshape</code></dt>
2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694
<dd><p>A layer for reshaping the sequence. Assume the input sequence has T instances,
the dimension of each instance is M, and the input reshape_size is N, then the
output sequence has T*M/N instances, the dimension of each instance is N.</p>
<p>Note that T*M/N must be an integer.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">reshape</span> <span class="o">=</span> <span class="n">seq_reshape</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span> <span class="n">reshape_size</span><span class="o">=</span><span class="mi">4</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">参数:</th><td class="field-body"><ul class="first simple">
2695
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
2696
<li><strong>reshape_size</strong> (<em>int</em>) &#8211; The dimension of the reshaped sequence.</li>
2697
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2698
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Identity is the default activation.</li>
2699 2700
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2701 2702 2703
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="math-layers">
<h2>Math Layers<a class="headerlink" href="#math-layers" title="永久链接至标题"></a></h2>
<div class="section" id="addto">
<h3>addto<a class="headerlink" href="#addto" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2725
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">addto</code></dt>
2726 2727 2728 2729 2730 2731 2732
<dd><p>AddtoLayer.</p>
<div class="math">
\[y = f(\sum_{i} x_i + b)\]</div>
<p>where <span class="math">\(y\)</span> is output, <span class="math">\(x\)</span> is input, <span class="math">\(b\)</span> is bias,
and <span class="math">\(f\)</span> is activation function.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">addto</span> <span class="o">=</span> <span class="n">addto</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">layer2</span><span class="p">],</span>
2733
                    <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">Relu</span><span class="p">(),</span>
2734 2735 2736
                    <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
2737 2738 2739
<p>This layer just simply adds all input layers together, then activates the
sum. All inputs should share the same dimension, which is also the dimension
of this layer&#8217;s output.</p>
2740 2741 2742 2743 2744 2745 2746 2747
<p>There is no weight matrix for each input, because it just a simple add
operation. If you want a complicated operation before add, please use
mixed.</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">参数:</th><td class="field-body"><ul class="first simple">
2748
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2749
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | list | tuple</em>) &#8211; The input layers. It could be a paddle.v2.config_base.Layer or list/tuple of
2750
paddle.v2.config_base.Layer.</li>
2751
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation Type. paddle.v2.activation.Linear is the default activation.</li>
2752 2753 2754
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
2755 2756
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="linear-comb">
<h3>linear_comb<a class="headerlink" href="#linear-comb" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2775
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">linear_comb</code></dt>
2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816
<dd><dl class="docutils">
<dt>A layer for weighted sum of vectors takes two inputs.</dt>
<dd><ul class="first last simple">
<li><dl class="first docutils">
<dt>Input: size of weights is M</dt>
<dd>size of vectors is M*N</dd>
</dl>
</li>
<li>Output: a vector of size=N</li>
</ul>
</dd>
</dl>
<div class="math">
\[z(i) = \sum_{j=0}^{M-1} x(j) y(i+Nj)\]</div>
<p>where <span class="math">\(0 \le i \le N-1\)</span></p>
<p>Or in the matrix notation:</p>
<div class="math">
\[z = x^\mathrm{T} Y\]</div>
<dl class="docutils">
<dt>In this formular:</dt>
<dd><ul class="first last simple">
<li><span class="math">\(x\)</span>: weights</li>
<li><span class="math">\(y\)</span>: vectors.</li>
<li><span class="math">\(z\)</span>: the output.</li>
</ul>
</dd>
</dl>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">linear_comb</span> <span class="o">=</span> <span class="n">linear_comb</span><span class="p">(</span><span class="n">weights</span><span class="o">=</span><span class="n">weight</span><span class="p">,</span> <span class="n">vectors</span><span class="o">=</span><span class="n">vectors</span><span class="p">,</span>
                                <span class="n">size</span><span class="o">=</span><span class="n">elem_dim</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>weights</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight layer.</li>
<li><strong>vectors</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The vector layer.</li>
2817
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer.</li>
2818
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2819 2820
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="interpolation">
<h3>interpolation<a class="headerlink" href="#interpolation" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2839
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">interpolation</code></dt>
2840
<dd><p>This layer performs linear interpolation on two inputs,
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[y.row[i] = w[i] * x_1.row[i] + (1 - w[i]) * x_2.row[i]\]</div>
<p>where <span class="math">\(x_1\)</span> and <span class="math">\(x_2\)</span> are two (batchSize x dataDim) inputs,
<span class="math">\(w\)</span> is (batchSize x 1) weight vector, and <span class="math">\(y\)</span> is
(batchSize x dataDim) output.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">interpolation</span> <span class="o">=</span> <span class="n">interpolation</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">layer2</span><span class="p">],</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer3</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">参数:</th><td class="field-body"><ul class="first simple">
2856
<li><strong>input</strong> (<em>list | tuple</em>) &#8211; The input of this layer.</li>
2857
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; Weight layer.</li>
2858
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2859 2860
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="bilinear-interp">
<h3>bilinear_interp<a class="headerlink" href="#bilinear-interp" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2879
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">bilinear_interp</code></dt>
2880
<dd><p>This layer implements bilinear interpolation on convolutional layer&#8217;s output.</p>
2881 2882 2883 2884 2885 2886 2887 2888 2889 2890
<p>Please refer to Wikipedia: <a class="reference external" href="https://en.wikipedia.org/wiki/Bilinear_interpolation">https://en.wikipedia.org/wiki/Bilinear_interpolation</a></p>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">bilinear</span> <span class="o">=</span> <span class="n">bilinear_interp</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">out_size_x</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span> <span class="n">out_size_y</span><span class="o">=</span><span class="mi">64</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">参数:</th><td class="field-body"><ul class="first simple">
2891 2892 2893 2894 2895 2896
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer.</em>) &#8211; The input of this layer.</li>
<li><strong>out_size_x</strong> (<em>int</em>) &#8211; The width of the output.</li>
<li><strong>out_size_y</strong> (<em>int</em>) &#8211; The height of the output.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926
</div>
<div class="section" id="dot-prod">
<h3>dot_prod<a class="headerlink" href="#dot-prod" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">dot_prod</code></dt>
<dd><p>A layer for computing the dot product of two vectors.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dot_prod</span> <span class="o">=</span> <span class="n">dot_prod</span><span class="p">(</span><span class="n">input1</span><span class="o">=</span><span class="n">vec1</span><span class="p">,</span> <span class="n">input2</span><span class="o">=</span><span class="n">vec2</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
2927
<li><strong>input1</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978
<li><strong>input2</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input layer.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="out-prod">
<h3>out_prod<a class="headerlink" href="#out-prod" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">out_prod</code></dt>
<dd><p>A layer for computing the outer product of two vectors
The result is a matrix of size(input1) x size(input2)</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">out_prod</span> <span class="o">=</span> <span class="n">out_prod</span><span class="p">(</span><span class="n">input1</span><span class="o">=</span><span class="n">vec1</span><span class="p">,</span> <span class="n">input2</span><span class="o">=</span><span class="n">vec2</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>input1</strong> &#8211; The first input layer.</li>
<li><strong>input2</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input layer.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2979 2980 2981 2982 2983
</div>
<div class="section" id="power">
<h3>power<a class="headerlink" href="#power" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
2984
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">power</code></dt>
2985 2986 2987 2988
<dd><p>This layer applies a power function to a vector element-wise,
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[y = x^w\]</div>
2989 2990
<p>where <span class="math">\(x\)</span> is an input vector, <span class="math">\(w\)</span> is a scalar exponent,
and <span class="math">\(y\)</span> is an output vector.</p>
2991 2992 2993 2994 2995 2996 2997 2998 2999
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">power</span> <span class="o">=</span> <span class="n">power</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
3000
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3001
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The exponent of the power.</li>
3002
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3003 3004
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="scaling">
<h3>scaling<a class="headerlink" href="#scaling" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3023
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">scaling</code></dt>
3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039
<dd><p>A layer for multiplying input vector by weight scalar.</p>
<div class="math">
\[y  = w x\]</div>
<p>where <span class="math">\(x\)</span> is size=dataDim input, <span class="math">\(w\)</span> is size=1 weight,
and <span class="math">\(y\)</span> is size=dataDim output.</p>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">scale</span> <span class="o">=</span> <span class="n">scaling</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
3040
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3041
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight of each sample.</li>
3042
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3043 3044
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078
</div>
<div class="section" id="clip">
<h3>clip<a class="headerlink" href="#clip" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">clip</code></dt>
<dd><blockquote>
<div><p>A layer for clipping the input value by the threshold.</p>
<div class="math">
\[out[i] = \min\left(\max\left(in[i],p_{1}\]</div>
</div></blockquote>
<p>ight),p_{2}
ight)</p>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">clip</span> <span class="o">=</span> <span class="n">clip</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="nb">min</span><span class="o">=-</span><span class="mi">10</span><span class="p">,</span> <span class="nb">max</span><span class="o">=</span><span class="mi">10</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">
3079
<tr class="field-odd field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
3080 3081 3082
</tr>
<tr class="field-even field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
</tr>
3083
<tr class="field-odd field"><th class="field-name">param input:</th><td class="field-body">The input of this layer.</td>
3084 3085 3086 3087 3088
</tr>
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer.</td>
</tr>
<tr class="field-odd field"><th class="field-name">param min:</th><td class="field-body">The lower threshold for clipping.</td>
</tr>
3089
<tr class="field-even field"><th class="field-name">type min:</th><td class="field-body">float</td>
3090 3091 3092
</tr>
<tr class="field-odd field"><th class="field-name">param max:</th><td class="field-body">The upper threshold for clipping.</td>
</tr>
3093
<tr class="field-even field"><th class="field-name">type max:</th><td class="field-body">float</td>
3094
</tr>
3095 3096 3097
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3098 3099 3100 3101 3102 3103
</tr>
</tbody>
</table>
</div></blockquote>
</dd></dl>

3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117
</div>
<div class="section" id="resize">
<h3>resize<a class="headerlink" href="#resize" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">resize</code></dt>
<dd><p>The resize layer resizes the input matrix with a shape of [Height, Width]
into the output matrix with a shape of [Height x Width / size, size],
where size is the parameter of this layer indicating the output dimension.</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">参数:</th><td class="field-body"><ul class="first simple">
3118
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer.</em>) &#8211; The input of this layer.</li>
3119
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3120
<li><strong>size</strong> (<em>int</em>) &#8211; The resized output dimension of this layer.</li>
3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">A paddle.v2.config_base.Layer object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3134 3135 3136 3137 3138
</div>
<div class="section" id="slope-intercept">
<h3>slope_intercept<a class="headerlink" href="#slope-intercept" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3139
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">slope_intercept</code></dt>
3140
<dd><p>This layer for applying a slope and an intercept to the input.</p>
3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151
<div class="math">
\[y = slope * x + intercept\]</div>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">scale</span> <span class="o">=</span> <span class="n">slope_intercept</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">slope</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">intercept</span><span class="o">=</span><span class="mf">1.0</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">参数:</th><td class="field-body"><ul class="first simple">
3152
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3153
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3154 3155 3156 3157
<li><strong>slope</strong> (<em>float</em>) &#8211; The scale factor.</li>
<li><strong>intercept</strong> (<em>float</em>) &#8211; The offset.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="tensor">
<h3>tensor<a class="headerlink" href="#tensor" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3176
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">tensor</code></dt>
3177 3178
<dd><p>This layer performs tensor operation on two inputs.
For example:</p>
3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200
<div class="math">
\[y_{i} = a * W_{i} * {b^\mathrm{T}}, i=0,1,...,K-1\]</div>
<dl class="docutils">
<dt>In this formular:</dt>
<dd><ul class="first last simple">
<li><span class="math">\(a\)</span>: the first input contains M elements.</li>
<li><span class="math">\(b\)</span>: the second input contains N elements.</li>
<li><span class="math">\(y_{i}\)</span>: the i-th element of y.</li>
<li><span class="math">\(W_{i}\)</span>: the i-th learned weight, shape if [M, N]</li>
<li><span class="math">\(b^\mathrm{T}\)</span>: the transpose of <span class="math">\(b_{2}\)</span>.</li>
</ul>
</dd>
</dl>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">tensor</span> <span class="o">=</span> <span class="n">tensor</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">1000</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">参数:</th><td class="field-body"><ul class="first simple">
3201
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3202 3203 3204 3205 3206 3207
<li><strong>a</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input of this layer.</li>
<li><strong>b</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input of this layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Linear is the default activation.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
3208 3209 3210 3211
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The parameter attribute for bias. If this parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute,
no bias is defined. If this parameter is set to True,
the bias is initialized to zero.</li>
3212 3213
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="cos-sim">
<span id="api-v2-layer-cos-sim"></span><h3>cos_sim<a class="headerlink" href="#cos-sim" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3232
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">cos_sim</code></dt>
3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250
<dd><p>Cosine Similarity Layer. The cosine similarity equation is here.</p>
<div class="math">
\[similarity = cos(\theta) = {\mathbf{a} \cdot \mathbf{b}
\over \|\mathbf{a}\| \|\mathbf{b}\|}\]</div>
<p>The size of a is M, size of b is M*N,
Similarity will be calculated N times by step M. The output size is
N. The scale will be multiplied to similarity.</p>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cos</span> <span class="o">=</span> <span class="n">cos_sim</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">3</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">参数:</th><td class="field-body"><ul class="first simple">
3251
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3252 3253 3254 3255 3256
<li><strong>a</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input of this layer.</li>
<li><strong>b</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input of this layer.</li>
<li><strong>scale</strong> (<em>float</em>) &#8211; The scale of the cosine similarity. 1 is the default value.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer. NOTE size_a * size should equal size_b.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for details.</li>
3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312
</div>
<div class="section" id="l2-distance">
<h3>l2_distance<a class="headerlink" href="#l2-distance" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">l2_distance</code></dt>
<dd><p>This layer calculates and returns the Euclidean distance between two input
vectors x and y. The equation is as follows:</p>
<div class="math">
\[l2_distance(\mathbf{x}, \mathbf{y}) = \sqrt{\sum_{i=1}^D(x_i - y_i)}\]</div>
<p>The output size of this layer is fixed to be 1. Note that the above
computation is for one sample. Multiple samples are processed in one batch.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">l2_sim</span> <span class="o">=</span> <span class="n">l2_distance</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">layer2</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>x</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input x for this layer, whose output is a matrix with
dimensionality N x D. N is the sample number in a mini-batch.
D is the dimensionality of x&#8217;s output.</li>
<li><strong>y</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The second input y for this layer, whose output is a matrix with
dimensionality N x D. N is the sample number in a mini-batch.
D is the dimensionality of y&#8217;s output.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attributes, for example, drop rate.
See paddle.v2.attr.ExtraAttribute for more details.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">The returned paddle.v2.config_base.Layer object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3313 3314 3315 3316 3317
</div>
<div class="section" id="trans">
<h3>trans<a class="headerlink" href="#trans" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3318
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">trans</code></dt>
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331
<dd><p>A layer for transposing a minibatch matrix.</p>
<div class="math">
\[y = x^\mathrm{T}\]</div>
<p>where <span class="math">\(x\)</span> is (M x N) input, and <span class="math">\(y\)</span> is (N x M) output.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">trans</span> <span class="o">=</span> <span class="n">trans</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</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">参数:</th><td class="field-body"><ul class="first simple">
3332
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3333
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3334 3335
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3349 3350 3351 3352 3353 3354 3355
</div>
<div class="section" id="scale-shift">
<h3>scale_shift<a class="headerlink" href="#scale-shift" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">scale_shift</code></dt>
<dd><p>A layer applies a linear transformation to each element in each row of
3356
the input matrix. For each element, the layer first re-scales it and then
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369
adds a bias to it.</p>
<p>This layer is very like the SlopeInterceptLayer, except the scale and
bias are trainable.</p>
<div class="math">
\[y = w * x + b\]</div>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">scale_shift</span> <span class="o">=</span> <span class="n">scale_shift</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</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">参数:</th><td class="field-body"><ul class="first simple">
3370
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3371
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3372 3373 3374 3375 3376
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute of scaling. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3390 3391 3392 3393 3394 3395
</div>
</div>
<div class="section" id="sampling-layers">
<h2>Sampling Layers<a class="headerlink" href="#sampling-layers" title="永久链接至标题"></a></h2>
<div class="section" id="maxid">
<h3>maxid<a class="headerlink" href="#maxid" title="永久链接至标题"></a></h3>
3396 3397
<dl class="class">
<dt>
3398
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">max_id</code></dt>
3399 3400 3401 3402
<dd><p>A layer for finding the id which has the maximal value for each sample.
The result is stored in output.ids.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">maxid</span> <span class="o">=</span> <span class="n">maxid</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
3403 3404
</pre></div>
</div>
3405 3406 3407 3408 3409
<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">参数:</th><td class="field-body"><ul class="first simple">
3410
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3411
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3412 3413
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3427 3428 3429 3430 3431
</div>
<div class="section" id="sampling-id">
<h3>sampling_id<a class="headerlink" href="#sampling-id" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3432
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">sampling_id</code></dt>
3433
<dd><p>A layer for sampling id from a multinomial distribution from the input layer.
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443
Sampling one id for one sample.</p>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">samping_id</span> <span class="o">=</span> <span class="n">sampling_id</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</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">参数:</th><td class="field-body"><ul class="first simple">
3444
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3445
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3446 3447
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3461 3462 3463 3464 3465 3466
</div>
<div class="section" id="multiplex">
<h3>multiplex<a class="headerlink" href="#multiplex" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">multiplex</code></dt>
3467 3468 3469
<dd><p>This layer multiplex multiple layers according to the indexes,
which are provided by the first input layer.
inputs[0]: the indexes of the layers to form the output of size batchSize.
3470
inputs[1:N]; the candidate output data.
3471 3472
For each index i from 0 to batchSize - 1, the i-th row of the output is the
the same to the i-th row of the (index[i] + 1)-th layer.</p>
3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489
<p>For each i-th row of output:
.. math:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">x_</span><span class="p">{</span><span class="n">x_</span><span class="p">{</span><span class="mi">0</span><span class="p">}[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">}[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span> <span class="o">...</span> <span class="p">,</span> <span class="p">(</span><span class="n">x_</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span><span class="o">.</span><span class="n">width</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>where, y is output. <span class="math">\(x_{k}\)</span> is the k-th input layer and
<span class="math">\(k = x_{0}[i] + 1\)</span>.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">maxid</span> <span class="o">=</span> <span class="n">multiplex</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layers</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>list of paddle.v2.config_base.Layer</em>) &#8211; Input layers.</li>
3490
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3491 3492
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576
</div>
</div>
<div class="section" id="factorization-machine-layer">
<h2>Factorization Machine Layer<a class="headerlink" href="#factorization-machine-layer" title="永久链接至标题"></a></h2>
<div class="section" id="factorization-machine">
<h3>factorization_machine<a class="headerlink" href="#factorization-machine" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">factorization_machine</code></dt>
<dd><blockquote>
<div><p>The Factorization Machine models pairwise feature interactions as inner
product of the learned latent vectors corresponding to each input feature.
The Factorization Machine can effectively capture feature interactions
especially when the input is sparse.</p>
<p>This implementation only consider the 2-order feature interactions using
Factorization Machine with the formula:</p>
<div class="math">
\[y = \sum_{i=1}^{n-1}\sum_{j=i+1}^n\langle v_i, v_j\]</div>
</div></blockquote>
<p>angle x_i x_j</p>
<blockquote>
<div><dl class="docutils">
<dt>Note:</dt>
<dd>X is the input vector with size n. V is the factor matrix. Each row of V
is the latent vector corresponding to each input dimesion. The size of
each latent vector is k.</dd>
</dl>
<p>For details of Factorization Machine, please refer to the paper:
Factorization machines.</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">param input:</th><td class="field-body">The input layer. Supported input types: all input data types
on CPU, and only dense input types on GPU.</td>
</tr>
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param factor_size:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The hyperparameter that defines the dimensionality of
the latent vector size.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type context_len:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">int</td>
</tr>
<tr class="field-odd field"><th class="field-name">param act:</th><td class="field-body">Activation Type. Default is linear activation.</td>
</tr>
<tr class="field-even field"><th class="field-name">type act:</th><td class="field-body">paddle.v2.activation.Base</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param param_attr:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type param_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ParameterAttribute</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
<tr class="field-odd field"><td>&#160;</td><td class="field-body">Extra Layer config.</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttributeNone</td>
</tr>
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
</tr>
</tbody>
</table>
</div></blockquote>
</dd></dl>

3577 3578 3579 3580 3581 3582 3583 3584
</div>
</div>
<div class="section" id="slicing-and-joining-layers">
<h2>Slicing and Joining Layers<a class="headerlink" href="#slicing-and-joining-layers" title="永久链接至标题"></a></h2>
<div class="section" id="pad">
<h3>pad<a class="headerlink" href="#pad" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3585
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">pad</code></dt>
3586
<dd><p>This operation pads zeros to the input data according to pad_c,pad_h
3587 3588 3589 3590 3591 3592
and pad_w. pad_c, pad_h, pad_w specify the size in the corresponding
dimension. And the input data shape is NCHW.</p>
<p>For example, pad_c=[2,3] means padding 2 zeros before the input data
and 3 zeros after the input data in the channel dimension. pad_h means
padding zeros in the height dimension. pad_w means padding zeros in the
width dimension.</p>
3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626
<p>For example,</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="nb">input</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>  <span class="o">=</span> <span class="p">[</span>
                    <span class="p">[</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">]]</span> <span class="p">],</span>
                    <span class="p">[</span> <span class="p">[[</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">7</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">3</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">]]</span> <span class="p">]</span>
                  <span class="p">]</span>

<span class="n">pad_c</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="n">pad_h</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">pad_w</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>

<span class="n">output</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span> <span class="o">=</span> <span class="p">[</span>
                    <span class="p">[</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]]</span> <span class="p">],</span>
                    <span class="p">[</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">7</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">3</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">5</span><span class="p">]],</span>
                      <span class="p">[[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]]</span> <span class="p">]</span>
                  <span class="p">]</span>
</pre></div>
</div>
<p>The simply usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">pad</span> <span class="o">=</span> <span class="n">pad</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">ipt</span><span class="p">,</span>
                <span class="n">pad_c</span><span class="o">=</span><span class="p">[</span><span class="mi">4</span><span class="p">,</span><span class="mi">4</span><span class="p">],</span>
                <span class="n">pad_h</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">pad_w</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</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">参数:</th><td class="field-body"><ul class="first simple">
3627
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
3628 3629 3630 3631 3632
<li><strong>pad_c</strong> (<em>list | None</em>) &#8211; The padding size in the channel dimension.</li>
<li><strong>pad_h</strong> (<em>list | None</em>) &#8211; The padding size in the height dimension.</li>
<li><strong>pad_w</strong> (<em>list | None</em>) &#8211; The padding size in the width dimension.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3633
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="cost-layers">
<span id="api-v2-layer-costs"></span><h2>Cost Layers<a class="headerlink" href="#cost-layers" title="永久链接至标题"></a></h2>
<div class="section" id="cross-entropy-cost">
<h3>cross_entropy_cost<a class="headerlink" href="#cross-entropy-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3655
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">cross_entropy_cost</code></dt>
3656
<dd><p>A loss layer for multi class entropy.</p>
3657
<p>The example usage is:</p>
3658 3659 3660 3661 3662 3663 3664 3665 3666
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">cross_entropy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                     <span class="n">label</span><span class="o">=</span><span class="n">label</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">参数:</th><td class="field-body"><ul class="first simple">
3667
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
3668
<li><strong>label</strong> &#8211; The input label.</li>
3669 3670
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
3671 3672 3673
1.0 is the default value.</li>
<li><strong>weight</strong> (<em>LayerOutout</em>) &#8211; The weight layer defines a weight for each sample in the
mini-batch. It is optional.</li>
3674 3675
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3676 3677 3678 3679 3680 3681
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
</td>
</tr>
3682
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="cross-entropy-with-selfnorm-cost">
<h3>cross_entropy_with_selfnorm_cost<a class="headerlink" href="#cross-entropy-with-selfnorm-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3694
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">cross_entropy_with_selfnorm_cost</code></dt>
3695 3696
<dd><p>A loss layer for multi class entropy with selfnorm.
Input should be a vector of positive numbers, without normalization.</p>
3697
<p>The example usage is:</p>
3698 3699 3700 3701 3702 3703 3704 3705 3706
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">cross_entropy_with_selfnorm</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                                   <span class="n">label</span><span class="o">=</span><span class="n">label</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">参数:</th><td class="field-body"><ul class="first simple">
3707
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
3708
<li><strong>label</strong> &#8211; The input label.</li>
3709 3710
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
3711
1.0 is the default value.</li>
3712 3713 3714
<li><strong>softmax_selfnorm_alpha</strong> (<em>float</em>) &#8211; The scale factor affects the cost.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3715 3716 3717 3718 3719 3720
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
</td>
</tr>
3721
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="multi-binary-label-cross-entropy-cost">
<h3>multi_binary_label_cross_entropy_cost<a class="headerlink" href="#multi-binary-label-cross-entropy-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3733
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">multi_binary_label_cross_entropy_cost</code></dt>
3734
<dd><p>A loss layer for multi binary label cross entropy.</p>
3735
<p>The example usage is:</p>
3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">multi_binary_label_cross_entropy</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                                        <span class="n">label</span><span class="o">=</span><span class="n">label</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
3747 3748
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
3749
1.0 is the default value.</li>
3750 3751
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
3766 3767
<div class="section" id="huber-regression-cost">
<h3>huber_regression_cost<a class="headerlink" href="#huber-regression-cost" title="永久链接至标题"></a></h3>
3768 3769
<dl class="class">
<dt>
3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">huber_regression_cost</code></dt>
<dd><blockquote>
<div>In statistics, the Huber loss is a loss function used in robust regression,
that is less sensitive to outliers in data than the squared error loss.
Given a prediction f(x), a label y and <span class="math">\(\delta\)</span>, the loss function
is defined as:</div></blockquote>
<p>ight )^2, left | y-f(x)
ight <a href="#id2"><span class="problematic" id="id3">|</span></a>leq delta</p>
<blockquote>
<div>loss = delta left | y-f(x)</div></blockquote>
<p>ight <a href="#id4"><span class="problematic" id="id5">|</span></a>-0.5delta ^2, otherwise</p>
<blockquote>
<div><p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">huber_regression_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
3784 3785 3786 3787 3788 3789
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
3790
<tr class="field-odd field"><th class="field-name">param input:</th><td class="field-body">The first input layer.</td>
3791
</tr>
3792
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3793
</tr>
3794 3795
<tr class="field-odd field"><th class="field-name">param label:</th><td class="field-body">The input label.</td>
</tr>
3796
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3797
</tr>
3798
<tr class="field-odd field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
3799
</tr>
3800
<tr class="field-even field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
3801 3802 3803
</tr>
<tr class="field-odd field"><th class="field-name">param delta:</th><td class="field-body">The difference between the observed and predicted values.</td>
</tr>
3804
<tr class="field-even field"><th class="field-name">type delta:</th><td class="field-body">float</td>
3805
</tr>
3806
<tr class="field-odd field"><th class="field-name">param coeff:</th><td class="field-body">The weight of the gradient in the back propagation.
3807
1.0 is the default value.</td>
3808
</tr>
3809
<tr class="field-even field"><th class="field-name">type coeff:</th><td class="field-body">float</td>
3810 3811
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
3812 3813
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</td>
3814 3815 3816 3817 3818 3819 3820
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttribute</td>
</tr>
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer.</td>
3821 3822 3823
</tr>
</tbody>
</table>
3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852
</div></blockquote>
</dd></dl>

</div>
<div class="section" id="huber-classification-cost">
<h3>huber_classification_cost<a class="headerlink" href="#huber-classification-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">huber_classification_cost</code></dt>
<dd><blockquote>
<div>For classification purposes, a variant of the Huber loss called modified Huber
is sometimes used. Given a prediction f(x) (a real-valued classifier score) and
a true binary class label :math:<a href="#id6"><span class="problematic" id="id7">`</span></a>yin left {-1, 1</div></blockquote>
<dl class="docutils">
<dt>ight }`, the modified Huber</dt>
<dd>loss is defined as:</dd>
<dt>ight )^2, yf(x)geq 1</dt>
<dd><blockquote class="first">
<div>loss = -4yf(x),  ext{otherwise}</div></blockquote>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">huber_classification_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="last 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">param input:</th><td class="field-body">The first input layer.</td>
</tr>
3853
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3854 3855 3856
</tr>
<tr class="field-odd field"><th class="field-name">param label:</th><td class="field-body">The input label.</td>
</tr>
3857
<tr class="field-even field"><th class="field-name">type input:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3858
</tr>
3859
<tr class="field-odd field"><th class="field-name">param name:</th><td class="field-body">The name of this layer. It is optional.</td>
3860
</tr>
3861
<tr class="field-even field"><th class="field-name">type name:</th><td class="field-body">basestring</td>
3862
</tr>
3863
<tr class="field-odd field"><th class="field-name">param coeff:</th><td class="field-body">The weight of the gradient in the back propagation.
3864
1.0 is the default value.</td>
3865
</tr>
3866
<tr class="field-even field"><th class="field-name">type coeff:</th><td class="field-body">float</td>
3867 3868
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">param layer_attr:</th></tr>
3869 3870
<tr class="field-odd field"><td>&#160;</td><td class="field-body">The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</td>
3871 3872 3873 3874 3875 3876
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">type layer_attr:</th></tr>
<tr class="field-even field"><td>&#160;</td><td class="field-body">paddle.v2.attr.ExtraAttribute</td>
</tr>
<tr class="field-odd field"><th class="field-name">return:</th><td class="field-body">paddle.v2.config_base.Layer object.</td>
</tr>
3877
<tr class="field-even field"><th class="field-name">rtype:</th><td class="field-body">paddle.v2.config_base.Layer</td>
3878 3879 3880 3881 3882
</tr>
</tbody>
</table>
</dd>
</dl>
3883 3884 3885 3886 3887 3888 3889
</dd></dl>

</div>
<div class="section" id="lambda-cost">
<h3>lambda_cost<a class="headerlink" href="#lambda-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
3890
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">lambda_cost</code></dt>
3891
<dd><p>lambdaCost for lambdaRank LTR approach.</p>
3892
<p>The example usage is:</p>
3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">lambda_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                   <span class="n">score</span><span class="o">=</span><span class="n">score</span><span class="p">,</span>
                   <span class="n">NDCG_num</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                   <span class="n">max_sort_size</span><span class="o">=-</span><span class="mi">1</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">参数:</th><td class="field-body"><ul class="first simple">
3904 3905 3906
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input of this layer, which is often a document
samples list of the same query and whose type must be sequence.</li>
<li><strong>score</strong> &#8211; The scores of the samples.</li>
3907
<li><strong>NDCG_num</strong> (<em>int</em>) &#8211; The size of NDCG (Normalized Discounted Cumulative Gain),
3908
e.g., 5 for NDCG&#64;5. It must be less than or equal to the
3909 3910 3911 3912 3913 3914 3915 3916 3917
minimum size of the list.</li>
<li><strong>max_sort_size</strong> (<em>int</em>) &#8211; The size of partial sorting in calculating gradient. If
max_sort_size is equal to -1 or greater than the number
of the samples in the list, then the algorithm will sort
the entire list to compute the gradient. In other cases,
max_sort_size must be greater than or equal to NDCG_num.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
3932 3933
<div class="section" id="square-error-cost">
<h3>square_error_cost<a class="headerlink" href="#square-error-cost" title="永久链接至标题"></a></h3>
3934 3935
<dl class="class">
<dt>
3936 3937
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">square_error_cost</code></dt>
<dd><p>sum of square error cost:</p>
3938
<div class="math">
3939
\[cost = \sum_{i=1}^N(t_i-y_i)^2\]</div>
3940
<table class="docutils field-list" frame="void" rules="none">
3941 3942 3943
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
3944
<tr class="field-odd field"><th class="field-name">参数:</th><td class="field-body"><ul class="first simple">
3945
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
3946 3947 3948 3949 3950 3951 3952 3953
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight layer defines a weight for each sample in the
mini-batch. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
1.0 is the default value.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
3954 3955
</ul>
</td>
3956
</tr>
3957 3958
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
</td>
3959
</tr>
3960 3961
<tr class="field-odd field"><th class="field-name">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
3962 3963 3964 3965
</tr>
</tbody>
</table>
</dd></dl>
3966 3967

</div>
3968 3969
<div class="section" id="rank-cost">
<h3>rank_cost<a class="headerlink" href="#rank-cost" title="永久链接至标题"></a></h3>
3970 3971
<dl class="class">
<dt>
3972
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">rank_cost</code></dt>
3973 3974 3975
<dd><p>A cost Layer for learning to rank using gradient descent.</p>
<dl class="docutils">
<dt>Reference:</dt>
3976 3977
<dd><a href="#id22"><span class="problematic" id="id23">`Learning to Rank using Gradient Descent
http://research.microsoft.com/en-us/um/people/cburges/papers/ICML_ranking.pdf`_</span></a></dd>
3978
</dl>
3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991
<div class="math">
\[ \begin{align}\begin{aligned}C_{i,j} &amp; = -\tilde{P_{ij}} * o_{i,j} + log(1 + e^{o_{i,j}})\\o_{i,j} &amp; =  o_i - o_j\\\tilde{P_{i,j}} &amp; = \{0, 0.5, 1\} \ or \ \{0, 1\}\end{aligned}\end{align} \]</div>
<dl class="docutils">
<dt>In this formula:</dt>
<dd><ul class="first last simple">
<li><span class="math">\(C_{i,j}\)</span> is the cross entropy cost.</li>
<li><span class="math">\(\tilde{P_{i,j}}\)</span> is the label. 1 means positive order
and 0 means reverse order.</li>
<li><span class="math">\(o_i\)</span> and <span class="math">\(o_j\)</span>: the left output and right output.
Their dimension is one.</li>
</ul>
</dd>
</dl>
3992
<p>The example usage is:</p>
3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">rank_cost</span><span class="p">(</span><span class="n">left</span><span class="o">=</span><span class="n">out_left</span><span class="p">,</span>
                 <span class="n">right</span><span class="o">=</span><span class="n">out_right</span><span class="p">,</span>
                 <span class="n">label</span><span class="o">=</span><span class="n">label</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>left</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input, the size of this layer is 1.</li>
<li><strong>right</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The right input, the size of this layer is 1.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; Label is 1 or 0, means positive order and reverse order.</li>
4006 4007 4008 4009 4010 4011 4012
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight layer defines a weight for each sample in the
mini-batch. It is optional.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
1.0 is the default value.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="sum-cost">
<h3>sum_cost<a class="headerlink" href="#sum-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4031
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">sum_cost</code></dt>
4032
<dd><p>A loss layer which calculates the sum of the input as loss.</p>
4033
<p>The example usage is:</p>
4034 4035 4036 4037 4038 4039 4040 4041
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">sum_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</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">参数:</th><td class="field-body"><ul class="first simple">
4042 4043 4044 4045
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="crf">
<h3>crf<a class="headerlink" href="#crf" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4064
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">crf</code></dt>
4065 4066
<dd><p>A layer for calculating the cost of sequential conditional random
field model.</p>
4067
<p>The example usage is:</p>
4068 4069 4070 4071 4072 4073 4074 4075 4076 4077
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">crf</span> <span class="o">=</span> <span class="n">crf</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                <span class="n">size</span><span class="o">=</span><span class="n">label_dim</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">参数:</th><td class="field-body"><ul class="first simple">
4078 4079
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
4080
<li><strong>size</strong> (<em>int</em>) &#8211; The category number.</li>
4081 4082 4083 4084 4085 4086 4087 4088 4089
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight layer defines a weight for each sample in the
mini-batch. It is optional.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
1.0 is the default value.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="crf-decoding">
<h3>crf_decoding<a class="headerlink" href="#crf-decoding" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4108
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">crf_decoding</code></dt>
4109 4110
<dd><p>A layer for calculating the decoding sequence of sequential conditional
random field model. The decoding sequence is stored in output.ids.
4111 4112 4113
If the input &#8216;label&#8217; is provided, it is treated as the ground-truth label, and
this layer will also calculate error. output.value[i] is 1 for an incorrect
decoding and 0 for the correct.</p>
4114
<p>The example usage is:</p>
4115 4116 4117 4118 4119 4120 4121 4122 4123 4124
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">crf_decoding</span> <span class="o">=</span> <span class="n">crf_decoding</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                                  <span class="n">size</span><span class="o">=</span><span class="n">label_dim</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The first input layer.</li>
4125 4126 4127 4128 4129 4130 4131
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer | None</em>) &#8211; The input label.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="ctc">
<h3>ctc<a class="headerlink" href="#ctc" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4150
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">ctc</code></dt>
4151
<dd><p>Connectionist Temporal Classification (CTC) is designed for temporal
4152
classication task. e.g. sequence labeling problems where the
4153
alignment between the inputs and the target labels is unknown.</p>
4154 4155
<dl class="docutils">
<dt>Reference:</dt>
4156
<dd><a href="#id24"><span class="problematic" id="id25">`Connectionist Temporal Classification: Labelling Unsegmented Sequence Data
4157
with Recurrent Neural Networks
4158
http://machinelearning.wustl.edu/mlpapers/paper_files/icml2006_GravesFGS06.pdf`_</span></a></dd>
4159
</dl>
4160 4161
<div class="admonition note">
<p class="first admonition-title">注解</p>
4162 4163 4164 4165 4166
<p class="last">Considering the &#8216;blank&#8217; label needed by CTC, you need to use (num_classes + 1)
as the size of the input, where num_classes is the category number.
And the &#8216;blank&#8217; is the last category index. So the size of &#8216;input&#8217; layer (e.g.
fc with softmax activation) should be (num_classes + 1). The size of
ctc should also be (num_classes + 1).</p>
4167
</div>
4168
<p>The example usage is:</p>
4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ctc</span> <span class="o">=</span> <span class="n">ctc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                <span class="n">size</span><span class="o">=</span><span class="mi">9055</span><span class="p">,</span>
                <span class="n">norm_by_times</span><span class="o">=</span><span class="bp">True</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">参数:</th><td class="field-body"><ul class="first simple">
4180
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4181 4182 4183 4184 4185 4186
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer, which must be equal to (category number + 1).</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>norm_by_times</strong> (<em>bool</em>) &#8211; Whether to do normalization by times. False is the default.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="warp-ctc">
<h3>warp_ctc<a class="headerlink" href="#warp-ctc" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4205
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">warp_ctc</code></dt>
4206 4207 4208 4209 4210 4211
<dd><p>A layer intergrating the open-source <a class="reference external" href="https://github.com/baidu-research/warp-ctc">warp-ctc</a> library, which is used in
<a class="reference external" href="https://arxiv.org/pdf/1512.02595v1.pdf">Deep Speech 2: End-toEnd Speech Recognition in English and Mandarin</a>, to compute Connectionist Temporal
Classification (CTC) loss. Besides, another <a class="reference external" href="https://github.com/gangliao/warp-ctc">warp-ctc</a> repository, which is forked from
the official one, is maintained to enable more compiling options. During the
building process, PaddlePaddle will clone the source codes, build and
install it to <code class="code docutils literal"><span class="pre">third_party/install/warpctc</span></code> directory.</p>
4212 4213
<dl class="docutils">
<dt>Reference:</dt>
4214
<dd><a href="#id26"><span class="problematic" id="id27">`Connectionist Temporal Classification: Labelling Unsegmented Sequence Data
4215
with Recurrent Neural Networks
4216
http://machinelearning.wustl.edu/mlpapers/paper_files/icml2006_GravesFGS06.pdf`_</span></a></dd>
4217
</dl>
4218 4219 4220
<div class="admonition note">
<p class="first admonition-title">注解</p>
<ul class="last simple">
4221 4222 4223
<li>Let num_classes represents the category number. Considering the &#8216;blank&#8217;
label needed by CTC, you need to use (num_classes + 1) as the size of
warp_ctc layer.</li>
4224
<li>You can set &#8216;blank&#8217; to any value ranged in [0, num_classes], which
4225
should be consistent with those used in your labels.</li>
4226
<li>As a native &#8216;softmax&#8217; activation is interated to the warp-ctc library,
4227
&#8216;linear&#8217; activation is expected to be used instead in the &#8216;input&#8217; layer.</li>
4228 4229
</ul>
</div>
4230
<p>The example usage is:</p>
4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ctc</span> <span class="o">=</span> <span class="n">warp_ctc</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                     <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                     <span class="n">size</span><span class="o">=</span><span class="mi">1001</span><span class="p">,</span>
                     <span class="n">blank</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span>
                     <span class="n">norm_by_times</span><span class="o">=</span><span class="bp">False</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">参数:</th><td class="field-body"><ul class="first simple">
4243
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4244 4245 4246 4247 4248 4249 4250
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer, which must be equal to (category number + 1).</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>blank</strong> (<em>int</em>) &#8211; The &#8216;blank&#8217; label used in ctc.</li>
<li><strong>norm_by_times</strong> (<em>bool</em>) &#8211; Whether to do normalization by times. False is the default.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</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="nce">
<h3>nce<a class="headerlink" href="#nce" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4269
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">nce</code></dt>
4270
<dd><p>Noise-contrastive estimation.</p>
4271 4272
<dl class="docutils">
<dt>Reference:</dt>
4273 4274
<dd><a href="#id28"><span class="problematic" id="id29">`A fast and simple algorithm for training neural probabilistic language
models. https://www.cs.toronto.edu/~amnih/papers/ncelm.pdf`_</span></a></dd>
4275
</dl>
4276
<p>The example usage is:</p>
4277 4278
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">nce</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">layer2</span><span class="p">],</span> <span class="n">label</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span>
                 <span class="n">param_attr</span><span class="o">=</span><span class="p">[</span><span class="n">attr1</span><span class="p">,</span> <span class="n">attr2</span><span class="p">],</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer3</span><span class="p">,</span>
4279 4280 4281 4282 4283 4284 4285 4286
                 <span class="n">num_classes</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">neg_distribution</span><span class="o">=</span><span class="p">[</span><span class="mf">0.1</span><span class="p">,</span><span class="mf">0.3</span><span class="p">,</span><span class="mf">0.6</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">参数:</th><td class="field-body"><ul class="first simple">
4287
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4288 4289
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | list | tuple | collections.Sequence</em>) &#8211; The first input of this layer.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
4290
<li><strong>weight</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The weight layer defines a weight for each sample in the
4291 4292 4293 4294 4295 4296 4297
mini-batch. It is optional.</li>
<li><strong>num_classes</strong> (<em>int</em>) &#8211; The number of classes.</li>
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type. paddle.v2.activation.Sigmoid is the default activation.</li>
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for
details.</li>
<li><strong>num_neg_samples</strong> (<em>int</em>) &#8211; The number of sampled negative labels. 10 is the
default value.</li>
4298 4299 4300
<li><strong>neg_distribution</strong> (<em>list | tuple | collections.Sequence | None</em>) &#8211; The discrete noisy distribution over the output
space from which num_neg_samples negative labels
are sampled. If this parameter is not set, a
4301
uniform distribution will be used. A user-defined
4302 4303 4304
distribution is a list whose length must be equal
to the num_classes. Each member of the list defines
the probability of a class given input x.</li>
4305 4306 4307 4308
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The parameter attribute for bias. If this parameter is set to
False or an object whose type is not paddle.v2.attr.ParameterAttribute,
no bias is defined. If this parameter is set to True,
the bias is initialized to zero.</li>
4309 4310
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4311 4312 4313
</ul>
</td>
</tr>
4314
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first">paddle.v2.config_base.Layer object.</p>
4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328
</td>
</tr>
<tr class="field-odd field"><th class="field-name">返回类型:</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="hsigmoid">
<h3>hsigmoid<a class="headerlink" href="#hsigmoid" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4329
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">hsigmoid</code></dt>
4330
<dd><p>Organize the classes into a binary tree. At each node, a sigmoid function
4331 4332 4333 4334 4335
is used to calculate the probability of belonging to the right branch.</p>
<dl class="docutils">
<dt>Reference:</dt>
<dd><a class="reference external" href="http://www.gatsby.ucl.ac.uk/aistats/fullpapers/208.pdf">Hierarchical Probabilistic Neural Network Language Model</a></dd>
</dl>
4336 4337
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">hsigmoid</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">layer2</span><span class="p">],</span>
4338
                <span class="n">label</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
4339 4340 4341 4342 4343 4344 4345
</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">参数:</th><td class="field-body"><ul class="first simple">
4346
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer | list | tuple</em>) &#8211; The input of this layer.</li>
4347 4348 4349 4350
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
<li><strong>num_classes</strong> (<em>int</em>) &#8211; The number of classes. And it should be larger than 2. If the parameter
is not set or set to None, its actual value will be automatically set to
the number of labels.</li>
4351
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4352 4353 4354
<li><strong>bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | None | bool | Any</em>) &#8211; The bias attribute. If the parameter is set to False or an object
whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined. If the
parameter is set to True, the bias is initialized to zero.</li>
4355 4356
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for details.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for details.</li>
4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4370 4371 4372 4373 4374
</div>
<div class="section" id="smooth-l1-cost">
<h3>smooth_l1_cost<a class="headerlink" href="#smooth-l1-cost" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4375
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">smooth_l1_cost</code></dt>
4376
<dd><p>This is a L1 loss but more smooth. It requires that the
4377
sizes of input and label are equal. The formula is as follows,</p>
4378 4379 4380 4381 4382
<div class="math">
\[L = \sum_{i} smooth_{L1}(input_i - label_i)\]</div>
<p>in which</p>
<div class="math">
\[\begin{split}smooth_{L1}(x) = \begin{cases} 0.5x^2&amp; \text{if}  \ |x| &lt; 1 \\ |x|-0.5&amp; \text{otherwise} \end{cases}\end{split}\]</div>
4383 4384
<dl class="docutils">
<dt>Reference:</dt>
4385 4386
<dd><a href="#id30"><span class="problematic" id="id31">`Fast R-CNN
https://arxiv.org/pdf/1504.08083v2.pdf`_</span></a></dd>
4387
</dl>
4388
<p>The example usage is:</p>
4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">smooth_l1_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                      <span class="n">label</span><span class="o">=</span><span class="n">label</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">参数:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
4400 4401
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The weight of the gradient in the back propagation.
4402
1.0 is the default value.</li>
4403 4404
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429
</div>
<div class="section" id="multibox-loss">
<h3>multibox_loss<a class="headerlink" href="#multibox-loss" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">multibox_loss</code></dt>
<dd><p>Compute the location loss and the confidence loss for ssd.</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">参数:</th><td class="field-body"><ul class="first simple">
4430
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449
<li><strong>input_loc</strong> (<em>paddle.v2.config_base.Layer | List of paddle.v2.config_base.Layer</em>) &#8211; The input predict locations.</li>
<li><strong>input_conf</strong> (<em>paddle.v2.config_base.Layer | List of paddle.v2.config_base.Layer</em>) &#8211; The input priorbox confidence.</li>
<li><strong>priorbox</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input priorbox location and the variance.</li>
<li><strong>label</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input label.</li>
<li><strong>num_classes</strong> (<em>int</em>) &#8211; The number of the classification.</li>
<li><strong>overlap_threshold</strong> (<em>float</em>) &#8211; The threshold of the overlap.</li>
<li><strong>neg_pos_ratio</strong> (<em>float</em>) &#8211; The ratio of the negative bbox to the positive bbox.</li>
<li><strong>neg_overlap</strong> (<em>float</em>) &#8211; The negative bbox overlap threshold.</li>
<li><strong>background_id</strong> (<em>int</em>) &#8211; The background class index.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4450 4451 4452 4453 4454 4455 4456 4457
</div>
</div>
<div class="section" id="check-layer">
<h2>Check Layer<a class="headerlink" href="#check-layer" title="永久链接至标题"></a></h2>
<div class="section" id="eos">
<h3>eos<a class="headerlink" href="#eos" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
4458
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">eos</code></dt>
4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471
<dd><p>A layer for checking EOS for each sample:
- output_id = (input_id == conf.eos_id)</p>
<p>The result is stored in output_.ids.
It is used by recurrent layer group.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">eos</span> <span class="o">=</span> <span class="n">eos</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span> <span class="n">eos_id</span><span class="o">=</span><span class="nb">id</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">参数:</th><td class="field-body"><ul class="first simple">
4472
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4473
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4474 4475 4476
<li><strong>eos_id</strong> (<em>int</em>) &#8211; End id of sequence</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498
</dd></dl>

</div>
</div>
<div class="section" id="miscs">
<h2>Miscs<a class="headerlink" href="#miscs" title="永久链接至标题"></a></h2>
<div class="section" id="dropout">
<h3>dropout<a class="headerlink" href="#dropout" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">dropout</code></dt>
4499 4500 4501 4502
<dd><p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dropout</span> <span class="o">=</span> <span class="n">dropout</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">dropout_rate</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
4503 4504 4505 4506 4507
<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">参数:</th><td class="field-body"><ul class="first simple">
4508
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4509
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4510
<li><strong>dropout_rate</strong> (<em>float</em>) &#8211; The probability of dropout.</li>
4511 4512 4513
</ul>
</td>
</tr>
4514 4515 4516 4517
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
4518 4519 4520 4521
</td>
</tr>
</tbody>
</table>
4522 4523
</dd></dl>

4524 4525 4526 4527 4528 4529 4530 4531 4532
</div>
</div>
<div class="section" id="activation-with-learnable-parameter">
<h2>Activation with learnable parameter<a class="headerlink" href="#activation-with-learnable-parameter" title="永久链接至标题"></a></h2>
<div class="section" id="prelu">
<h3>prelu<a class="headerlink" href="#prelu" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">prelu</code></dt>
4533
<dd><p>The Parametric Relu activation that actives outputs with a learnable weight.</p>
4534 4535
<dl class="docutils">
<dt>Reference:</dt>
4536 4537
<dd><a href="#id32"><span class="problematic" id="id33">`Delving Deep into Rectifiers: Surpassing Human-Level Performance on
ImageNet Classification http://arxiv.org/pdf/1502.01852v1.pdf`_</span></a></dd>
4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550
</dl>
<div class="math">
\[\begin{split}z_i &amp;\quad if \quad z_i &gt; 0 \\
a_i * z_i  &amp;\quad \mathrm{otherwise}\end{split}\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">prelu</span> <span class="o">=</span> <span class="n">prelu</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layers</span><span class="p">,</span> <span class="n">partial_sum</span><span class="o">=</span><span class="mi">1</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">参数:</th><td class="field-body"><ul class="first simple">
4551
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4552
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4553
<li><strong>partial_sum</strong> (<em>int</em>) &#8211; <p>this parameter makes a group of inputs share the same weight.</p>
4554 4555
<ul>
<li>partial_sum = 1, indicates the element-wise activation: each element has a weight.</li>
4556 4557
<li>partial_sum = number of elements in one channel, indicates the channel-wise activation, elements in a channel share the same weight.</li>
<li>partial_sum = number of outputs, indicates all elements share the same weight.</li>
4558 4559
</ul>
</li>
4560 4561 4562 4563 4564 4565
<li><strong>channel_shared</strong> (<em>bool</em>) &#8211; <p>whether or not the parameter are shared across channels.</p>
<ul>
<li>channel_shared = True, we set the partial_sum to the number of outputs.</li>
<li>channel_shared = False, we set the partial_sum to the number of elements in one channel.</li>
</ul>
</li>
4566
<li><strong>num_channels</strong> (<em>int</em>) &#8211; number of input channel.</li>
4567 4568 4569
<li><strong>param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute. See paddle.v2.attr.ParameterAttribute for details.</li>
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The extra layer attribute. See paddle.v2.attr.ExtraAttribute for
details.</li>
4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4583 4584 4585 4586 4587 4588 4589 4590 4591
</div>
<div class="section" id="gated-unit">
<h3>gated_unit<a class="headerlink" href="#gated-unit" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">gated_unit</code></dt>
<dd><p>The gated unit layer implements a simple gating mechanism over the input.
The input <span class="math">\(X\)</span> is first projected into a new space <span class="math">\(X'\)</span>, and
it is also used to produce a gate weight <span class="math">\(\sigma\)</span>. Element-wise
4592
product between <a href="#id10"><span class="problematic" id="id11">:match:`X&#8217;`</span></a> and <span class="math">\(\sigma\)</span> is finally returned.</p>
4593 4594
<dl class="docutils">
<dt>Reference:</dt>
4595 4596
<dd><a href="#id34"><span class="problematic" id="id35">`Language Modeling with Gated Convolutional Networks
https://arxiv.org/abs/1612.08083`_</span></a></dd>
4597 4598 4599 4600 4601 4602 4603 4604 4605
</dl>
<div class="math">
\[y=\text{act}(X \cdot W + b)\otimes \sigma(X \cdot V + c)\]</div>
<p>The example usage is:</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">参数:</th><td class="field-body"><ul class="first simple">
4606
<li><strong>input</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input of this layer.</li>
4607
<li><strong>size</strong> (<em>int</em>) &#8211; The dimension of this layer&#8217;s output.</li>
4608 4609
<li><strong>act</strong> (<em>paddle.v2.activation.Base</em>) &#8211; Activation type of the projection. paddle.v2.activation.Linear is the default
activation.</li>
4610
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4611 4612 4613 4614
<li><strong>gate_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; The extra layer attribute of the gate. See paddle.v2.attr.ExtraAttribute for
details.</li>
<li><strong>gate_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute of the gate. See paddle.v2.attr.ParameterAttribute
for details.</li>
4615
<li><strong>gate_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | bool | None | Any</em>) &#8211; The bias attribute of the gate. If this parameter is set to False or
4616
an object whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined.
4617
If this parameter is set to True, the bias is initialized to zero.</li>
4618 4619 4620 4621
<li><strong>inproj_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra layer attributes of the projection. See paddle.v2.attr.ExtraAttribute for
details.</li>
<li><strong>inproj_param_attr</strong> (<em>paddle.v2.attr.ParameterAttribute</em>) &#8211; The parameter attribute of the projection. See paddle.v2.attr.ParameterAttribute
for details.</li>
4622
<li><strong>inproj_bias_attr</strong> (<em>paddle.v2.attr.ParameterAttribute | bool | None | Any</em>) &#8211; The bias attribute of the projection. If this parameter is set to False
4623
or an object whose type is not paddle.v2.attr.ParameterAttribute, no bias is defined.
4624
If this parameter is set to True, the bias is initialized to zero.</li>
4625 4626
<li><strong>layer_attr</strong> (<em>paddle.v2.attr.ExtraAttribute | None</em>) &#8211; Extra layer attribute of the product. See paddle.v2.attr.ExtraAttribute for
details.</li>
4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</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">返回类型:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4640 4641 4642 4643 4644 4645 4646 4647 4648 4649
</div>
</div>
<div class="section" id="detection-output-layer">
<h2>Detection output Layer<a class="headerlink" href="#detection-output-layer" title="永久链接至标题"></a></h2>
<div class="section" id="detection-output">
<h3>detection_output<a class="headerlink" href="#detection-output" title="永久链接至标题"></a></h3>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.v2.layer.</code><code class="descname">detection_output</code></dt>
<dd><p>Apply the NMS to the output of network and compute the predict bounding
4650 4651
box location. The output&#8217;s shape of this layer could be zero if there is
no valid bounding box.</p>
4652 4653 4654 4655 4656
<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">参数:</th><td class="field-body"><ul class="first simple">
4657
<li><strong>name</strong> (<em>basestring</em>) &#8211; The name of this layer. It is optional.</li>
4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676
<li><strong>input_loc</strong> (<em>paddle.v2.config_base.Layer | List of paddle.v2.config_base.Layer.</em>) &#8211; The input predict locations.</li>
<li><strong>input_conf</strong> (<em>paddle.v2.config_base.Layer | List of paddle.v2.config_base.Layer.</em>) &#8211; The input priorbox confidence.</li>
<li><strong>priorbox</strong> (<em>paddle.v2.config_base.Layer</em>) &#8211; The input priorbox location and the variance.</li>
<li><strong>num_classes</strong> (<em>int</em>) &#8211; The number of the classification.</li>
<li><strong>nms_threshold</strong> (<em>float</em>) &#8211; The Non-maximum suppression threshold.</li>
<li><strong>nms_top_k</strong> (<em>int</em>) &#8211; The bbox number kept of the NMS&#8217;s output</li>
<li><strong>keep_top_k</strong> (<em>int</em>) &#8211; The bbox number kept of the layer&#8217;s output</li>
<li><strong>confidence_threshold</strong> (<em>float</em>) &#8211; The classification confidence threshold</li>
<li><strong>background_id</strong> (<em>int</em>) &#8211; The background class index.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">返回:</th><td class="field-body"><p class="first last">paddle.v2.config_base.Layer</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
4688
        <a href="evaluators.html" class="btn btn-neutral float-right" title="Evaluators" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724
      
      
        <a href="activation.html" class="btn btn-neutral" title="Activation" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; 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',
4725 4726
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
4727 4728 4729 4730 4731 4732
        };
    </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="../../../_static/translations.js"></script>
4733
      <script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>
4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747
       
  

  
  
    <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>