MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / parse_single_example_v2

Function parse_single_example_v2

tensorflow/python/ops/parsing_ops.py:2031–2094  ·  view source on GitHub ↗

Parses an `Example` proto into a `dict` of tensors. Parses a serialized [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto) proto given in `serialized`. This op parses serialized examples into a dictionary mapping keys to `Tensor` and `SparseTensor` objects

(serialized, features, name=None)

Source from the content-addressed store, hash-verified

2029# TODO(b/70890287): Combine the implementation of this op and
2030# `parse_single_example()` after 1/10/2018.
2031def parse_single_example_v2(serialized, features, name=None):
2032 # pylint: disable=line-too-long
2033 """Parses an `Example` proto into a `dict` of tensors.
2034
2035 Parses a serialized
2036 [`Example`](https://www.tensorflow.org/code/tensorflow/core/example/example.proto)
2037 proto given in `serialized`.
2038
2039 This op parses serialized examples into a dictionary mapping keys to `Tensor`
2040 and `SparseTensor` objects. `features` is a dict from keys to `VarLenFeature`,
2041 `SparseFeature`, and `FixedLenFeature` objects. Each `VarLenFeature`
2042 and `SparseFeature` is mapped to a `SparseTensor`, and each
2043 `FixedLenFeature` is mapped to a `Tensor`.
2044
2045 Each `VarLenFeature` maps to a `SparseTensor` of the specified type
2046 representing a ragged matrix. Its indices are `[index]` where
2047 `index` is the value's index in the list of values associated with
2048 that feature and example.
2049
2050 Each `SparseFeature` maps to a `SparseTensor` of the specified type
2051 representing a Tensor of `dense_shape` `SparseFeature.size`.
2052 Its `values` come from the feature in the examples with key `value_key`.
2053 A `values[i]` comes from a position `k` in the feature of an example at batch
2054 entry `batch`. This positional information is recorded in `indices[i]` as
2055 `[batch, index_0, index_1, ...]` where `index_j` is the `k-th` value of
2056 the feature in the example at with key `SparseFeature.index_key[j]`.
2057 In other words, we split the indices (except the first index indicating the
2058 batch entry) of a `SparseTensor` by dimension into different features of the
2059 `Example`. Due to its complexity a `VarLenFeature` should be preferred over a
2060 `SparseFeature` whenever possible.
2061
2062 Each `FixedLenFeature` `df` maps to a `Tensor` of the specified type (or
2063 `tf.float32` if not specified) and shape `df.shape`.
2064
2065 `FixedLenFeature` entries with a `default_value` are optional. With no default
2066 value, we will fail if that `Feature` is missing from any example in
2067 `serialized`.
2068
2069 Each `FixedLenSequenceFeature` `df` maps to a `Tensor` of the specified type
2070 (or `tf.float32` if not specified) and shape `(None,) + df.shape`.
2071
2072 Args:
2073 serialized: A scalar (0-D Tensor) string, a serialized `Example` proto.
2074 features: A `dict` mapping feature keys to `FixedLenFeature`,
2075 `VarLenFeature`, and `SparseFeature` values.
2076 name: A name for this operation (optional).
2077
2078 Returns:
2079 A `dict` mapping feature keys to `Tensor` and `SparseTensor` values.
2080
2081 Raises:
2082 ValueError: if any feature is invalid.
2083 """
2084 if not features:
2085 raise ValueError("Missing: features was %s." % features)
2086 features = _prepend_none_dimension(features)
2087 (sparse_keys, sparse_types, dense_keys, dense_types,
2088 dense_defaults, dense_shapes) = _features_to_raw_params(

Callers 1

Tested by

no test coverage detected