layers.html 79.8 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 175 176 177 178 179 180
<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>
</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>
181
<li class="toctree-l2"><a class="reference internal" href="../../../mobile/cross_compiling_for_ios_en.html">PaddlePaddle Compiling Guide for iOS</a></li>
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
<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>
222 223
<dl class="function">
<dt>
224
<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>
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
<dd><p><strong>Fully Connected Layer</strong></p>
<p>This layer accepts multiple inputs and applies a linear transformation to each input.
If activation type is provided, the corresponding activation function is applied to the
output of the linear transformation. For each input <span class="math">\(X\)</span>, the equation is:</p>
<div class="math">
\[Out = Act(WX + b)\]</div>
<p>In the above equation:</p>
<blockquote>
<div><ul class="simple">
<li><span class="math">\(X\)</span>: Input value, a tensor with rank at least 2.</li>
<li><span class="math">\(W\)</span>: Weight, a 2-D tensor with shape [M, N].</li>
<li><span class="math">\(b\)</span>: Bias, a 2-D tensor with shape [M, 1].</li>
<li><span class="math">\(Act\)</span>: Activation function.</li>
<li><span class="math">\(Out\)</span>: Output value, same shape with <span class="math">\(X\)</span>.</li>
</ul>
</div></blockquote>
<p>All the input variables are passed in as local variables to the LayerHelper
constructor.</p>
243 244 245 246
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
247 248 249 250 251 252 253 254
<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; Input tensors. Each tensor has a rank of atleast 2</li>
<li><strong>size</strong> (<em>int</em>) &#8211; Output size</li>
<li><strong>num_flatten_dims</strong> (<em>int</em>) &#8211; Number of columns in input</li>
<li><strong>param_attr</strong> (<em>ParamAttr|list</em>) &#8211; The parameters/weights to the FC Layer</li>
<li><strong>bias_attr</strong> (<em>ParamAttr|list</em>) &#8211; Bias parameter for the FC layer</li>
<li><strong>act</strong> (<em>str</em>) &#8211; Activation type</li>
<li><strong>name</strong> (<em>str</em>) &#8211; Name/alias of the function</li>
255 256 257
</ul>
</td>
</tr>
258 259 260 261 262 263 264 265 266
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The tensor variable storing the transformation 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 rank of input tensor is less than 2.</p>
</td>
</tr>
267 268
</tbody>
</table>
269 270 271 272 273
<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">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>
274 275
</dd></dl>

276 277 278
</div>
<div class="section" id="embedding">
<h2>embedding<a class="headerlink" href="#embedding" title="Permalink to this headline"></a></h2>
279 280
<dl class="function">
<dt>
281
<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>
282 283 284 285 286
<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>
287 288 289 290
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
291 292 293 294 295 296
<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>
<li><strong>size</strong> (<em>int</em>) &#8211; Output size</li>
<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>
297 298 299
</ul>
</td>
</tr>
300 301 302 303 304 305
<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>
306 307
</tbody>
</table>
308 309 310 311 312
<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;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="mi">16</span><span class="p">)</span>
</pre></div>
</div>
313 314
</dd></dl>

315 316 317
</div>
<div class="section" id="dynamic-lstm">
<h2>dynamic_lstm<a class="headerlink" href="#dynamic-lstm" title="Permalink to this headline"></a></h2>
318 319
<dl class="function">
<dt>
320
<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>
321 322
<dd></dd></dl>

323 324 325
</div>
<div class="section" id="data">
<h2>data<a class="headerlink" href="#data" title="Permalink to this headline"></a></h2>
326 327
<dl class="function">
<dt>
328
<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>
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
<dd><p>Data 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 last simple">
<li><strong>name</strong> &#8211; The name/alias of the function</li>
<li><strong>shape</strong> &#8211; Tuple declaring the shape.</li>
<li><strong>append_batch_size</strong> &#8211; Whether or not to append the data as a batch.</li>
<li><strong>dtype</strong> &#8211; The type of data : float32, float_16, int etc</li>
<li><strong>type</strong> &#8211; The output type. By default it is LOD_TENSOR.</li>
<li><strong>lod_level</strong> (<em>int</em>) &#8211; The LoD Level. 0 means the input data is not a sequence.</li>
<li><strong>main_program</strong> &#8211; Name of the main program that calls this</li>
<li><strong>startup_program</strong> &#8211; Name of the startup program</li>
<li><strong>stop_gradient</strong> &#8211; A boolean that mentions whether gradient should flow.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>This function takes in 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>
</dd></dl>

357 358 359
</div>
<div class="section" id="mean">
<h2>mean<a class="headerlink" href="#mean" title="Permalink to this headline"></a></h2>
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
<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>

378 379 380
</div>
<div class="section" id="mul">
<h2>mul<a class="headerlink" href="#mul" title="Permalink to this headline"></a></h2>
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
<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>
<p>This operator is used to perform matrix multiplication for input X and Y.</p>
<p>The equation is:</p>
<blockquote>
<div>$$Out = X * Y$$</div></blockquote>
<p>Both the input <cite>X</cite> and <cite>Y</cite> can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD information with input <cite>X</cite>.</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; The first input of mul op
Duplicable: False  Optional: False</li>
<li><strong>y</strong> &#8211; The second input of mul op
Duplicable: False  Optional: False</li>
<li><strong>x_num_col_dims</strong> (<em>INT</em>) &#8211; (int, default 1) mul_op can take tensors with more than two dimensions as input <cite>X</cite>,
in that case, tensors will be reshaped to a matrix. The matrix&#8217;s first
dimension(column length) will be the product of tensor&#8217;s last
<cite>num_col_dims</cite> dimensions, and the matrix&#8217;s second dimension(row length)
will be the product of tensor&#8217;s first <cite>rank - num_col_dims</cite> dimensions.</li>
<li><strong>y_num_col_dims</strong> (<em>INT</em>) &#8211; (int, default 1) mul_op can take tensors with more than two dimensions as input <cite>Y</cite>,
in that case, tensors will be reshaped to a matrix. Just like input <cite>X</cite>.</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 mul op</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

417 418 419
</div>
<div class="section" id="elementwise-add">
<h2>elementwise_add<a class="headerlink" href="#elementwise-add" title="Permalink to this headline"></a></h2>
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
<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>
<p>$Out = X + Y$</p>
<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>
<p class="rubric">example</p>
<p>shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5)
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0</p>
<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>
<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>

462 463 464
</div>
<div class="section" id="elementwise-div">
<h2>elementwise_div<a class="headerlink" href="#elementwise-div" title="Permalink to this headline"></a></h2>
465 466 467 468 469 470 471 472 473 474 475 476 477 478 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
<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>
<p>$Out = X / Y$</p>
<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>
<p class="rubric">example</p>
<p>shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5)
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0</p>
<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>
<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>

507 508 509
</div>
<div class="section" id="dropout">
<h2>dropout<a class="headerlink" href="#dropout" title="Permalink to this headline"></a></h2>
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
<dl class="function">
<dt>
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">dropout</code><span class="sig-paren">(</span><em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Dropout Operator.</p>
<p>Dropout refers to randomly dropping out units in a nerual network. It is a
regularization technique for reducing overfitting by preventing neuron
co-adaption during training. The dropout operator randomly set (according to
the given dropout probability) the outputs of some units to zero, while others
are set equal to their corresponding inputs.</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; The input of dropout op.
Duplicable: False  Optional: False</li>
<li><strong>dropout_prob</strong> (<em>FLOAT</em>) &#8211; Probability of setting units to zero.</li>
<li><strong>is_test</strong> (<em>BOOLEAN</em>) &#8211; True if in test phase.</li>
<li><strong>seed</strong> (<em>INT</em>) &#8211; Dropout random seed.</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 dropout op.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

539 540 541
</div>
<div class="section" id="reshape">
<h2>reshape<a class="headerlink" href="#reshape" title="Permalink to this headline"></a></h2>
542 543 544 545 546 547 548 549 550 551
<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
552
the tensor X into a 2-D tensor:</p>
553
<blockquote>
554
<div>[[1, 2, 3, 4]]</div></blockquote>
555 556 557
<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>
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
<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>

576 577 578
</div>
<div class="section" id="sigmoid">
<h2>sigmoid<a class="headerlink" href="#sigmoid" title="Permalink to this headline"></a></h2>
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
<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>
<p>$$y = 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 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>

597 598 599
</div>
<div class="section" id="scale">
<h2>scale<a class="headerlink" href="#scale" title="Permalink to this headline"></a></h2>
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
<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>

623 624 625
</div>
<div class="section" id="id1">
<h2>reshape<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
626 627 628 629 630 631 632 633 634 635
<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
636
the tensor X into a 2-D tensor:</p>
637
<blockquote>
638
<div>[[1, 2, 3, 4]]</div></blockquote>
639 640 641
<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>
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
<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>

660 661 662
</div>
<div class="section" id="transpose">
<h2>transpose<a class="headerlink" href="#transpose" title="Permalink to this headline"></a></h2>
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
<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.
The op functions similar to how numpy.transpose works in python.
For example:</p>
<blockquote>
<div><p>&gt;&gt; input = numpy.arange(6).reshape((2,3))
&gt;&gt; input
array([[0, 1, 2],</p>
<blockquote>
<div>[3, 4, 5]])</div></blockquote>
<p>&gt;&gt; axis = [1, 0]
&gt;&gt; output = input.transpose(axis)
&gt;&gt; output
array([[0, 3],</p>
<blockquote>
<div><dl class="docutils">
<dt>[1, 4],</dt>
<dd>[2, 5]])</dd>
</dl>
</div></blockquote>
</div></blockquote>
<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>

707 708 709 710 711 712
</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>
713 714
<dl class="function">
<dt>
715
<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>
716 717 718 719
<dd><p>This function takes in the input with input_dtype
and casts it to the output_dtype as the output.</p>
</dd></dl>

720 721 722
</div>
<div class="section" id="concat">
<h2>concat<a class="headerlink" href="#concat" title="Permalink to this headline"></a></h2>
723 724
<dl class="function">
<dt>
725
<code class="descclassname">paddle.v2.fluid.layers.</code><code class="descname">concat</code><span class="sig-paren">(</span><em>input</em>, <em>axis</em><span class="sig-paren">)</span></dt>
726 727 728 729
<dd><p>This function concats the input along the axis mentioned
and returns that as the output.</p>
</dd></dl>

730 731 732
</div>
<div class="section" id="sums">
<h2>sums<a class="headerlink" href="#sums" title="Permalink to this headline"></a></h2>
733 734
<dl class="function">
<dt>
735
<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>
736 737 738 739
<dd><p>This function takes in the input and performs the sum operation on it
and returns that as the output.</p>
</dd></dl>

740 741 742
</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>
743 744
<dl class="function">
<dt>
745
<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>
746 747
<dd></dd></dl>

748 749 750
</div>
<div class="section" id="assign">
<h2>assign<a class="headerlink" href="#assign" title="Permalink to this headline"></a></h2>
751 752
<dl class="function">
<dt>
753
<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>
754 755 756 757 758
<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>
759 760 761 762
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
763 764 765 766 767 768
<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>
<li><strong>size</strong> (<em>int</em>) &#8211; Output size</li>
<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>
769 770 771
</ul>
</td>
</tr>
772 773 774 775 776 777
<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>
778 779
</tbody>
</table>
780 781 782 783 784
<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;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="mi">16</span><span class="p">)</span>
</pre></div>
</div>
785 786
</dd></dl>

787 788 789
</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>
790 791
<dl class="function">
<dt>
792
<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>
793 794
<dd></dd></dl>

795 796 797
</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>
798 799
<dl class="function">
<dt>
800
<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>
801 802
<dd></dd></dl>

803 804 805
</div>
<div class="section" id="cos-sim">
<h2>cos_sim<a class="headerlink" href="#cos-sim" title="Permalink to this headline"></a></h2>
806 807 808 809 810 811 812
<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>

813 814 815
</div>
<div class="section" id="cross-entropy">
<h2>cross_entropy<a class="headerlink" href="#cross-entropy" title="Permalink to this headline"></a></h2>
816 817 818 819 820 821
<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>
<dd><p>This function computes cross_entropy using the input and label.</p>
</dd></dl>

822 823 824
</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>
825 826 827 828 829 830 831
<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>
<dd><p>This functions returns the squared error cost using the input and label.
The output is appending the op to do the above.</p>
</dd></dl>

832 833 834
</div>
<div class="section" id="accuracy">
<h2>accuracy<a class="headerlink" href="#accuracy" title="Permalink to this headline"></a></h2>
835 836 837 838 839 840 841
<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>

842 843 844
</div>
<div class="section" id="sequence-conv">
<h2>sequence_conv<a class="headerlink" href="#sequence-conv" title="Permalink to this headline"></a></h2>
845 846
<dl class="function">
<dt>
847
<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>
848 849 850 851 852
<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>

853 854 855
</div>
<div class="section" id="conv2d">
<h2>conv2d<a class="headerlink" href="#conv2d" title="Permalink to this headline"></a></h2>
856 857
<dl class="function">
<dt>
858
<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>, <em>name=None</em><span class="sig-paren">)</span></dt>
859 860 861 862 863 864 865
<dd><p>This function creates the op for a 2-dimensional Convolution.
This is performed using the parameters of filters(size, dimensionality etc)
, stride and other configurations for a Convolution operation.
This funciton can also append an activation on top of the
conv-2d output, if mentioned in the input parameters.</p>
</dd></dl>

866 867 868
</div>
<div class="section" id="sequence-pool">
<h2>sequence_pool<a class="headerlink" href="#sequence-pool" title="Permalink to this headline"></a></h2>
869 870 871 872 873 874 875 876
<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.
This is applied on top of the input using pool_type mentioned
in the parameters.</p>
</dd></dl>

877 878 879
</div>
<div class="section" id="pool2d">
<h2>pool2d<a class="headerlink" href="#pool2d" title="Permalink to this headline"></a></h2>
880 881
<dl class="function">
<dt>
882
<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>
883 884 885 886
<dd><p>This function adds the operator for pooling in 2 dimensions, using the
pooling configurations mentioned in input parameters.</p>
</dd></dl>

887 888 889
</div>
<div class="section" id="batch-norm">
<h2>batch_norm<a class="headerlink" href="#batch-norm" title="Permalink to this headline"></a></h2>
890 891
<dl class="function">
<dt>
892
<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>
893 894 895 896
<dd><p>This function helps create an operator to implement
the BatchNorm layer using the configurations from the input parameters.</p>
</dd></dl>

897 898 899
</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>
900 901
<dl class="function">
<dt>
902
<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>
903 904
<dd></dd></dl>

905 906 907
</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>
908 909
<dl class="function">
<dt>
910
<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>
911 912 913 914
<dd><p>This function creates an operator for creating a LOD_RANK_TABLE
using the input x.</p>
</dd></dl>

915 916 917
</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>
918 919
<dl class="function">
<dt>
920
<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>
921 922 923 924
<dd><p>This function creates an operator to calculate the length of
max seqence through input rank_table(should be a lod_rank_table)</p>
</dd></dl>

925 926 927
</div>
<div class="section" id="topk">
<h2>topk<a class="headerlink" href="#topk" title="Permalink to this headline"></a></h2>
928 929
<dl class="function">
<dt>
930
<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>
931 932
<dd></dd></dl>

933 934 935
</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>
936 937
<dl class="function">
<dt>
938
<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>
939 940 941 942
<dd><p>This function creates an operator to convert an LOD_Tensor to
an array.</p>
</dd></dl>

943 944 945
</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>
946 947
<dl class="function">
<dt>
948
<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>
949 950 951 952
<dd><p>This function creates an operator to convert an array to a
LOD_Tensor.</p>
</dd></dl>

953 954 955
</div>
<div class="section" id="fill-constant">
<h2>fill_constant<a class="headerlink" href="#fill-constant" title="Permalink to this headline"></a></h2>
956 957
<dl class="function">
<dt>
958
<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>out=None</em><span class="sig-paren">)</span></dt>
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
<dd><p><strong>fill_constant</strong></p>
<p>This function creates a tensor of specified <em>shape</em> and
<em>dtype</em>, and initializes this with a constant supplied in <em>value</em>.</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>
<li><strong>value</strong> (<em>float</em>) &#8211; Constant value to initialize the output tensor</li>
<li><strong>out</strong> (<em>Variable</em>) &#8211; Output Variable to initialize</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">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>
987 988
</dd></dl>

989 990 991
</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>
992 993
<dl class="function">
<dt>
994
<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>
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>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>
<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>
</dd></dl>
1027

1028 1029 1030
</div>
<div class="section" id="ones">
<h2>ones<a class="headerlink" href="#ones" title="Permalink to this headline"></a></h2>
1031 1032
<dl class="function">
<dt>
1033
<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>
1034 1035 1036 1037
<dd><p>This function performs the same function as fill_constant() declared above
with the constant value being 1.0.</p>
</dd></dl>

1038 1039 1040
</div>
<div class="section" id="zeros">
<h2>zeros<a class="headerlink" href="#zeros" title="Permalink to this headline"></a></h2>
1041 1042
<dl class="function">
<dt>
1043
<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>
1044 1045 1046 1047
<dd><p>This function performs the same function as fill_constant() declared above
with the constant value being 0.0.</p>
</dd></dl>

1048 1049 1050
</div>
<div class="section" id="increment">
<h2>increment<a class="headerlink" href="#increment" title="Permalink to this headline"></a></h2>
1051 1052
<dl class="function">
<dt>
1053
<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>
1054 1055 1056 1057 1058
<dd><p>This function creates an operator to increment each value in the input
<cite>x</cite> by an amount: <cite>value</cite> as mentioned in the input parameter. This
operation is performed in-place by default.</p>
</dd></dl>

1059 1060 1061
</div>
<div class="section" id="array-write">
<h2>array_write<a class="headerlink" href="#array-write" title="Permalink to this headline"></a></h2>
1062 1063
<dl class="function">
<dt>
1064
<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>
1065 1066 1067 1068
<dd><p>This function creates an operator to write the data out as a
LOD_TENSOR_ARRAY.</p>
</dd></dl>

1069 1070 1071
</div>
<div class="section" id="create-array">
<h2>create_array<a class="headerlink" href="#create-array" title="Permalink to this headline"></a></h2>
1072 1073
<dl class="function">
<dt>
1074
<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>
1075 1076
<dd></dd></dl>

1077 1078 1079
</div>
<div class="section" id="less-than">
<h2>less_than<a class="headerlink" href="#less-than" title="Permalink to this headline"></a></h2>
1080 1081
<dl class="function">
<dt>
1082
<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>
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
<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>
1109

1110 1111 1112
</div>
<div class="section" id="array-read">
<h2>array_read<a class="headerlink" href="#array-read" title="Permalink to this headline"></a></h2>
1113 1114
<dl class="function">
<dt>
1115
<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>
1116 1117 1118 1119
<dd><p>This function creates an operator to read the data in as a
LOD_TENSOR_ARRAY.</p>
</dd></dl>

1120 1121 1122
</div>
<div class="section" id="shrink-memory">
<h2>shrink_memory<a class="headerlink" href="#shrink-memory" title="Permalink to this headline"></a></h2>
1123 1124
<dl class="function">
<dt>
1125
<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>
1126 1127 1128 1129
<dd><p>This function creates an operator to shrink_rnn_memory using the RankTable
as mentioned in the input parameter.</p>
</dd></dl>

1130 1131 1132
</div>
<div class="section" id="array-length">
<h2>array_length<a class="headerlink" href="#array-length" title="Permalink to this headline"></a></h2>
1133 1134
<dl class="function">
<dt>
1135
<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>
1136 1137 1138 1139
<dd><p>This function creates an operator to find the length of the
LOD_TENSOR_ARRAY.</p>
</dd></dl>

1140 1141 1142
</div>
<div class="section" id="conv2d-transpose">
<h2>conv2d_transpose<a class="headerlink" href="#conv2d-transpose" title="Permalink to this headline"></a></h2>
1143 1144
<dl class="function">
<dt>
1145
<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>
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
<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>
1169 1170 1171
<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>
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
<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>

1188 1189 1190 1191 1192
</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>
1193
<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>
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
<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>
</pre></div>
</div>
</dd></dl>

1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 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
</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">
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{x_i}x_{t} + W_{h_i}h_{t-1} + W_{c_i}c_{t-1} + b_i)\\f_t &amp; = \sigma(W_{x_f}x_{t} + W_{h_f}h_{t-1} + W_{c_f}c_{t-1} + b_f)\\c_t &amp; = f_tc_{t-1} + i_t tanh (W_{x_c}x_t+W_{h_c}h_{t-1} + b_c)\\o_t &amp; = \sigma(W_{x_o}x_{t} + W_{h_o}h_{t-1} + W_{c_o}c_t + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
</div></blockquote>
<p>The inputs of lstm unit includes <span class="math">\(x_t\)</span>, <span class="math">\(h_{t-1}\)</span> and
<span class="math">\(c_{t-1}\)</span>. 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>
<blockquote>
<div><div class="math">
\[L_{i_t} = W_{x_i}x_{t} + W_{h_i}h_{t-1} + W_{c_i}c_{t-1} + b_i\]</div>
</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">
<li><strong>x_t</strong> (<em>Variable</em>) &#8211; The input value of current step.</li>
<li><strong>hidden_t_prev</strong> (<em>Variable</em>) &#8211; The hidden value of lstm unit.</li>
<li><strong>cell_t_prev</strong> (<em>Variable</em>) &#8211; The cell value of lstm unit.</li>
<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>
<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.</p>
</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>
<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">20</span><span class="p">)</span>
<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>

1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
</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>
1335 1336 1337 1338 1339 1340
<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>
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
<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>

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 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
</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>

1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 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
</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>