|
|
|
@ -37,6 +37,7 @@ __all__ = [
|
|
|
|
|
"dotmul_projection",
|
|
|
|
|
"dotmul_operator",
|
|
|
|
|
"repeat_layer",
|
|
|
|
|
"seq_reshape_layer",
|
|
|
|
|
"table_projection",
|
|
|
|
|
"mixed_layer",
|
|
|
|
|
"data_layer",
|
|
|
|
@ -125,6 +126,7 @@ class LayerType(object):
|
|
|
|
|
GRUMEMORY = "gated_recurrent"
|
|
|
|
|
SEQUENCE_LAST_INSTANCE = "seqlastins"
|
|
|
|
|
SEQUENCE_FIRST_INSTANCE = "seqfirstins"
|
|
|
|
|
SEQUENCE_RESHAPE = "seqreshape"
|
|
|
|
|
POOLING_MAX = "max"
|
|
|
|
|
POOLING_AVG = 'average'
|
|
|
|
|
FC_LAYER = "fc"
|
|
|
|
@ -1450,6 +1452,61 @@ def repeat_layer(input, num_repeats, name=None, layer_attr=None):
|
|
|
|
|
parents=[input])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@wrap_name_default("seqreshape")
|
|
|
|
|
@wrap_act_default(act=IdentityActivation())
|
|
|
|
|
@wrap_bias_attr_default(has_bias=False)
|
|
|
|
|
@layer_support()
|
|
|
|
|
def seq_reshape_layer(input,
|
|
|
|
|
reshape_size,
|
|
|
|
|
act=None,
|
|
|
|
|
name=None,
|
|
|
|
|
layer_attr=None,
|
|
|
|
|
bias_attr=None):
|
|
|
|
|
"""
|
|
|
|
|
A layer for reshaping the sequence. Assume the input sequence has T instances,
|
|
|
|
|
the dimension of each instance is M, and the input reshape_size is N, then the
|
|
|
|
|
output sequence has T*M/N instances, the dimension of each instance is N.
|
|
|
|
|
|
|
|
|
|
Note that T*M/N must be an integer.
|
|
|
|
|
|
|
|
|
|
The example usage is:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
reshape = seq_reshape_layer(input=layer, reshape_size=4)
|
|
|
|
|
|
|
|
|
|
:param input: Input layer.
|
|
|
|
|
:type input: LayerOutput
|
|
|
|
|
:param reshape_size: the size of reshaped sequence.
|
|
|
|
|
:type reshape_size: int
|
|
|
|
|
:param name: Layer name.
|
|
|
|
|
:type name: basestring
|
|
|
|
|
:param act: Activation type.
|
|
|
|
|
:type act: BaseActivation
|
|
|
|
|
:param layer_attr: extra layer attributes.
|
|
|
|
|
:type layer_attr: ExtraLayerAttribute.
|
|
|
|
|
:param bias_attr: The Bias Attribute. If no bias, then pass False or
|
|
|
|
|
something not type of ParameterAttribute. None will get a
|
|
|
|
|
default Bias.
|
|
|
|
|
:type bias_attr: ParameterAttribute or None or bool
|
|
|
|
|
:return: LayerOutput object.
|
|
|
|
|
:rtype: LayerOutput
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Layer(
|
|
|
|
|
inputs=[input.name],
|
|
|
|
|
name=name,
|
|
|
|
|
size=reshape_size,
|
|
|
|
|
type=LayerType.SEQUENCE_RESHAPE,
|
|
|
|
|
bias=ParamAttr.to_bias(bias_attr),
|
|
|
|
|
**ExtraAttr.to_kwargs(layer_attr))
|
|
|
|
|
return LayerOutput(
|
|
|
|
|
name=name,
|
|
|
|
|
size=reshape_size,
|
|
|
|
|
layer_type=LayerType.SEQUENCE_RESHAPE,
|
|
|
|
|
parents=[input])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@wrap_name_default()
|
|
|
|
|
@layer_support()
|
|
|
|
|
def interpolation_layer(input, weight, name=None, layer_attr=None):
|
|
|
|
@ -2604,6 +2661,10 @@ def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
|
|
|
|
|
:type act: BaseActivation
|
|
|
|
|
:param layer_attr: Extra Layer Attribute.
|
|
|
|
|
:type layer_attr: ExtraLayerAttribute
|
|
|
|
|
:param bias_attr: The Bias Attribute. If no bias, then pass False or
|
|
|
|
|
something not type of ParameterAttribute. None will get a
|
|
|
|
|
default Bias.
|
|
|
|
|
:type bias_attr: ParameterAttribute or None or bool
|
|
|
|
|
:return: LayerOutput object.
|
|
|
|
|
:rtype: LayerOutput
|
|
|
|
|
"""
|
|
|
|
|