aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-01-06 14:55:01 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-01-06 15:09:26 -0800
commit72d7d9dfc46d85330f2b8d43d3500d4eaf07a0cc (patch)
tree486900534047f73af564fe57fba3e5aef100ecd9 /tensorflow/python
parent1d58d57dfaf275a64a9aeafa734351a3fbfd162c (diff)
_construct_sparse_tensors_for_sparse_features returns a new dictionary instead of modifying the one passed in.
Change: 143819066
Diffstat (limited to 'tensorflow/python')
-rw-r--r--tensorflow/python/ops/parsing_ops.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/tensorflow/python/ops/parsing_ops.py b/tensorflow/python/ops/parsing_ops.py
index 6e7b0fe083..079837bce3 100644
--- a/tensorflow/python/ops/parsing_ops.py
+++ b/tensorflow/python/ops/parsing_ops.py
@@ -206,10 +206,12 @@ def _features_to_raw_params(features, types):
def _construct_sparse_tensors_for_sparse_features(features, tensor_dict):
"""Merges SparseTensors of indices and values of SparseFeatures.
- Updates `tensor_dict`. For `SparseFeatures` in the values of `features`
- expects their `index_key`s and `index_value`s to be present in `tensor_dict`
- mapping to `SparseTensor`s. Removes those, constructs a single `SparseTensor`
- from them, and adds it to `tensor_dict` with the key from `features`.
+ Constructs new dict based on `tensor_dict`. For `SparseFeatures` in the values
+ of `features` expects their `index_key`s and `index_value`s to be present in
+ `tensor_dict` mapping to `SparseTensor`s. Constructs a single `SparseTensor`
+ from them, and adds it to the result with the key from `features`.
+ Copies other keys and values from `tensor_dict` with keys present in
+ `features`.
Args:
features: A `dict` mapping feature keys to `SparseFeature` values.
@@ -217,7 +219,12 @@ def _construct_sparse_tensors_for_sparse_features(features, tensor_dict):
tensor_dict: A `dict` mapping feature keys to `Tensor` and `SparseTensor`
values. Expected to contain keys of the `SparseFeature`s' `index_key`s and
`value_key`s and mapping them to `SparseTensor`s.
+ Returns:
+ A `dict` mapping feature keys to `Tensor` and `SparseTensor` values. Similar
+ to `tensor_dict` except each `SparseFeature`s in `features` results in a
+ single `SparseTensor`.
"""
+ tensor_dict = dict(tensor_dict) # Do not modify argument passed in.
# Construct SparseTensors for SparseFeatures.
for key in sorted(features.keys()):
feature = features[key]
@@ -231,8 +238,9 @@ def _construct_sparse_tensors_for_sparse_features(features, tensor_dict):
already_sorted=feature.already_sorted)
# Remove tensors from dictionary that were only used to construct
# SparseTensors for SparseFeature.
- for key in set(tensor_dict.keys()) - set(features.keys()):
+ for key in set(tensor_dict) - set(features):
del tensor_dict[key]
+ return tensor_dict
def parse_example(serialized, features, name=None, example_names=None):
@@ -435,8 +443,7 @@ def parse_example(serialized, features, name=None, example_names=None):
outputs = _parse_example_raw(
serialized, example_names, sparse_keys, sparse_types, dense_keys,
dense_types, dense_defaults, dense_shapes, name)
- _construct_sparse_tensors_for_sparse_features(features, outputs)
- return outputs
+ return _construct_sparse_tensors_for_sparse_features(features, outputs)
def _parse_example_raw(serialized,
@@ -586,8 +593,7 @@ def parse_single_example(serialized, features, name=None, example_names=None):
outputs = _parse_single_example_raw(
serialized, example_names, sparse_keys, sparse_types, dense_keys,
dense_types, dense_defaults, dense_shapes, name)
- _construct_sparse_tensors_for_sparse_features(features, outputs)
- return outputs
+ return _construct_sparse_tensors_for_sparse_features(features, outputs)
def _parse_single_example_raw(serialized,