fix pylint errors (Line too long)

This commit is contained in:
Angus-Luo 2020-03-27 11:51:14 +08:00
parent 8f48b4ae06
commit 9fc04fc531
12 changed files with 68 additions and 45 deletions
tensorflow

View File

@ -87,7 +87,8 @@ class TextEmbeddingModel(tf.train.Checkpoint):
return tf.nn.safe_embedding_lookup_sparse(
embedding_weights=self.embeddings,
sparse_ids=tf.sparse.SparseTensor(token_ids, token_values, token_dense_shape),
sparse_ids=tf.sparse.SparseTensor(token_ids, token_values,
token_dense_shape),
sparse_weights=None,
combiner="sqrtn")

View File

@ -121,9 +121,9 @@ def dense_to_sparse_batch(batch_size, row_shape):
consecutive elements of this dataset to combine in a single batch.
row_shape: A `tf.TensorShape` or `tf.int64` vector tensor-like object
representing the equivalent dense shape of a row in the resulting
`tf.sparse.SparseTensor`. Each element of this dataset must have the same rank as
`row_shape`, and must have size less than or equal to `row_shape` in each
dimension.
`tf.sparse.SparseTensor`. Each element of this dataset must have the same
rank as `row_shape`, and must have size less than or equal to
`row_shape` in each dimension.
Returns:
A `Dataset` transformation function, which can be passed to

View File

@ -2915,8 +2915,8 @@ class SparseTensorSliceDataset(DatasetSource):
"""See `Dataset.from_sparse_tensor_slices()` for details."""
if not isinstance(sparse_tensor, sparse_tensor_lib.SparseTensor):
raise TypeError(
"`sparse_tensor` must be a `tf.sparse.SparseTensor` object. Was {}.".format(
sparse_tensor))
"`sparse_tensor` must be a `tf.sparse.SparseTensor` object."
"Was {}.".format(sparse_tensor))
self._sparse_tensor = sparse_tensor
indices_shape = self._sparse_tensor.indices.get_shape()

View File

@ -65,8 +65,8 @@ def as_dense_types(types, classes):
Returns:
a structure matching the nested structure of `types`, containing
`dtypes.variant` at positions where `classes` contains `tf.sparse.SparseTensor` and
matching contents of `types` otherwise
`dtypes.variant` at positions where `classes` contains
`tf.sparse.SparseTensor` and matching contents of `types` otherwise
"""
ret = nest.pack_sequence_as(types, [
dtypes.variant if c is sparse_tensor.SparseTensor else ty
@ -106,8 +106,8 @@ def get_classes(tensors):
Returns:
a structure matching the nested structure of `tensors`, containing
`tf.sparse.SparseTensor` at positions where `tensors` contains a sparse tensor and
`tf.Tensor` otherwise
`tf.sparse.SparseTensor` at positions where `tensors` contains a sparse
tensor and `tf.Tensor` otherwise.
"""
return nest.pack_sequence_as(tensors, [
sparse_tensor.SparseTensor

View File

@ -1969,7 +1969,8 @@ class _CategoricalColumn(_FeatureColumn):
WARNING: Do not subclass this layer unless you know what you are doing:
the API is subject to future changes.
A categorical feature typically handled with a `tf.sparse.SparseTensor` of IDs.
A categorical feature typically handled with a `tf.sparse.SparseTensor` of
IDs.
"""
IdWeightPair = collections.namedtuple( # pylint: disable=invalid-name

View File

@ -2515,7 +2515,8 @@ def _create_dense_column_weighted_sum(column, transformation_cache,
class CategoricalColumn(FeatureColumn):
"""Represents a categorical feature.
A categorical feature typically handled with a `tf.sparse.SparseTensor` of IDs.
A categorical feature typically handled with a `tf.sparse.SparseTensor` of
IDs.
"""
IdWeightPair = collections.namedtuple( # pylint: disable=invalid-name

View File

@ -480,6 +480,7 @@ def is_sparse(x):
x: A python object to check.
Returns:
`True` iff `x` is a `tf.sparse.SparseTensor` or `tf.compat.v1.SparseTensorValue`.
`True` iff `x` is a `tf.sparse.SparseTensor` or
`tf.compat.v1.SparseTensorValue`.
"""
return isinstance(x, (SparseTensor, SparseTensorValue))

View File

@ -3069,7 +3069,8 @@ def sparse_placeholder(dtype, shape=None, name=None):
print(sess.run(y, feed_dict={
x: (indices, values, shape)})) # Will succeed.
sp = tf.sparse.SparseTensor(indices=indices, values=values, dense_shape=shape)
sp = tf.sparse.SparseTensor(indices=indices, values=values,
dense_shape=shape)
sp_value = sp.eval(session=sess)
print(sess.run(y, feed_dict={x: sp_value})) # Will succeed.
```

View File

@ -193,7 +193,8 @@ def map_fn(fn,
* `tf.sparse.SparseTensor(st.indices, fn(st.values), st.dense_shape)`
(if the function is expressible as TensorFlow ops)
* `tf.sparse.SparseTensor(st.indices, tf.map_fn(fn, st.values), st.dense_shape)`
* `tf.sparse.SparseTensor(st.indices, tf.map_fn(fn, st.values),
st.dense_shape)`
(otherwise).
#### `map_fn` vs. vectorized operations

View File

@ -1637,7 +1637,8 @@ class RaggedTensor(composite_tensor.CompositeTensor):
Example:
>>> st = tf.sparse.SparseTensor(indices=[[0, 0], [0, 1], [0, 2], [1, 0], [3, 0]],
>>> st = tf.sparse.SparseTensor(indices=
... [[0, 0], [0, 1], [0, 2], [1, 0], [3, 0]],
... values=[1, 2, 3, 4, 5],
... dense_shape=[4, 3])
>>> tf.RaggedTensor.from_sparse(st).to_list()

View File

@ -156,7 +156,8 @@ def set_intersection(a, b, validate_indices=True):
((1, 1, 0), 5),
((1, 1, 1), 6),
])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()), dense_shape=[2,2,2])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()),
dense_shape=[2,2,2])
# b = np.array([[{1}, {}], [{4}, {5, 6, 7, 8}]])
b = collections.OrderedDict([
@ -167,7 +168,8 @@ def set_intersection(a, b, validate_indices=True):
((1, 1, 2), 7),
((1, 1, 3), 8),
])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()), dense_shape=[2, 2, 4])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()),
dense_shape=[2, 2, 4])
# `tf.sets.intersection` is applied to each aligned pair of sets.
tf.sets.intersection(a, b)
@ -224,7 +226,8 @@ def set_difference(a, b, aminusb=True, validate_indices=True):
((1, 1, 0), 5),
((1, 1, 1), 6),
])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()), dense_shape=[2, 2, 2])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()),
dense_shape=[2, 2, 2])
# np.array([[{1, 3}, {2}], [{4, 5}, {5, 6, 7, 8}]])
b = collections.OrderedDict([
@ -238,7 +241,8 @@ def set_difference(a, b, aminusb=True, validate_indices=True):
((1, 1, 2), 7),
((1, 1, 3), 8),
])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()), dense_shape=[2, 2, 4])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()),
dense_shape=[2, 2, 4])
# `set_difference` is applied to each aligned pair of sets.
tf.sets.difference(a, b)
@ -302,7 +306,8 @@ def set_union(a, b, validate_indices=True):
((1, 1, 0), 5),
((1, 1, 1), 6),
])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()), dense_shape=[2, 2, 2])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()),
dense_shape=[2, 2, 2])
# [[{1, 3}, {2}], [{4, 5}, {5, 6, 7, 8}]]
b = collections.OrderedDict([
@ -316,7 +321,8 @@ def set_union(a, b, validate_indices=True):
((1, 1, 2), 7),
((1, 1, 3), 8),
])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()), dense_shape=[2, 2, 4])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()),
dense_shape=[2, 2, 4])
# `set_union` is applied to each aligned pair of sets.
tf.sets.union(a, b)

View File

@ -310,8 +310,9 @@ def flatten(structure, expand_composites=False):
Args:
structure: an arbitrarily nested structure. Note, numpy arrays are
considered atoms and are not flattened.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A Python list, the flattened version of the input.
@ -364,8 +365,9 @@ def assert_same_structure(nest1, nest2, check_types=True,
considered the same if they are both list subtypes (which allows "list"
and "_ListWrapper" from trackable dependency tracking to compare
equal).
expand_composites: If true, then composite tensors such as `tf.sparse.SparseTensor`
and `tf.RaggedTensor` are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
`tf.sparse.SparseTensor` and `tf.RaggedTensor` are expanded into their
component tensors.
Raises:
ValueError: If the two structures do not have the same number of elements or
@ -537,8 +539,9 @@ def pack_sequence_as(structure, flat_sequence, expand_composites=False):
tuples, and dicts. Note: numpy arrays and strings are considered
scalars.
flat_sequence: flat sequence to pack.
expand_composites: If true, then composite tensors such as `tf.sparse.SparseTensor`
and `tf.RaggedTensor` are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
`tf.sparse.SparseTensor` and `tf.RaggedTensor` are expanded into their
component tensors.
Returns:
packed: `flat_sequence` converted to have the same recursive structure as
@ -574,9 +577,9 @@ def map_structure(func, *structure, **kwargs):
Note that namedtuples with identical name and fields are always
considered to have the same shallow structure.
* `expand_composites`: If set to `True`, then composite tensors such
as `tf.sparse.SparseTensor` and `tf.RaggedTensor` are expanded into their
component tensors. If `False` (the default), then composite tensors
are not expanded.
as `tf.sparse.SparseTensor` and `tf.RaggedTensor` are expanded into
their component tensors. If `False` (the default), then composite
tensors are not expanded.
Returns:
A new structure with the same arity as `structure`, whose values correspond
@ -762,8 +765,9 @@ def assert_shallow_structure(shallow_tree,
`input_tree` have to be the same. Note that even with check_types==True,
this function will consider two different namedtuple classes with the same
name and _fields attribute to be the same class.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Raises:
TypeError: If `shallow_tree` is a sequence but `input_tree` is not.
TypeError: If the sequence types of `shallow_tree` are different from
@ -911,8 +915,9 @@ def flatten_up_to(shallow_tree, input_tree, check_types=True,
Note, numpy arrays are considered scalars.
check_types: bool. If True, check that each node in shallow_tree has the
same type as the corresponding node in input_tree.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A Python list, the partially flattened version of `input_tree` according to
@ -1015,8 +1020,9 @@ def flatten_with_tuple_paths_up_to(shallow_tree,
Note, numpy arrays are considered scalars.
check_types: bool. If True, check that each node in shallow_tree has the
same type as the corresponding node in input_tree.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A Python list, the partially flattened version of `input_tree` according to
@ -1233,8 +1239,9 @@ def get_traverse_shallow_structure(traverse_fn, structure,
shallow structure of the same type, describing which parts of the
substructure to traverse.
structure: The structure to traverse.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A shallow structure containing python bools, which can be passed to
@ -1313,8 +1320,9 @@ def yield_flat_paths(nest, expand_composites=False):
Args:
nest: the value to produce a flattened paths list for.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Yields:
Tuples containing index or key values which form the path to a specific
@ -1338,8 +1346,9 @@ def flatten_with_joined_string_paths(structure, separator="/",
structure: the nested structure to flatten.
separator: string to separate levels of hierarchy in the results, defaults
to '/'.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A list of (string, data element) tuples.
@ -1362,8 +1371,9 @@ def flatten_with_tuple_paths(structure, expand_composites=False):
Args:
structure: the nested structure to flatten.
expand_composites: If true, then composite tensors such as tf.sparse.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
expand_composites: If true, then composite tensors such as
tf.sparse.SparseTensor and tf.RaggedTensor are expanded into their
component tensors.
Returns:
A list of `(tuple_path, leaf_element)` tuples. Each `tuple_path` is a tuple