layers.html 190.2 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 37 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115


<!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  documentation</title>
  

  
  

  

  
  
    

  

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

  
  
        <link rel="index" title="Index"
              href="../../../genindex.html"/>
        <link rel="search" title="Search" href="../../../search.html"/>
    <link rel="top" title="PaddlePaddle  documentation" href="../../../index.html"/>
        <link rel="up" title="Fluid" href="../fluid.html"/>
        <link rel="next" title="DataFeeder" href="data_feeder.html"/>
        <link rel="prev" title="Fluid" href="../fluid.html"/> 

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/override.css" type="text/css" />
  <script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
  })();
  </script>

  

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  
  <header class="site-header">
    <div class="site-logo">
      <a href="/"><img src="../../../_static/images/PP_w.png"></a>
    </div>
    <div class="site-nav-links">
      <div class="site-menu">
        <a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
        <div class="language-switcher dropdown">
          <a type="button" data-toggle="dropdown">
            <span>English</span>
            <i class="fa fa-angle-up"></i>
            <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown-menu">
            <li><a href="/doc_cn">中文</a></li>
            <li><a href="/doc">English</a></li>
          </ul>
        </div>
        <ul class="site-page-links">
          <li><a href="/">Home</a></li>
        </ul>
      </div>
      <div class="doc-module">
        
        <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../getstarted/index_en.html">GET STARTED</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../howto/index_en.html">HOW TO</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../index_en.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mobile/index_en.html">MOBILE</a></li>
</ul>

        
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>        
      </div>
    </div>
  </header>
  
  <div class="main-content-wrap">

    
    <nav class="doc-menu-vertical" role="navigation">
        
          
          <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../getstarted/index_en.html">GET STARTED</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../getstarted/build_and_install/index_en.html">Install and Build</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/pip_install_en.html">Install Using pip</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/docker_install_en.html">Run in Docker Containers</a></li>
116
<li class="toctree-l3"><a class="reference internal" href="../../../howto/dev/build_en.html">Build using Docker</a></li>
117 118 119 120 121 122 123 124 125 126 127 128
<li class="toctree-l3"><a class="reference internal" href="../../../getstarted/build_and_install/build_from_source_en.html">Build from Sources</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../howto/index_en.html">HOW TO</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
</ul>
</li>
129 130 131 132 133 134 135
<li class="toctree-l2"><a class="reference internal" href="../../../howto/usage/cluster/cluster_train_en.html">Distributed Training</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cluster/fabric_en.html">fabric</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cluster/openmpi_en.html">openmpi</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cluster/k8s_en.html">kubernetes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/usage/cluster/k8s_aws_en.html">kubernetes on AWS</a></li>
</ul>
</li>
136 137
<li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/new_layer_en.html">Write New Layers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/contribute_to_paddle_en.html">Contribute Code</a></li>
138
<li class="toctree-l2"><a class="reference internal" href="../../../howto/dev/write_docs_en.html">Contribute Documentation</a></li>
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
<li class="toctree-l2"><a class="reference internal" href="../../../howto/deep_model/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../../howto/deep_model/rnn/rnn_config_en.html">RNN Configuration</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../../howto/optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../../index_en.html">API</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../model_configs.html">Model Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../config/activation.html">Activation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/layer.html">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/evaluators.html">Evaluators</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/pooling.html">Pooling</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../config/attr.html">Parameter Attribute</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../data.html">Data Reader Interface and DataSets</a><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>
<li class="toctree-l2"><a class="reference internal" href="../run_logic.html">Training and Inference</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../fluid.html">Fluid</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="data_feeder.html">DataFeeder</a></li>
<li class="toctree-l3"><a class="reference internal" href="executor.html">Executor</a></li>
<li class="toctree-l3"><a class="reference internal" href="initializer.html">Initializer</a></li>
<li class="toctree-l3"><a class="reference internal" href="evaluator.html">Evaluator</a></li>
<li class="toctree-l3"><a class="reference internal" href="nets.html">Nets</a></li>
<li class="toctree-l3"><a class="reference internal" href="optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="param_attr.html">ParamAttr</a></li>
<li class="toctree-l3"><a class="reference internal" href="profiler.html">Profiler</a></li>
<li class="toctree-l3"><a class="reference internal" href="regularizer.html">Regularizer</a></li>
175
<li class="toctree-l3"><a class="reference internal" href="io.html">IO</a></li>
176 177 178 179 180 181
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../mobile/index_en.html">MOBILE</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_android_en.html">Build PaddlePaddle for Android</a></li>
182
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_ios_en.html">Build PaddlePaddle for iOS</a></li>
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 220 221 222
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_raspberry_en.html">Build PaddlePaddle for Raspberry Pi</a></li>
</ul>
</li>
</ul>

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

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
        <li><a href="../../index_en.html">API</a> > </li>
      
        <li><a href="../fluid.html">Fluid</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">
<h1>Layers<a class="headerlink" href="#layers" title="Permalink to this headline"></a></h1>
<div class="section" id="fc">
<h2>fc<a class="headerlink" href="#fc" title="Permalink to this headline"></a></h2>
223 224
<dl class="function">
<dt>
225
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">fc</code><span class="sig-paren">(</span><em>input</em>, <em>size</em>, <em>num_flatten_dims=1</em>, <em>param_attr=None</em>, <em>bias_attr=None</em>, <em>act=None</em>, <em>name=None</em><span class="sig-paren">)</span></dt>
226
<dd><p><strong>Fully Connected Layer</strong></p>
227 228 229 230 231 232 233 234 235 236
<p>The fully connected layer can take multiple tensors as its inputs. It
creates a variable (one for each input tensor) called weights for each input
tensor, which represents a fully connected weight matrix from each input
unit to each output unit. The fully connected layer multiplies each input
tensor with its coresponding weight to produce an output Tensor. If
multiple input tensors are given, the results of multiple multiplications
will be sumed up. If bias_attr is not None, a biases variable will be
created and added to the output. Finally, if activation is not None,
it will be applied to the output as well.</p>
<p>This process can be formulated as follows:</p>
237
<div class="math">
238 239
\[Out = Act({\sum_{i=0}^{N-1}W_iX_i + b})\]</div>
<p>In the above equation:</p>
240 241 242 243 244 245 246
<ul class="simple">
<li><span class="math">\(N\)</span>: Number of the input.</li>
<li><span class="math">\(X_i\)</span>: The input tensor.</li>
<li><span class="math">\(W\)</span>: The weights created by this layer.</li>
<li><span class="math">\(b\)</span>: The bias parameter created by this layer (if needed).</li>
<li><span class="math">\(Act\)</span>: The activation funtion.</li>
<li><span class="math">\(Out\)</span>: The output tensor.</li>
247
</ul>
248 249 250 251 252 253 254 255 256
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable|list</em>) &#8211; The input tensor(s) to the fully connected layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The number of output units in the fully connected layer.</li>
<li><strong>num_flatten_dims</strong> (<em>int</em>) &#8211; The fc layer can accept an input tensor with more
than two dimensions. If this happens, the
257 258 259 260 261 262
multidimensional tensor will first be flattened
into a 2-dimensional matrix. The parameter
<cite>num_flatten_dims</cite> determines how the input tensor
is flattened: the first <cite>num_flatten_dims</cite>
dimensions will be flatten to form the first
dimension of the final matrix (height of the
263
matrix), and the rest <cite>rank(X) - num_flatten_dims</cite>
264 265 266 267
dimensions are flattened to form the second
dimension of the final matrix (width of the matrix).
For example, suppose <cite>X</cite> is a 6-dimensional tensor
with a shape [2, 3, 4, 5, 6], and
268
<cite>num_flatten_dims</cite> = 3. Then, the flattened matrix
269
will have a shape [2 x 3 x 4, 5 x 6] = [24, 30].
270
By default, <cite>num_flatten_dims</cite> is set to 1.</li>
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
<li><strong>param_attr</strong> (<em>ParamAttr|list</em>) &#8211; The parameter attribute for learnable
parameters/weights of the fully connected
layer.</li>
<li><strong>param_initializer</strong> (<em>ParamAttr|list</em>) &#8211; The initializer used for the
weight/parameter. If set None,
XavierInitializer() will be used.</li>
<li><strong>bias_attr</strong> (<em>ParamAttr|list</em>) &#8211; The parameter attribute for the bias parameter
for this layer. If set None, no bias will be
added to the output units.</li>
<li><strong>bias_initializer</strong> (<em>ParamAttr|list</em>) &#8211; The initializer used for the bias.
If set None, then ConstantInitializer()
will be used.</li>
<li><strong>act</strong> (<em>str</em>) &#8211; Activation to be applied to the output of the fully connected
layer.</li>
<li><strong>name</strong> (<em>str</em>) &#8211; Name/alias of the fully connected layer.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The output tensor variable.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">Variable</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> &#8211; If rank of the input tensor is less than 2.</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;data&quot;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;float32&quot;</span><span class="p">)</span>
302 303 304
<span class="n">fc</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">data</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="s2">&quot;tanh&quot;</span><span class="p">)</span>
</pre></div>
</div>
305 306
</dd></dl>

307 308 309
</div>
<div class="section" id="embedding">
<h2>embedding<a class="headerlink" href="#embedding" title="Permalink to this headline"></a></h2>
310 311
<dl class="function">
<dt>
312
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">embedding</code><span class="sig-paren">(</span><em>input</em>, <em>size</em>, <em>is_sparse=False</em>, <em>param_attr=None</em>, <em>dtype='float32'</em><span class="sig-paren">)</span></dt>
313 314 315 316 317
<dd><p><strong>Embedding Layer</strong></p>
<p>This layer is used to lookup a vector of IDs, provided by <em>input</em>, in a lookup table.
The result of this lookup is the embedding of each ID in the <em>input</em>.</p>
<p>All the input variables are passed in as local variables to the LayerHelper
constructor.</p>
318 319 320 321
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
322 323
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; Input to the function</li>
324
<li><strong>size</strong> (<em>tuple|list|None</em>) &#8211; Shape of the look up table parameter</li>
325 326 327
<li><strong>is_sparse</strong> (<em>bool</em>) &#8211; Boolean flag that specifying whether the input is sparse</li>
<li><strong>param_attr</strong> (<em>ParamAttr</em>) &#8211; Parameters for this layer</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; The type of data : float32, float_16, int etc</li>
328 329 330
</ul>
</td>
</tr>
331 332 333 334 335 336
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the embeddings of the                   supplied inputs.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
337 338
</tbody>
</table>
339
<p class="rubric">Examples</p>
340 341 342
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dict_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">dataset</span><span class="o">.</span><span class="n">ids</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;ids&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">fc</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">embedding</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">size</span><span class="o">=</span><span class="p">[</span><span class="n">dict_size</span><span class="p">,</span> <span class="mi">16</span><span class="p">])</span>
343 344
</pre></div>
</div>
345 346
</dd></dl>

347 348 349
</div>
<div class="section" id="dynamic-lstm">
<h2>dynamic_lstm<a class="headerlink" href="#dynamic-lstm" title="Permalink to this headline"></a></h2>
350 351
<dl class="function">
<dt>
352
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">dynamic_lstm</code><span class="sig-paren">(</span><em>input</em>, <em>size</em>, <em>param_attr=None</em>, <em>bias_attr=None</em>, <em>use_peepholes=True</em>, <em>is_reverse=False</em>, <em>gate_activation='sigmoid'</em>, <em>cell_activation='tanh'</em>, <em>candidate_activation='tanh'</em>, <em>dtype='float32'</em><span class="sig-paren">)</span></dt>
353 354
<dd></dd></dl>

355 356 357
</div>
<div class="section" id="data">
<h2>data<a class="headerlink" href="#data" title="Permalink to this headline"></a></h2>
358 359
<dl class="function">
<dt>
360
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">data</code><span class="sig-paren">(</span><em>name</em>, <em>shape</em>, <em>append_batch_size=True</em>, <em>dtype='float32'</em>, <em>lod_level=0</em>, <em>type=VarType.LOD_TENSOR</em>, <em>stop_gradient=True</em><span class="sig-paren">)</span></dt>
361 362 363 364 365 366 367
<dd><p><strong>Data Layer</strong></p>
<p>This function takes in the input and based on whether data has
to be returned back as a minibatch, it creates the global variable using
the helper functions. The global variables can be accessed by all the
following operations and layers in the graph.</p>
<p>All the input variables of this function are passed in as local variables
to the LayerHelper constructor.</p>
368 369 370 371
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
372 373 374 375 376 377
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>str</em>) &#8211; The name/alias of the function</li>
<li><strong>shape</strong> (<em>list</em>) &#8211; Tuple declaring the shape.</li>
<li><strong>append_batch_size</strong> (<em>bool</em>) &#8211; Whether or not to append the data as a batch.</li>
<li><strong>dtype</strong> (<em>int|float</em>) &#8211; The type of data : float32, float_16, int etc</li>
<li><strong>type</strong> (<em>VarType</em>) &#8211; The output type. By default it is LOD_TENSOR.</li>
378
<li><strong>lod_level</strong> (<em>int</em>) &#8211; The LoD Level. 0 means the input data is not a sequence.</li>
379 380 381
<li><strong>main_program</strong> (<em>Program</em>) &#8211; Name of the main program that calls this</li>
<li><strong>startup_program</strong> (<em>Program</em>) &#8211; Name of the startup program</li>
<li><strong>stop_gradient</strong> (<em>bool</em>) &#8211; A boolean that mentions whether gradient should flow.</li>
382 383 384
</ul>
</td>
</tr>
385 386 387 388 389 390
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The global variable that gives access to the data.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
391 392
</tbody>
</table>
393 394 395 396
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">784</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
</pre></div>
</div>
397 398
</dd></dl>

399 400 401
</div>
<div class="section" id="mean">
<h2>mean<a class="headerlink" href="#mean" title="Permalink to this headline"></a></h2>
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">mean</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Mean Operator.</p>
<p>Out is a scalar which is the mean of all elements in X.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; The input of mean op
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The output of mean op</td>
</tr>
</tbody>
</table>
</dd></dl>

420 421 422
</div>
<div class="section" id="mul">
<h2>mul<a class="headerlink" href="#mul" title="Permalink to this headline"></a></h2>
423 424 425 426
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">mul</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Mul Operator.</p>
427
<p>This operator is used to perform matrix multiplication for input $X$ and $Y$.</p>
428
<p>The equation is:</p>
429
<p>$$Out = X * Y$$</p>
430 431
<p>Both the input $X$ and $Y$ can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD information with input $X$.</p>
432 433 434 435 436
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
437
<li><strong>x</strong> &#8211; (Tensor), The first input tensor of mul op.
438
Duplicable: False  Optional: False</li>
439
<li><strong>y</strong> &#8211; (Tensor), The second input tensor of mul op.
440
Duplicable: False  Optional: False</li>
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
<li><strong>x_num_col_dims</strong> (<em>INT</em>) &#8211; (int, default 1), The mul_op can take tensors with more than two
dimensions as its inputs. If the input $X$ is a tensor with more
than two dimensions, $X$ will be flattened into a two-dimensional
matrix first. The flattening rule is: the first <cite>num_col_dims</cite>
will be flattened to form the first dimension of the final matrix
(the height of the matrix), and the rest <cite>rank(X) - num_col_dims</cite>
dimensions are flattened to form the second dimension of the final
matrix (the width of the matrix). As a result, height of the
flattened matrix is equal to the product of $X$&#8217;s first
<cite>x_num_col_dims</cite> dimensions&#8217; sizes, and width of the flattened
matrix is equal to the product of $X$&#8217;s last <cite>rank(x) - num_col_dims</cite>
dimensions&#8217; size. For example, suppose $X$ is a 6-dimensional
tensor with the shape [2, 3, 4, 5, 6], and <cite>x_num_col_dims</cite> = 3.
Thus, the flattened matrix will have a shape [2 x 3 x 4, 5 x 6] =
[24, 30].</li>
<li><strong>y_num_col_dims</strong> (<em>INT</em>) &#8211; (int, default 1), The mul_op can take tensors with more than two,
dimensions as its inputs. If the input $Y$ is a tensor with more
than two dimensions, $Y$ will be flattened into a two-dimensional
matrix first. The attribute <cite>y_num_col_dims</cite> determines how $Y$ is
flattened. See comments of <cite>x_num_col_dims</cite> for more details.</li>
461 462 463
</ul>
</td>
</tr>
464
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">(Tensor), The output tensor of mul op.</p>
465 466 467 468 469 470
</td>
</tr>
</tbody>
</table>
</dd></dl>

471 472 473
</div>
<div class="section" id="elementwise-add">
<h2>elementwise_add<a class="headerlink" href="#elementwise-add" title="Permalink to this headline"></a></h2>
474 475 476 477 478
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">elementwise_add</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Limited Elementwise Add Operator.</p>
<p>The equation is:</p>
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
<div class="math">
\[Out = X + Y\]</div>
<p>X is a tensor of any dimension and the dimensions of tensor Y must be smaller than
or equal to the dimensions of X.</p>
<p>There are two cases for this operator:
1. The shape of Y is same with X;
2. The shape of Y is a subset of X.</p>
<p>For case 2:
Y will be broadcasted to match the shape of X and axis should be
the starting dimension index for broadcasting Y onto X.</p>
<dl class="docutils">
<dt>For example</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span></span><span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">5</span><span class="p">,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span>
</pre></div>
</div>
</dd>
</dl>
<p>Either of the inputs X and Y or none can carry the LoD (Level of Details) information. However, the output only shares the LoD information with input X.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor) The first input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>y</strong> &#8211; (Tensor) The second input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>axis</strong> (<em>INT</em>) &#8211; (int, default -1) The starting dimension index for broadcasting Y onto X</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The output of elementwise op</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="elementwise-sub">
<h2>elementwise_sub<a class="headerlink" href="#elementwise-sub" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">elementwise_sub</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Limited Elementwise Sub Operator.</p>
<p>The equation is:</p>
<div class="math">
\[Out = X - Y\]</div>
<p>X is a tensor of any dimension and the dimensions of tensor Y must be smaller than
or equal to the dimensions of X.</p>
<p>There are two cases for this operator:
1. The shape of Y is same with X;
2. The shape of Y is a subset of X.</p>
<p>For case 2:
Y will be broadcasted to match the shape of X and axis should be
the starting dimension index for broadcasting Y onto X.</p>
<dl class="docutils">
<dt>For example</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span></span><span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">5</span><span class="p">,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span>
</pre></div>
</div>
</dd>
</dl>
<p>Either of the inputs X and Y or none can carry the LoD (Level of Details) information. However, the output only shares the LoD information with input X.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor) The first input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>y</strong> &#8211; (Tensor) The second input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>axis</strong> (<em>INT</em>) &#8211; (int, default -1) The starting dimension index for broadcasting Y onto X</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The output of elementwise op</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="elementwise-mul">
<h2>elementwise_mul<a class="headerlink" href="#elementwise-mul" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">elementwise_mul</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Limited Elementwise Mul Operator.</p>
<p>The equation is:</p>
<div class="math">
\[Out = X \odot\ Y\]</div>
581 582 583 584 585 586 587 588
<p>X is a tensor of any dimension and the dimensions of tensor Y must be smaller than
or equal to the dimensions of X.</p>
<p>There are two cases for this operator:
1. The shape of Y is same with X;
2. The shape of Y is a subset of X.</p>
<p>For case 2:
Y will be broadcasted to match the shape of X and axis should be
the starting dimension index for broadcasting Y onto X.</p>
589 590 591 592 593 594 595 596 597 598 599 600
<dl class="docutils">
<dt>For example</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span></span><span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">5</span><span class="p">,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span>
</pre></div>
</div>
</dd>
</dl>
<p>Either of the inputs X and Y or none can carry the LoD (Level of Details) information. However, the output only shares the LoD information with input X.</p>
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor) The first input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>y</strong> &#8211; (Tensor) The second input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>axis</strong> (<em>INT</em>) &#8211; (int, default -1) The starting dimension index for broadcasting Y onto X</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The output of elementwise op</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

621 622 623
</div>
<div class="section" id="elementwise-div">
<h2>elementwise_div<a class="headerlink" href="#elementwise-div" title="Permalink to this headline"></a></h2>
624 625 626 627 628
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">elementwise_div</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Limited Elementwise Div Operator.</p>
<p>The equation is:</p>
629 630
<div class="math">
\[Out = X / Y\]</div>
631 632 633 634 635 636 637 638
<p>X is a tensor of any dimension and the dimensions of tensor Y must be smaller than
or equal to the dimensions of X.</p>
<p>There are two cases for this operator:
1. The shape of Y is same with X;
2. The shape of Y is a subset of X.</p>
<p>For case 2:
Y will be broadcasted to match the shape of X and axis should be
the starting dimension index for broadcasting Y onto X.</p>
639 640 641 642 643 644 645 646 647 648 649 650
<dl class="docutils">
<dt>For example</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span></span><span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">5</span><span class="p">,)</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</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="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span>
<span class="n">shape</span><span class="p">(</span><span class="n">X</span><span class="p">)</span> <span class="o">=</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">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">shape</span><span class="p">(</span><span class="n">Y</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="k">with</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span>
</pre></div>
</div>
</dd>
</dl>
<p>Either of the inputs X and Y or none can carry the LoD (Level of Details) information. However, the output only shares the LoD information with input X.</p>
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor) The first input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>y</strong> &#8211; (Tensor) The second input tensor of elementwise op
Duplicable: False  Optional: False</li>
<li><strong>axis</strong> (<em>INT</em>) &#8211; (int, default -1) The starting dimension index for broadcasting Y onto X</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The output of elementwise op</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

671 672 673
</div>
<div class="section" id="dropout">
<h2>dropout<a class="headerlink" href="#dropout" title="Permalink to this headline"></a></h2>
674 675
<dl class="function">
<dt>
676 677
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">dropout</code><span class="sig-paren">(</span><em>x</em>, <em>dropout_prob</em>, <em>is_test=False</em>, <em>seed=0</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd></dd></dl>
678

679 680 681
</div>
<div class="section" id="reshape">
<h2>reshape<a class="headerlink" href="#reshape" title="Permalink to this headline"></a></h2>
682 683 684 685 686 687 688 689 690 691
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reshape</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Reshape Operator.</p>
<p>Reshape Input(X) into the shape specified by Attr(shape).</p>
<p>An example:
Given a 2-D tensor X with 2 rows and 2 columns</p>
<blockquote>
<div>[[1, 2], [3, 4]]</div></blockquote>
<p>and target shape = [1, 4], the reshape operator will transform
692
the tensor X into a 2-D tensor:</p>
693
<blockquote>
694
<div>[[1, 2, 3, 4]]</div></blockquote>
695 696 697
<p>One dimension in the target shape can be set -1, representing that its
size is unknown. In this case, the real dimension will be infered from
the original shape of Input(X) and other dimensions in the target shape.</p>
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; The input tensor of reshape operator.
Duplicable: False  Optional: False</li>
<li><strong>shape</strong> (<em>INTS</em>) &#8211; (vector&lt;int&gt;) Target shape of reshape operator.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The output tensor of reshape operator.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

716 717 718
</div>
<div class="section" id="sigmoid">
<h2>sigmoid<a class="headerlink" href="#sigmoid" title="Permalink to this headline"></a></h2>
719 720 721 722
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sigmoid</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Sigmoid Activation Operator</p>
723
<p>$$out = frac{1}{1 + e^{-x}}$$</p>
724 725 726 727 728 729 730 731 732 733 734 735 736
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Sigmoid operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Sigmoid operator</td>
</tr>
</tbody>
</table>
</dd></dl>

737 738 739
</div>
<div class="section" id="scale">
<h2>scale<a class="headerlink" href="#scale" title="Permalink to this headline"></a></h2>
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">scale</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Scale operator</p>
<p>$$Out = scale*X$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor) Input tensor of scale operator.
Duplicable: False  Optional: False</li>
<li><strong>scale</strong> (<em>FLOAT</em>) &#8211; (float, default 0)The scaling factor of the scale operator.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">(Tensor) Output tensor of scale operator.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

763 764 765
</div>
<div class="section" id="transpose">
<h2>transpose<a class="headerlink" href="#transpose" title="Permalink to this headline"></a></h2>
766 767 768 769 770
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">transpose</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Transpose Operator.</p>
<p>The input tensor will be permuted according to the axis values given.
771
The op functions is similar to how numpy.transpose works in python.</p>
772
<p>For example:</p>
773
<blockquote>
774 775 776 777 778 779 780 781 782 783 784 785 786
<div><div class="highlight-text"><div class="highlight"><pre><span></span>input = numpy.arange(6).reshape((2,3))

the input is:

array([[0, 1, 2],
       [3, 4, 5]])

given axis is:

[1, 0]

output = input.transpose(axis)

787
then the output is:
788 789 790 791 792 793 794

array([[0, 3],
       [1, 4],
       [2, 5]])
</pre></div>
</div>
</div></blockquote>
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
<p>So, given a input tensor of shape(N, C, H, W) and the axis is {0, 2, 3, 1},
the output tensor shape will be (N, H, W, C)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; (Tensor)The input tensor, tensors with rank at most 6 are supported
Duplicable: False  Optional: False</li>
<li><strong>axis</strong> (<em>INTS</em>) &#8211; (vector&lt;int&gt;)A list of values, and the size of the list should be the same with the input tensor rank, the tensor will permute the axes according the the values given</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">(Tensor)The output tensor</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

815 816 817 818 819 820
</div>
<div class="section" id="sigmoid-cross-entropy-with-logits">
<h2>sigmoid_cross_entropy_with_logits<a class="headerlink" href="#sigmoid-cross-entropy-with-logits" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="cast">
<h2>cast<a class="headerlink" href="#cast" title="Permalink to this headline"></a></h2>
821 822
<dl class="function">
<dt>
823
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">cast</code><span class="sig-paren">(</span><em>x</em>, <em>dtype</em><span class="sig-paren">)</span></dt>
824 825 826 827
<dd><p>This function takes in the input with input_dtype
and casts it to the output_dtype as the output.</p>
</dd></dl>

828 829 830
</div>
<div class="section" id="concat">
<h2>concat<a class="headerlink" href="#concat" title="Permalink to this headline"></a></h2>
831 832
<dl class="function">
<dt>
833 834 835
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">concat</code><span class="sig-paren">(</span><em>input</em>, <em>axis=0</em><span class="sig-paren">)</span></dt>
<dd><p><strong>Concat</strong></p>
<p>This function concatenates the input along the axis mentioned
836
and returns that as the output.</p>
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>list</em>) &#8211; List of tensors to be concatenated</li>
<li><strong>axis</strong> (<em>int</em>) &#8211; Integer axis along which the tensors will be concatenated</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Output variable of the concatenation</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
856 857
</dd></dl>

858 859 860
</div>
<div class="section" id="sums">
<h2>sums<a class="headerlink" href="#sums" title="Permalink to this headline"></a></h2>
861 862
<dl class="function">
<dt>
863
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sums</code><span class="sig-paren">(</span><em>input</em>, <em>out=None</em><span class="sig-paren">)</span></dt>
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
<dd><p>This function performs the sum operation on the input and returns the
result as the output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>input</strong> (<em>Variable|list</em>) &#8211; The input tensor that has the elements
that need to be summed up.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="docutils">
<dt>The tensor type variable that has the sum of input</dt>
<dd>written to it.</dd>
</dl>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">Variable</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
884 885
</dd></dl>

886 887 888
</div>
<div class="section" id="linear-chain-crf">
<h2>linear_chain_crf<a class="headerlink" href="#linear-chain-crf" title="Permalink to this headline"></a></h2>
889 890
<dl class="function">
<dt>
891
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">linear_chain_crf</code><span class="sig-paren">(</span><em>input</em>, <em>label</em>, <em>param_attr=None</em><span class="sig-paren">)</span></dt>
892 893
<dd></dd></dl>

894 895 896
</div>
<div class="section" id="assign">
<h2>assign<a class="headerlink" href="#assign" title="Permalink to this headline"></a></h2>
897 898
<dl class="function">
<dt>
899
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">embedding</code><span class="sig-paren">(</span><em>input</em>, <em>size</em>, <em>is_sparse=False</em>, <em>param_attr=None</em>, <em>dtype='float32'</em><span class="sig-paren">)</span></dt>
900 901 902 903 904
<dd><p><strong>Embedding Layer</strong></p>
<p>This layer is used to lookup a vector of IDs, provided by <em>input</em>, in a lookup table.
The result of this lookup is the embedding of each ID in the <em>input</em>.</p>
<p>All the input variables are passed in as local variables to the LayerHelper
constructor.</p>
905 906 907 908
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
909 910
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; Input to the function</li>
911
<li><strong>size</strong> (<em>tuple|list|None</em>) &#8211; Shape of the look up table parameter</li>
912 913 914
<li><strong>is_sparse</strong> (<em>bool</em>) &#8211; Boolean flag that specifying whether the input is sparse</li>
<li><strong>param_attr</strong> (<em>ParamAttr</em>) &#8211; Parameters for this layer</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; The type of data : float32, float_16, int etc</li>
915 916 917
</ul>
</td>
</tr>
918 919 920 921 922 923
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the embeddings of the                   supplied inputs.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
924 925
</tbody>
</table>
926
<p class="rubric">Examples</p>
927 928 929
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">dict_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">dataset</span><span class="o">.</span><span class="n">ids</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;ids&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">fc</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">embedding</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">size</span><span class="o">=</span><span class="p">[</span><span class="n">dict_size</span><span class="p">,</span> <span class="mi">16</span><span class="p">])</span>
930 931
</pre></div>
</div>
932 933
</dd></dl>

934 935 936
</div>
<div class="section" id="split-lod-tensor">
<h2>split_lod_tensor<a class="headerlink" href="#split-lod-tensor" title="Permalink to this headline"></a></h2>
937 938
<dl class="function">
<dt>
939
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">split_lod_tensor</code><span class="sig-paren">(</span><em>input</em>, <em>mask</em>, <em>level=0</em><span class="sig-paren">)</span></dt>
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
<dd><p><strong>split_lod_tensor</strong></p>
<p>This function takes in an input that contains the complete lod information,
and takes in a mask which is used to mask certain parts of the input.
The output is the true branch and the false branch with the mask applied to
the input at a certain level in the tensor.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>tuple|list|None</em>) &#8211; The input tensor that contains complete
lod information needed to construct the output.</li>
<li><strong>mask</strong> (<em>list</em>) &#8211; A bool column vector which masks the input.</li>
<li><strong>level</strong> (<em>int</em>) &#8211; The specific lod level to rank.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The true branch of tensor as per the mask applied to input.
Variable: The false branch of tensor as per the mask applied to input.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">x</span><span class="o">.</span><span class="n">persistable</span> <span class="o">=</span> <span class="bp">True</span>

<span class="n">y</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">y</span><span class="o">.</span><span class="n">persistable</span> <span class="o">=</span> <span class="bp">True</span>

<span class="n">out_true</span><span class="p">,</span> <span class="n">out_false</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">split_lod_tensor</span><span class="p">(</span>
      <span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="n">level</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
978

979 980 981
</div>
<div class="section" id="merge-lod-tensor">
<h2>merge_lod_tensor<a class="headerlink" href="#merge-lod-tensor" title="Permalink to this headline"></a></h2>
982 983
<dl class="function">
<dt>
984
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">merge_lod_tensor</code><span class="sig-paren">(</span><em>in_true</em>, <em>in_false</em>, <em>x</em>, <em>mask</em>, <em>level=0</em><span class="sig-paren">)</span></dt>
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
<dd><p><strong>merge_lod_tensor</strong></p>
<p>This function takes in an input <span class="math">\(x\)</span>, the True branch, the False
branch and a binary <span class="math">\(mask\)</span>. Using this information, this function
merges the True and False branches of the tensor into a single Output
at a certain lod level indiacted by <span class="math">\(level\)</span>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>in_true</strong> (<em>tuple|list|None</em>) &#8211; The True branch to be merged.</li>
<li><strong>in_false</strong> (<em>tuple|list|None</em>) &#8211; The False branch to be merged.</li>
<li><strong>x</strong> (<em>tuple|list|None</em>) &#8211; The input tensor that contains complete
lod information needed to construct the output.</li>
<li><strong>mask</strong> (<em>list</em>) &#8211; A bool column vector which masks the input.</li>
<li><strong>level</strong> (<em>int</em>) &#8211; The specific lod level to rank.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The merged output tensor.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span>
            <span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">stop_gradient</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span>
      <span class="n">name</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;bool&#39;</span><span class="p">,</span> <span class="n">stop_gradient</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

<span class="n">level</span> <span class="o">=</span> <span class="mi">0</span>

<span class="n">out_true</span><span class="p">,</span> <span class="n">out_false</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">split_lod_tensor</span><span class="p">(</span>
      <span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="n">level</span><span class="p">)</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">merge_lod_tensor</span><span class="p">(</span>
      <span class="n">in_true</span><span class="o">=</span><span class="n">out_true</span><span class="p">,</span> <span class="n">in_false</span><span class="o">=</span><span class="n">out_false</span><span class="p">,</span> <span class="n">mask</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="n">level</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
1027

1028 1029 1030
</div>
<div class="section" id="cos-sim">
<h2>cos_sim<a class="headerlink" href="#cos-sim" title="Permalink to this headline"></a></h2>
1031 1032 1033 1034 1035 1036 1037
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">cos_sim</code><span class="sig-paren">(</span><em>X</em>, <em>Y</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This function performs the cosine similarity between two tensors
X and Y and returns that as the output.</p>
</dd></dl>

1038 1039 1040
</div>
<div class="section" id="cross-entropy">
<h2>cross_entropy<a class="headerlink" href="#cross-entropy" title="Permalink to this headline"></a></h2>
1041 1042 1043
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">cross_entropy</code><span class="sig-paren">(</span><em>input</em>, <em>label</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
<dd><p><strong>Cross Entropy Layer</strong></p>
<p>This layer computes the cross entropy between <cite>input</cite> and <cite>label</cite>. It supports
both standard cross-entropy and soft-label cross-entropy loss computation.</p>
<ol class="arabic">
<li><dl class="first docutils">
<dt>One-hot cross-entropy:</dt>
<dd><p class="first"><cite>soft_label = False</cite>, <cite>Label[i, 0]</cite> indicates the class index for sample i:</p>
<div class="last math">
\[Y[i] = -\log(X[i, Label[i]])\]</div>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>Soft-label cross-entropy:</dt>
<dd><p class="first"><cite>soft_label = True</cite>, <cite>Label[i, j]</cite> indicates the soft label of class j
for sample i:</p>
<div class="last math">
\[Y[i] = \sum_j{-Label[i, j] * log(X[i, j])}\]</div>
</dd>
</dl>
<p>Please make sure that in this case the summation of each row of <cite>label</cite>
equals one.</p>
</li>
<li><dl class="first docutils">
<dt>One-hot cross-entropy with vecterized <cite>label</cite>:</dt>
<dd><p class="first last">As a special case of 2), when each row of &#8216;label&#8217; has only one
non-zero element which is equal to 1, soft-label cross-entropy degenerates
to a one-hot cross-entropy with one-hot label representation.</p>
</dd>
</dl>
</li>
</ol>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable|list</em>) &#8211; a 2-D tensor with shape [N x D], where N is the
batch size and D is the number of classes. This input is a probability
computed by the previous operator, which is almost always the result
of a softmax operator.</li>
<li><strong>label</strong> (<em>Variable|list</em>) &#8211; the ground truth which is a 2-D tensor. When
<cite>soft_label</cite> is set to <cite>False</cite>, <cite>label</cite> is a tensor&lt;int64&gt; with shape
[N x 1]. When <cite>soft_label</cite> is set to <cite>True</cite>, <cite>label</cite> is a
tensor&lt;float/double&gt; with shape [N x D].</li>
<li><strong>soft_label</strong> (bool, via <cite>**kwargs</cite>) &#8211; a flag indicating whether to interpretate
the given labels as soft labels, default <cite>False</cite>.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A 2-D tensor with shape [N x 1], the cross entropy loss.</p>
</td>
</tr>
1097
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><cite>ValueError</cite> &#8211; 1) the 1st dimension of <cite>input</cite> and <cite>label</cite> are not equal; 2) when               <cite>soft_label == True</cite>, and the 2nd dimension of <cite>input</cite> and <cite>label</cite> are not                equal; 3) when <cite>soft_label == False</cite>, and the 2nd dimension of <cite>label</cite> is not 1.</p>
1098 1099 1100 1101 1102 1103 1104 1105 1106
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">predict</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">net</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">classdim</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="s1">&#39;softmax&#39;</span><span class="p">)</span>
<span class="n">cost</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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="n">predict</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>
1107 1108
</dd></dl>

1109 1110 1111
</div>
<div class="section" id="square-error-cost">
<h2>square_error_cost<a class="headerlink" href="#square-error-cost" title="Permalink to this headline"></a></h2>
1112 1113 1114
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">square_error_cost</code><span class="sig-paren">(</span><em>input</em>, <em>label</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
<dd><p><strong>Square error cost layer</strong></p>
<p>This layer accepts input predictions and target label and returns the squared error cost.
For predictions, <span class="math">\(X\)</span>, and target labels, <span class="math">\(Y\)</span>, the equation is:</p>
<div class="math">
\[Out = (X - Y)^2\]</div>
<p>In the above equation:</p>
<blockquote>
<div><ul class="simple">
<li><span class="math">\(X\)</span>: Input predictions, a tensor.</li>
<li><span class="math">\(Y\)</span>: Input labels, a tensor.</li>
<li><span class="math">\(Out\)</span>: Output value, same shape with <span class="math">\(X\)</span>.</li>
</ul>
</div></blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; Input tensor, has predictions.</li>
<li><strong>label</strong> (<em>Variable</em>) &#8211; Label tensor, has target labels.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the element-wise squared error difference                   of input and label.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">y_predict</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;y_predict&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">cost</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">square_error_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">y_predict</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">y</span><span class="p">)</span>
</pre></div>
</div>
1152 1153
</dd></dl>

1154 1155 1156
</div>
<div class="section" id="accuracy">
<h2>accuracy<a class="headerlink" href="#accuracy" title="Permalink to this headline"></a></h2>
1157 1158 1159 1160 1161 1162 1163
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">accuracy</code><span class="sig-paren">(</span><em>input</em>, <em>label</em>, <em>k=1</em>, <em>correct=None</em>, <em>total=None</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This function computes the accuracy using the input and label.
The output is the top_k inputs and their indices.</p>
</dd></dl>

1164 1165 1166
</div>
<div class="section" id="sequence-conv">
<h2>sequence_conv<a class="headerlink" href="#sequence-conv" title="Permalink to this headline"></a></h2>
1167 1168
<dl class="function">
<dt>
1169
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_conv</code><span class="sig-paren">(</span><em>input</em>, <em>num_filters</em>, <em>filter_size=3</em>, <em>filter_stride=1</em>, <em>padding=None</em>, <em>bias_attr=None</em>, <em>param_attr=None</em>, <em>act=None</em><span class="sig-paren">)</span></dt>
1170 1171 1172 1173 1174
<dd><p>This function creates the op for sequence_conv, using the inputs and
other convolutional configurations for the filters and stride as given
in the input parameters to the function.</p>
</dd></dl>

1175 1176 1177
</div>
<div class="section" id="conv2d">
<h2>conv2d<a class="headerlink" href="#conv2d" title="Permalink to this headline"></a></h2>
1178 1179
<dl class="function">
<dt>
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">conv2d</code><span class="sig-paren">(</span><em>input</em>, <em>num_filters</em>, <em>filter_size</em>, <em>stride=None</em>, <em>padding=None</em>, <em>groups=None</em>, <em>param_attr=None</em>, <em>bias_attr=None</em>, <em>act=None</em><span class="sig-paren">)</span></dt>
<dd><p><strong>Convlution2D Layer</strong></p>
<p>The convolution2D layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output)
are in NCHW format. Where N is batch size, C is the number of channels, H is the height
of the feature, and W is the width of the feature.
The details of convolution layer, please refer UFLDL&#8217;s <a class="reference external" href="http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/">convolution,</a> .
If bias attribution and activation type are provided, bias is added to the output of the convolution,
and the corresponding activation function is applied to the final result.
For each input <span class="math">\(X\)</span>, the equation is:</p>
<div class="math">
\[Out = \sigma (W \ast X + b)\]</div>
<p>In the above equation:</p>
<blockquote>
<div><ul class="simple">
<li><span class="math">\(X\)</span>: Input value, a tensor with NCHW format.</li>
<li><span class="math">\(W\)</span>: Filter value, a tensor with MCHW format.</li>
<li><span class="math">\(\ast\)</span>: Convolution operation.</li>
<li><span class="math">\(b\)</span>: Bias value, a 2-D tensor with shape [M, 1].</li>
<li><span class="math">\(\sigma\)</span>: Activation function.</li>
<li><span class="math">\(Out\)</span>: Output value, the shape of <span class="math">\(Out\)</span> and <span class="math">\(X\)</span> may be different.</li>
</ul>
</div></blockquote>
<p class="rubric">Example</p>
<dl class="docutils">
<dt>Input:</dt>
<dd><p class="first">Input shape: $(N, C_{in}, H_{in}, W_{in})$</p>
<p class="last">Filter shape: $(C_{out}, C_{in}, H_f, W_f)$</p>
</dd>
<dt>Output:</dt>
<dd>Output shape: $(N, C_{out}, H_{out}, W_{out})$</dd>
</dl>
<p>Where</p>
<div class="math">
\[\begin{split}H_{out}&amp;= \frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (H_f - 1) + 1))}{strides[0]} + 1 \\
W_{out}&amp;= \frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1\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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input image with [N, C, H, W] format.</li>
<li><strong>num_filters</strong> (<em>int</em>) &#8211; The number of filter. It is as same as the output
image channel.</li>
<li><strong>filter_size</strong> (<em>int|tuple|None</em>) &#8211; The filter size. If filter_size is a tuple,
it must contain two integers, (filter_size_H, filter_size_W).
Otherwise, the filter will be a square.</li>
<li><strong>stride</strong> (<em>int|tuple</em>) &#8211; The stride size. If stride is a tuple, it must
contain two integers, (stride_H, stride_W). Otherwise, the
stride_H = stride_W = stride. Default: stride = 1.</li>
<li><strong>padding</strong> (<em>int|tuple</em>) &#8211; The padding size. If padding is a tuple, it must
contain two integers, (padding_H, padding_W). Otherwise, the
padding_H = padding_W = padding. Default: padding = 0.</li>
<li><strong>groups</strong> (<em>int</em>) &#8211; The groups number of the Conv2d Layer. According to grouped
convolution in Alex Krizhevsky&#8217;s Deep CNN paper: when group=2,
the first half of the filters is only connected to the first half
of the input channels, while the second half of the filters is only
connected to the second half of the input channels. Default: groups=1</li>
<li><strong>param_attr</strong> (<em>ParamAttr</em>) &#8211; The parameters to the Conv2d Layer. Default: None</li>
<li><strong>bias_attr</strong> (<em>ParamAttr</em>) &#8211; Bias parameter for the Conv2d layer. Default: None</li>
<li><strong>act</strong> (<em>str</em>) &#8211; Activation type. Default: None</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the convolution and                   non-linearity activation result.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">Variable</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> &#8211; If the shapes of input, filter_size, stride, padding and groups mismatch.</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">conv2d</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">conv2d</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">num_filters</span><span class="o">=</span><span class="mi">2</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">act</span><span class="o">=</span><span class="s2">&quot;relu&quot;</span><span class="p">)</span>
</pre></div>
</div>
1260 1261
</dd></dl>

1262 1263 1264
</div>
<div class="section" id="sequence-pool">
<h2>sequence_pool<a class="headerlink" href="#sequence-pool" title="Permalink to this headline"></a></h2>
1265 1266 1267 1268
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_pool</code><span class="sig-paren">(</span><em>input</em>, <em>pool_type</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This function add the operator for sequence pooling.
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 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 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
It pools features of all time-steps of each instance, and is applied
on top of the input using pool_type mentioned in the parameters.</p>
<p>It supports four pool_type:</p>
<ul class="simple">
<li>average: <span class="math">\(Out[i] = \frac{\sum_i X_i}{N}\)</span></li>
<li>sum:     <span class="math">\(Out[i] = \sum_jX_{ij}\)</span></li>
<li>sqrt:    <span class="math">\(Out[i] = \frac{\sum_jX_{ij}}{\sqrt{len(X_i)}}\)</span></li>
<li>max:     <span class="math">\(Out[i] = max(X_i)\)</span></li>
</ul>
<div class="highlight-text"><div class="highlight"><pre><span></span>x is a 1-level LoDTensor:
  x.lod = [[0, 2, 5, 7]]
  x.data = [1, 3, 2, 4, 6, 5, 1]
  x.dims = [7, 1]

then output is a Tensor:
  out.dim = [3, 1]
  with condition len(x.lod[-1]) - 1 == out.dims[0]

for different pool_type:
  average: out.data = [2, 4, 3], where 2=(1+3)/2, 4=(2+4+6)/3, 3=(5+1)/2
  sum    : out.data = [4, 12, 6], where 4=1+3, 12=2+4+6, 6=5+1
  sqrt   : out.data = [2.82, 6.93, 4.24], where 2.82=(1+3)/sqrt(2),
             6.93=(2+4+6)/sqrt(3), 4.24=(5+1)/sqrt(2)
  max    : out.data = [3, 6, 5], where 3=max(1,3), 6=max(2,4,6), 5=max(5,1)
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>variable</em>) &#8211; The input variable which is a LoDTensor.</li>
<li><strong>pool_type</strong> (<em>string</em>) &#8211; The pooling type of sequence_pool.
It supports average, sum, sqrt and max.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The sequence pooling variable which is a Tensor.</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                 <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">avg_x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_pool</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">pool_type</span><span class="o">=</span><span class="s1">&#39;average&#39;</span><span class="p">)</span>
<span class="n">sum_x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_pool</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">pool_type</span><span class="o">=</span><span class="s1">&#39;sum&#39;</span><span class="p">)</span>
<span class="n">sqrt_x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_pool</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">pool_type</span><span class="o">=</span><span class="s1">&#39;sqrt&#39;</span><span class="p">)</span>
<span class="n">max_x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_pool</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">pool_type</span><span class="o">=</span><span class="s1">&#39;max&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="sequence-first-step">
<h2>sequence_first_step<a class="headerlink" href="#sequence-first-step" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_first_step</code><span class="sig-paren">(</span><em>input</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This funciton get the first step of sequence.</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>x is a 1-level LoDTensor:
  x.lod = [[0, 2, 5, 7]]
  x.data = [1, 3, 2, 4, 6, 5, 1]
  x.dims = [7, 1]

then output is a Tensor:
  out.dim = [3, 1]
  with condition len(x.lod[-1]) - 1 == out.dims[0]
  out.data = [1, 2, 5], where 1=first(1,3), 2=first(2,4,6), 5=first(5,1)
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>input</strong> (<em>variable</em>) &#8211; The input variable which is a LoDTensor.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The sequence&#8217;s first step variable which is a Tensor.</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                 <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">x_first_step</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_first_step</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="sequence-last-step">
<h2>sequence_last_step<a class="headerlink" href="#sequence-last-step" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_last_step</code><span class="sig-paren">(</span><em>input</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This funciton get the last step of sequence.</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>x is a 1-level LoDTensor:
  x.lod = [[0, 2, 5, 7]]
  x.data = [1, 3, 2, 4, 6, 5, 1]
  x.dims = [7, 1]

then output is a Tensor:
  out.dim = [3, 1]
  with condition len(x.lod[-1]) - 1 == out.dims[0]
  out.data = [3, 6, 1], where 3=last(1,3), 6=last(2,4,6), 1=last(5,1)
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>input</strong> (<em>variable</em>) &#8211; The input variable which is a LoDTensor.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The sequence&#8217;s last step variable which is a Tensor.</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span>
                 <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">x_last_step</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">sequence_last_step</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x</span><span class="p">)</span>
</pre></div>
</div>
1392 1393
</dd></dl>

1394 1395 1396
</div>
<div class="section" id="pool2d">
<h2>pool2d<a class="headerlink" href="#pool2d" title="Permalink to this headline"></a></h2>
1397 1398
<dl class="function">
<dt>
1399
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">pool2d</code><span class="sig-paren">(</span><em>input</em>, <em>pool_size</em>, <em>pool_type</em>, <em>pool_stride=None</em>, <em>pool_padding=None</em>, <em>global_pooling=False</em><span class="sig-paren">)</span></dt>
1400 1401 1402 1403
<dd><p>This function adds the operator for pooling in 2 dimensions, using the
pooling configurations mentioned in input parameters.</p>
</dd></dl>

1404 1405 1406
</div>
<div class="section" id="batch-norm">
<h2>batch_norm<a class="headerlink" href="#batch-norm" title="Permalink to this headline"></a></h2>
1407 1408
<dl class="function">
<dt>
1409
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">batch_norm</code><span class="sig-paren">(</span><em>input</em>, <em>act=None</em>, <em>is_test=False</em>, <em>momentum=0.9</em>, <em>epsilon=1e-05</em>, <em>param_attr=None</em>, <em>bias_attr=None</em>, <em>data_layout='NCHW'</em><span class="sig-paren">)</span></dt>
1410 1411 1412 1413
<dd><p>This function helps create an operator to implement
the BatchNorm layer using the configurations from the input parameters.</p>
</dd></dl>

1414 1415 1416
</div>
<div class="section" id="beam-search-decode">
<h2>beam_search_decode<a class="headerlink" href="#beam-search-decode" title="Permalink to this headline"></a></h2>
1417 1418
<dl class="function">
<dt>
1419
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">beam_search_decode</code><span class="sig-paren">(</span><em>ids</em>, <em>scores</em><span class="sig-paren">)</span></dt>
1420 1421
<dd></dd></dl>

1422 1423 1424
</div>
<div class="section" id="lod-rank-table">
<h2>lod_rank_table<a class="headerlink" href="#lod-rank-table" title="Permalink to this headline"></a></h2>
1425 1426
<dl class="function">
<dt>
1427
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">lod_rank_table</code><span class="sig-paren">(</span><em>x</em>, <em>level=0</em><span class="sig-paren">)</span></dt>
1428 1429 1430
<dd><p>LoD Rank Table Operator. Given an input variable <strong>x</strong> and a level number
of LoD, this layer creates a LodRankTable object. A LoDRankTable object
contains a list of bi-element tuples. Each tuple consists of an index and
1431
a length, both of which are int type. Refering to specified level of LoD,
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
the index is the sequence index number and the length representes the
sequence length. Please note that the list is ranked in descending order by
the length. The following is an example:</p>
<blockquote>
<div><div class="highlight-text"><div class="highlight"><pre><span></span>x is a LoDTensor:
    x.lod = [[0,                2, 3],
             [0,             5, 6, 7]]
    x.data = [a, b, c, d, e, f, g]

1. set level to 0:
    Create lod rank table:
        lod_rank_table_obj = lod_rank_table(x, level=0)

    Get:
        lod_rank_table_obj.items() = [(0, 2), (1, 1)]

2. set level to 1:
    Create lod rank table:
        lod_rank_table_obj = lod_rank_table(x, level=1)

    Get:
        lod_rank_table_obj.items() = [(0, 5), (1, 1), (2, 1)]
</pre></div>
</div>
</div></blockquote>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> (<em>Variable</em>) &#8211; Input variable, a LoDTensor based which to create the lod
rank table.</li>
<li><strong>level</strong> (<em>int</em>) &#8211; Specify the LoD level, on which to create the lod rank
table.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The created LoDRankTable object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span>
                <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">lod_rank_table</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
1483 1484
</dd></dl>

1485 1486 1487
</div>
<div class="section" id="max-sequence-len">
<h2>max_sequence_len<a class="headerlink" href="#max-sequence-len" title="Permalink to this headline"></a></h2>
1488 1489
<dl class="function">
<dt>
1490
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">max_sequence_len</code><span class="sig-paren">(</span><em>rank_table</em><span class="sig-paren">)</span></dt>
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
<dd><p>Max Sequence Len Operator. Given a LoDRankTable object, this layer
returns the max length of a batch of sequences. In fact, a LoDRankTable
object contains a list of tuples(&lt;sequence index, sequence length&gt;) and
the list is already sorted by sequence length in descending order, so the
operator just returns the sequence length of the first tuple element.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>rank_table</strong> (<em>Variable</em>) &#8211; Input variable which is a LoDRankTable object.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The max length of sequence.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">Variable</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span>
                <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">rank_table</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">lod_rank_table</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">max_seq_len</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">max_sequence_len</span><span class="p">(</span><span class="n">rank_table</span><span class="p">)</span>
</pre></div>
</div>
1515 1516
</dd></dl>

1517 1518 1519
</div>
<div class="section" id="topk">
<h2>topk<a class="headerlink" href="#topk" title="Permalink to this headline"></a></h2>
1520 1521
<dl class="function">
<dt>
1522
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">topk</code><span class="sig-paren">(</span><em>input</em>, <em>k</em><span class="sig-paren">)</span></dt>
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
<dd><p><strong>topk</strong></p>
<p>This function performs the operation that selects the k entries in the input
vector and outputs their values and indices as vectors. Thus topk_out[j] is
the j-th largest entry in input, and its index is topk_indices[j]</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable|list</em>) &#8211; The input tensor that has all the data.</li>
<li><strong>k</strong> (<em>int</em>) &#8211; The number of top elements that the function will pick.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><dl class="docutils">
<dt>The variable of type array that contains the k largest entries</dt>
<dd><p class="first last">from input.</p>
</dd>
<dt>Variable: The variable of type array that contains the indices of k</dt>
<dd><p class="first last">largest entries from input.</p>
</dd>
</dl>
</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">])</span>
<span class="n">k</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">array</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">topk</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
1560

1561 1562 1563
</div>
<div class="section" id="lod-tensor-to-array">
<h2>lod_tensor_to_array<a class="headerlink" href="#lod-tensor-to-array" title="Permalink to this headline"></a></h2>
1564 1565
<dl class="function">
<dt>
1566
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">lod_tensor_to_array</code><span class="sig-paren">(</span><em>x</em>, <em>table</em><span class="sig-paren">)</span></dt>
1567
<dd><p>Convert a LOD_TENSOR to an LOD_TENSOR_ARRAY.</p>
1568 1569 1570 1571 1572
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1573
<li><strong>x</strong> (<em>Variable|list</em>) &#8211; The LOD tensor to be converted to a LOD tensor array.</li>
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
<li><strong>table</strong> (<em>ParamAttr|list</em>) &#8211; The variable that stores the level of lod
which is ordered by sequence length in
descending order.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><dl class="docutils">
<dt>The variable of type array that has been converted from a</dt>
<dd><p class="first last">tensor.</p>
</dd>
</dl>
</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">])</span>
<span class="n">table</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">lod_rank_table</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">array</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">lod_tensor_to_array</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">table</span><span class="p">)</span>
</pre></div>
</div>
1599 1600
</dd></dl>

1601 1602 1603
</div>
<div class="section" id="array-to-lod-tensor">
<h2>array_to_lod_tensor<a class="headerlink" href="#array-to-lod-tensor" title="Permalink to this headline"></a></h2>
1604 1605
<dl class="function">
<dt>
1606
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">array_to_lod_tensor</code><span class="sig-paren">(</span><em>x</em>, <em>table</em><span class="sig-paren">)</span></dt>
1607
<dd><p>Convert a LoD_Tensor_Aarry to an LoDTensor.</p>
1608 1609 1610 1611 1612
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1613
<li><strong>x</strong> (<em>Variable|list</em>) &#8211; The lod tensor array to be converted to a tensor.</li>
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
<li><strong>table</strong> (<em>ParamAttr|list</em>) &#8211; The variable that stores the level of lod
which is ordered by sequence length in
descending order.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><dl class="docutils">
<dt>The variable of type tensor that has been converted</dt>
<dd><p class="first last">from an array.</p>
</dd>
</dl>
</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">])</span>
<span class="n">table</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">lod_rank_table</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">array</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">lod_tensor_to_array</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">table</span><span class="p">)</span>
<span class="n">lod_tensor</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">array_to_lod_tensor</span><span class="p">(</span><span class="n">array</span><span class="p">,</span> <span class="n">table</span><span class="p">)</span>
</pre></div>
</div>
1640 1641
</dd></dl>

1642 1643 1644
</div>
<div class="section" id="fill-constant">
<h2>fill_constant<a class="headerlink" href="#fill-constant" title="Permalink to this headline"></a></h2>
1645 1646
<dl class="function">
<dt>
1647
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">fill_constant</code><span class="sig-paren">(</span><em>shape</em>, <em>dtype</em>, <em>value</em>, <em>force_cpu=False</em>, <em>out=None</em><span class="sig-paren">)</span></dt>
1648
<dd><p><strong>fill_constant</strong></p>
1649 1650 1651
<p>This function creates a tensor with specified <cite>shape</cite> and <cite>dtype</cite>, and
initializes it with a constant specifed by <cite>value</cite>.</p>
<p>The attribute <cite>stop_gradient</cite> of the created tensor is set to True.</p>
1652 1653 1654 1655 1656
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1657 1658 1659 1660
<li><strong>shape</strong> (<em>tuple|list|None</em>) &#8211; Shape of the output tensor.</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; Data type of the output tensor.</li>
<li><strong>value</strong> (<em>float</em>) &#8211; The constant value used to initialize the output tensor.</li>
<li><strong>out</strong> (<em>Variable</em>) &#8211; The output tensor.</li>
1661 1662 1663
</ul>
</td>
</tr>
1664
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the output.</p>
1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">fill_constant</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">value</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;int64&#39;</span><span class="p">)</span>
</pre></div>
</div>
1676 1677
</dd></dl>

1678 1679 1680
</div>
<div class="section" id="fill-constant-batch-size-like">
<h2>fill_constant_batch_size_like<a class="headerlink" href="#fill-constant-batch-size-like" title="Permalink to this headline"></a></h2>
1681 1682
<dl class="function">
<dt>
1683
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">fill_constant_batch_size_like</code><span class="sig-paren">(</span><em>input</em>, <em>shape</em>, <em>dtype</em>, <em>value</em>, <em>input_dim_idx=0</em>, <em>output_dim_idx=0</em><span class="sig-paren">)</span></dt>
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
<dd><p><strong>fill_constant_batch_size_like</strong></p>
<p>This function creates a tensor of specified <em>shape</em>, <em>dtype</em> and batch size,
and initializes this with a constant supplied in <em>value</em>. The batch size is
obtained from the <cite>input</cite> tensor.</p>
<p>It also sets <em>stop_gradient</em> to True.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; Tensor whose dimensions will be used to get batch size</li>
<li><strong>shape</strong> (<em>tuple|list|None</em>) &#8211; Shape of output tensor</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; Data type of output tensor</li>
<li><strong>value</strong> (<em>float</em>) &#8211; Constant value to initialize the output tensor</li>
<li><strong>input_dim_idx</strong> (<em>int</em>) &#8211; Index of input&#8217;s batch size dimension</li>
<li><strong>output_dim_idx</strong> (<em>int</em>) &#8211; Index of output&#8217;s batch size dimension</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the output</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
1712 1713
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">fill_constant_batch_size_like</span><span class="p">(</span>
    <span class="nb">input</span><span class="o">=</span><span class="n">like</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">value</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;int64&#39;</span><span class="p">)</span>
1714 1715 1716
</pre></div>
</div>
</dd></dl>
1717

1718 1719 1720
</div>
<div class="section" id="ones">
<h2>ones<a class="headerlink" href="#ones" title="Permalink to this headline"></a></h2>
1721 1722
<dl class="function">
<dt>
1723
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">ones</code><span class="sig-paren">(</span><em>shape</em>, <em>dtype</em><span class="sig-paren">)</span></dt>
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749
<dd><p><strong>ones</strong></p>
<p>This function creates a tensor of specified <em>shape</em> and
<em>dtype</em>, and initializes this with 1.</p>
<p>It also sets <em>stop_gradient</em> to True.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>shape</strong> (<em>tuple|list|None</em>) &#8211; Shape of output tensor</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; Data type of output tensor</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the output</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;int64&#39;</span><span class="p">)</span>
</pre></div>
</div>
1750 1751
</dd></dl>

1752 1753 1754
</div>
<div class="section" id="zeros">
<h2>zeros<a class="headerlink" href="#zeros" title="Permalink to this headline"></a></h2>
1755 1756
<dl class="function">
<dt>
1757
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">zeros</code><span class="sig-paren">(</span><em>shape</em>, <em>dtype</em><span class="sig-paren">)</span></dt>
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
<dd><p><strong>zeros</strong></p>
<p>This function creates a tensor of specified <em>shape</em> and
<em>dtype</em>, and initializes this with 0.</p>
<p>It also sets <em>stop_gradient</em> to True.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>shape</strong> (<em>tuple|list|None</em>) &#8211; Shape of output tensor</li>
<li><strong>dtype</strong> (<em>np.dtype|core.DataType|str</em>) &#8211; Data type of output tensor</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the output</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;int64&#39;</span><span class="p">)</span>
</pre></div>
</div>
1784 1785
</dd></dl>

1786 1787 1788
</div>
<div class="section" id="increment">
<h2>increment<a class="headerlink" href="#increment" title="Permalink to this headline"></a></h2>
1789 1790
<dl class="function">
<dt>
1791
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">increment</code><span class="sig-paren">(</span><em>x</em>, <em>value=1.0</em>, <em>in_place=True</em><span class="sig-paren">)</span></dt>
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823
<dd><p>This function performs an operation that increments each value in the
input <span class="math">\(x\)</span> by an amount: <span class="math">\(value\)</span> as mentioned in the input
parameter. This operation is performed in-place by default.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> (<em>Variable|list</em>) &#8211; The tensor that has the input values.</li>
<li><strong>value</strong> (<em>float</em>) &#8211; The amount by which the values should be incremented.</li>
<li><strong>in_place</strong> (<em>bool</em>) &#8211; If the increment should be performed in-place.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><dl class="docutils">
<dt>The tensor variable storing the transformation of</dt>
<dd><p class="first last">element-wise increment of each value in the input.</p>
</dd>
</dl>
</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">increment</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="mf">3.0</span><span class="p">,</span> <span class="n">in_place</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
1824 1825
</dd></dl>

1826 1827 1828
</div>
<div class="section" id="array-write">
<h2>array_write<a class="headerlink" href="#array-write" title="Permalink to this headline"></a></h2>
1829 1830
<dl class="function">
<dt>
1831
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">array_write</code><span class="sig-paren">(</span><em>x</em>, <em>i</em>, <em>array=None</em><span class="sig-paren">)</span></dt>
1832 1833 1834 1835
<dd><p>This function writes the given input variable to the specified position
indicating by the arrary index to an output LOD_TENSOR_ARRAY. If the
output LOD_TENSOR_ARRAY is not given(None), a new one will be created and
returned.</p>
1836 1837 1838 1839 1840 1841
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> (<em>Variable|list</em>) &#8211; The input tensor from which the data will be read.</li>
1842 1843 1844 1845 1846 1847 1848
<li><strong>i</strong> (<em>Variable|list</em>) &#8211; The index of the output LOD_TENSOR_ARRAY, pointing to
the position to which the input tensor will be
written.</li>
<li><strong>array</strong> (<em>Variable|list</em>) &#8211; The output LOD_TENSOR_ARRAY to which the input
tensor will be written. If this parameter is
NONE, a new LOD_TENSOR_ARRAY will be created and
returned.</li>
1849 1850 1851
</ul>
</td>
</tr>
1852
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The output LOD_TENSOR_ARRAY where the input tensor is written.</p>
1853 1854 1855 1856 1857 1858 1859 1860
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
1861 1862
</dd></dl>

1863 1864 1865
</div>
<div class="section" id="create-array">
<h2>create_array<a class="headerlink" href="#create-array" title="Permalink to this headline"></a></h2>
1866 1867
<dl class="function">
<dt>
1868
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">create_array</code><span class="sig-paren">(</span><em>dtype</em><span class="sig-paren">)</span></dt>
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
<dd><p>This function creates an array of type <span class="math">\(LOD_TENSOR_ARRAY\)</span> using the
LayerHelper.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>dtype</strong> (<em>int|float</em>) &#8211; The data type of the elements in the array.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The tensor variable storing the elements of data type.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">Variable</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">create_array</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
1888

1889 1890 1891
</div>
<div class="section" id="less-than">
<h2>less_than<a class="headerlink" href="#less-than" title="Permalink to this headline"></a></h2>
1892 1893
<dl class="function">
<dt>
1894
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">less_than</code><span class="sig-paren">(</span><em>x</em>, <em>y</em>, <em>cond=None</em>, <em>**ignored</em><span class="sig-paren">)</span></dt>
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
<dd><p><strong>Less than</strong></p>
<p>This layer returns the truth value of <span class="math">\(x &lt; y\)</span> elementwise.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> (<em>Variable</em>) &#8211; First operand of <em>less_than</em></li>
<li><strong>y</strong> (<em>Variable</em>) &#8211; Second operand of <em>less_than</em></li>
<li><strong>cond</strong> (<em>Variable|None</em>) &#8211; Optional output variable to store the result of <em>less_than</em></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the output of <em>less_than</em>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">less</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">less_than</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
1921

1922 1923 1924
</div>
<div class="section" id="array-read">
<h2>array_read<a class="headerlink" href="#array-read" title="Permalink to this headline"></a></h2>
1925 1926
<dl class="function">
<dt>
1927
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">array_read</code><span class="sig-paren">(</span><em>array</em>, <em>i</em><span class="sig-paren">)</span></dt>
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
<dd><p>This function performs the operation to read the data in as an
LOD_TENSOR_ARRAY.
:param array: The input tensor that will be written to an array.
:type array: Variable|list
:param i: The subscript index in tensor array, that points the</p>
<blockquote>
<div>place where data will be written to.</div></blockquote>
<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">Returns:</th><td class="field-body">The tensor type variable that has the data written to it.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">Variable</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
1946 1947
</dd></dl>

1948 1949 1950
</div>
<div class="section" id="shrink-memory">
<h2>shrink_memory<a class="headerlink" href="#shrink-memory" title="Permalink to this headline"></a></h2>
1951 1952
<dl class="function">
<dt>
1953
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">shrink_memory</code><span class="sig-paren">(</span><em>x</em>, <em>i</em>, <em>table</em><span class="sig-paren">)</span></dt>
1954 1955 1956 1957
<dd><p>This function creates an operator to shrink_rnn_memory using the RankTable
as mentioned in the input parameter.</p>
</dd></dl>

1958 1959 1960
</div>
<div class="section" id="array-length">
<h2>array_length<a class="headerlink" href="#array-length" title="Permalink to this headline"></a></h2>
1961 1962
<dl class="function">
<dt>
1963
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">array_length</code><span class="sig-paren">(</span><em>array</em><span class="sig-paren">)</span></dt>
1964
<dd><p>This function performs the operation to find the length of the input
1965
LOD_TENSOR_ARRAY.</p>
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>array</strong> (<em>LOD_TENSOR_ARRAY</em>) &#8211; The input array that will be used
to compute the length.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The length of the input LoDTensorArray.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">Variable</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
1980 1981
</dd></dl>

1982 1983 1984
</div>
<div class="section" id="conv2d-transpose">
<h2>conv2d_transpose<a class="headerlink" href="#conv2d-transpose" title="Permalink to this headline"></a></h2>
1985 1986
<dl class="function">
<dt>
1987
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">conv2d_transpose</code><span class="sig-paren">(</span><em>input</em>, <em>num_filters</em>, <em>output_size=None</em>, <em>filter_size=None</em>, <em>padding=None</em>, <em>stride=None</em>, <em>dilation=None</em>, <em>param_attr=None</em><span class="sig-paren">)</span></dt>
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
<dd><p>The transpose of conv2d layer.</p>
<p>This layer is also known as deconvolution 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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input image with [N, C, H, W] format.</li>
<li><strong>num_filters</strong> (<em>int</em>) &#8211; The number of filter. It is as same as the output
image channel.</li>
<li><strong>output_size</strong> (<em>int|tuple|None</em>) &#8211; The output image size. If output size is a
tuple, it must contain two integers, (image_H, image_W). This
parameter only works when filter_size is None.</li>
<li><strong>filter_size</strong> (<em>int|tuple|None</em>) &#8211; The filter size. If filter_size is a tuple,
it must contain two integers, (filter_size_H, filter_size_W).
Otherwise, the filter will be a square.  None if use output size to
calculate filter_size</li>
<li><strong>padding</strong> (<em>int|tuple</em>) &#8211; The padding size. If padding is a tuple, it must
contain two integers, (padding_H, padding_W). Otherwise, the
padding_H = padding_W = padding.</li>
<li><strong>stride</strong> (<em>int|tuple</em>) &#8211; The stride size. If stride is a tuple, it must
contain two integers, (stride_H, stride_W). Otherwise, the
stride_H = stride_W = stride.</li>
2011 2012 2013
<li><strong>dilation</strong> (<em>int|tuple</em>) &#8211; The dilation size. If dilation is a tuple, it must
contain two integers, (dilation_H, dilation_W). Otherwise, the
dilation_H = dilation_W = dilation.</li>
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
<li><strong>param_attr</strong> &#8211; Parameter Attribute.</li>
<li><strong>main_program</strong> (<em>Program</em>) &#8211; the main program</li>
<li><strong>startup_program</strong> (<em>Program</em>) &#8211; the startup program</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Output image.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

2030 2031 2032 2033 2034
</div>
<div class="section" id="sequence-expand">
<h2>sequence_expand<a class="headerlink" href="#sequence-expand" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
2035
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_expand</code><span class="sig-paren">(</span><em>x</em>, <em>y</em><span class="sig-paren">)</span></dt>
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 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 2089 2090 2091 2092 2093 2094 2095 2096
<dd><p>Sequence Expand Layer. This layer will expand the input variable <strong>x</strong>
according to LoD information of <strong>y</strong>. And the following examples will
explain how sequence_expand works:</p>
<div class="highlight-text"><div class="highlight"><pre><span></span>* Case 1
    x is a LoDTensor:
        x.lod = [[0,       2, 3],
                 [0, 1,    3, 4]]
        x.data = [a, b, c, d]
        x.dims = [4, 1]

    y is a LoDTensor:
        y.lod = [[0,    2,    4],
                 [0, 3, 6, 7, 8]]

    with condition len(y.lod[-1]) - 1 == x.dims[0]

    then output is a 2-level LoDTensor:
        out.lod = [[0,                2,    4],
                   [0,       3,       6, 7, 8]]
        out.data = [a, a, a, b, b, b, c, d]
        out.dims = [8, 1]

* Case 2
    x is a Tensor:
        x.data = [a, b, c]
        x.dims = [3, 1]

    y is a LoDTensor:
        y.lod = [[0, 2, 3, 6]]

    with condition len(y.lod[-1]) - 1 == x.dims[0]

    then output is a 1-level LoDTensor:
        out.lod = [[0,    2, 3,      6]]
        out.data = [a, a, b, c, c, c]
        out.dims = [6, 1]
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> (<em>Variable</em>) &#8211; The input variable which is a Tensor or LoDTensor.</li>
<li><strong>y</strong> (<em>Variable</em>) &#8211; The input variable which is a LoDTensor.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The expanded variable which is a LoDTensor.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">data</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">],</span>
                 <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;float32&#39;</span><span class="p">,</span> <span class="n">lod_level</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">layers</span><span class="o">.</span><span class="n">sequence_expand</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">)</span>
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="gru-unit">
<h2>gru_unit<a class="headerlink" href="#gru-unit" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">gru_unit</code><span class="sig-paren">(</span><em>input</em>, <em>hidden</em>, <em>size</em>, <em>weight=None</em>, <em>bias=None</em>, <em>activation='tanh'</em>, <em>gate_activation='sigmoid'</em><span class="sig-paren">)</span></dt>
<dd><p>GRU unit layer. The equation of a gru step is:</p>
<blockquote>
<div><div class="math">
2110
\[ \begin{align}\begin{aligned}u_t &amp; = actGate(xu_{t} + W_u h_{t-1} + b_u)\\r_t &amp; = actGate(xr_{t} + W_r h_{t-1} + b_r)\\m_t &amp; = actNode(xm_t + W_c dot(r_t, h_{t-1}) + b_m)\\h_t &amp; = dot((1-u_t), m_t) + dot(u_t, h_{t-1})\end{aligned}\end{align} \]</div>
2111 2112 2113
</div></blockquote>
<p>The inputs of gru unit includes <span class="math">\(z_t\)</span>, <span class="math">\(h_{t-1}\)</span>. In terms
of the equation above, the <span class="math">\(z_t\)</span> is split into 3 parts -
2114
<span class="math">\(xu_t\)</span>, <span class="math">\(xr_t\)</span> and <span class="math">\(xm_t\)</span>. This means that in order to
2115 2116
implement a full GRU unit operator for an input, a fully
connected layer has to be applied, such that <span class="math">\(z_t = W_{fc}x_t\)</span>.</p>
2117 2118 2119 2120 2121
<p>The terms <span class="math">\(u_t\)</span> and <span class="math">\(r_t\)</span> represent the update and reset gates
of the GRU cell. Unlike LSTM, GRU has one lesser gate. However, there is
an intermediate candidate hidden output, which is denoted by <span class="math">\(m_t\)</span>.
This layer has three outputs <span class="math">\(h_t\)</span>, <span class="math">\(dot(r_t, h_{t-1})\)</span>
and concatenation of <span class="math">\(u_t\)</span>, <span class="math">\(r_t\)</span> and <span class="math">\(m_t\)</span>.</p>
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The fc transformed input value of current step.</li>
<li><strong>hidden</strong> (<em>Variable</em>) &#8211; The hidden value of lstm unit from previous step.</li>
<li><strong>size</strong> (<em>integer</em>) &#8211; The input dimension value.</li>
<li><strong>weight</strong> (<em>ParamAttr</em>) &#8211; The weight parameters for gru unit. Default: None</li>
<li><strong>bias</strong> (<em>ParamAttr</em>) &#8211; The bias parameters for gru unit. Default: None</li>
<li><strong>activation</strong> (<em>string</em>) &#8211; The activation type for cell (actNode). Default: &#8216;tanh&#8217;</li>
<li><strong>gate_activation</strong> (<em>string</em>) &#8211; The activation type for gates (actGate). Default: &#8216;sigmoid&#8217;</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The hidden value, reset-hidden value and gate values.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">tuple</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># assuming we have x_t_data and prev_hidden of size=10</span>
<span class="n">x_t</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">x_t_data</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
<span class="n">hidden_val</span><span class="p">,</span> <span class="n">r_h_val</span><span class="p">,</span> <span class="n">gate_val</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">gru_unit</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">x_t</span><span class="p">,</span>
                                       <span class="n">hidden</span> <span class="o">=</span> <span class="n">prev_hidden</span><span class="p">)</span>
2150 2151 2152 2153
</pre></div>
</div>
</dd></dl>

2154 2155 2156 2157 2158 2159 2160 2161 2162
</div>
<div class="section" id="lstm-unit">
<h2>lstm_unit<a class="headerlink" href="#lstm-unit" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">lstm_unit</code><span class="sig-paren">(</span><em>x_t</em>, <em>hidden_t_prev</em>, <em>cell_t_prev</em>, <em>forget_bias=0.0</em>, <em>param_attr=None</em>, <em>bias_attr=None</em><span class="sig-paren">)</span></dt>
<dd><p>Lstm unit layer. The equation of a lstm step is:</p>
<blockquote>
<div><div class="math">
2163
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{x_i}x_{t} + W_{h_i}h_{t-1} + b_i)\\f_t &amp; = \sigma(W_{x_f}x_{t} + W_{h_f}h_{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} + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
2164
</div></blockquote>
2165 2166 2167 2168 2169 2170
<p>The inputs of lstm unit include <span class="math">\(x_t\)</span>, <span class="math">\(h_{t-1}\)</span> and
<span class="math">\(c_{t-1}\)</span>. The 2nd dimensions of <span class="math">\(h_{t-1}\)</span> and <span class="math">\(c_{t-1}\)</span>
should be same. The implementation separates the linear transformation and
non-linear transformation apart. Here, we take <span class="math">\(i_t\)</span> as an example.
The linear transformation is applied by calling a <cite>fc</cite> layer and the
equation is:</p>
2171 2172
<blockquote>
<div><div class="math">
2173
\[L_{i_t} = W_{x_i}x_{t} + W_{h_i}h_{t-1} + b_i\]</div>
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186
</div></blockquote>
<p>The non-linear transformation is applied by calling <cite>lstm_unit_op</cite> and the
equation is:</p>
<blockquote>
<div><div class="math">
\[i_t = \sigma(L_{i_t})\]</div>
</div></blockquote>
<p>This layer has two outputs including <span class="math">\(h_t\)</span> and <span class="math">\(o_t\)</span>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
2187 2188 2189 2190 2191 2192
<li><strong>x_t</strong> (<em>Variable</em>) &#8211; The input value of current step, a 2-D tensor with shape
M x N, M for batch size and N for input size.</li>
<li><strong>hidden_t_prev</strong> (<em>Variable</em>) &#8211; The hidden value of lstm unit, a 2-D tensor
with shape M x S, M for batch size and S for size of lstm unit.</li>
<li><strong>cell_t_prev</strong> (<em>Variable</em>) &#8211; The cell value of lstm unit, a 2-D tensor with
shape M x S, M for batch size and S for size of lstm unit.</li>
2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
<li><strong>forget_bias</strong> (<em>float</em>) &#8211; The forget bias of lstm unit.</li>
<li><strong>param_attr</strong> (<em>ParamAttr</em>) &#8211; The attributes of parameter weights, used to set
initializer, name etc.</li>
<li><strong>bias_attr</strong> (<em>ParamAttr</em>) &#8211; The attributes of bias weights, if not False,
bias weights will be created and be set to default value.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The hidden value and cell value of lstm unit.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">tuple</p>
</td>
</tr>
2207
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> &#8211; The ranks of <strong>x_t</strong>, <strong>hidden_t_prev</strong> and <strong>cell_t_prev</strong>                not be 2 or the 1st dimensions of <strong>x_t</strong>, <strong>hidden_t_prev</strong>                 and <strong>cell_t_prev</strong> not be the same or the 2nd dimensions of                 <strong>hidden_t_prev</strong> and <strong>cell_t_prev</strong> not be the same.</p>
2208 2209 2210 2211 2212 2213
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">x_t</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">x_t_data</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
2214
<span class="n">prev_hidden</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">prev_hidden_data</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
2215 2216 2217 2218 2219 2220 2221 2222
<span class="n">prev_cell</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</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">prev_cell_data</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
<span class="n">hidden_value</span><span class="p">,</span> <span class="n">cell_value</span> <span class="o">=</span> <span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">lstm_unit</span><span class="p">(</span><span class="n">x_t</span><span class="o">=</span><span class="n">x_t</span><span class="p">,</span>
                                       <span class="n">hidden_t_prev</span><span class="o">=</span><span class="n">prev_hidden</span><span class="p">,</span>
                                       <span class="n">cell_t_prev</span><span class="o">=</span><span class="n">prev_cell</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233
</div>
<div class="section" id="sequence-softmax">
<h2>sequence_softmax<a class="headerlink" href="#sequence-softmax" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sequence_softmax</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Sequence Softmax Operator.</p>
<p>SequenceSoftmaxOp computes the softmax activation among all time-steps for each
sequence. The dimension of each time-step should be 1. Thus, the shape of
input Tensor can be either [N, 1] or [N], where N is the sum of the length
of all sequences.</p>
2234 2235 2236 2237 2238 2239
<p>The algorithm works as follows:</p>
<blockquote>
<div>for i-th sequence in a mini-batch:</div></blockquote>
<p>$$
Out(X[lod[i]:lod[i+1]], :) = frac{exp(X[lod[i]:lod[i+1], :])} {sum(exp(X[lod[i]:lod[i+1], :]))}
$$</p>
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
<p>For example, for a mini-batch of 3 sequences with variable-length,
each containing 2, 3, 2 time-steps, the lod of which is [0, 2, 5, 7],
then softmax will be computed among X[0:2, :], X[2:5, :], X[5:7, :]
and N turns out to be 7.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; (LoDTensor) 1-D or 2-D input LoDTensor with the 2-nd dimension of length 1.
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">(LoDTensor) 1-D or 2-D output LoDTensor with the 2-nd dimension of length 1.</td>
</tr>
</tbody>
</table>
</dd></dl>

2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
</div>
<div class="section" id="reduce-sum">
<h2>reduce_sum<a class="headerlink" href="#reduce-sum" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reduce_sum</code><span class="sig-paren">(</span><em>input</em>, <em>dim=None</em>, <em>keep_dim=False</em><span class="sig-paren">)</span></dt>
<dd><p>Computes the sum of tensor elements over the given 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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input variable which is a Tensor or LoDTensor.</li>
<li><strong>dim</strong> (<em>int|None</em>) &#8211; The dimension along which the sum is performed. If
<code class="xref py py-attr docutils literal"><span class="pre">None</span></code>, sum all elements of <code class="xref py py-attr docutils literal"><span class="pre">input</span></code> and return a
Tensor variable with a single element, otherwise must be in the
range <span class="math">\([-rank(input), rank(input))\)</span>. If <span class="math">\(dim &lt; 0\)</span>,
the dimension to reduce is <span class="math">\(rank + dim\)</span>.</li>
<li><strong>keep_dim</strong> (<em>bool</em>) &#8211; Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension
than the <code class="xref py py-attr docutils literal"><span class="pre">input</span></code> unless <code class="xref py py-attr docutils literal"><span class="pre">keep_dim</span></code> is true.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The reduced Tensor variable.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># x is a Tensor variable with following elements:</span>
<span class="c1">#    [[0.2, 0.3, 0.5, 0.9]</span>
<span class="c1">#     [0.1, 0.2, 0.6, 0.7]]</span>
<span class="c1"># Each example is followed by the correspending output tensor.</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_sum</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>  <span class="c1"># [3.5]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>  <span class="c1"># [0.3, 0.5, 1.1, 1.6]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># [1.9, 1.6]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keep_dim</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>  <span class="c1"># [[1.9], [1.6]]</span>
</pre></div>
</div>
</dd></dl>

2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346
</div>
<div class="section" id="reduce-mean">
<h2>reduce_mean<a class="headerlink" href="#reduce-mean" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reduce_mean</code><span class="sig-paren">(</span><em>input</em>, <em>dim=None</em>, <em>keep_dim=False</em><span class="sig-paren">)</span></dt>
<dd><p>Computes the mean of tensor elements over the given 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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input variable which is a Tensor or LoDTensor.</li>
<li><strong>dim</strong> (<em>int|None</em>) &#8211; The dimension along which the mean is computed. If
<code class="xref py py-attr docutils literal"><span class="pre">None</span></code>, compute the mean over all elements of <code class="xref py py-attr docutils literal"><span class="pre">input</span></code>
and return a Tensor variable with a single element, otherwise
must be in the range <span class="math">\([-rank(input), rank(input))\)</span>. If
<span class="math">\(dim &lt; 0\)</span>, the dimension to reduce is <span class="math">\(rank + dim\)</span>.</li>
<li><strong>keep_dim</strong> (<em>bool</em>) &#8211; Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension
than the <code class="xref py py-attr docutils literal"><span class="pre">input</span></code> unless <code class="xref py py-attr docutils literal"><span class="pre">keep_dim</span></code> is true.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The reduced Tensor variable.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># x is a Tensor variable with following elements:</span>
<span class="c1">#    [[0.2, 0.3, 0.5, 0.9]</span>
<span class="c1">#     [0.1, 0.2, 0.6, 0.7]]</span>
<span class="c1"># Each example is followed by the correspending output tensor.</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>  <span class="c1"># [0.4375]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>  <span class="c1"># [0.15, 0.25, 0.55, 0.8]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># [0.475, 0.4]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_mean</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keep_dim</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>  <span class="c1"># [[0.475], [0.4]]</span>
</pre></div>
</div>
</dd></dl>

2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 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 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436
</div>
<div class="section" id="reduce-max">
<h2>reduce_max<a class="headerlink" href="#reduce-max" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reduce_max</code><span class="sig-paren">(</span><em>input</em>, <em>dim=None</em>, <em>keep_dim=False</em><span class="sig-paren">)</span></dt>
<dd><p>Computes the maximum of tensor elements over the given 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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input variable which is a Tensor or LoDTensor.</li>
<li><strong>dim</strong> (<em>int|None</em>) &#8211; The dimension along which the maximum is computed.
If <code class="xref py py-attr docutils literal"><span class="pre">None</span></code>, compute the maximum over all elements of
<code class="xref py py-attr docutils literal"><span class="pre">input</span></code> and return a Tensor variable with a single element,
otherwise must be in the range <span class="math">\([-rank(input), rank(input))\)</span>.
If <span class="math">\(dim &lt; 0\)</span>, the dimension to reduce is <span class="math">\(rank + dim\)</span>.</li>
<li><strong>keep_dim</strong> (<em>bool</em>) &#8211; Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension
than the <code class="xref py py-attr docutils literal"><span class="pre">input</span></code> unless <code class="xref py py-attr docutils literal"><span class="pre">keep_dim</span></code> is true.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The reduced Tensor variable.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># x is a Tensor variable with following elements:</span>
<span class="c1">#    [[0.2, 0.3, 0.5, 0.9]</span>
<span class="c1">#     [0.1, 0.2, 0.6, 0.7]]</span>
<span class="c1"># Each example is followed by the correspending output tensor.</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_max</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>  <span class="c1"># [0.9]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_max</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>  <span class="c1"># [0.2, 0.3, 0.6, 0.9]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_max</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># [0.9, 0.7]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_max</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keep_dim</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>  <span class="c1"># [[0.9], [0.7]]</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="reduce-min">
<h2>reduce_min<a class="headerlink" href="#reduce-min" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reduce_min</code><span class="sig-paren">(</span><em>input</em>, <em>dim=None</em>, <em>keep_dim=False</em><span class="sig-paren">)</span></dt>
<dd><p>Computes the minimum of tensor elements over the given 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">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>Variable</em>) &#8211; The input variable which is a Tensor or LoDTensor.</li>
<li><strong>dim</strong> (<em>int|None</em>) &#8211; The dimension along which the minimum is computed.
If <code class="xref py py-attr docutils literal"><span class="pre">None</span></code>, compute the minimum over all elements of
<code class="xref py py-attr docutils literal"><span class="pre">input</span></code> and return a Tensor variable with a single element,
otherwise must be in the range <span class="math">\([-rank(input), rank(input))\)</span>.
If <span class="math">\(dim &lt; 0\)</span>, the dimension to reduce is <span class="math">\(rank + dim\)</span>.</li>
<li><strong>keep_dim</strong> (<em>bool</em>) &#8211; Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension
than the <code class="xref py py-attr docutils literal"><span class="pre">input</span></code> unless <code class="xref py py-attr docutils literal"><span class="pre">keep_dim</span></code> is true.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The reduced Tensor variable.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Variable</p>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># x is a Tensor variable with following elements:</span>
<span class="c1">#    [[0.2, 0.3, 0.5, 0.9]</span>
<span class="c1">#     [0.1, 0.2, 0.6, 0.7]]</span>
<span class="c1"># Each example is followed by the correspending output tensor.</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_min</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>  <span class="c1"># [0.1]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_min</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>  <span class="c1"># [0.1, 0.2, 0.5, 0.7]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_min</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># [0.2, 0.1]</span>
<span class="n">fluid</span><span class="o">.</span><span class="n">layers</span><span class="o">.</span><span class="n">reduce_min</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">keep_dim</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>  <span class="c1"># [[0.2], [0.1]]</span>
</pre></div>
</div>
</dd></dl>

2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 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 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 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 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067
</div>
<div class="section" id="logsigmoid">
<h2>logsigmoid<a class="headerlink" href="#logsigmoid" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">logsigmoid</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Logsigmoid Activation Operator</p>
<p>$$out = log frac{1}{1 + e^{-x}}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of LogSigmoid operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of LogSigmoid operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="exp">
<h2>exp<a class="headerlink" href="#exp" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">exp</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Exp Activation Operator.</p>
<p>$out = e^x$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Exp operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Exp operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="relu">
<h2>relu<a class="headerlink" href="#relu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">relu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Relu Activation Operator.</p>
<p>$out = max(x, 0)$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Relu operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Relu operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="tanh">
<h2>tanh<a class="headerlink" href="#tanh" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">tanh</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Tanh Activation Operator.</p>
<p>$$out = frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Tanh operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Tanh operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="tanh-shrink">
<h2>tanh_shrink<a class="headerlink" href="#tanh-shrink" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">tanh_shrink</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>TanhShrink Activation Operator.</p>
<p>$$out = x - frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of TanhShrink operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of TanhShrink operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="softshrink">
<h2>softshrink<a class="headerlink" href="#softshrink" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">softshrink</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Softshrink Activation Operator.</p>
<p>$$
out = begin{cases}</p>
<blockquote>
<div>x - lambda, text{if } x &gt; lambda \
x + lambda, text{if } x &lt; -lambda \
0,  text{otherwise}
end{cases}</div></blockquote>
<p>$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of Softshrink operator
Duplicable: False  Optional: False</li>
<li><strong>lambda</strong> (<em>FLOAT</em>) &#8211; non-negative offset</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of Softshrink operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="sqrt">
<h2>sqrt<a class="headerlink" href="#sqrt" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">sqrt</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Sqrt Activation Operator.</p>
<p>$out = sqrt{x}$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Sqrt operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Sqrt operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="abs">
<h2>abs<a class="headerlink" href="#abs" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">abs</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Abs Activation Operator.</p>
<p>$out = <a href="#id1"><span class="problematic" id="id2">|</span></a>x|$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Abs operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Abs operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="ceil">
<h2>ceil<a class="headerlink" href="#ceil" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">ceil</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Ceil Activation Operator.</p>
<p>$out = ceil(x)$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Ceil operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Ceil operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="floor">
<h2>floor<a class="headerlink" href="#floor" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">floor</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Floor Activation Operator.</p>
<p>$out = floor(x)$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Floor operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Floor operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="round">
<h2>round<a class="headerlink" href="#round" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">round</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Round Activation Operator.</p>
<p>$out = [x]$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Round operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Round operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="reciprocal">
<h2>reciprocal<a class="headerlink" href="#reciprocal" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">reciprocal</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Reciprocal Activation Operator.</p>
<p>$$out = frac{1}{x}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Reciprocal operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Reciprocal operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="log">
<h2>log<a class="headerlink" href="#log" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">log</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Log Activation Operator.</p>
<p>$out = ln(x)$</p>
<p>Natural logarithm of x.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Log operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Log operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="square">
<h2>square<a class="headerlink" href="#square" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">square</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Square Activation Operator.</p>
<p>$out = x^2$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Square operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Square operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="softplus">
<h2>softplus<a class="headerlink" href="#softplus" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">softplus</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Softplus Activation Operator.</p>
<p>$out = ln(1 + e^{x})$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Softplus operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Softplus operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="softsign">
<h2>softsign<a class="headerlink" href="#softsign" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">softsign</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Softsign Activation Operator.</p>
<p>$$out = frac{x}{1 + <a href="#id3"><span class="problematic" id="id4">|x|</span></a>}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>x</strong> &#8211; Input of Softsign operator
Duplicable: False  Optional: False</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Output of Softsign operator</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="brelu">
<h2>brelu<a class="headerlink" href="#brelu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">brelu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>BRelu Activation Operator.</p>
<p>$out = max(min(x, t_{min}), t_{max})$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of BRelu operator
Duplicable: False  Optional: False</li>
<li><strong>t_min</strong> (<em>FLOAT</em>) &#8211; The min marginal value of BRelu</li>
<li><strong>t_max</strong> (<em>FLOAT</em>) &#8211; The max marginal value of BRelu</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of BRelu operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="leaky-relu">
<h2>leaky_relu<a class="headerlink" href="#leaky-relu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">leaky_relu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>LeakyRelu Activation Operator.</p>
<p>$out = max(x, alpha * x)$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of LeakyRelu operator
Duplicable: False  Optional: False</li>
<li><strong>alpha</strong> (<em>FLOAT</em>) &#8211; The small negative slope</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of LeakyRelu operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="soft-relu">
<h2>soft_relu<a class="headerlink" href="#soft-relu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">soft_relu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>SoftRelu Activation Operator.</p>
<p>$out = ln(1 + exp(max(min(x, threshold), threshold))$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of SoftRelu operator
Duplicable: False  Optional: False</li>
<li><strong>threshold</strong> (<em>FLOAT</em>) &#8211; The threshold value of SoftRelu</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of SoftRelu operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="elu">
<h2>elu<a class="headerlink" href="#elu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">elu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>ELU Activation Operator.</p>
<p>Applies the following element-wise computation on the input according to
<a class="reference external" href="https://arxiv.org/abs/1511.07289">https://arxiv.org/abs/1511.07289</a>.</p>
<p>$out = max(0, x) + min(0, alpha * (e^x - 1))$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of ELU operator
Duplicable: False  Optional: False</li>
<li><strong>alpha</strong> (<em>FLOAT</em>) &#8211; The alpha value of ELU</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of ELU operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="relu6">
<h2>relu6<a class="headerlink" href="#relu6" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">relu6</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Relu6 Activation Operator.</p>
<p>$out = min(max(0, x), 6)$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of Relu6 operator
Duplicable: False  Optional: False</li>
<li><strong>threshold</strong> (<em>FLOAT</em>) &#8211; The threshold value of Relu6</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of Relu6 operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="pow">
<h2>pow<a class="headerlink" href="#pow" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">pow</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Pow Activation Operator.</p>
<p>$out = x^{factor}$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of Pow operator
Duplicable: False  Optional: False</li>
<li><strong>factor</strong> (<em>FLOAT</em>) &#8211; The exponential factor of Pow</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of Pow operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="hard-shrink">
<h2>hard_shrink<a class="headerlink" href="#hard-shrink" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">hard_shrink</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>HardShrink Activation Operator.</p>
<p>$$
out = begin{cases}</p>
<blockquote>
<div>x, text{if } x &gt; lambda \
x, text{if } x &lt; -lambda \
0,  text{otherwise}
end{cases}</div></blockquote>
<p>$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of HardShrink operator
Duplicable: False  Optional: False</li>
<li><strong>threshold</strong> (<em>FLOAT</em>) &#8211; The value of threshold for HardShrink</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of HardShrink operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="thresholded-relu">
<h2>thresholded_relu<a class="headerlink" href="#thresholded-relu" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">thresholded_relu</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>ThresholdedRelu Activation Operator.</p>
<p>$$
out = begin{cases}</p>
<blockquote>
<div>x, text{if } x &gt; threshold \
0,  text{otherwise}
end{cases}</div></blockquote>
<p>$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of ThresholdedRelu operator
Duplicable: False  Optional: False</li>
<li><strong>threshold</strong> (<em>FLOAT</em>) &#8211; The threshold location of activation</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of ThresholdedRelu operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="hard-sigmoid">
<h2>hard_sigmoid<a class="headerlink" href="#hard-sigmoid" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">hard_sigmoid</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>HardSigmoid Activation Operator.</p>
<p>Segment-wise linear approximation of sigmoid(<a class="reference external" href="https://arxiv.org/abs/1603.00391">https://arxiv.org/abs/1603.00391</a>),
which is much faster than sigmoid.</p>
<p>$out = max(0, min(1, slope * x + shift))$</p>
<p>The slope should be positive. The offset can be either positive or negative.
The default slope and shift are set according to the above reference.
It is recommended to use the defaults for this activation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of HardSigmoid operator
Duplicable: False  Optional: False</li>
<li><strong>slope</strong> (<em>FLOAT</em>) &#8211; Slope for linear approximation of sigmoid</li>
<li><strong>offset</strong> (<em>FLOAT</em>) &#8211; Offset for linear approximation of sigmoid</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of HardSigmoid operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="swish">
<h2>swish<a class="headerlink" href="#swish" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">swish</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Swish Activation Operator.</p>
<p>$$out = frac{x}{1 + e^{- beta x}}$$</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>x</strong> &#8211; Input of Swish operator
Duplicable: False  Optional: False</li>
<li><strong>beta</strong> (<em>FLOAT</em>) &#8211; Constant beta of swish operator</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Output of Swish operator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="data_feeder.html" class="btn btn-neutral float-right" title="DataFeeder" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="../fluid.html" class="btn btn-neutral" title="Fluid" 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',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
       
  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  
  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script>
  <script src="../../../_static/js/paddle_doc_init.js"></script> 

</body>
</html>