layers.html 155.4 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
9
    <title>Base &#8212; PaddlePaddle  documentation</title>
Y
Yu Yang 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    
    <link rel="stylesheet" href="../../../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="PaddlePaddle  documentation" href="../../../index.html" />
    <link rel="up" title="Layers" href="layers_index.html" />
Y
Yu Yang 已提交
29
    <link rel="next" title="Activations" href="activations_index.html" />
Y
Yu Yang 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42
    <link rel="prev" title="Layers" href="layers_index.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
Y
Yu Yang 已提交
43
          <a href="activations_index.html" title="Activations"
Y
Yu Yang 已提交
44 45 46 47
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="layers_index.html" title="Layers"
             accesskey="P">previous</a> |</li>
48 49 50 51
        <li class="nav-item nav-item-0"><a href="../../../index.html">PaddlePaddle  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >User Interface</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Model Config Interface</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="layers_index.html" accesskey="U">Layers</a> &#187;</li> 
Y
Yu Yang 已提交
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
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="base">
<h1>Base<a class="headerlink" href="#base" title="Permalink to this headline"></a></h1>
<div class="section" id="layertype">
<h2>LayerType<a class="headerlink" href="#layertype" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt>
<em class="property">class </em><code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">LayerType</code></dt>
<dd><p>Layer type enumerations.</p>
<dl class="staticmethod">
<dt>
<em class="property">static </em><code class="descname">is_layer_type</code><span class="sig-paren">(</span><em>type_name</em><span class="sig-paren">)</span></dt>
<dd><p>If type_name is a layer type.</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>type_name</strong> (<em>basestring</em>) &#8211; layer type name. Because layer type enumerations are
strings.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True if is a layer_type</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="layeroutput">
<h2>LayerOutput<a class="headerlink" href="#layeroutput" title="Permalink to this headline"></a></h2>
<dl class="class">
<dt>
94
<em class="property">class </em><code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">LayerOutput</code><span class="sig-paren">(</span><em>name</em>, <em>layer_type</em>, <em>parents=None</em>, <em>activation=None</em>, <em>num_filters=None</em>, <em>img_norm_type=None</em>, <em>size=None</em>, <em>outputs=None</em>, <em>reverse=None</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
<dd><p>LayerOutput is output for layer function. It is used internally by several
reasons.</p>
<ul>
<li><p class="first">Check layer connection make sense.</p>
<blockquote>
<div><ul class="simple">
<li>FC(Softmax) =&gt; Cost(MSE Error) is not good for example.</li>
</ul>
</div></blockquote>
</li>
<li><p class="first">Tracking layer connection.</p>
</li>
<li><p class="first">Pass to layer methods as input.</p>
</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer output name.</li>
<li><strong>layer_type</strong> (<em>basestring</em>) &#8211; Current Layer Type. One of LayerType enumeration.</li>
<li><strong>activation</strong> (<em>BaseActivation.</em>) &#8211; Layer Activation.</li>
118
<li><strong>parents</strong> (<em>list|tuple|collection.Sequence</em>) &#8211; Layer&#8217;s parents.</li>
Y
Yu Yang 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="data-layer">
<h1>Data layer<a class="headerlink" href="#data-layer" title="Permalink to this headline"></a></h1>
<div class="section" id="id1">
<h2>data_layer<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">data_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Define DataLayer For NeuralNetwork.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">data_layer</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;input&quot;</span><span class="p">,</span>
                  <span class="n">size</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Name of this data layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; Size of this data layer.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; Extra Layer Attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
152
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="fully-connected-layers">
<h1>Fully Connected Layers<a class="headerlink" href="#fully-connected-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="fc-layer">
<h2>fc_layer<a class="headerlink" href="#fc-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">fc_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
171
<dd><p>Helper for declare fully connected layer.</p>
Y
Yu Yang 已提交
172 173 174 175 176 177 178 179
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">fc</span> <span class="o">=</span> <span class="n">fc_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
              <span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span>
              <span class="n">act</span><span class="o">=</span><span class="n">LinearActivation</span><span class="p">(),</span>
              <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
<p>which is equal to:</p>
Y
Yu Yang 已提交
180
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">)</span> <span class="k">as</span> <span class="n">fc</span><span class="p">:</span>
Y
Yu Yang 已提交
181 182 183 184 185 186 187
    <span class="n">fc</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
Y
Yu Yang 已提交
188 189 190 191 192 193 194
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
<li><strong>input</strong> (<em>LayerOutput|list|tuple</em>) &#8211; The input layer. Could be a list/tuple of input layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The layer dimension.</li>
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type. Default is tanh.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; The Parameter Attribute|list.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|Any</em>) &#8211; The Bias Attribute. If no bias, then pass False or
Y
Yu Yang 已提交
195
something not type of ParameterAttribute. None will get a
Y
Yu Yang 已提交
196 197 198 199
default Bias.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra Layer config.</li>
</ul>
</td>
Y
Yu Yang 已提交
200
</tr>
Y
Yu Yang 已提交
201
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
202
</td>
Y
Yu Yang 已提交
203
</tr>
Y
Yu Yang 已提交
204 205
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
Y
Yu Yang 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="selective-fc-layer">
<h2>selective_fc_layer<a class="headerlink" href="#selective-fc-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">selective_fc_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Selectived fully connected layer. Different from fc_layer, the output
of this layer maybe sparse. It requires an additional input to indicate
several selected columns for output. If the selected columns is not
specified, selective_fc_layer acts exactly like fc_layer.</p>
<p>The simple usage is:</p>
222
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sel_fc</span> <span class="o">=</span> <span class="n">selective_fc_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">act</span><span class="o">=</span><span class="n">TanhActivation</span><span class="p">())</span>
Y
Yu Yang 已提交
223 224 225 226 227 228 229 230 231
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
<li><strong>input</strong> (<em>LayerOutput|list|tuple</em>) &#8211; The input layer.</li>
232 233
<li><strong>select</strong> (<em>LayerOutput</em>) &#8211; The select layer. The output of select layer should be a
sparse binary matrix, and treat as the mask of selective fc.</li>
Y
Yu Yang 已提交
234
<li><strong>size</strong> (<em>int</em>) &#8211; The layer dimension.</li>
Y
Yu Yang 已提交
235
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type. Default is tanh.</li>
Y
Yu Yang 已提交
236 237 238 239 240 241 242 243
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; The Parameter Attribute.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|Any</em>) &#8211; The Bias Attribute. If no bias, then pass False or
something not type of ParameterAttribute. None will get a
default Bias.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra Layer config.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
244
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="conv-layers">
<h1>Conv Layers<a class="headerlink" href="#conv-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="conv-operator">
<h2>conv_operator<a class="headerlink" href="#conv-operator" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
262
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">conv_operator</code><span class="sig-paren">(</span><em>img</em>, <em>filter</em>, <em>filter_size</em>, <em>num_filters</em>, <em>num_channel=None</em>, <em>stride=1</em>, <em>padding=0</em>, <em>filter_size_y=None</em>, <em>stride_y=None</em>, <em>padding_y=None</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
263 264 265 266 267
<dd><p>Different from img_conv_layer, conv_op is an Operator, which can be used
in mixed_layer. And conv_op takes two inputs to perform convolution.
The first input is the image and the second is filter kernel. It only
support GPU mode.</p>
<p>The example usage is:</p>
268 269
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">op</span> <span class="o">=</span> <span class="n">conv_operator</span><span class="p">(</span><span class="n">img</span><span class="o">=</span><span class="n">input1</span><span class="p">,</span>
                   <span class="nb">filter</span><span class="o">=</span><span class="n">input2</span><span class="p">,</span>
270
                   <span class="n">filter_size</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
Y
Yu Yang 已提交
271 272 273 274 275 276 277 278 279
                   <span class="n">num_filters</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span>
                   <span class="n">num_channels</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
280 281
<li><strong>img</strong> (<em>LayerOutput</em>) &#8211; input image</li>
<li><strong>filter</strong> (<em>LayerOutput</em>) &#8211; input filter</li>
Y
Yu Yang 已提交
282
<li><strong>filter_size</strong> (<em>int</em>) &#8211; The x dimension of a filter kernel.</li>
Y
Yu Yang 已提交
283 284 285
<li><strong>filter_size_y</strong> (<em>int</em>) &#8211; The y dimension of a filter kernel. Since
PaddlePaddle now supports rectangular filters,
the filter&#8217;s shape can be (filter_size, filter_size_y).</li>
286
<li><strong>num_filters</strong> (<em>int</em>) &#8211; channel of output data.</li>
Y
Yu Yang 已提交
287 288 289
<li><strong>num_channel</strong> (<em>int</em>) &#8211; channel of input data.</li>
<li><strong>stride</strong> (<em>int</em>) &#8211; The x dimension of the stride.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The y dimension of the stride.</li>
Y
Yu Yang 已提交
290 291 292 293 294
<li><strong>padding</strong> (<em>int</em>) &#8211; The x dimension of padding.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The y dimension of padding.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
295
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A ConvOperator Object.</p>
Y
Yu Yang 已提交
296 297
</td>
</tr>
Y
Yu Yang 已提交
298
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">ConvOperator</p>
Y
Yu Yang 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="conv-shift-layer">
<h2>conv_shift_layer<a class="headerlink" href="#conv-shift-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">conv_shift_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><dl class="docutils">
<dt>This layer performs cyclic convolution for two input. For example:</dt>
<dd><ul class="first last simple">
<li>a[in]: contains M elements.</li>
<li>b[in]: contains N elements (N should be odd).</li>
<li>c[out]: contains M elements.</li>
</ul>
</dd>
</dl>
<div class="math">
\[c[i] = \sum_{j=-(N-1)/2}^{(N-1)/2}a_{i+j} * b_{j}\]</div>
<dl class="docutils">
<dt>In this formular:</dt>
<dd><ul class="first last simple">
325 326 327 328
<li>a&#8217;s index is computed modulo M. When it is negative, then get item from
the right side (which is the end of array) to the left.</li>
<li>b&#8217;s index is computed modulo N. When it is negative, then get item from
the right size (which is the end of array) to the left.</li>
Y
Yu Yang 已提交
329 330 331 332
</ul>
</dd>
</dl>
<p>The example usage is:</p>
333
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">conv_shift</span> <span class="o">=</span> <span class="n">conv_shift_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">,</span> <span class="n">layer2</span><span class="p">])</span>
Y
Yu Yang 已提交
334 335 336 337 338 339 340 341
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name</li>
342 343
<li><strong>a</strong> (<em>LayerOutput</em>) &#8211; Input layer a.</li>
<li><strong>b</strong> (<em>LayerOutput</em>) &#8211; input layer b</li>
Y
Yu Yang 已提交
344 345 346
</ul>
</td>
</tr>
Y
Yu Yang 已提交
347
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="img-conv-layer">
<h2>img_conv_layer<a class="headerlink" href="#img-conv-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">img_conv_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Convolution layer for image. Paddle only support square input currently and
thus input image&#8217;s width equals height.</p>
<p>The details of convolution layer, please refer UFLDL&#8217;s <a class="reference external" href="http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/">convolution</a> .</p>
<p>The num_channel means input image&#8217;s channel number. It may be 1 or 3 when
input is raw pixels of image(mono or RGB), or it may be the previous layer&#8217;s
num_filters * num_group.</p>
Y
Yu Yang 已提交
369 370 371
<p>There are several group of filter in PaddlePaddle implementation.
Each group will process some channel of the inputs. For example, if an input
num_channel = 256, group = 4, num_filter=32, the PaddlePaddle will create
Y
Yu Yang 已提交
372
32*4 = 128 filters to process inputs. The channels will be split into 4
Y
Yu Yang 已提交
373 374
pieces. First 256/4 = 64 channels will process by first 32 filters. The
rest channels will be processed by rest group of filters.</p>
Y
Yu Yang 已提交
375 376 377 378 379 380 381
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Layer Input.</li>
382 383 384
<li><strong>filter_size</strong> (<em>int|tuple|list</em>) &#8211; The x dimension of a filter kernel. Or input a tuple for
two image dimension.</li>
<li><strong>filter_size_y</strong> (<em>int|None</em>) &#8211; The y dimension of a filter kernel. Since PaddlePaddle
Y
Yu Yang 已提交
385 386
currently supports rectangular filters, the filter&#8217;s
shape will be (filter_size, filter_size_y).</li>
Y
Yu Yang 已提交
387
<li><strong>num_filters</strong> &#8211; Each filter group&#8217;s number of filter</li>
Y
Yu Yang 已提交
388
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation type. Default is tanh</li>
Y
Yu Yang 已提交
389
<li><strong>groups</strong> (<em>int</em>) &#8211; Group size of filters.</li>
390 391
<li><strong>stride</strong> (<em>int|tuple|list</em>) &#8211; The x dimension of the stride. Or input a tuple for two image
dimension.</li>
Y
Yu Yang 已提交
392
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The y dimension of the stride.</li>
393 394
<li><strong>padding</strong> (<em>int|tuple|list</em>) &#8211; The x dimension of the padding. Or input a tuple for two
image dimension</li>
Y
Yu Yang 已提交
395 396 397 398 399 400 401 402 403 404 405
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The y dimension of the padding.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|False</em>) &#8211; Convolution bias attribute. None means default bias.
False means no bias.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; number of input channels. If None will be set
automatically from previous output.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Convolution param attribute. None means default attribute</li>
<li><strong>shared_biases</strong> (<em>bool</em>) &#8211; Is biases will be shared between filters or not.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Layer Extra Attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
406
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419 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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="context-projection">
<h2>context_projection<a class="headerlink" href="#context-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">context_projection</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Context Projection.</p>
<p>It just simply reorganizes input sequence, combines &#8220;context_len&#8221; sequence
to one context from context_start. &#8220;context_start&#8221; will be set to
-(context_len - 1) / 2 by default. If context position out of sequence
length, padding will be filled as zero if padding_attr = False, otherwise
it is trainable.</p>
<p>For example, origin sequence is [A B C D E F G], context len is 3, then
after context projection and not set padding_attr, sequence will
be [ 0AB ABC BCD CDE DEF EFG FG0 ].</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input Sequence.</li>
<li><strong>context_len</strong> (<em>int</em>) &#8211; context length.</li>
<li><strong>context_start</strong> (<em>int</em>) &#8211; context start position. Default is
-(context_len - 1)/2</li>
<li><strong>padding_attr</strong> (<em>bool|ParameterAttribute</em>) &#8211; Padding Parameter Attribute. If false, it means padding
always be zero. Otherwise Padding is learnable, and
parameter attribute is set by this parameter.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Projection</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">Projection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="image-pooling-layer">
<h1>Image Pooling Layer<a class="headerlink" href="#image-pooling-layer" title="Permalink to this headline"></a></h1>
<div class="section" id="img-pool-layer">
<h2>img_pool_layer<a class="headerlink" href="#img-pool-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">img_pool_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Image pooling Layer.</p>
<p>The details of pooling layer, please refer ufldl&#8217;s <a class="reference external" href="http://ufldl.stanford.edu/tutorial/supervised/Pooling/">pooling</a> .</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>padding</strong> (<em>int</em>) &#8211; pooling padding</li>
<li><strong>name</strong> (<em>basestring.</em>) &#8211; name of pooling layer</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; layer&#8217;s input</li>
<li><strong>pool_size</strong> (<em>int</em>) &#8211; pooling size</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; number of input channel.</li>
Y
Yu Yang 已提交
477
<li><strong>pool_type</strong> (<em>BasePoolingType</em>) &#8211; pooling type. MaxPooling or AveragePooling. Default is
Y
Yu Yang 已提交
478 479 480 481 482 483 484
MaxPooling.</li>
<li><strong>stride</strong> (<em>int</em>) &#8211; stride of pooling.</li>
<li><strong>start</strong> (<em>int</em>) &#8211; start position of pooling operation.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
485 486 487 488
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
Y
Yu Yang 已提交
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="norm-layer">
<h1>Norm Layer<a class="headerlink" href="#norm-layer" title="Permalink to this headline"></a></h1>
<div class="section" id="img-cmrnorm-layer">
<h2>img_cmrnorm_layer<a class="headerlink" href="#img-cmrnorm-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">img_cmrnorm_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
504
<dd><p>Response normalization across feature maps.
Y
Yu Yang 已提交
505 506
The details please refer to
<a class="reference external" href="http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf">Alex&#8217;s paper</a>.</p>
Y
Yu Yang 已提交
507 508 509 510 511
<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">
Y
Yu Yang 已提交
512
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; layer name.</li>
Y
Yu Yang 已提交
513
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; layer&#8217;s input.</li>
514
<li><strong>size</strong> (<em>int</em>) &#8211; Normalize in number of <span class="math">\(size\)</span> feature maps.</li>
Y
Yu Yang 已提交
515 516
<li><strong>scale</strong> (<em>float</em>) &#8211; The hyper-parameter.</li>
<li><strong>power</strong> (<em>float</em>) &#8211; The hyper-parameter.</li>
Y
Yu Yang 已提交
517 518 519 520 521 522
<li><strong>num_channels</strong> &#8211; input layer&#8217;s filers number or channels. If
num_channels is None, it will be set automatically.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer Attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
523
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="batch-norm-layer">
<h2>batch_norm_layer<a class="headerlink" href="#batch-norm-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">batch_norm_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Batch Normalization Layer. The notation of this layer as follow.</p>
<p><span class="math">\(x\)</span> is the input features over a mini-batch.</p>
<div class="math">
\[\begin{split}\mu_{\beta} &amp;\gets \frac{1}{m} \sum_{i=1}^{m} x_i \qquad &amp;//\
\ mini-batch\ mean \\
\sigma_{\beta}^{2} &amp;\gets \frac{1}{m} \sum_{i=1}^{m}(x_i - \
\mu_{\beta})^2 \qquad &amp;//\ mini-batch\ variance \\
\hat{x_i} &amp;\gets \frac{x_i - \mu_\beta} {\sqrt{\
\sigma_{\beta}^{2} + \epsilon}} \qquad &amp;//\ normalize \\
y_i &amp;\gets \gamma \hat{x_i} + \beta \qquad &amp;//\ scale\ and\ shift\end{split}\]</div>
<p>The details of batch normalization please refer to this
<a class="reference external" href="http://arxiv.org/abs/1502.03167">paper</a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; batch normalization input. Better be linear activation.
Because there is an activation inside batch_normalization.</li>
559
<li><strong>batch_norm_type</strong> (<em>None|string, None or &quot;batch_norm&quot; or &quot;cudnn_batch_norm&quot;</em>) &#8211; We have batch_norm and cudnn_batch_norm. batch_norm
Y
Yu Yang 已提交
560 561 562 563 564 565 566 567
supports both CPU and GPU. cudnn_batch_norm requires
cuDNN version greater or equal to v4 (&gt;=v4). But
cudnn_batch_norm is faster and needs less memory
than batch_norm. By default (None), we will
automaticly select cudnn_batch_norm for GPU and
batch_norm for CPU. Otherwise, select batch norm
type based on the specified type. If you use cudnn_batch_norm,
we suggested you use latest version, such as v5.1.</li>
Y
Yu Yang 已提交
568
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type. Better be relu. Because batch
Y
Yu Yang 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
normalization will normalize input near zero.</li>
<li><strong>num_channels</strong> (<em>int</em>) &#8211; num of image channels or previous layer&#8217;s number of
filters. None will automatically get from layer&#8217;s
input.</li>
<li><strong>bias_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; <span class="math">\(\beta\)</span>, better be zero when initialize. So the
initial_std=0, initial_mean=1 is best practice.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; <span class="math">\(\gamma\)</span>, better be one when initialize. So the
initial_std=0, initial_mean=1 is best practice.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer Attribute.</li>
<li><strong>use_global_stats</strong> (<em>bool|None.</em>) &#8211; whether use moving mean/variance statistics
during testing peroid. If None or True,
it will use moving mean/variance statistics during
testing. If False, it will use the mean
and variance of current batch of test data for
testing.</li>
<li><strong>moving_average_fraction</strong> (<em>float.</em>) &#8211; Factor used in the moving average
computation, referred to as facotr,
<span class="math">\(runningMean = newMean*(1-factor)
+ runningMean*factor\)</span></li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
591
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="sum-to-one-norm-layer">
<h2>sum_to_one_norm_layer<a class="headerlink" href="#sum-to-one-norm-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">sum_to_one_norm_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for sum-to-one normalization,
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[out[i] = \frac {in[i]} {\sum_{k=1}^N in[k]}\]</div>
<p>where <span class="math">\(in\)</span> is a (batchSize x dataDim) input vector,
and <span class="math">\(out\)</span> is a (batchSize x dataDim) output vector.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sum_to_one_norm</span> <span class="o">=</span> <span class="n">sum_to_one_norm_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
628
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="recurrent-layers">
<h1>Recurrent Layers<a class="headerlink" href="#recurrent-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="recurrent-layer">
<h2>recurrent_layer<a class="headerlink" href="#recurrent-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">recurrent_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
647 648 649 650 651 652 653 654 655 656
<dd><p>Simple recurrent unit layer. It is just a fully connect layer through both
time and neural network.</p>
<p>For each sequence [start, end] it performs the following computation:</p>
<div class="math">
\[\begin{split}out_{i} = act(in_{i})     \      \      \text{for} \ i = start \\
out_{i} = act(in_{i} + out_{i-1} * W) \ \ \text{for} \ start &lt; i &lt;= end\end{split}\]</div>
<p>If reversed is true, the order is reversed:</p>
<div class="math">
\[\begin{split}out_{i} = act(in_{i})           \    \   \text{for} \ i = end  \\
out_{i} = act(in_{i} + out_{i+1} * W) \ \ \text{for} \ start &lt;= i &lt; end\end{split}\]</div>
Y
Yu Yang 已提交
657 658 659 660 661
<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">
662 663 664 665 666 667
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input Layer</li>
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; activation.</li>
<li><strong>bias_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; bias attribute.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; parameter attribute.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; name of the layer</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Layer Attribute.</li>
Y
Yu Yang 已提交
668 669 670
</ul>
</td>
</tr>
671 672 673 674
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
Y
Yu Yang 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="lstmemory">
<h2>lstmemory<a class="headerlink" href="#lstmemory" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">lstmemory</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Long Short-term Memory Cell.</p>
<p>The memory cell was implemented as follow equations.</p>
<div class="math">
690
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{xi}x_{t} + W_{hi}h_{t-1} + W_{ci}c_{t-1} + b_i)\\f_t &amp; = \sigma(W_{xf}x_{t} + W_{hf}h_{t-1} + W_{cf}c_{t-1} + b_f)\\c_t &amp; = f_tc_{t-1} + i_t tanh (W_{xc}x_t+W_{hc}h_{t-1} + b_c)\\o_t &amp; = \sigma(W_{xo}x_{t} + W_{ho}h_{t-1} + W_{co}c_t + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
Y
Yu Yang 已提交
691
<p>NOTE: In PaddlePaddle&#8217;s implementation, the multiplications
Y
Yu Yang 已提交
692
<span class="math">\(W_{xi}x_{t}\)</span> , <span class="math">\(W_{xf}x_{t}\)</span>,
Y
Yu Yang 已提交
693 694 695 696 697
<span class="math">\(W_{xc}x_t\)</span>, <span class="math">\(W_{xo}x_{t}\)</span> are not done in the lstmemory layer,
so an additional mixed_layer with full_matrix_projection or a fc_layer must
be included in the configuration file to complete the input-to-hidden
mappings before lstmemory is called.</p>
<p>NOTE: This is a low level user interface. You can use network.simple_lstm
Y
Yu Yang 已提交
698
to config a simple plain lstm layer.</p>
Y
Yu Yang 已提交
699 700 701
<p>Please refer to <strong>Generating Sequences With Recurrent Neural Networks</strong> for
more details about LSTM.</p>
<p><a class="reference external" href="http://arxiv.org/abs/1308.0850">Link</a> goes as below.</p>
Y
Yu Yang 已提交
702 703 704 705 706 707 708 709
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; The lstmemory layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; input layer name.</li>
<li><strong>reverse</strong> (<em>bool</em>) &#8211; is sequence process reversed or not.</li>
Y
Yu Yang 已提交
710 711 712
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; activation type, TanhActivation by default. <span class="math">\(h_t\)</span></li>
<li><strong>gate_act</strong> (<em>BaseActivation</em>) &#8211; gate activation type, SigmoidActivation by default.</li>
<li><strong>state_act</strong> (<em>BaseActivation</em>) &#8211; state activation type, TanhActivation by default.</li>
Y
Yu Yang 已提交
713 714 715 716 717 718 719
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Bias attribute. None means default bias. False means no
bias.</li>
<li><strong>param_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Parameter Attribute.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra Layer attribute</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
720
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="lstm-step-layer">
<h2>lstm_step_layer<a class="headerlink" href="#lstm-step-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">lstm_step_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>LSTM Step Layer. It used in recurrent_group. The lstm equations are shown
as follow.</p>
<div class="math">
739
\[ \begin{align}\begin{aligned}i_t &amp; = \sigma(W_{xi}x_{t} + W_{hi}h_{t-1} + W_{ci}c_{t-1} + b_i)\\f_t &amp; = \sigma(W_{xf}x_{t} + W_{hf}h_{t-1} + W_{cf}c_{t-1} + b_f)\\c_t &amp; = f_tc_{t-1} + i_t tanh (W_{xc}x_t+W_{hc}h_{t-1} + b_c)\\o_t &amp; = \sigma(W_{xo}x_{t} + W_{ho}h_{t-1} + W_{co}c_t + b_o)\\h_t &amp; = o_t tanh(c_t)\end{aligned}\end{align} \]</div>
Y
Yu Yang 已提交
740
<p>The input of lstm step is <span class="math">\(Wx_t + Wh_{t-1}\)</span>, and user should use
Y
Yu Yang 已提交
741 742 743 744
<code class="code docutils literal"><span class="pre">mixed_layer</span></code> and <code class="code docutils literal"><span class="pre">full_matrix_projection</span></code> to calculate these
input vector.</p>
<p>The state of lstm step is <span class="math">\(c_{t-1}\)</span>. And lstm step layer will do</p>
<div class="math">
745
\[ \begin{align}\begin{aligned}i_t = \sigma(input + W_{ci}c_{t-1} + b_i)\\...\end{aligned}\end{align} \]</div>
Y
Yu Yang 已提交
746 747 748 749 750 751 752 753 754 755 756 757 758 759
<p>This layer contains two outputs. Default output is <span class="math">\(h_t\)</span>. The other
output is <span class="math">\(o_t\)</span>, which name is &#8216;state&#8217; and can use
<code class="code docutils literal"><span class="pre">get_output_layer</span></code> to extract this output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer&#8217;s name.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; Layer&#8217;s size. NOTE: lstm layer&#8217;s size, should be equal as
<code class="code docutils literal"><span class="pre">input.size/4</span></code>, and should be equal as
<code class="code docutils literal"><span class="pre">state.size</span></code>.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; input layer. <span class="math">\(Wx_t + Wh_{t-1}\)</span></li>
<li><strong>state</strong> (<em>LayerOutput</em>) &#8211; State Layer. <span class="math">\(c_{t-1}\)</span></li>
Y
Yu Yang 已提交
760 761
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation type. Default is tanh</li>
<li><strong>gate_act</strong> (<em>BaseActivation</em>) &#8211; Gate Activation Type. Default is sigmoid, and should
Y
Yu Yang 已提交
762
be sigmoid only.</li>
Y
Yu Yang 已提交
763
<li><strong>state_act</strong> (<em>BaseActivation</em>) &#8211; State Activation Type. Default is sigmoid, and should
Y
Yu Yang 已提交
764 765 766 767 768 769
be sigmoid only.</li>
<li><strong>bias_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Bias Attribute.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; layer&#8217;s extra attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
770
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="grumemory">
<h2>grumemory<a class="headerlink" href="#grumemory" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">grumemory</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Gate Recurrent Unit Layer.</p>
<p>The memory cell was implemented as follow equations.</p>
<p>1. update gate <span class="math">\(z\)</span>: defines how much of the previous memory to
keep around or the unit updates its activations. The update gate
is computed by:</p>
<div class="math">
\[z_t = \sigma(W_{z}x_{t} + U_{z}h_{t-1} + b_z)\]</div>
<p>2. reset gate <span class="math">\(r\)</span>: determines how to combine the new input with the
previous memory. The reset gate is computed similarly to the update gate:</p>
<div class="math">
\[r_t = \sigma(W_{r}x_{t} + U_{r}h_{t-1} + b_r)\]</div>
Y
Yu Yang 已提交
797 798
<p>3. The candidate activation <span class="math">\(\tilde{h_t}\)</span> is computed similarly to
that of the traditional recurrent unit:</p>
Y
Yu Yang 已提交
799 800
<div class="math">
\[{\tilde{h_t}} = tanh(W x_{t} + U (r_{t} \odot h_{t-1}) + b)\]</div>
Y
Yu Yang 已提交
801 802 803
<p>4. The hidden activation <span class="math">\(h_t\)</span> of the GRU at time t is a linear
interpolation between the previous activation <span class="math">\(h_{t-1}\)</span> and the
candidate activation <span class="math">\(\tilde{h_t}\)</span>:</p>
Y
Yu Yang 已提交
804 805
<div class="math">
\[h_t = (1 - z_t) h_{t-1} + z_t {\tilde{h_t}}\]</div>
Y
Yu Yang 已提交
806
<p>NOTE: In PaddlePaddle&#8217;s implementation, the multiplication operations
Y
Yu Yang 已提交
807
<span class="math">\(W_{r}x_{t}\)</span>, <span class="math">\(W_{z}x_{t}\)</span> and <span class="math">\(W x_t\)</span> are not computed in
Y
Yu Yang 已提交
808 809 810 811 812
gate_recurrent layer. Consequently, an additional mixed_layer with
full_matrix_projection or a fc_layer must be included before grumemory
is called.</p>
<p>More details can be found by referring to <a class="reference external" href="https://arxiv.org/abs/1412.3555">Empirical Evaluation of Gated
Recurrent Neural Networks on Sequence Modeling.</a></p>
Y
Yu Yang 已提交
813 814 815 816 817 818 819 820 821 822 823
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">gru</span> <span class="o">=</span> <span class="n">grumemory</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The gru layer name.</li>
<li><strong>input</strong> (<em>LayerOutput.</em>) &#8211; input layer.</li>
824
<li><strong>reverse</strong> (<em>bool</em>) &#8211; Whether sequence process is reversed or not.</li>
Y
Yu Yang 已提交
825
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; activation type, TanhActivation by default. This activation
Y
Yu Yang 已提交
826
affects the <span class="math">\({\tilde{h_t}}\)</span>.</li>
Y
Yu Yang 已提交
827
<li><strong>gate_act</strong> (<em>BaseActivation</em>) &#8211; gate activation type, SigmoidActivation by default.
Y
Yu Yang 已提交
828 829 830 831 832 833
This activation affects the <span class="math">\(z_t\)</span> and <span class="math">\(r_t\)</span>. It is the
<span class="math">\(\sigma\)</span> in the above formula.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Bias attribute. None means default bias. False means no
bias.</li>
<li><strong>param_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Parameter Attribute.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra Layer attribute</li>
834 835
<li><strong>size</strong> (<em>None</em>) &#8211; Stub parameter of size, but actually not used. If set this size
will get a warning.</li>
Y
Yu Yang 已提交
836 837 838
</ul>
</td>
</tr>
Y
Yu Yang 已提交
839
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="gru-step-layer">
<h2>gru_step_layer<a class="headerlink" href="#gru-step-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">gru_step_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; </li>
<li><strong>output_mem</strong> &#8211; </li>
<li><strong>size</strong> &#8211; </li>
<li><strong>act</strong> &#8211; </li>
<li><strong>name</strong> &#8211; </li>
<li><strong>gate_act</strong> &#8211; </li>
<li><strong>bias_attr</strong> &#8211; </li>
<li><strong>layer_attr</strong> &#8211; </li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
871
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="recurrent-layer-group">
<h1>Recurrent Layer Group<a class="headerlink" href="#recurrent-layer-group" title="Permalink to this headline"></a></h1>
Y
Yu Yang 已提交
885 886 887 888 889
<div class="section" id="recurrent-group">
<h2>recurrent_group<a class="headerlink" href="#recurrent-group" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">recurrent_group</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
890 891 892 893 894
<dd><p>Recurrent layer group is an extremely flexible recurrent unit in
PaddlePaddle. As long as the user defines the calculation done within a
time step, PaddlePaddle will iterate such a recurrent calculation over
sequence input. This is extremely usefull for attention based model, or
Neural Turning Machine like models.</p>
Y
Yu Yang 已提交
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
<p>The basic usage (time steps) is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="nb">input</span><span class="p">):</span>
    <span class="n">output</span> <span class="o">=</span> <span class="n">fc_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                      <span class="n">size</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span>
                      <span class="n">act</span><span class="o">=</span><span class="n">LinearActivation</span><span class="p">(),</span>
                      <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">output</span>

<span class="n">group</span> <span class="o">=</span> <span class="n">recurrent_group</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                        <span class="n">step</span><span class="o">=</span><span class="n">step</span><span class="p">)</span>
</pre></div>
</div>
<p>You can see following configs for further usages:</p>
<ul class="simple">
<li>time steps: lstmemory_group, paddle/gserver/tests/sequence_layer_group.conf,                   demo/seqToseq/seqToseq_net.py</li>
<li>sequence steps: paddle/gserver/tests/sequence_nest_layer_group.conf</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>step</strong> (<em>callable</em>) &#8211; <p>recurrent one time step function.The input of this function is
input of the group. The return of this function will be
recurrent group&#8217;s return value.</p>
<p>The recurrent group scatter a sequence into time steps. And
for each time step, will invoke step function, and return
a time step result. Then gather each time step of output into
layer group&#8217;s output.</p>
</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; recurrent_group&#8217;s name.</li>
<li><strong>input</strong> (<em>LayerOutput|StaticInput|SubsequenceInput|list|tuple</em>) &#8211; <p>Input links array.</p>
<p>LayerOutput will be scattered into time steps.
SubsequenceInput will be scattered into sequence steps.
StaticInput will be imported to each time step, and doesn&#8217;t change
through time. It&#8217;s a mechanism to access layer outside step function.</p>
</li>
<li><strong>reverse</strong> (<em>bool</em>) &#8211; If reverse is set true, the recurrent unit will process the
input sequence in a reverse order.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
937
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="beam-search">
<h2>beam_search<a class="headerlink" href="#beam-search" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">beam_search</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Beam search is a heuristic search algorithm used in sequence generation.
It explores a graph by expanding the most promising nodes in a limited set
to maintain tractability.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">rnn_step</span><span class="p">(</span><span class="nb">input</span><span class="p">):</span>
    <span class="n">last_time_step_output</span> <span class="o">=</span> <span class="n">memory</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;rnn&#39;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">)</span>
959
    <span class="k">with</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">512</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;rnn&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">simple_rnn</span><span class="p">:</span>
Y
Yu Yang 已提交
960 961 962 963 964 965
        <span class="n">simple_rnn</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
        <span class="n">simple_rnn</span> <span class="o">+=</span> <span class="n">last_time_step_output</span>
    <span class="k">return</span> <span class="n">simple_rnn</span>

<span class="n">beam_gen</span> <span class="o">=</span> <span class="n">beam_search</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;decoder&quot;</span><span class="p">,</span>
                       <span class="n">step</span><span class="o">=</span><span class="n">rnn_step</span><span class="p">,</span>
966
                       <span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">StaticInput</span><span class="p">(</span><span class="n">encoder_last</span><span class="p">)],</span>
Y
Yu Yang 已提交
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
                       <span class="n">bos_id</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                       <span class="n">eos_id</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                       <span class="n">beam_size</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
                       <span class="n">result_file</span><span class="o">=</span><span class="s2">&quot;./generated_sequences.txt&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Please see the following demo for more details:</p>
<ul class="simple">
<li>machine translation : demo/seqToseq/translation/gen.conf                             demo/seqToseq/seqToseq_net.py</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>base string</em>) &#8211; Name of the recurrent unit that generates sequences.</li>
<li><strong>step</strong> (<em>callable</em>) &#8211; <p>A callable function that defines the calculation in a time
984
step, and it is applied to sequences with arbitrary length by
Y
Yu Yang 已提交
985 986 987 988
sharing a same set of weights.</p>
<p>You can refer to the first parameter of recurrent_group, or
demo/seqToseq/seqToseq_net.py for more details.</p>
</li>
989
<li><strong>input</strong> (<em>list</em>) &#8211; Input data for the recurrent unit</li>
Y
Yu Yang 已提交
990 991 992
<li><strong>bos_id</strong> (<em>int</em>) &#8211; Index of the start symbol in the dictionary. The start symbol
is a special token for NLP task, which indicates the
beginning of a sequence. In the generation task, the start
993
symbol is essential, since it is used to initialize the RNN
Y
Yu Yang 已提交
994 995 996 997 998 999
internal state.</li>
<li><strong>eos_id</strong> (<em>int</em>) &#8211; Index of the end symbol in the dictionary. The end symbol is
a special token for NLP task, which indicates the end of a
sequence. The generation process will stop once the end
symbol is generated, or a pre-defined max iteration number
is exceeded.</li>
1000
<li><strong>max_length</strong> (<em>int</em>) &#8211; Max generated sequence length.</li>
Y
Yu Yang 已提交
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 1027 1028 1029 1030 1031
<li><strong>beam_size</strong> (<em>int</em>) &#8211; Beam search for sequence generation is an iterative search
algorithm. To maintain tractability, every iteration only
only stores a predetermined number, called the beam_size,
of the most promising next words. The greater the beam
size, the fewer candidate words are pruned.</li>
<li><strong>result_file</strong> (<em>basestring</em>) &#8211; Path of the file to store the generated results.</li>
<li><strong>dict_file</strong> (<em>basestring</em>) &#8211; Path of dictionary. This is an optional parameter.
Every line is a word in the dictionary with
(line number - 1) as the word index.
If this parameter is set to None, or to an empty string,
only word index are printed in the generated results.</li>
<li><strong>num_results_per_sample</strong> (<em>int</em>) &#8211; Number of the generated results per input
sequence. This number must always be less than
beam size.</li>
<li><strong>id_input</strong> (<em>LayerOutput</em>) &#8211; Index of the input sequence, and the specified index will
be prited in the gereated results. This an optional
parameter.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The seq_text_printer that prints the generated sequence to a file.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">evaluator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
Y
Yu Yang 已提交
1032 1033 1034 1035 1036
<div class="section" id="get-output-layer">
<h2>get_output_layer<a class="headerlink" href="#get-output-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">get_output_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
1037 1038 1039 1040
<dd><p>Get layer&#8217;s output by name. In PaddlePaddle, a layer might return multiple
values, but returns one layer&#8217;s output. If the user wants to use another
output besides the default one, please use get_output_layer first to get
the output from input.</p>
Y
Yu Yang 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer&#8217;s name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; get output layer&#8217;s input. And this layer should contains
multiple outputs.</li>
<li><strong>arg_name</strong> (<em>basestring</em>) &#8211; Output name from input.</li>
<li><strong>layer_attr</strong> &#8211; Layer&#8217;s extra attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1054
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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 1097 1098 1099 1100
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="mixed-layer">
<h1>Mixed Layer<a class="headerlink" href="#mixed-layer" title="Permalink to this headline"></a></h1>
<div class="section" id="id2">
<h2>mixed_layer<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">mixed_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Mixed Layer. A mixed layer will add all inputs together, then activate.
Each inputs is a projection or operator.</p>
<p>There are two styles of usages.</p>
<ol class="arabic simple">
<li>When not set inputs parameter, use mixed_layer like this:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span> <span class="k">as</span> <span class="n">m</span><span class="p">:</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">)</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer2</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>You can also set all inputs when invoke mixed_layer as follows:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">256</span><span class="p">,</span>
                <span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">),</span>
                       <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer2</span><span class="p">)])</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; mixed layer name. Can be referenced by other layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; layer size.</li>
<li><strong>input</strong> &#8211; inputs layer. It is an optional parameter. If set,
then this function will just return layer&#8217;s name.</li>
Y
Yu Yang 已提交
1101
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type.</li>
Y
Yu Yang 已提交
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 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
<li><strong>bias_attr</strong> (<em>ParameterAttribute or None or bool</em>) &#8211; The Bias Attribute. If no bias, then pass False or
something not type of ParameterAttribute. None will get a
default Bias.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; The extra layer config. Default is None.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">MixedLayerType object can add inputs or layer name.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">MixedLayerType</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="embedding-layer">
<h2>embedding_layer<a class="headerlink" href="#embedding-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">embedding_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Define a embedding Layer.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Name of this embedding layer.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The input layer for this embedding. NOTE: must be Index Data.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The embedding dimension.</li>
<li><strong>param_attr</strong> (<em>ParameterAttribute|None</em>) &#8211; The embedding parameter attribute. See ParameterAttribute
for details.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra layer Config. Default is None.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1140
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="dotmul-projection">
<h2>dotmul_projection<a class="headerlink" href="#dotmul-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">dotmul_projection</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
1156
<dd><p>DotMulProjection with a layer as input.
Y
Yu Yang 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
It performs element-wise multiplication with weight.</p>
<div class="math">
\[out.row[i] += in.row[i] .* weight\]</div>
<p>where <span class="math">\(.*\)</span> means element-wise multiplication.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">dotmul_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1170
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer.</li>
Y
Yu Yang 已提交
1171 1172 1173 1174
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
1175
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A DotMulProjection Object.</p>
Y
Yu Yang 已提交
1176 1177
</td>
</tr>
1178
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">DotMulProjection</p>
Y
Yu Yang 已提交
1179 1180 1181 1182 1183 1184
</td>
</tr>
</tbody>
</table>
</dd></dl>

1185 1186 1187 1188 1189
</div>
<div class="section" id="dotmul-operator">
<h2>dotmul_operator<a class="headerlink" href="#dotmul-operator" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
1190
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">dotmul_operator</code><span class="sig-paren">(</span><em>a=None</em>, <em>b=None</em>, <em>scale=1</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
<dd><p>DotMulOperator takes two inputs and performs element-wise multiplication:</p>
<div class="math">
\[out.row[i] += scale * (x.row[i] .* y.row[i])\]</div>
<p>where <span class="math">\(.*\)</span> means element-wise multiplication, and
scale is a config scalar, its default value is one.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">op</span> <span class="o">=</span> <span class="n">dotmul_operator</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1205 1206
<li><strong>a</strong> (<em>LayerOutput</em>) &#8211; Input layer1</li>
<li><strong>b</strong> (<em>LayerOutput</em>) &#8211; Input layer2</li>
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
<li><strong>scale</strong> (<em>float</em>) &#8211; config scalar, default value is one.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A DotMulOperator Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">DotMulOperator</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

Y
Yu Yang 已提交
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 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
</div>
<div class="section" id="full-matrix-projection">
<h2>full_matrix_projection<a class="headerlink" href="#full-matrix-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">full_matrix_projection</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Full Matrix Projection. It performs full matrix multiplication.</p>
<div class="math">
\[out.row[i] += in.row[i] * weight\]</div>
<p>There are two styles of usage.</p>
<ol class="arabic simple">
<li>When used in mixed_layer like this, you can only set the input:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="k">as</span> <span class="n">m</span><span class="p">:</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>When used as an independant object like this, you must set the size:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                              <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                              <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</span><span class="p">))</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; input layer</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A FullMatrixProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">FullMatrixProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="identity-projection">
<h2>identity_projection<a class="headerlink" href="#identity-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">identity_projection</code><span class="sig-paren">(</span><em>input</em>, <em>offset=None</em><span class="sig-paren">)</span></dt>
<dd><ol class="arabic simple">
<li>IdentityProjection if offset=None. It performs:</li>
</ol>
<div class="math">
\[out.row[i] += in.row[i]\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<p>2. IdentityOffsetProjection if offset!=None. It likes IdentityProjection,
but layer size may be smaller than input size.
It select dimesions [offset, offset+layer_size) from input:</p>
<div class="math">
\[out.row[i] += in.row[i + \textrm{offset}]\]</div>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">identity_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                           <span class="n">offset</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that both of two projections should not have any parameter.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1298
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input Layer.</li>
Y
Yu Yang 已提交
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 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
<li><strong>offset</strong> (<em>int</em>) &#8211; Offset, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A IdentityProjection or IdentityOffsetProjection Object</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">IdentityProjection or IdentityOffsetProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="table-projection">
<h2>table_projection<a class="headerlink" href="#table-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">table_projection</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Table Projection. It selects rows from parameter where row_id
is in input_ids.</p>
<div class="math">
\[out.row[i] += table.row[ids[i]]\]</div>
<p>where <span class="math">\(out\)</span> is output, <span class="math">\(table\)</span> is parameter, <span class="math">\(ids\)</span> is input_ids,
and <span class="math">\(i\)</span> is row_id.</p>
<p>There are two styles of usage.</p>
<ol class="arabic simple">
<li>When used in mixed_layer like this, you can only set the input:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mixed_layer</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span> <span class="k">as</span> <span class="n">m</span><span class="p">:</span>
    <span class="n">m</span> <span class="o">+=</span> <span class="n">table_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li>When used as an independant object like this, you must set the size:</li>
</ol>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">table_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                        <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                        <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</span><span class="p">))</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer, which must contains id fields.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A TableProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">TableProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="trans-full-matrix-projection">
<h2>trans_full_matrix_projection<a class="headerlink" href="#trans-full-matrix-projection" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">trans_full_matrix_projection</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Different from full_matrix_projection, this projection performs matrix
multiplication, using transpose of weight.</p>
<div class="math">
\[out.row[i] += in.row[i] * w^\mathrm{T}\]</div>
<p><span class="math">\(w^\mathrm{T}\)</span> means transpose of weight.
The simply usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">proj</span> <span class="o">=</span> <span class="n">trans_full_matrix_projection</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                                    <span class="n">size</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span>
                                    <span class="n">param_attr</span><span class="o">=</span><span class="n">ParamAttr</span><span class="p">(</span>
                                         <span class="n">name</span><span class="o">=</span><span class="s1">&#39;_proj&#39;</span><span class="p">,</span>
                                         <span class="n">initial_mean</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span>
                                         <span class="n">initial_std</span><span class="o">=</span><span class="mf">0.01</span><span class="p">))</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; input layer</li>
<li><strong>size</strong> (<em>int</em>) &#8211; The parameter size. Means the width of parameter.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter config, None if use default.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A TransposedFullMatrixProjection Object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">TransposedFullMatrixProjection</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="aggregate-layers">
<h1>Aggregate Layers<a class="headerlink" href="#aggregate-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="pooling-layer">
<h2>pooling_layer<a class="headerlink" href="#pooling-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">pooling_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Pooling layer for sequence inputs, not used for Image.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">seq_pool</span> <span class="o">=</span> <span class="n">pooling_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span>
                         <span class="n">pooling_type</span><span class="o">=</span><span class="n">AvgPooling</span><span class="p">(),</span>
                         <span class="n">agg_level</span><span class="o">=</span><span class="n">AggregateLevel</span><span class="o">.</span><span class="n">EACH_SEQUENCE</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
Y
Yu Yang 已提交
1424 1425
<li><strong>agg_level</strong> (<em>AggregateLevel</em>) &#8211; AggregateLevel.EACH_TIMESTEP or
AggregateLevel.EACH_SEQUENCE</li>
Y
Yu Yang 已提交
1426 1427 1428 1429 1430 1431 1432 1433 1434
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; input layer name.</li>
<li><strong>pooling_type</strong> (<em>BasePoolingType|None</em>) &#8211; Type of pooling, MaxPooling(default), AvgPooling,
SumPooling, SquareRootNPooling.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Bias parameter attribute. False if no bias.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; The Extra Attributes for layer, such as dropout.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1435
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerType</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="last-seq">
<h2>last_seq<a class="headerlink" href="#last-seq" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">last_seq</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Get Last Timestamp Activation of a sequence.</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>agg_level</strong> &#8211; Aggregated level</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1464
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="first-seq">
<h2>first_seq<a class="headerlink" href="#first-seq" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">first_seq</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Get First Timestamp Activation of a sequence.</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>agg_level</strong> &#8211; aggregation level</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1493
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="concat-layer">
<h2>concat_layer<a class="headerlink" href="#concat-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">concat_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Concat all input vector into one huge vector.
Inputs can be list of LayerOutput or list of projection.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
1517
<li><strong>input</strong> (<em>list|tuple|collection.Sequence</em>) &#8211; input layers or projections</li>
Y
Yu Yang 已提交
1518
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation type.</li>
Y
Yu Yang 已提交
1519 1520 1521 1522
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer Attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1523
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="reshaping-layers">
<h1>Reshaping Layers<a class="headerlink" href="#reshaping-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="block-expand-layer">
<h2>block_expand_layer<a class="headerlink" href="#block-expand-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">block_expand_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><dl class="docutils">
<dt>Expand feature map to minibatch matrix.</dt>
<dd><ul class="first last simple">
<li>matrix width is: block_y * block_x * channel</li>
<li>matirx height is: outputH * outputW</li>
</ul>
</dd>
</dl>
<div class="math">
1551
\[ \begin{align}\begin{aligned}outputH = 1 + (2 * padding_y + imgSizeH - block_y + stride_y - 1) / stride_y\\outputW = 1 + (2 * padding_x + imgSizeW - block_x + stride_x - 1) / stride_x\end{aligned}\end{align} \]</div>
Y
Yu Yang 已提交
1552 1553 1554 1555 1556
<p>The expand method is the same with ExpandConvLayer, but saved the transposed
value. After expanding, output.sequenceStartPositions will store timeline.
The number of time steps are outputH * outputW and the dimension of each
time step is block_y * block_x * channel. This layer can be used after
convolution neural network, and before recurrent neural network.</p>
Y
Yu Yang 已提交
1557 1558 1559 1560 1561 1562 1563 1564 1565
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">block_expand</span> <span class="o">=</span> <span class="n">block_expand_layer</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span>
                                  <span class="n">channel</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span>
                                  <span class="n">stride_x</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">stride_y</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">block_x</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                                  <span class="n">block_x</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
Y
Yu Yang 已提交
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
<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>LayerOutput</em>) &#8211; The input layer.</li>
<li><strong>channel</strong> (<em>int</em>) &#8211; The channel number of input layer.</li>
<li><strong>block_x</strong> (<em>int</em>) &#8211; The width of sub block.</li>
<li><strong>block_y</strong> (<em>int</em>) &#8211; The width of sub block.</li>
<li><strong>stride_x</strong> (<em>int</em>) &#8211; The stride size in horizontal direction.</li>
<li><strong>stride_y</strong> (<em>int</em>) &#8211; The stride size in vertical direction.</li>
<li><strong>padding_x</strong> (<em>int</em>) &#8211; The padding size in horizontal direction.</li>
<li><strong>padding_y</strong> (<em>int</em>) &#8211; The padding size in vertical direction.</li>
<li><strong>name</strong> (<em>None|basestring.</em>) &#8211; The name of this layer, which can not specify.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1583
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="expand-layer">
<h2>expand_layer<a class="headerlink" href="#expand-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">expand_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for &#8220;Expand Dense data or (sequence data where the length of each
sequence is one) to sequence data.&#8221;</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">expand</span> <span class="o">=</span> <span class="n">expand_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span>
                      <span class="n">expand_as</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span>
                      <span class="n">expand_level</span><span class="o">=</span><span class="n">ExpandLevel</span><span class="o">.</span><span class="n">FROM_TIMESTEP</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer</li>
<li><strong>expand_as</strong> (<em>LayerOutput</em>) &#8211; Expand as this layer&#8217;s sequence info.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|False</em>) &#8211; Bias attribute. None means default bias. False means no
bias.</li>
<li><strong>expand_level</strong> (<em>ExpandLevel</em>) &#8211; whether input layer is timestep(default) or sequence.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1622
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="math-layers">
<h1>Math Layers<a class="headerlink" href="#math-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="addto-layer">
<h2>addto_layer<a class="headerlink" href="#addto-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">addto_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>AddtoLayer.</p>
<div class="math">
\[y = f(\sum_{i} x_i + b)\]</div>
<p>where <span class="math">\(y\)</span> is output, <span class="math">\(x\)</span> is input, <span class="math">\(b\)</span> is bias,
and <span class="math">\(f\)</span> is activation function.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">addto</span> <span class="o">=</span> <span class="n">addto_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">,</span> <span class="n">layer2</span><span class="p">],</span>
                    <span class="n">act</span><span class="o">=</span><span class="n">ReluActivation</span><span class="p">(),</span>
                    <span class="n">bias_attr</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
<p>This layer just simply add all input layers together, then activate the sum
inputs. Each input of this layer should be the same size, which is also the
output size of this layer.</p>
Y
Yu Yang 已提交
1655 1656 1657
<p>There is no weight matrix for each input, because it just a simple add
operation. If you want a complicated operation before add, please use
mixed_layer.</p>
Y
Yu Yang 已提交
1658
<p>It is a very good way to set dropout outside the layers. Since not all
Y
Yu Yang 已提交
1659 1660
PaddlePaddle layer support dropout, you can add an add_to layer, set
dropout here.
Y
Yu Yang 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669
Please refer to dropout_layer for details.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>input</strong> (<em>LayerOutput|list|tuple</em>) &#8211; Input layers. It could be a LayerOutput or list/tuple of
LayerOutput.</li>
Y
Yu Yang 已提交
1670
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type, default is tanh.</li>
Y
Yu Yang 已提交
1671 1672 1673 1674 1675 1676
<li><strong>bias_attr</strong> (<em>ParameterAttribute|bool</em>) &#8211; Bias attribute. If False, means no bias. None is default
bias.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1677
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
1688 1689
<div class="section" id="linear-comb-layer">
<h2>linear_comb_layer<a class="headerlink" href="#linear-comb-layer" title="Permalink to this headline"></a></h2>
Y
Yu Yang 已提交
1690 1691
<dl class="function">
<dt>
1692
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">linear_comb_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
1693
<dd><dl class="docutils">
1694
<dt>A layer for weighted sum of vectors takes two inputs.</dt>
Y
Yu Yang 已提交
1695 1696
<dd><ul class="first last">
<li><dl class="first docutils">
1697 1698
<dt>Input: size of weights is M</dt>
<dd><p class="first last">size of vectors is M*N</p>
Y
Yu Yang 已提交
1699 1700 1701
</dd>
</dl>
</li>
1702
<li><p class="first">Output: a vector of size=N</p>
Y
Yu Yang 已提交
1703 1704 1705 1706 1707
</li>
</ul>
</dd>
</dl>
<div class="math">
1708 1709 1710 1711 1712
\[z(i) = \sum_{j=0}^{M-1} x(j) y(i+Nj)\]</div>
<p>where <span class="math">\(0 \le i \le N-1\)</span></p>
<p>Or in the matrix notation:</p>
<div class="math">
\[z = x^\mathrm{T} Y\]</div>
Y
Yu Yang 已提交
1713 1714 1715
<dl class="docutils">
<dt>In this formular:</dt>
<dd><ul class="first last simple">
1716 1717 1718
<li><span class="math">\(x\)</span>: weights</li>
<li><span class="math">\(y\)</span>: vectors.</li>
<li><span class="math">\(z\)</span>: the output.</li>
Y
Yu Yang 已提交
1719 1720 1721
</ul>
</dd>
</dl>
1722 1723
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
Y
Yu Yang 已提交
1724
<p>The simple usage is:</p>
1725
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">linear_comb</span> <span class="o">=</span> <span class="n">linear_comb_layer</span><span class="p">(</span><span class="n">weights</span><span class="o">=</span><span class="n">weight</span><span class="p">,</span> <span class="n">vectors</span><span class="o">=</span><span class="n">vectors</span><span class="p">,</span>
Y
Yu Yang 已提交
1726 1727 1728 1729 1730 1731 1732 1733
                                <span class="n">size</span><span class="o">=</span><span class="n">elem_dim</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
1734 1735
<li><strong>weights</strong> (<em>LayerOutput</em>) &#8211; The weight layer.</li>
<li><strong>vectors</strong> (<em>LayerOutput</em>) &#8211; The vector layer.</li>
Y
Yu Yang 已提交
1736 1737 1738 1739 1740
<li><strong>size</strong> (<em>int</em>) &#8211; the dimension of this layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1741
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="interpolation-layer">
<h2>interpolation_layer<a class="headerlink" href="#interpolation-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">interpolation_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This layer is for linear interpolation with two inputs,
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[y.row[i] = w[i] * x_1.row[i] + (1 - w[i]) * x_2.row[i]\]</div>
<p>where <span class="math">\(x_1\)</span> and <span class="math">\(x_2\)</span> are two (batchSize x dataDim) inputs,
<span class="math">\(w\)</span> is (batchSize x 1) weight vector, and <span class="math">\(y\)</span> is
(batchSize x dataDim) output.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">interpolation</span> <span class="o">=</span> <span class="n">interpolation_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">,</span> <span class="n">layer2</span><span class="p">],</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer3</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>list|tuple</em>) &#8211; Input layer.</li>
<li><strong>weight</strong> (<em>LayerOutput</em>) &#8211; Weight layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1780
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="power-layer">
<h2>power_layer<a class="headerlink" href="#power-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">power_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This layer applies a power function to a vector element-wise,
which is used in NEURAL TURING MACHINE.</p>
<div class="math">
\[y = x^w\]</div>
<p>where <span class="math">\(x\)</span> is a input vector, <span class="math">\(w\)</span> is scalar weight,
and <span class="math">\(y\)</span> is a output vector.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">power</span> <span class="o">=</span> <span class="n">power_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer2</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer.</li>
<li><strong>weight</strong> (<em>LayerOutput</em>) &#8211; Weight layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1818
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="scaling-layer">
<h2>scaling_layer<a class="headerlink" href="#scaling-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">scaling_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
1834
<dd><p>A layer for multiplying input vector by weight scalar.</p>
Y
Yu Yang 已提交
1835
<div class="math">
1836 1837 1838 1839 1840
\[y  = w x\]</div>
<p>where <span class="math">\(x\)</span> is size=dataDim input, <span class="math">\(w\)</span> is size=1 weight,
and <span class="math">\(y\)</span> is size=dataDim output.</p>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
Y
Yu Yang 已提交
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">scale</span> <span class="o">=</span> <span class="n">scaling_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="n">layer2</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer.</li>
<li><strong>weight</strong> (<em>LayerOutput</em>) &#8211; Weight layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1857
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="slope-intercept-layer">
<h2>slope_intercept_layer<a class="headerlink" href="#slope-intercept-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">slope_intercept_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This layer for applying a slope and an intercept to the input
element-wise. There is no activation and weight.</p>
<div class="math">
\[y = slope * x + intercept\]</div>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">scale</span> <span class="o">=</span> <span class="n">slope_intercept_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span> <span class="n">slope</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">intercept</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The input layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
<li><strong>slope</strong> (<em>float.</em>) &#8211; the scale factor.</li>
<li><strong>intercept</strong> (<em>float.</em>) &#8211; the offset.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1893
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="tensor-layer">
<h2>tensor_layer<a class="headerlink" href="#tensor-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">tensor_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>This layer performs tensor operation for two input.
For example, each sample:</p>
<div class="math">
1912
\[y_{i} = a * W_{i} * {b^\mathrm{T}}, i=0,1,...,K-1\]</div>
Y
Yu Yang 已提交
1913 1914 1915
<dl class="docutils">
<dt>In this formular:</dt>
<dd><ul class="first last simple">
1916 1917
<li><span class="math">\(a\)</span>: the first input contains M elements.</li>
<li><span class="math">\(b\)</span>: the second input contains N elements.</li>
Y
Yu Yang 已提交
1918 1919
<li><span class="math">\(y_{i}\)</span>: the i-th element of y.</li>
<li><span class="math">\(W_{i}\)</span>: the i-th learned weight, shape if [M, N]</li>
1920
<li><span class="math">\(b^\mathrm{T}\)</span>: the transpose of <span class="math">\(b_{2}\)</span>.</li>
Y
Yu Yang 已提交
1921 1922 1923 1924
</ul>
</dd>
</dl>
<p>The simple usage is:</p>
1925
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">tensor</span> <span class="o">=</span> <span class="n">tensor_layer</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">layer1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="n">layer2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
Y
Yu Yang 已提交
1926 1927 1928 1929 1930 1931 1932 1933
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name</li>
1934 1935
<li><strong>a</strong> (<em>LayerOutput</em>) &#8211; Input layer a.</li>
<li><strong>b</strong> (<em>LayerOutput</em>) &#8211; input layer b.</li>
Y
Yu Yang 已提交
1936 1937
<li><strong>size</strong> (<em>int.</em>) &#8211; the layer dimension.</li>
<li><strong>act</strong> (<em>BaseActivation</em>) &#8211; Activation Type. Default is tanh.</li>
1938
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; The Parameter Attribute.</li>
Y
Yu Yang 已提交
1939 1940 1941 1942 1943 1944 1945
<li><strong>bias_attr</strong> (<em>ParameterAttribute|None|Any</em>) &#8211; The Bias Attribute. If no bias, then pass False or
something not type of ParameterAttribute. None will get a
default Bias.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute|None</em>) &#8211; Extra Layer config.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
1946
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
1947 1948
</td>
</tr>
Y
Yu Yang 已提交
1949
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
Y
Yu Yang 已提交
1950 1951 1952 1953 1954 1955
</td>
</tr>
</tbody>
</table>
</dd></dl>

1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
</div>
<div class="section" id="cos-sim">
<h2>cos_sim<a class="headerlink" href="#cos-sim" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">cos_sim</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Cosine Similarity Layer. The cosine similarity equation is here.</p>
<div class="math">
\[similarity = cos(\theta) = {\mathbf{a} \cdot \mathbf{b}
\over \|\mathbf{a}\| \|\mathbf{b}\|}\]</div>
<p>The size of a is M, size of b is M*N,
Similarity will be calculated N times by step M. The output size is
N. The scale will be multiplied to similarity.</p>
<p>Note that the above computation is for one sample. Multiple samples are
processed in one batch.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name</li>
<li><strong>a</strong> (<em>LayerOutput</em>) &#8211; input layer a</li>
<li><strong>b</strong> (<em>LayerOutput</em>) &#8211; input layer b</li>
<li><strong>scale</strong> (<em>float</em>) &#8211; scale for cosine value. default is 5.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; layer size. NOTE size_a * size should equal size_b.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer Attribute.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

Y
Yu Yang 已提交
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019
</div>
<div class="section" id="trans-layer">
<h2>trans_layer<a class="headerlink" href="#trans-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">trans_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for transposition.</p>
<div class="math">
\[y = x^\mathrm{T}\]</div>
<p>where <span class="math">\(x\)</span> is (M x N) input, and <span class="math">\(y\)</span> is (N x M) output.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">trans</span> <span class="o">=</span> <span class="n">trans_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2020
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="sampling-layers">
<h1>Sampling Layers<a class="headerlink" href="#sampling-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="maxid-layer">
<h2>maxid_layer<a class="headerlink" href="#maxid-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">maxid_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for finding the id which has the maximal value for each sample.
The result is stored in output.ids.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">maxid</span> <span class="o">=</span> <span class="n">maxid_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer name.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2056
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="sampling-id-layer">
<h2>sampling_id_layer<a class="headerlink" href="#sampling-id-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">sampling_id_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for sampling id from multinomial distribution from the input layer.
Sampling one id for one sample.</p>
<p>The simple usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">samping_id</span> <span class="o">=</span> <span class="n">sampling_id_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The input layer.</li>
<li><strong>name</strong> (<em>basestring</em>) &#8211; The Layer Name.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2088
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="cost-layers">
<h1>Cost Layers<a class="headerlink" href="#cost-layers" title="Permalink to this headline"></a></h1>
<div class="section" id="cross-entropy">
<h2>cross_entropy<a class="headerlink" href="#cross-entropy" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">cross_entropy</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A loss layer for multi class entropy.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">cross_entropy</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput.</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
<li><strong>type</strong> (<em>basestring.</em>) &#8211; The type of cost.</li>
<li><strong>name</strong> (<em>None|basestring.</em>) &#8211; The name of this layers. It is not necessary.</li>
<li><strong>coeff</strong> (<em>float.</em>) &#8211; The coefficient affects the gradient in the backward.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2124
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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 2150 2151 2152 2153 2154 2155 2156 2157
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="cross-entropy-with-selfnorm">
<h2>cross_entropy_with_selfnorm<a class="headerlink" href="#cross-entropy-with-selfnorm" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">cross_entropy_with_selfnorm</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A loss layer for multi class entropy with selfnorm.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">cross_entropy_with_selfnorm</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput.</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
<li><strong>type</strong> (<em>basestring.</em>) &#8211; The type of cost.</li>
<li><strong>name</strong> (<em>None|basestring.</em>) &#8211; The name of this layers. It is not necessary.</li>
<li><strong>coeff</strong> (<em>float.</em>) &#8211; The coefficient affects the gradient in the backward.</li>
<li><strong>softmax_selfnorm_alpha</strong> (<em>float.</em>) &#8211; The scale factor affects the cost.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2158
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="multi-binary-label-cross-entropy">
<h2>multi_binary_label_cross_entropy<a class="headerlink" href="#multi-binary-label-cross-entropy" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">multi_binary_label_cross_entropy</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A loss layer for multi binary label cross entropy.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">multi_binary_label_cross_entropy</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
<li><strong>type</strong> (<em>basestring</em>) &#8211; The type of cost.</li>
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The name of this layers. It is not necessary.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The coefficient affects the gradient in the backward.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2191
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="huber-cost">
<h2>huber_cost<a class="headerlink" href="#huber-cost" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">huber_cost</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A loss layer for huber loss.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">huber_cost</span><span class="p">(</span><span class="nb">input</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput.</em>) &#8211; The first input layer.</li>
<li><strong>label</strong> &#8211; The input label.</li>
<li><strong>name</strong> (<em>None|basestring.</em>) &#8211; The name of this layers. It is not necessary.</li>
<li><strong>coeff</strong> (<em>float.</em>) &#8211; The coefficient affects the gradient in the backward.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2223
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="lambda-cost">
<h2>lambda_cost<a class="headerlink" href="#lambda-cost" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">lambda_cost</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>lambdaCost for lambdaRank LTR approach.</p>
<p>The simple usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">lambda_cost</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                   <span class="n">score</span><span class="o">=</span><span class="n">score</span><span class="p">,</span>
                   <span class="n">NDCG_num</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                   <span class="n">max_sort_size</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
2252
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Samples of the same query should be loaded as sequence.</li>
Y
Yu Yang 已提交
2253 2254 2255 2256 2257 2258 2259 2260
<li><strong>score</strong> &#8211; The 2nd input. Score of each sample.</li>
<li><strong>NDCG_num</strong> (<em>int</em>) &#8211; The size of NDCG (Normalized Discounted Cumulative Gain),
e.g., 5 for NDCG&#64;5. It must be less than for equal to the
minimum size of lists.</li>
<li><strong>max_sort_size</strong> (<em>int</em>) &#8211; The size of partial sorting in calculating gradient.
If max_sort_size = -1, then for each list, the
algorithm will sort the entire list to get gradient.
In other cases, max_sort_size must be greater than or
Y
Yu Yang 已提交
2261 2262 2263
equal to NDCG_num. And if max_sort_size is greater
than the size of a list, the algorithm will sort the
entire list of get gradient.</li>
Y
Yu Yang 已提交
2264 2265 2266 2267
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The name of this layers. It is not necessary.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2268
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="rank-cost">
<h2>rank_cost<a class="headerlink" href="#rank-cost" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">rank_cost</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
Y
Yu Yang 已提交
2284
<dd><p>A cost Layer for learning to rank using gradient descent. Details can refer
Y
Yu Yang 已提交
2285 2286 2287 2288
to <a class="reference external" href="http://research.microsoft.com/en-us/um/people/cburges/papers/ICML_ranking.pdf">papers</a>.
This layer contains at least three inputs. The weight is an optional
argument, which affects the cost.</p>
<div class="math">
2289
\[ \begin{align}\begin{aligned}C_{i,j} &amp; = -\tilde{P_{ij}} * o_{i,j} + log(1 + e^{o_{i,j}})\\o_{i,j} &amp; =  o_i - o_j\\\tilde{P_{i,j}} &amp; = \{0, 0.5, 1\} \ or \ \{0, 1\}\end{aligned}\end{align} \]</div>
Y
Yu Yang 已提交
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321
<dl class="docutils">
<dt>In this formula:</dt>
<dd><ul class="first last simple">
<li><span class="math">\(C_{i,j}\)</span> is the cross entropy cost.</li>
<li><span class="math">\(\tilde{P_{i,j}}\)</span> is the label. 1 means positive order
and 0 means reverse order.</li>
<li><span class="math">\(o_i\)</span> and <span class="math">\(o_j\)</span>: the left output and right output.
Their dimension is one.</li>
</ul>
</dd>
</dl>
<p>The simple usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">rank_cost</span><span class="p">(</span><span class="n">left</span><span class="o">=</span><span class="n">out_left</span><span class="p">,</span>
                 <span class="n">right</span><span class="o">=</span><span class="n">out_right</span><span class="p">,</span>
                 <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>left</strong> (<em>LayerOutput</em>) &#8211; The first input, the size of this layer is 1.</li>
<li><strong>right</strong> (<em>LayerOutput</em>) &#8211; The right input, the size of this layer is 1.</li>
<li><strong>label</strong> (<em>LayerOutput</em>) &#8211; Label is 1 or 0, means positive order and reverse order.</li>
<li><strong>weight</strong> (<em>LayerOutput</em>) &#8211; The weight affects the cost, namely the scale of cost.
It is an optional argument.</li>
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The name of this layers. It is not necessary.</li>
<li><strong>coeff</strong> (<em>float</em>) &#8211; The coefficient affects the gradient in the backward.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2322
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="crf-layer">
<h2>crf_layer<a class="headerlink" href="#crf-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">crf_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for calculating the cost of sequential conditional random
field model.</p>
<p>The simple usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">crf</span> <span class="o">=</span> <span class="n">crf_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                <span class="n">size</span><span class="o">=</span><span class="n">label_dim</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The first input layer is the feature.</li>
2352
<li><strong>label</strong> (<em>LayerOutput</em>) &#8211; The second input layer is label.</li>
Y
Yu Yang 已提交
2353 2354 2355 2356 2357 2358 2359 2360
<li><strong>size</strong> (<em>int</em>) &#8211; The category number.</li>
<li><strong>weight</strong> (<em>LayerOutput</em>) &#8211; The third layer is &#8220;weight&#8221; of each sample, which is an
optional argument.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter attribute. None means default attribute</li>
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The name of this layers. It is not necessary.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2361
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="crf-decoding-layer">
<h2>crf_decoding_layer<a class="headerlink" href="#crf-decoding-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">crf_decoding_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for calculating the decoding sequence of sequential conditional
random field model. The decoding sequence is stored in output.ids.
If a second input is provided, it is treated as the ground-truth label, and
this layer will also calculate error. output.value[i] is 1 for incorrect
decoding or 0 for correct decoding.</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>LayerOutput</em>) &#8211; The first input layer.</li>
<li><strong>size</strong> (<em>int</em>) &#8211; size of this layer.</li>
<li><strong>label</strong> (<em>LayerOutput or None</em>) &#8211; None or ground-truth label.</li>
<li><strong>param_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ParameterAttribute" title="paddle.trainer_config_helpers.attrs.ParameterAttribute"><em>ParameterAttribute</em></a>) &#8211; Parameter attribute. None means default attribute</li>
<li><strong>name</strong> (<em>None|basestring</em>) &#8211; The name of this layers. It is not necessary.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2395
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="ctc-layer">
<h2>ctc_layer<a class="headerlink" href="#ctc-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">ctc_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Connectionist Temporal Classification (CTC) is designed for temporal
classication task. That is, for sequence labeling problems where the
alignment between the inputs and the target labels is unknown.</p>
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424
<p>More details can be found by referring to <a class="reference external" href="http://machinelearning.wustl.edu/mlpapers/paper_files/icml2006_GravesFGS06.pdf">Connectionist Temporal
Classification: Labelling Unsegmented Sequence Data with Recurrent
Neural Networks</a></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Considering the &#8216;blank&#8217; label needed by CTC, you need to use
(num_classes + 1) as the input size. num_classes is the category number.
And the &#8216;blank&#8217; is the last category index. So the size of &#8216;input&#8217; layer, such as
fc_layer with softmax activation, should be num_classes + 1. The size of ctc_layer
should also be num_classes + 1.</p>
</div>
Y
Yu Yang 已提交
2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436
<p>The simple usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ctc</span> <span class="o">=</span> <span class="n">ctc_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="nb">input</span><span class="p">,</span>
                <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                <span class="n">size</span><span class="o">=</span><span class="mi">9055</span><span class="p">,</span>
                <span class="n">norm_by_times</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
2437
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; The input layer.</li>
Y
Yu Yang 已提交
2438
<li><strong>label</strong> (<em>LayerOutput</em>) &#8211; The data layer of label with variable length.</li>
2439
<li><strong>size</strong> (<em>int</em>) &#8211; category numbers + 1.</li>
2440
<li><strong>name</strong> (<em>basestring|None</em>) &#8211; The name of this layer</li>
Y
Yu Yang 已提交
2441 2442 2443 2444
<li><strong>norm_by_times</strong> (<em>bool</em>) &#8211; Whether to normalization by times. False by default.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2445
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="hsigmoid">
<h2>hsigmoid<a class="headerlink" href="#hsigmoid" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">hsigmoid</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>Organize the classes into a binary tree. At each node, a sigmoid function
is used to calculate the probability of belonging to the right branch.
This idea is from &#8220;F. Morin, Y. Bengio (AISTATS 05):
Hierarchical Probabilistic Neural Network Language Model.&#8221;</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cost</span> <span class="o">=</span> <span class="n">hsigmoid</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="p">[</span><span class="n">layer1</span><span class="p">,</span> <span class="n">layer2</span><span class="p">],</span>
                <span class="n">label</span><span class="o">=</span><span class="n">data_layer</span><span class="p">,</span>
                <span class="n">num_classes</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>input</strong> (<em>LayerOutput|list|tuple</em>) &#8211; Input layers. It could be a LayerOutput or list/tuple of
LayerOutput.</li>
<li><strong>label</strong> (<em>LayerOutput</em>) &#8211; Label layer.</li>
<li><strong>num_classes</strong> (<em>int</em>) &#8211; number of classes.</li>
Y
Yu Yang 已提交
2480
<li><strong>name</strong> (<em>basestring</em>) &#8211; layer name</li>
Y
Yu Yang 已提交
2481 2482 2483 2484 2485 2486
<li><strong>bias_attr</strong> (<em>ParameterAttribute|False</em>) &#8211; Bias attribute. None means default bias.
False means no bias.</li>
<li><strong>layer_attr</strong> (<a class="reference internal" href="attrs.html#paddle.trainer_config_helpers.attrs.ExtraLayerAttribute" title="paddle.trainer_config_helpers.attrs.ExtraLayerAttribute"><em>ExtraLayerAttribute</em></a>) &#8211; Extra Layer Attribute.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2487
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>
<div class="section" id="check-layer">
<h1>Check Layer<a class="headerlink" href="#check-layer" title="Permalink to this headline"></a></h1>
<div class="section" id="eos-layer">
<h2>eos_layer<a class="headerlink" href="#eos-layer" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt>
<code class="descclassname">paddle.trainer_config_helpers.layers.</code><code class="descname">eos_layer</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span></dt>
<dd><p>A layer for checking EOS for each sample:
- output_id = (input_id == conf.eos_id)</p>
<p>The result is stored in output_.ids.
It is used by recurrent layer group.</p>
<p>The example usage is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">eos</span> <span class="o">=</span> <span class="n">eos_layer</span><span class="p">(</span><span class="nb">input</span><span class="o">=</span><span class="n">layer</span><span class="p">,</span> <span class="n">eos_id</span><span class="o">=</span><span class="nb">id</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
Y
Yu Yang 已提交
2519
<li><strong>name</strong> (<em>basestring</em>) &#8211; Layer name.</li>
Y
Yu Yang 已提交
2520 2521 2522 2523 2524 2525
<li><strong>input</strong> (<em>LayerOutput</em>) &#8211; Input layer name.</li>
<li><strong>eos_id</strong> (<em>int</em>) &#8211; end id of sequence</li>
<li><strong>layer_attr</strong> (<em>ExtraLayerAttribute.</em>) &#8211; extra layer attributes.</li>
</ul>
</td>
</tr>
Y
Yu Yang 已提交
2526
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">LayerOutput object.</p>
Y
Yu Yang 已提交
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
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">LayerOutput</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Base</a><ul>
<li><a class="reference internal" href="#layertype">LayerType</a></li>
<li><a class="reference internal" href="#layeroutput">LayerOutput</a></li>
</ul>
</li>
<li><a class="reference internal" href="#data-layer">Data layer</a><ul>
<li><a class="reference internal" href="#id1">data_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#fully-connected-layers">Fully Connected Layers</a><ul>
<li><a class="reference internal" href="#fc-layer">fc_layer</a></li>
<li><a class="reference internal" href="#selective-fc-layer">selective_fc_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#conv-layers">Conv Layers</a><ul>
<li><a class="reference internal" href="#conv-operator">conv_operator</a></li>
<li><a class="reference internal" href="#conv-shift-layer">conv_shift_layer</a></li>
<li><a class="reference internal" href="#img-conv-layer">img_conv_layer</a></li>
<li><a class="reference internal" href="#context-projection">context_projection</a></li>
</ul>
</li>
<li><a class="reference internal" href="#image-pooling-layer">Image Pooling Layer</a><ul>
<li><a class="reference internal" href="#img-pool-layer">img_pool_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#norm-layer">Norm Layer</a><ul>
<li><a class="reference internal" href="#img-cmrnorm-layer">img_cmrnorm_layer</a></li>
<li><a class="reference internal" href="#batch-norm-layer">batch_norm_layer</a></li>
<li><a class="reference internal" href="#sum-to-one-norm-layer">sum_to_one_norm_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#recurrent-layers">Recurrent Layers</a><ul>
<li><a class="reference internal" href="#recurrent-layer">recurrent_layer</a></li>
<li><a class="reference internal" href="#lstmemory">lstmemory</a></li>
<li><a class="reference internal" href="#lstm-step-layer">lstm_step_layer</a></li>
<li><a class="reference internal" href="#grumemory">grumemory</a></li>
<li><a class="reference internal" href="#gru-step-layer">gru_step_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#recurrent-layer-group">Recurrent Layer Group</a><ul>
Y
Yu Yang 已提交
2587 2588
<li><a class="reference internal" href="#recurrent-group">recurrent_group</a></li>
<li><a class="reference internal" href="#beam-search">beam_search</a></li>
Y
Yu Yang 已提交
2589 2590 2591 2592 2593 2594 2595
<li><a class="reference internal" href="#get-output-layer">get_output_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#mixed-layer">Mixed Layer</a><ul>
<li><a class="reference internal" href="#id2">mixed_layer</a></li>
<li><a class="reference internal" href="#embedding-layer">embedding_layer</a></li>
<li><a class="reference internal" href="#dotmul-projection">dotmul_projection</a></li>
2596
<li><a class="reference internal" href="#dotmul-operator">dotmul_operator</a></li>
Y
Yu Yang 已提交
2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616
<li><a class="reference internal" href="#full-matrix-projection">full_matrix_projection</a></li>
<li><a class="reference internal" href="#identity-projection">identity_projection</a></li>
<li><a class="reference internal" href="#table-projection">table_projection</a></li>
<li><a class="reference internal" href="#trans-full-matrix-projection">trans_full_matrix_projection</a></li>
</ul>
</li>
<li><a class="reference internal" href="#aggregate-layers">Aggregate Layers</a><ul>
<li><a class="reference internal" href="#pooling-layer">pooling_layer</a></li>
<li><a class="reference internal" href="#last-seq">last_seq</a></li>
<li><a class="reference internal" href="#first-seq">first_seq</a></li>
<li><a class="reference internal" href="#concat-layer">concat_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#reshaping-layers">Reshaping Layers</a><ul>
<li><a class="reference internal" href="#block-expand-layer">block_expand_layer</a></li>
<li><a class="reference internal" href="#expand-layer">expand_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#math-layers">Math Layers</a><ul>
<li><a class="reference internal" href="#addto-layer">addto_layer</a></li>
2617
<li><a class="reference internal" href="#linear-comb-layer">linear_comb_layer</a></li>
Y
Yu Yang 已提交
2618 2619 2620 2621 2622
<li><a class="reference internal" href="#interpolation-layer">interpolation_layer</a></li>
<li><a class="reference internal" href="#power-layer">power_layer</a></li>
<li><a class="reference internal" href="#scaling-layer">scaling_layer</a></li>
<li><a class="reference internal" href="#slope-intercept-layer">slope_intercept_layer</a></li>
<li><a class="reference internal" href="#tensor-layer">tensor_layer</a></li>
2623
<li><a class="reference internal" href="#cos-sim">cos_sim</a></li>
Y
Yu Yang 已提交
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
<li><a class="reference internal" href="#trans-layer">trans_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#sampling-layers">Sampling Layers</a><ul>
<li><a class="reference internal" href="#maxid-layer">maxid_layer</a></li>
<li><a class="reference internal" href="#sampling-id-layer">sampling_id_layer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#cost-layers">Cost Layers</a><ul>
<li><a class="reference internal" href="#cross-entropy">cross_entropy</a></li>
<li><a class="reference internal" href="#cross-entropy-with-selfnorm">cross_entropy_with_selfnorm</a></li>
<li><a class="reference internal" href="#multi-binary-label-cross-entropy">multi_binary_label_cross_entropy</a></li>
<li><a class="reference internal" href="#huber-cost">huber_cost</a></li>
<li><a class="reference internal" href="#lambda-cost">lambda_cost</a></li>
<li><a class="reference internal" href="#rank-cost">rank_cost</a></li>
<li><a class="reference internal" href="#crf-layer">crf_layer</a></li>
<li><a class="reference internal" href="#crf-decoding-layer">crf_decoding_layer</a></li>
<li><a class="reference internal" href="#ctc-layer">ctc_layer</a></li>
<li><a class="reference internal" href="#hsigmoid">hsigmoid</a></li>
</ul>
</li>
<li><a class="reference internal" href="#check-layer">Check Layer</a><ul>
<li><a class="reference internal" href="#eos-layer">eos_layer</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="layers_index.html"
                        title="previous chapter">Layers</a></p>
  <h4>Next topic</h4>
Y
Yu Yang 已提交
2655
  <p class="topless"><a href="activations_index.html"
Y
Yu Yang 已提交
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666
                        title="next chapter">Activations</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/ui/api/trainer_config_helpers/layers.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
2667 2668
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
Y
Yu Yang 已提交
2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
Y
Yu Yang 已提交
2688
          <a href="activations_index.html" title="Activations"
Y
Yu Yang 已提交
2689 2690 2691 2692
             >next</a> |</li>
        <li class="right" >
          <a href="layers_index.html" title="Layers"
             >previous</a> |</li>
2693 2694 2695 2696
        <li class="nav-item nav-item-0"><a href="../../../index.html">PaddlePaddle  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >User Interface</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Model Config Interface</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="layers_index.html" >Layers</a> &#187;</li> 
Y
Yu Yang 已提交
2697 2698 2699
      </ul>
    </div>
    <div class="footer" role="contentinfo">
2700 2701
        &#169; Copyright 2016, PaddlePaddle developers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
Y
Yu Yang 已提交
2702 2703 2704
    </div>
  </body>
</html>