Skip to content

Commit

Permalink
Merge pull request #16459 from code-review-doctor:fix-probably-meant-…
Browse files Browse the repository at this point in the history
…fstring

PiperOrigin-RevId: 444340251
  • Loading branch information
tensorflower-gardener committed Apr 25, 2022
2 parents 4087259 + 932c53e commit babde7f
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion keras/applications/mobilenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def MobileNet(input_shape=None,
if depth_multiplier != 1:
raise ValueError('If imagenet weights are being loaded, '
'depth multiplier must be 1. '
'Received depth_multiplier={depth_multiplier}')
f'Received depth_multiplier={depth_multiplier}')

if alpha not in [0.25, 0.50, 0.75, 1.0]:
raise ValueError('If imagenet weights are being loaded, '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def __init__(self, embed_dim, num_heads=8):
self.embed_dim = embed_dim
self.num_heads = num_heads
if embed_dim % num_heads != 0:
raise ValueError('embedding dimension = {embed_dim} should be divisible'
'by number of heads = {num_heads}')
raise ValueError(f'embedding dimension = {embed_dim} should be divisible'
f'by number of heads = {num_heads}')
self.projection_dim = embed_dim // num_heads
self.query_dense = tf.keras.layers.Dense(embed_dim)
self.key_dense = tf.keras.layers.Dense(embed_dim)
Expand Down
6 changes: 3 additions & 3 deletions keras/dtensor/layout_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __setitem__(self, key, layout):
'not use duplicated keys.')
if not isinstance(layout, dtensor.Layout):
raise ValueError(f'{layout} should be a dtensor.Layout type, '
'got {type(layout)}')
f'got {type(layout)}')

self._layout_map[key] = layout

Expand Down Expand Up @@ -435,8 +435,8 @@ def _set_object_by_path(object_to_set, path, value):
if i == len(path) - 1:
# We found the actual attribute to set
if isinstance(attr_name, int):
# This means we are trying to set an element in the array, make sure the
# instance is array like object.
# This means we are trying to set an element in the array, make sure the
# instance is array like object.
object_to_set[attr_name] = value
else:
setattr(object_to_set, attr_name, value)
Expand Down
3 changes: 1 addition & 2 deletions keras/dtensor/lazy_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
initial_value, "graph") and initial_value.graph.building_function:
raise ValueError(f"Argument `initial_value` ({initial_value}) could not "
"be lifted out of a `tf.function`. "
"(Tried to create variable with name='{name}'). "
f"(Tried to create variable with name='{name}'). "
"To avoid this error, when constructing `tf.Variable`s "
"inside of `tf.function` you can create the "
"`initial_value` tensor in a "
Expand Down Expand Up @@ -217,4 +217,3 @@ def disable_init_variable_creator():
yield
finally:
_DISABLE_LAZY_VARIABLE_INIT.disabled = existing_value

2 changes: 1 addition & 1 deletion keras/engine/base_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ def _get_node_attribute_at_index(self, node_index, attr, attr_name):
"""
if not self._inbound_nodes:
raise RuntimeError(f'The layer {self.name} has never been called '
'and thus has no defined {attr_name}.')
f'and thus has no defined {attr_name}.')
if not len(self._inbound_nodes) > node_index:
raise ValueError(f'Asked to get {attr_name} at node '
f'{node_index}, but the layer has only '
Expand Down
5 changes: 2 additions & 3 deletions keras/layers/rnn/cell_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ def tensor_and_const_value(v):
tensor_prob, const_prob = tensor_and_const_value(prob)
if const_prob is not None:
if const_prob < 0 or const_prob > 1:
raise ValueError(
f"Parameter {attr} must be between 0 and 1. "
"Received {const_prob}")
raise ValueError(f"Parameter {attr} must be between 0 and 1. "
f"Received {const_prob}")
setattr(self, "_%s" % attr, float(const_prob))
else:
setattr(self, "_%s" % attr, tensor_prob)
Expand Down
5 changes: 2 additions & 3 deletions keras/layers/rnn/legacy_cell_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ def tensor_and_const_value(v):
tensor_prob, const_prob = tensor_and_const_value(prob)
if const_prob is not None:
if const_prob < 0 or const_prob > 1:
raise ValueError(
f"Parameter {attr} must be between 0 and 1. "
"Received {const_prob}")
raise ValueError(f"Parameter {attr} must be between 0 and 1. "
f"Received {const_prob}")
setattr(self, "_%s" % attr, float(const_prob))
else:
setattr(self, "_%s" % attr, tensor_prob)
Expand Down
13 changes: 5 additions & 8 deletions keras/layers/rnn/legacy_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,9 @@ class GRUCell(LayerRNNCell):
the first input). Required when `build` is called before `call`.
**kwargs: Dict, keyword named properties for common layer attributes, like
`trainable` etc when constructing the cell from configs of get_config().
References:
Learning Phrase Representations using RNN Encoder Decoder for Statistical
Machine Translation:
[Cho et al., 2014]
References: Learning Phrase Representations using RNN Encoder Decoder for
Statistical
Machine Translation: [Cho et al., 2014]
(https://aclanthology.coli.uni-saarland.de/papers/D14-1179/d14-1179)
([pdf](http://emnlp2014.org/papers/pdf/EMNLP2014179.pdf))
"""
Expand Down Expand Up @@ -938,9 +936,8 @@ def output_size(self):
@tf_utils.shape_type_conversion
def build(self, inputs_shape):
if inputs_shape[-1] is None:
raise ValueError(
"Expected inputs.shape[-1] to be known, "
"received shape: {inputs_shape}")
raise ValueError("Expected inputs.shape[-1] to be known, "
f"received shape: {inputs_shape}")
_check_supported_dtypes(self.dtype)
input_depth = inputs_shape[-1]
h_depth = self._num_units if self._num_proj is None else self._num_proj
Expand Down
2 changes: 1 addition & 1 deletion keras/optimizers/optimizer_v2/optimizer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ def set_weights(self, weights):
params = self.weights
if len(params) != len(weights):
raise ValueError(
"You called `set_weights(weights)` on optimizer {self._name} "
f"You called `set_weights(weights)` on optimizer {self._name} "
f"with a weight list of length {str(len(weights))}, "
f"but the optimizer was expecting {str(len(params))} "
f"weights. Provided weights: {str(weights)[:50]}...")
Expand Down
2 changes: 1 addition & 1 deletion keras/saving/utils_v1/signature_def_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _supervised_signature_def(
ValueError: If inputs or outputs is `None`.
"""
if inputs is None or not inputs:
raise ValueError('f{method_name} `inputs` cannot be None or empty.')
raise ValueError(f'{method_name} `inputs` cannot be None or empty.')

signature_inputs = {key: tf.compat.v1.saved_model.build_tensor_info(tensor)
for key, tensor in inputs.items()}
Expand Down
12 changes: 4 additions & 8 deletions keras/utils/audio_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,12 @@ def audio_dataset_from_directory(

if sampling_rate is not None:
if not isinstance(sampling_rate, int):
raise ValueError(
'`sampling_rate` should have an integer value. '
'Received: sampling_rate={sampling_rate}'
)
raise ValueError('`sampling_rate` should have an integer value. '
f'Received: sampling_rate={sampling_rate}')

if sampling_rate <= 0:
raise ValueError(
f'`sampling_rate` should be higher than 0. '
'Received: sampling_rate={sampling_rate}'
)
raise ValueError(f'`sampling_rate` should be higher than 0. '
f'Received: sampling_rate={sampling_rate}')

if tfio is None:
raise ImportError(
Expand Down

0 comments on commit babde7f

Please sign in to comment.