未验证 提交 c8ef4529 编写于 作者: A Abhinav Arora 提交者: GitHub

Polishing the embedding layer and the fc layer documentation (#6806)

* Polishing the embedding layer and the fc layer documentation
* Addressing code review feedback
上级 aad8b223
...@@ -25,32 +25,48 @@ def fc(input, ...@@ -25,32 +25,48 @@ def fc(input,
act=None, act=None,
name=None): name=None):
""" """
Fully Connected Layer. **Fully Connected Layer**
This layer accepts multiple inputs and applies a linear transformation to each input.
If activation type is provided, the corresponding activation function is applied to the
output of the linear transformation. For each input :math:`X`, the equation is:
.. math::
Out = Act(WX + b)
In the above equation:
* :math:`X`: Input value, a tensor with rank at least 2.
* :math:`W`: Weight, a 2-D tensor with shape [M, N].
* :math:`b`: Bias, a 2-D tensor with shape [M, 1].
* :math:`Act`: Activation function.
* :math:`Out`: Output value, same shape with :math:`X`.
All the input variables are passed in as local variables to the LayerHelper
constructor.
Args: Args:
input: The input tensor to the function input(Variable|list): Input tensors. Each tensor has a rank of atleast 2
size: The size of the layer size(int): Output size
num_flatten_dims: Number of columns in input num_flatten_dims(int): Number of columns in input
param_attr: The parameters/weights to the FC Layer param_attr(ParamAttr|list): The parameters/weights to the FC Layer
param_initializer: Initializer used for the weight/parameter. If None, XavierInitializer() is used bias_attr(ParamAttr|list): Bias parameter for the FC layer
bias_attr: The bias parameter for the FC layer act(str): Activation type
bias_initializer: Initializer used for the bias. If None, then ConstantInitializer() is used name(str): Name/alias of the function
act: Activation to be applied to the output of FC layer
name: Name/alias of the function Returns:
main_program: Name of the main program that calls this Variable: The tensor variable storing the transformation and \
startup_program: Name of the startup program non-linearity activation result.
This function can take in multiple inputs and performs the Fully Connected Raises:
function (linear transformation) on top of each of them. ValueError: If rank of input tensor is less than 2.
So for input x, the output will be : Wx + b. Where W is the parameter,
b the bias and x is the input.
The function also applies an activation (non-linearity) on top of the
output, if activation is passed in the input.
All the input variables of this function are passed in as local variables
to the LayerHelper constructor.
Examples:
.. code-block:: python
data = fluid.layers.data(name='data', shape=[32, 32], dtype='float32')
fc = fluid.layers.fc(input=data, size=1000, act="tanh")
""" """
helper = LayerHelper('fc', **locals()) helper = LayerHelper('fc', **locals())
...@@ -91,25 +107,30 @@ def fc(input, ...@@ -91,25 +107,30 @@ def fc(input,
def embedding(input, size, is_sparse=False, param_attr=None, dtype='float32'): def embedding(input, size, is_sparse=False, param_attr=None, dtype='float32'):
""" """
Embedding Layer. **Embedding Layer**
This layer is used to lookup a vector of IDs, provided by *input*, in a lookup table.
The result of this lookup is the embedding of each ID in the *input*.
All the input variables are passed in as local variables to the LayerHelper
constructor.
Args: Args:
param_initializer: input(Variable): Input to the function
input: The input to the function size(int): Output size
size: The size of the layer is_sparse(bool): Boolean flag that specifying whether the input is sparse
is_sparse: A flag that decleares whether the input is sparse param_attr(ParamAttr): Parameters for this layer
param_attr: Parameters for this layer dtype(np.dtype|core.DataType|str): The type of data : float32, float_16, int etc
dtype: The type of data : float32, float_16, int etc
main_program: Name of the main program that calls this Returns:
startup_program: Name of the startup program Variable: The tensor variable storing the embeddings of the \
supplied inputs.
This function can take in the input (which is a vector of IDs) and
performs a lookup in the lookup_table using these IDs, to result into Examples:
the embedding of each ID in the input. .. code-block:: python
All the input variables of this function are passed in as local variables
to the LayerHelper constructor.
data = fluid.layers.data(name='ids', shape=[32, 32], dtype='float32')
fc = fluid.layers.embedding(input=data, size=16)
""" """
helper = LayerHelper('embedding', **locals()) helper = LayerHelper('embedding', **locals())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册