fused_embedding_seq_pool

paddle.fluid.contrib.layers.nn. fused_embedding_seq_pool ( input, size, is_sparse=False, padding_idx=None, combiner='sum', param_attr=None, dtype='float32' ) [source]

Embedding Sequence pool

This layer is the fusion of lookup table and sequence_pool.

Parameters
  • input (Variable) – Input is a Tensor<int64> Variable, which contains the IDs’ information. The value of the input IDs should satisfy \(0<= id < size[0]\).

  • size (tuple|list) – The shape of the lookup_table parameter. It should have two elements which indicate the size of the dictionary of embedding and the size of each embedding vector respectively.

  • is_sparse (bool) – The flag indicating whether to use sparse update. Default: False.

  • padding_idx (int|long|None) – It will output all-zero padding data whenever lookup encounters \(padding\_idx\) in Ids. If set None, it makes no effect to output. If \(padding\_idx < 0\), the \(padding\_idx\) will automatically be converted to \(size[0] + padding\_idx\) to use. Default: None.

  • combiner (str) – The pooling type of sequence_pool, and only support sum. Default: sum.

  • param_attr (ParamAttr) – Parameters for this layer.

  • dtype (np.dtype|core.VarDesc.VarType|str) – The dtype refers to the data type of output tensor. It can be float32, float_16, int etc.

Returns

The sequence pooling variable which is a Tensor.

Examples

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/layers/nn.py:docstring of paddle.fluid.contrib.layers.nn.fused_embedding_seq_pool, line 34)

Error in “code-block” directive: maximum 1 argument(s) allowed, 9 supplied.

.. code-block:: python
    import numpy as np
    import paddle.fluid as fluid

    dict_size = 20
    data_t = fluid.layers.data(
        name='word', shape=[1], dtype='int64', lod_level=1)
    padding_idx = np.random.randint(1, 10)
    out = fluid.contrib.fused_embedding_seq_pool(
        input=data_t,
        size=[dict_size, 32],
        param_attr='w',
        padding_idx=padding_idx,
        is_sparse=False)