提交 fd41a87a 编写于 作者: Y Yu Yang

complete data_type documentation

上级 3e398eaa
...@@ -7,4 +7,12 @@ Model Config API ...@@ -7,4 +7,12 @@ Model Config API
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
v2/model_configs.rst v2/model_configs.rst
\ No newline at end of file
Data API
--------
.. toctree::
:maxdepth: 1
v2/data.rst
#########
DataTypes
#########
.. automodule:: paddle.v2.data_type
:members:
...@@ -45,6 +45,23 @@ class CacheType(object): ...@@ -45,6 +45,23 @@ class CacheType(object):
class InputType(object): class InputType(object):
"""
InputType is the base class for paddle input types.
.. note::
this is a base class, and should never be used by user.
:param dim: dimension of input. If the input is an integer, it means the
value range. Otherwise, it means the size of layer.
:type dim: int
:param seq_type: sequence type of input. 0 means it is not a sequence. 1
means it is a variable length sequence. 2 means it is a
nested sequence.
:type seq_type: int
:param type: data type of input.
:type type: int
"""
__slots__ = ['dim', 'seq_type', 'type'] __slots__ = ['dim', 'seq_type', 'type']
def __init__(self, dim, seq_type, tp): def __init__(self, dim, seq_type, tp):
...@@ -54,20 +71,61 @@ class InputType(object): ...@@ -54,20 +71,61 @@ class InputType(object):
def dense_slot(dim, seq_type=SequenceType.NO_SEQUENCE): def dense_slot(dim, seq_type=SequenceType.NO_SEQUENCE):
"""
Dense Vector. It means the input feature is dense float vector. For example,
if the input is an image with 28*28 pixels, the input of Paddle neural
network should be a dense vector with dimension 784.
:param dim: dimension of this vector.
:type dim: int
:param seq_type: sequence type of input.
:type seq_type: int
:return: An input type object.
:rtype: InputType
"""
return InputType(dim, seq_type, DataType.Dense) return InputType(dim, seq_type, DataType.Dense)
def sparse_non_value_slot(dim, seq_type=SequenceType.NO_SEQUENCE): def sparse_non_value_slot(dim, seq_type=SequenceType.NO_SEQUENCE):
"""
Sparse binary vector. It means the input feature is a sparse vector and the
every element in this vector is either zero or one.
:param dim: dimension of this vector.
:type dim: int
:param seq_type: sequence type of this input.
:type seq_type: int
:return: An input type object.
:rtype: InputType
"""
return InputType(dim, seq_type, DataType.SparseNonValue) return InputType(dim, seq_type, DataType.SparseNonValue)
def sparse_value_slot(dim, seq_type=SequenceType.NO_SEQUENCE): def sparse_value_slot(dim, seq_type=SequenceType.NO_SEQUENCE):
"""
Sparse vector. It means the input feature is a sparse vector. Most of the
elements in this vector are zero, others could be any float value.
:param dim: dimension of this vector.
:type dim: int
:param seq_type: sequence type of this input.
:type seq_type: int
:return: An input type object.
:rtype: InputType
"""
return InputType(dim, seq_type, DataType.SparseValue) return InputType(dim, seq_type, DataType.SparseValue)
def index_slot(value_range, seq_type=SequenceType.NO_SEQUENCE): def index_slot(value_range, seq_type=SequenceType.NO_SEQUENCE):
"""Data type of integer. """
Data type of integer.
:param seq_type: sequence type of this input.
:type seq_type: int
:param value_range: range of this integer. :param value_range: range of this integer.
:type value_range: int
:return: An input type object
:rtype: InputType
""" """
return InputType(value_range, seq_type, DataType.Index) return InputType(value_range, seq_type, DataType.Index)
...@@ -76,10 +134,17 @@ dense_vector = dense_slot ...@@ -76,10 +134,17 @@ dense_vector = dense_slot
sparse_binary_vector = sparse_non_value_slot sparse_binary_vector = sparse_non_value_slot
sparse_vector = sparse_value_slot sparse_vector = sparse_value_slot
integer_value = index_slot integer_value = index_slot
integer_value.__doc__ = index_slot.__doc__
def dense_vector_sequence(dim): def dense_vector_sequence(dim):
"""
Data type of a sequence of dense vector.
:param dim: dimension of dense vector.
:type dim: int
:return: An input type object
:rtype: InputType
"""
return dense_vector(dim, seq_type=SequenceType.SEQUENCE) return dense_vector(dim, seq_type=SequenceType.SEQUENCE)
...@@ -88,6 +153,15 @@ def dense_vector_sub_sequence(dim): ...@@ -88,6 +153,15 @@ def dense_vector_sub_sequence(dim):
def sparse_binary_vector_sequence(dim): def sparse_binary_vector_sequence(dim):
"""
Data type of a sequence of sparse vector, which every element is either zero
or one.
:param dim: dimension of sparse vector.
:type dim: int
:return: An input type object
:rtype: InputType
"""
return sparse_binary_vector(dim, seq_type=SequenceType.SEQUENCE) return sparse_binary_vector(dim, seq_type=SequenceType.SEQUENCE)
...@@ -96,6 +170,15 @@ def sparse_binary_vector_sub_sequence(dim): ...@@ -96,6 +170,15 @@ def sparse_binary_vector_sub_sequence(dim):
def sparse_vector_sequence(dim): def sparse_vector_sequence(dim):
"""
Data type of a sequence of sparse vector, which most elements are zero,
others could be any float value.
:param dim: dimension of sparse vector.
:type dim: int
:return: An input type object
:rtype: InputType
"""
return sparse_vector(dim, seq_type=SequenceType.SEQUENCE) return sparse_vector(dim, seq_type=SequenceType.SEQUENCE)
...@@ -104,8 +187,11 @@ def sparse_vector_sub_sequence(dim): ...@@ -104,8 +187,11 @@ def sparse_vector_sub_sequence(dim):
def integer_value_sequence(value_range): def integer_value_sequence(value_range):
"""Data type of a sequence of integer. """
Data type of a sequence of integer.
:param value_range: range of each element. :param value_range: range of each element.
:type value_range: int
""" """
return integer_value(value_range, seq_type=SequenceType.SEQUENCE) return integer_value(value_range, seq_type=SequenceType.SEQUENCE)
...@@ -115,7 +201,6 @@ def integer_value_sub_sequence(dim): ...@@ -115,7 +201,6 @@ def integer_value_sub_sequence(dim):
integer_sequence = integer_value_sequence integer_sequence = integer_value_sequence
integer_sequence.__doc__ = integer_value_sequence.__doc__
class SingleSlotWrapper(object): class SingleSlotWrapper(object):
......
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from paddle.trainer.PyDataProvider2 import \ import paddle.trainer.PyDataProvider2 as pydp2
InputType, DataType, dense_vector, sparse_binary_vector,\
sparse_vector, integer_value, integer_value_sequence
__all__ = [ import_list = [
'InputType', 'DataType', 'dense_vector', 'sparse_binary_vector', nm for nm in dir(pydp2)
'sparse_vector', 'integer_value', 'integer_value_sequence' if '_' in nm and nm[0] != '_' and ('value' in nm or 'vector' in nm)
] ]
import_list.extend(['InputType'])
for nm in import_list:
globals()[nm] = getattr(pydp2, nm)
__all__ = import_list
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册