From d8aca13fb894d688a33dcb67b0fa5de3a8c21e61 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 20:33:04 +0000 Subject: [PATCH 01/24] Bump the black version. Fixes the ci. --- build_deps/toolchains/gpu/find_cuda_config.py | 15 ++- .../activations/tests/sparsemax_test.py | 12 +- tensorflow_addons/image/compose_ops.py | 2 +- tensorflow_addons/image/cutout_ops.py | 8 +- tensorflow_addons/image/filters.py | 5 +- tensorflow_addons/image/interpolate_spline.py | 2 +- tensorflow_addons/image/sparse_image_warp.py | 4 +- .../image/tests/connected_components_test.py | 6 +- .../image/tests/dense_image_warp_test.py | 9 +- .../image/tests/distort_image_ops_test.py | 5 +- tensorflow_addons/image/tests/filters_test.py | 12 +- .../image/tests/sparse_image_warp_test.py | 3 +- .../image/tests/transform_ops_test.py | 6 +- tensorflow_addons/image/utils.py | 2 +- tensorflow_addons/layers/crf.py | 3 +- tensorflow_addons/layers/esn.py | 2 +- .../layers/spatial_pyramid_pooling.py | 10 +- tensorflow_addons/layers/tests/maxout_test.py | 5 +- .../layers/tests/optical_flow_test.py | 21 +++- .../tests/spectral_normalization_test.py | 12 +- .../layers/tests/wrappers_test.py | 13 ++- tensorflow_addons/losses/metric_learning.py | 15 ++- .../losses/tests/kappa_loss_test.py | 5 +- tensorflow_addons/losses/tests/lifted_test.py | 5 +- .../losses/tests/triplet_test.py | 10 +- tensorflow_addons/metrics/r_square.py | 8 +- .../metrics/tests/hamming_test.py | 6 +- .../tests/multilabel_confusion_matrix_test.py | 14 ++- .../optimizers/average_wrapper.py | 3 +- tensorflow_addons/optimizers/lookahead.py | 17 ++- .../optimizers/moving_average.py | 18 ++- .../tests/conditional_gradient_test.py | 3 +- .../optimizers/tests/lookahead_test.py | 8 +- .../optimizers/tests/moving_average_test.py | 30 ++++- .../optimizers/tests/rectified_adam_test.py | 29 ++++- .../tests/weight_decay_optimizers_test.py | 17 ++- .../optimizers/tests/yogi_test.py | 12 +- .../optimizers/weight_decay_optimizers.py | 4 +- tensorflow_addons/rnn/esn_cell.py | 6 +- tensorflow_addons/rnn/tests/esn_cell_test.py | 7 +- .../seq2seq/beam_search_decoder.py | 3 +- tensorflow_addons/seq2seq/decoder.py | 7 +- .../seq2seq/tests/basic_decoder_test.py | 106 ++++++++++++------ .../seq2seq/tests/beam_search_decoder_test.py | 6 +- .../seq2seq/tests/beam_search_ops_test.py | 3 +- .../seq2seq/tests/decoder_test.py | 16 ++- tensorflow_addons/seq2seq/tests/loss_test.py | 9 +- .../text/tests/parse_time_op_test.py | 4 +- .../text/tests/skip_gram_ops_test.py | 33 +++++- tensorflow_addons/utils/keras_utils.py | 42 +++---- tensorflow_addons/version.py | 8 +- tools/install_deps/black.txt | 2 +- tools/testing/source_code_test.py | 5 +- 53 files changed, 456 insertions(+), 162 deletions(-) diff --git a/build_deps/toolchains/gpu/find_cuda_config.py b/build_deps/toolchains/gpu/find_cuda_config.py index 868f7bddae..daffa05182 100644 --- a/build_deps/toolchains/gpu/find_cuda_config.py +++ b/build_deps/toolchains/gpu/find_cuda_config.py @@ -277,12 +277,23 @@ def get_nvcc_version(path): nvcc_name = "nvcc.exe" if _is_windows() else "nvcc" nvcc_path, nvcc_version = _find_versioned_file( - base_paths, ["", "bin",], nvcc_name, cuda_version, get_nvcc_version + base_paths, + [ + "", + "bin", + ], + nvcc_name, + cuda_version, + get_nvcc_version, ) nvvm_path = _find_file( base_paths, - ["nvvm/libdevice", "share/cuda", "lib/nvidia-cuda-toolkit/libdevice",], + [ + "nvvm/libdevice", + "share/cuda", + "lib/nvidia-cuda-toolkit/libdevice", + ], "libdevice*.10.bc", ) diff --git a/tensorflow_addons/activations/tests/sparsemax_test.py b/tensorflow_addons/activations/tests/sparsemax_test.py index a027b13453..14245a8a41 100644 --- a/tensorflow_addons/activations/tests/sparsemax_test.py +++ b/tensorflow_addons/activations/tests/sparsemax_test.py @@ -112,7 +112,11 @@ def test_sparsemax_against_numpy_high_rank(dtype): def test_sparsemax_of_nan(dtype): """check sparsemax transfers nan.""" z_nan = np.asarray( - [[0, np.nan, 0], [0, np.nan, np.nan], [np.nan, np.nan, np.nan],] + [ + [0, np.nan, 0], + [0, np.nan, np.nan], + [np.nan, np.nan, np.nan], + ] ).astype(dtype) tf_sparsemax_nan = sparsemax(z_nan) @@ -132,7 +136,11 @@ def test_sparsemax_of_nan(dtype): def test_sparsemax_of_inf(dtype): """check sparsemax is infinity safe.""" z_neg = np.asarray( - [[0, -np.inf, 0], [0, -np.inf, -np.inf], [-np.inf, -np.inf, -np.inf],] + [ + [0, -np.inf, 0], + [0, -np.inf, -np.inf], + [-np.inf, -np.inf, -np.inf], + ] ).astype(dtype) z_pos = np.asarray( [[0, np.inf, 0], [0, np.inf, np.inf], [np.inf, np.inf, np.inf]] diff --git a/tensorflow_addons/image/compose_ops.py b/tensorflow_addons/image/compose_ops.py index 9d3aacac97..263fe5cfa5 100644 --- a/tensorflow_addons/image/compose_ops.py +++ b/tensorflow_addons/image/compose_ops.py @@ -43,7 +43,7 @@ def blend(image1: TensorLike, image2: TensorLike, factor: Number) -> tf.Tensor: Returns: A blended image Tensor of `tf.float32`. - """ + """ with tf.name_scope("blend"): if factor == 0.0: diff --git a/tensorflow_addons/image/cutout_ops.py b/tensorflow_addons/image/cutout_ops.py index 6cf52b0980..7c94145a7c 100644 --- a/tensorflow_addons/image/cutout_ops.py +++ b/tensorflow_addons/image/cutout_ops.py @@ -100,7 +100,13 @@ def random_cutout( ) offset = tf.transpose([cutout_center_height, cutout_center_width], [1, 0]) - return cutout(images, mask_size, offset, constant_values, data_format,) + return cutout( + images, + mask_size, + offset, + constant_values, + data_format, + ) def cutout( diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index cc4fc11cad..172335ccc3 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -305,7 +305,10 @@ def gaussian_filter2d( ) image = _pad( - image, filter_shape, mode=padding, constant_values=constant_values, + image, + filter_shape, + mode=padding, + constant_values=constant_values, ) output = tf.nn.depthwise_conv2d( diff --git a/tensorflow_addons/image/interpolate_spline.py b/tensorflow_addons/image/interpolate_spline.py index 6d27599245..3af817bdf2 100644 --- a/tensorflow_addons/image/interpolate_spline.py +++ b/tensorflow_addons/image/interpolate_spline.py @@ -296,7 +296,7 @@ def interpolate_spline( train_values to perform polyharmonic interpolation. The query values are the values of the interpolant evaluated at the locations specified in query_points. - """ + """ with tf.name_scope(name or "interpolate_spline"): train_points = tf.convert_to_tensor(train_points) train_values = tf.convert_to_tensor(train_values) diff --git a/tensorflow_addons/image/sparse_image_warp.py b/tensorflow_addons/image/sparse_image_warp.py index 9b50a4da08..f813f32e60 100644 --- a/tensorflow_addons/image/sparse_image_warp.py +++ b/tensorflow_addons/image/sparse_image_warp.py @@ -39,7 +39,9 @@ def _expand_to_minibatch(np_array: TensorLike, batch_size: TensorLike) -> Tensor def _get_boundary_locations( - image_height: TensorLike, image_width: TensorLike, num_points_per_edge: TensorLike, + image_height: TensorLike, + image_width: TensorLike, + num_points_per_edge: TensorLike, ) -> TensorLike: """Compute evenly-spaced indices along edge of image.""" y_range = np.linspace(0, image_height - 1, num_points_per_edge + 2) diff --git a/tensorflow_addons/image/tests/connected_components_test.py b/tensorflow_addons/image/tests/connected_components_test.py index ec354932ad..6240584923 100644 --- a/tensorflow_addons/image/tests/connected_components_test.py +++ b/tensorflow_addons/image/tests/connected_components_test.py @@ -118,7 +118,8 @@ def test_multiple_images(): @pytest.mark.usefixtures("maybe_run_functions_eagerly") def test_zeros(): np.testing.assert_equal( - connected_components(tf.zeros((100, 20, 50), tf.bool)), np.zeros((100, 20, 50)), + connected_components(tf.zeros((100, 20, 50), tf.bool)), + np.zeros((100, 20, 50)), ) @@ -134,7 +135,8 @@ def test_ones(): def test_ones_small(): np.testing.assert_equal( - connected_components(tf.ones((3, 5), tf.bool)).numpy(), np.ones((3, 5)), + connected_components(tf.ones((3, 5), tf.bool)).numpy(), + np.ones((3, 5)), ) diff --git a/tensorflow_addons/image/tests/dense_image_warp_test.py b/tensorflow_addons/image/tests/dense_image_warp_test.py index 24397ec7be..a09f964f3a 100644 --- a/tensorflow_addons/image/tests/dense_image_warp_test.py +++ b/tensorflow_addons/image/tests/dense_image_warp_test.py @@ -30,7 +30,8 @@ def test_interpolate_small_grid_ij(): shape=[1, 4, 3, 1], ) query_points = tf.constant( - [[0.0, 0.0], [1.0, 0.0], [2.0, 0.5], [1.5, 1.5], [3.0, 2.0]], shape=[1, 5, 2], + [[0.0, 0.0], [1.0, 0.0], [2.0, 0.5], [1.5, 1.5], [3.0, 2.0]], + shape=[1, 5, 2], ) expected_results = np.reshape(np.array([0.0, 3.0, 6.5, 6.0, 11.0]), [1, 5, 1]) @@ -45,7 +46,8 @@ def test_interpolate_small_grid_xy(): shape=[1, 4, 3, 1], ) query_points = tf.constant( - [[0.0, 0.0], [0.0, 1.0], [0.5, 2.0], [1.5, 1.5], [2.0, 3.0]], shape=[1, 5, 2], + [[0.0, 0.0], [0.0, 1.0], [0.5, 2.0], [1.5, 1.5], [2.0, 3.0]], + shape=[1, 5, 2], ) expected_results = np.reshape(np.array([0.0, 3.0, 6.5, 6.0, 11.0]), [1, 5, 1]) @@ -91,7 +93,8 @@ def _check_zero_flow_correctness(shape, image_type, flow_type): rand_flows *= 0 interp = dense_image_warp( - image=tf.convert_to_tensor(rand_image), flow=tf.convert_to_tensor(rand_flows), + image=tf.convert_to_tensor(rand_image), + flow=tf.convert_to_tensor(rand_flows), ) np.testing.assert_allclose(rand_image, interp, rtol=1e-6, atol=1e-6) diff --git a/tensorflow_addons/image/tests/distort_image_ops_test.py b/tensorflow_addons/image/tests/distort_image_ops_test.py index af37c75d77..ae24ebe8e1 100644 --- a/tensorflow_addons/image/tests/distort_image_ops_test.py +++ b/tensorflow_addons/image/tests/distort_image_ops_test.py @@ -125,7 +125,10 @@ def test_adjust_hsv_in_yiq_unknown_shape(): image_np = np.random.rand(*shape) * 255.0 image_tf = tf.constant(image_np) np.testing.assert_allclose( - _adjust_hue_in_yiq_np(image_np, 0), fn(image_tf), rtol=2e-4, atol=1e-4, + _adjust_hue_in_yiq_np(image_np, 0), + fn(image_tf), + rtol=2e-4, + atol=1e-4, ) diff --git a/tensorflow_addons/image/tests/filters_test.py b/tensorflow_addons/image/tests/filters_test.py index 1376a4c039..819d246550 100644 --- a/tensorflow_addons/image/tests/filters_test.py +++ b/tensorflow_addons/image/tests/filters_test.py @@ -62,7 +62,9 @@ def setup_values( assert 3 <= len(image_shape) <= 4 height, width = image_shape[-3], image_shape[-2] plane = tf.constant( - [x for x in range(1, height * width + 1)], shape=(height, width), dtype=dtype, + [x for x in range(1, height * width + 1)], + shape=(height, width), + dtype=dtype, ) image = tile_image(plane, image_shape=image_shape) @@ -172,7 +174,13 @@ def test_reflect_padding_with_3x3_filter_mean(image_shape): @pytest.mark.parametrize("image_shape", _image_shapes_to_test) def test_reflect_padding_with_4x4_filter_mean(image_shape): - expected_plane = tf.constant([[5.0, 5.0, 5.0], [5.0, 5.0, 5.0], [5.0, 5.0, 5.0],]) + expected_plane = tf.constant( + [ + [5.0, 5.0, 5.0], + [5.0, 5.0, 5.0], + [5.0, 5.0, 5.0], + ] + ) verify_values( mean_filter2d, diff --git a/tensorflow_addons/image/tests/sparse_image_warp_test.py b/tensorflow_addons/image/tests/sparse_image_warp_test.py index ce22ff8126..3a89897f46 100644 --- a/tensorflow_addons/image/tests/sparse_image_warp_test.py +++ b/tensorflow_addons/image/tests/sparse_image_warp_test.py @@ -121,7 +121,8 @@ def assert_move_single_pixel(order, num_boundary_points, type_to_use): # Shift it one pixel to the right. control_point_displacements = [[0.0, 1.0]] control_point_displacements = tf.constant( - np.float32(np.expand_dims(control_point_displacements, 0)), dtype=type_to_use, + np.float32(np.expand_dims(control_point_displacements, 0)), + dtype=type_to_use, ) (warped_image, flow) = sparse_image_warp( diff --git a/tensorflow_addons/image/tests/transform_ops_test.py b/tensorflow_addons/image/tests/transform_ops_test.py index d634455548..ca8470a9b0 100644 --- a/tensorflow_addons/image/tests/transform_ops_test.py +++ b/tensorflow_addons/image/tests/transform_ops_test.py @@ -36,7 +36,8 @@ @pytest.mark.parametrize("dtype", _DTYPES) def test_compose(dtype): image = tf.constant( - [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=dtype, + [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]], + dtype=dtype, ) # Rotate counter-clockwise by pi / 2. rotation = transform_ops.angles_to_projective_transforms(np.pi / 2, 4, 4) @@ -56,7 +57,8 @@ def test_compose(dtype): @pytest.mark.parametrize("dtype", _DTYPES) def test_extreme_projective_transform(dtype): image = tf.constant( - [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], dtype=dtype, + [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], + dtype=dtype, ) transformation = tf.constant([1, 0, 0, 0, 1, 0, -1, 0], tf.dtypes.float32) image_transformed = transform_ops.transform(image, transformation) diff --git a/tensorflow_addons/image/utils.py b/tensorflow_addons/image/utils.py index e4bf497ebc..9fb688736a 100644 --- a/tensorflow_addons/image/utils.py +++ b/tensorflow_addons/image/utils.py @@ -126,7 +126,7 @@ def unwrap(image, replace): Returns: image: A 3D image `Tensor` with 3 channels. - """ + """ image_shape = tf.shape(image) # Flatten the spatial dimensions. flattened_image = tf.reshape(image, [-1, image_shape[2]]) diff --git a/tensorflow_addons/layers/crf.py b/tensorflow_addons/layers/crf.py index 7449ce7dcc..3663eb5f56 100644 --- a/tensorflow_addons/layers/crf.py +++ b/tensorflow_addons/layers/crf.py @@ -77,7 +77,8 @@ def __init__( if self.use_kernel: self._dense_layer = tf.keras.layers.Dense( - units=self.units, dtype=self.dtype, + units=self.units, + dtype=self.dtype, ) else: self._dense_layer = lambda x: tf.cast(x, dtype=self.dtype) diff --git a/tensorflow_addons/layers/esn.py b/tensorflow_addons/layers/esn.py index ceaf68741b..1abe43333c 100644 --- a/tensorflow_addons/layers/esn.py +++ b/tensorflow_addons/layers/esn.py @@ -90,7 +90,7 @@ class ESN(tf.keras.layers.RNN): `recurrent_dropout` is used. initial_state: List of initial state tensors to be passed to the first call of the cell. - """ + """ @typechecked def __init__( diff --git a/tensorflow_addons/layers/spatial_pyramid_pooling.py b/tensorflow_addons/layers/spatial_pyramid_pooling.py index f96c0067eb..3653813555 100644 --- a/tensorflow_addons/layers/spatial_pyramid_pooling.py +++ b/tensorflow_addons/layers/spatial_pyramid_pooling.py @@ -87,7 +87,10 @@ def call(self, inputs, **kwargs): new_input_width = dynamic_input_shape[2] - width_overflow new_inp = inputs[ - :, :new_input_height, :new_input_width, :, + :, + :new_input_height, + :new_input_width, + :, ] output = self.pool_layers[index](new_inp) output = tf.reshape( @@ -104,7 +107,10 @@ def call(self, inputs, **kwargs): new_input_width = dynamic_input_shape[3] - width_overflow new_inp = inputs[ - :, :, :new_input_height, :new_input_width, + :, + :, + :new_input_height, + :new_input_width, ] output = self.pool_layers[index](new_inp) output = tf.reshape( diff --git a/tensorflow_addons/layers/tests/maxout_test.py b/tensorflow_addons/layers/tests/maxout_test.py index 6fcd88fe55..07efadb6b9 100644 --- a/tensorflow_addons/layers/tests/maxout_test.py +++ b/tensorflow_addons/layers/tests/maxout_test.py @@ -42,7 +42,10 @@ def test_nchw(): def test_unknown(): inputs = np.random.random((5, 4, 2, 18)).astype("float32") test_utils.layer_test( - Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, None), input_data=inputs, + Maxout, + kwargs={"num_units": 3}, + input_shape=(5, 4, 2, None), + input_data=inputs, ) test_utils.layer_test( diff --git a/tensorflow_addons/layers/tests/optical_flow_test.py b/tensorflow_addons/layers/tests/optical_flow_test.py index 894f141485..eff642a6ee 100644 --- a/tensorflow_addons/layers/tests/optical_flow_test.py +++ b/tensorflow_addons/layers/tests/optical_flow_test.py @@ -105,11 +105,28 @@ def test_forward_simple(data_format): actual = tf.transpose(actual, [0, 3, 1, 2]) # We can test fixed ids, as output is independent from data_format - expected_ids = np.concatenate([np.zeros(464,), np.ones(464,)]) + expected_ids = np.concatenate( + [ + np.zeros( + 464, + ), + np.ones( + 464, + ), + ] + ) np.testing.assert_allclose(tf.where(actual == 0)[:, 0].numpy(), expected_ids) counts = [54, 52, 54, 50, 44, 50, 54, 52, 54] - expected_ids = np.concatenate([k * np.ones(v,) for k, v in enumerate(counts)]) + expected_ids = np.concatenate( + [ + k + * np.ones( + v, + ) + for k, v in enumerate(counts) + ] + ) expected_ids = np.concatenate([expected_ids, expected_ids]) np.testing.assert_allclose(tf.where(actual == 0)[:, 1], expected_ids) assert actual.shape == (2, 9, 7, 8) diff --git a/tensorflow_addons/layers/tests/spectral_normalization_test.py b/tensorflow_addons/layers/tests/spectral_normalization_test.py index 48b96aa5e3..3fbccb9160 100644 --- a/tensorflow_addons/layers/tests/spectral_normalization_test.py +++ b/tensorflow_addons/layers/tests/spectral_normalization_test.py @@ -95,7 +95,10 @@ def test_model_fit(base_layer_fn, input_shape, output_shape): "base_layer_fn, input_shape", [ (lambda: tf.keras.layers.Dense(2), [3, 2]), - (lambda: tf.keras.layers.Conv2D(3, (2, 2), padding="same"), [4, 4, 3],), + ( + lambda: tf.keras.layers.Conv2D(3, (2, 2), padding="same"), + [4, 4, 3], + ), (lambda: tf.keras.layers.Embedding(2, 10), [2]), ], ) @@ -113,7 +116,9 @@ def test_normalization(): inputs = tf.keras.layers.Input(shape=[2, 2, 1]) base_layer = tf.keras.layers.Conv2D( - 1, (2, 2), kernel_initializer=tf.constant_initializer(value=2), + 1, + (2, 2), + kernel_initializer=tf.constant_initializer(value=2), ) sn_layer = spectral_normalization.SpectralNormalization(base_layer) model = tf.keras.models.Sequential(layers=[inputs, sn_layer]) @@ -125,7 +130,8 @@ def test_normalization(): for training in [False, True]: _ = model( - tf.constant(np.ones((1, 2, 2, 1), dtype=np.float32)), training=training, + tf.constant(np.ones((1, 2, 2, 1), dtype=np.float32)), + training=training, ) if training: w = weights_normalized diff --git a/tensorflow_addons/layers/tests/wrappers_test.py b/tensorflow_addons/layers/tests/wrappers_test.py index 372e467663..50bbfdac31 100644 --- a/tensorflow_addons/layers/tests/wrappers_test.py +++ b/tensorflow_addons/layers/tests/wrappers_test.py @@ -27,7 +27,9 @@ def test_basic(): test_utils.layer_test( wrappers.WeightNormalization, - kwargs={"layer": tf.keras.layers.Conv2D(5, (2, 2)),}, + kwargs={ + "layer": tf.keras.layers.Conv2D(5, (2, 2)), + }, input_shape=(2, 4, 4, 3), ) @@ -35,7 +37,9 @@ def test_basic(): def test_no_bias(): test_utils.layer_test( wrappers.WeightNormalization, - kwargs={"layer": tf.keras.layers.Dense(5, use_bias=False),}, + kwargs={ + "layer": tf.keras.layers.Dense(5, use_bias=False), + }, input_shape=(2, 4), ) @@ -49,7 +53,10 @@ def _check_data_init(data_init, input_data, expected_output): ) test_utils.layer_test( wrappers.WeightNormalization, - kwargs={"layer": layer, "data_init": data_init,}, + kwargs={ + "layer": layer, + "data_init": data_init, + }, input_data=input_data, expected_output=expected_output, ) diff --git a/tensorflow_addons/losses/metric_learning.py b/tensorflow_addons/losses/metric_learning.py index c9e8889247..2cbf43affa 100644 --- a/tensorflow_addons/losses/metric_learning.py +++ b/tensorflow_addons/losses/metric_learning.py @@ -31,12 +31,15 @@ def pairwise_distance(feature: TensorLike, squared: bool = False): Returns: pairwise_distances: 2-D Tensor of size `[number of data, number of data]`. """ - pairwise_distances_squared = tf.math.add( - tf.math.reduce_sum(tf.math.square(feature), axis=[1], keepdims=True), - tf.math.reduce_sum( - tf.math.square(tf.transpose(feature)), axis=[0], keepdims=True - ), - ) - 2.0 * tf.matmul(feature, tf.transpose(feature)) + pairwise_distances_squared = ( + tf.math.add( + tf.math.reduce_sum(tf.math.square(feature), axis=[1], keepdims=True), + tf.math.reduce_sum( + tf.math.square(tf.transpose(feature)), axis=[0], keepdims=True + ), + ) + - 2.0 * tf.matmul(feature, tf.transpose(feature)) + ) # Deal with numerical inaccuracies. Set small negatives to zero. pairwise_distances_squared = tf.math.maximum(pairwise_distances_squared, 0.0) diff --git a/tensorflow_addons/losses/tests/kappa_loss_test.py b/tensorflow_addons/losses/tests/kappa_loss_test.py index 9b647b9ded..d6658a7918 100644 --- a/tensorflow_addons/losses/tests/kappa_loss_test.py +++ b/tensorflow_addons/losses/tests/kappa_loss_test.py @@ -79,7 +79,10 @@ def test_quadratic_weighted_kappa_loss(np_seed): def test_config(): kappa_loss = WeightedKappaLoss( - num_classes=4, weightage="linear", name="kappa_loss", epsilon=0.001, + num_classes=4, + weightage="linear", + name="kappa_loss", + epsilon=0.001, ) assert kappa_loss.num_classes == 4 assert kappa_loss.weightage == "linear" diff --git a/tensorflow_addons/losses/tests/lifted_test.py b/tensorflow_addons/losses/tests/lifted_test.py index 5223dd3871..a88e05a1ef 100644 --- a/tensorflow_addons/losses/tests/lifted_test.py +++ b/tensorflow_addons/losses/tests/lifted_test.py @@ -112,7 +112,10 @@ def test_lifted_struct(dtype): def test_keras_model_compile(): model = tf.keras.models.Sequential( - [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10),] + [ + tf.keras.layers.Input(shape=(784,)), + tf.keras.layers.Dense(10), + ] ) model.compile(loss="Addons>lifted_struct_loss", optimizer="adam") diff --git a/tensorflow_addons/losses/tests/triplet_test.py b/tensorflow_addons/losses/tests/triplet_test.py index eda7dc0b50..ee98406a64 100644 --- a/tensorflow_addons/losses/tests/triplet_test.py +++ b/tensorflow_addons/losses/tests/triplet_test.py @@ -182,7 +182,10 @@ def test_semihard_tripled_loss_angular(dtype, dist_func, dist_metric): def test_keras_model_compile_semihard(): model = tf.keras.models.Sequential( - [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10),] + [ + tf.keras.layers.Input(shape=(784,)), + tf.keras.layers.Dense(10), + ] ) model.compile(loss="Addons>triplet_semihard_loss", optimizer="adam") @@ -225,7 +228,10 @@ def test_hard_tripled_loss_angular(dtype, soft, dist_func, dist_metric): def test_keras_model_compile_hard(): model = tf.keras.models.Sequential( - [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10),] + [ + tf.keras.layers.Input(shape=(784,)), + tf.keras.layers.Dense(10), + ] ) model.compile(loss="Addons>triplet_hard_loss", optimizer="adam") diff --git a/tensorflow_addons/metrics/r_square.py b/tensorflow_addons/metrics/r_square.py index 8ae78fc543..20d5545dea 100644 --- a/tensorflow_addons/metrics/r_square.py +++ b/tensorflow_addons/metrics/r_square.py @@ -30,8 +30,7 @@ def _reduce_average( input_tensor: tf.Tensor, axis=None, keepdims=False, weights=None ) -> tf.Tensor: - """Computes the (weighted) mean of elements across dimensions of a tensor. - """ + """Computes the (weighted) mean of elements across dimensions of a tensor.""" if weights is None: return tf.reduce_mean(input_tensor, axis=axis, keepdims=keepdims) @@ -116,7 +115,10 @@ def update_state(self, y_true, y_pred, sample_weight=None) -> None: self.sum.assign_add(tf.reduce_sum(weighted_y_true, axis=0)) self.squared_sum.assign_add(tf.reduce_sum(y_true * weighted_y_true, axis=0)) self.res.assign_add( - tf.reduce_sum((y_true - y_pred) ** 2 * sample_weight, axis=0,) + tf.reduce_sum( + (y_true - y_pred) ** 2 * sample_weight, + axis=0, + ) ) self.count.assign_add(tf.reduce_sum(sample_weight, axis=0)) diff --git a/tensorflow_addons/metrics/tests/hamming_test.py b/tensorflow_addons/metrics/tests/hamming_test.py index 4ed1b4dc8e..8e63d6cb65 100644 --- a/tensorflow_addons/metrics/tests/hamming_test.py +++ b/tensorflow_addons/metrics/tests/hamming_test.py @@ -101,7 +101,11 @@ def test_mc_5_classes(): def test_ml_4_classes(): actuals = tf.constant([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 0, 1]], dtype=tf.float32) predictions = tf.constant( - [[0.97, 0.56, 0.83, 0.77], [0.34, 0.95, 0.7, 0.89], [0.95, 0.45, 0.23, 0.56],], + [ + [0.97, 0.56, 0.83, 0.77], + [0.34, 0.95, 0.7, 0.89], + [0.95, 0.45, 0.23, 0.56], + ], dtype=tf.float32, ) # Initialize diff --git a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py index 36f586a032..e9e6c5fb58 100644 --- a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py +++ b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py @@ -84,7 +84,12 @@ def test_mcm_4_classes(dtype): # Check results check_results( mcm_obj, - [[[4, 1], [1, 4]], [[6, 0], [2, 2]], [[6, 1], [1, 2]], [[2, 0], [2, 6]],], + [ + [[4, 1], [1, 4]], + [[6, 0], [2, 2]], + [[6, 1], [1, 2]], + [[2, 0], [2, 6]], + ], ) @@ -127,5 +132,10 @@ def test_multiclass(dtype): # Check results check_results( mcm_obj, - [[[5, 2], [0, 3]], [[7, 1], [2, 0]], [[7, 0], [1, 2]], [[8, 0], [0, 2]],], + [ + [[5, 2], [0, 3]], + [[7, 1], [2, 0]], + [[7, 0], [1, 2]], + [[8, 0], [0, 2]], + ], ) diff --git a/tensorflow_addons/optimizers/average_wrapper.py b/tensorflow_addons/optimizers/average_wrapper.py index 86f815bb4d..62751ffd47 100644 --- a/tensorflow_addons/optimizers/average_wrapper.py +++ b/tensorflow_addons/optimizers/average_wrapper.py @@ -137,7 +137,8 @@ def get_config(self): @classmethod def from_config(cls, config, custom_objects=None): optimizer = tf.keras.optimizers.deserialize( - config.pop("optimizer"), custom_objects=custom_objects, + config.pop("optimizer"), + custom_objects=custom_objects, ) return cls(optimizer, **config) diff --git a/tensorflow_addons/optimizers/lookahead.py b/tensorflow_addons/optimizers/lookahead.py index 8f96dc9c62..61c4170875 100644 --- a/tensorflow_addons/optimizers/lookahead.py +++ b/tensorflow_addons/optimizers/lookahead.py @@ -125,10 +125,20 @@ def _look_ahead_op(self, var): ) with tf.control_dependencies([step_back]): slow_update = slow_var.assign( - tf.where(sync_cond, step_back, slow_var,), use_locking=self._use_locking + tf.where( + sync_cond, + step_back, + slow_var, + ), + use_locking=self._use_locking, ) var_update = var.assign( - tf.where(sync_cond, step_back, var,), use_locking=self._use_locking + tf.where( + sync_cond, + step_back, + var, + ), + use_locking=self._use_locking, ) return tf.group(slow_update, var_update) @@ -184,6 +194,7 @@ def lr(self, lr): @classmethod def from_config(cls, config, custom_objects=None): optimizer = tf.keras.optimizers.deserialize( - config.pop("optimizer"), custom_objects=custom_objects, + config.pop("optimizer"), + custom_objects=custom_objects, ) return cls(optimizer, **config) diff --git a/tensorflow_addons/optimizers/moving_average.py b/tensorflow_addons/optimizers/moving_average.py index 7e92186ad9..4a0fd99fac 100644 --- a/tensorflow_addons/optimizers/moving_average.py +++ b/tensorflow_addons/optimizers/moving_average.py @@ -140,11 +140,11 @@ def has_shadow_copy(self): def swap_weights(self): """Swap the average and moving weights. - This is a convenience method to allow one to evaluate the averaged weights - at test time. Loads the weights stored in `self._average_weights` into the model, - keeping a copy of the original model weights. Swapping twice will return - the original weights. - """ + This is a convenience method to allow one to evaluate the averaged weights + at test time. Loads the weights stored in `self._average_weights` into the model, + keeping a copy of the original model weights. Swapping twice will return + the original weights. + """ if tf.distribute.in_cross_replica_context(): strategy = tf.distribute.get_strategy() return strategy.run(self._swap_weights, args=()) @@ -178,4 +178,10 @@ def swap(strategy, a, b): ) # a = a - b ctx = tf.distribute.get_replica_context() - return ctx.merge_call(swap, args=(self._average_weights, self._model_weights,)) + return ctx.merge_call( + swap, + args=( + self._average_weights, + self._model_weights, + ), + ) diff --git a/tensorflow_addons/optimizers/tests/conditional_gradient_test.py b/tensorflow_addons/optimizers/tests/conditional_gradient_test.py index b3f7ac37be..2adf04cef5 100644 --- a/tensorflow_addons/optimizers/tests/conditional_gradient_test.py +++ b/tensorflow_addons/optimizers/tests/conditional_gradient_test.py @@ -1355,7 +1355,8 @@ def test_sparse_nuclear(): tf.constant([4, 2]), ) top_singular_vector0 = tf.constant( - [[0.0, 0.0], [0.7071067, 0.7071067], [0.0, 0.0], [0.0, 0.0]], dtype=dtype, + [[0.0, 0.0], [0.7071067, 0.7071067], [0.0, 0.0], [0.0, 0.0]], + dtype=dtype, ) top_singular_vector1 = tf.constant( [ diff --git a/tensorflow_addons/optimizers/tests/lookahead_test.py b/tensorflow_addons/optimizers/tests/lookahead_test.py index 4802bf0fd5..6e4a760b7c 100644 --- a/tensorflow_addons/optimizers/tests/lookahead_test.py +++ b/tensorflow_addons/optimizers/tests/lookahead_test.py @@ -55,10 +55,14 @@ def run_sparse_sample(iterations, optimizer, seed=0x2019): var_1 = tf.Variable(val_1, dtype=tf.dtypes.float32) grad_0 = tf.IndexedSlices( - tf.constant([np.random.standard_normal()]), tf.constant([0]), tf.constant([2]), + tf.constant([np.random.standard_normal()]), + tf.constant([0]), + tf.constant([2]), ) grad_1 = tf.IndexedSlices( - tf.constant([np.random.standard_normal()]), tf.constant([1]), tf.constant([2]), + tf.constant([np.random.standard_normal()]), + tf.constant([1]), + tf.constant([2]), ) grads_and_vars = list(zip([grad_0, grad_1], [var_0, var_1])) diff --git a/tensorflow_addons/optimizers/tests/moving_average_test.py b/tensorflow_addons/optimizers/tests/moving_average_test.py index 3e1d77e1e5..91ab8f892d 100644 --- a/tensorflow_addons/optimizers/tests/moving_average_test.py +++ b/tensorflow_addons/optimizers/tests/moving_average_test.py @@ -31,7 +31,10 @@ def test_run(): grads_and_vars = list(zip([grads0, grads1], [var0, var1])) - opt = MovingAverage(tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5,) + opt = MovingAverage( + tf.keras.optimizers.SGD(lr=2.0), + average_decay=0.5, + ) opt.apply_gradients(grads_and_vars) opt.apply_gradients(grads_and_vars) @@ -118,7 +121,11 @@ def test_optimizer_string(): def test_config(): sgd_opt = tf.keras.optimizers.SGD(lr=2.0, nesterov=True, momentum=0.3, decay=0.1) opt = MovingAverage( - sgd_opt, average_decay=0.5, num_updates=None, start_step=5, dynamic_decay=True, + sgd_opt, + average_decay=0.5, + num_updates=None, + start_step=5, + dynamic_decay=True, ) config = opt.get_config() @@ -166,7 +173,11 @@ def test_fit_simple_linear_model(): def test_serialization(): sgd_opt = tf.keras.optimizers.SGD(lr=2.0, nesterov=True, momentum=0.3, decay=0.1) optimizer = MovingAverage( - sgd_opt, average_decay=0.5, num_updates=None, start_step=5, dynamic_decay=True, + sgd_opt, + average_decay=0.5, + num_updates=None, + start_step=5, + dynamic_decay=True, ) config = tf.keras.optimizers.serialize(optimizer) new_optimizer = tf.keras.optimizers.deserialize(config) @@ -180,7 +191,9 @@ def test_start_step(): grads_and_vars = [(grads0, var0)] opt = MovingAverage( - tf.keras.optimizers.SGD(lr=1.0), average_decay=0.5, start_step=1, + tf.keras.optimizers.SGD(lr=1.0), + average_decay=0.5, + start_step=1, ) opt.apply_gradients(grads_and_vars) @@ -203,7 +216,9 @@ def test_dynamic_decay(): grads_and_vars = [(grads0, var0)] opt = MovingAverage( - tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5, dynamic_decay=True, + tf.keras.optimizers.SGD(lr=2.0), + average_decay=0.5, + dynamic_decay=True, ) opt.apply_gradients(grads_and_vars) @@ -222,7 +237,10 @@ def test_swap_weights(device): var = tf.Variable([1.0, 2.0]) grads = tf.constant([0.1, 0.1]) - opt = MovingAverage(tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5,) + opt = MovingAverage( + tf.keras.optimizers.SGD(lr=2.0), + average_decay=0.5, + ) @tf.function def apply_gradients(): diff --git a/tensorflow_addons/optimizers/tests/rectified_adam_test.py b/tensorflow_addons/optimizers/tests/rectified_adam_test.py index 3fe0043bcb..1e7b967066 100644 --- a/tensorflow_addons/optimizers/tests/rectified_adam_test.py +++ b/tensorflow_addons/optimizers/tests/rectified_adam_test.py @@ -121,7 +121,10 @@ def test_dense_sample_with_warmup(): iterations=100, expected=[[0.994062, 1.993912], [2.994167, 3.994152]], optimizer=RectifiedAdam( - lr=1e-3, total_steps=100, warmup_proportion=0.1, min_lr=1e-5, + lr=1e-3, + total_steps=100, + warmup_proportion=0.1, + min_lr=1e-5, ), ) @@ -132,7 +135,10 @@ def test_sparse_sample_with_warmup(): iterations=200, expected=[[0.982629, 2.0], [3.0, 3.982674]], optimizer=RectifiedAdam( - lr=1e-3, total_steps=200, warmup_proportion=0.1, min_lr=1e-5, + lr=1e-3, + total_steps=200, + warmup_proportion=0.1, + min_lr=1e-5, ), ) @@ -145,7 +151,12 @@ def test_dense_sample_with_lookahead(): iterations=100, expected=[[0.993126, 1.992901], [2.993283, 3.993261]], optimizer=Lookahead( - RectifiedAdam(lr=1e-3, beta_1=0.95,), sync_period=6, slow_step_size=0.45, + RectifiedAdam( + lr=1e-3, + beta_1=0.95, + ), + sync_period=6, + slow_step_size=0.45, ), ) @@ -158,7 +169,12 @@ def test_sparse_sample_with_lookahead(): iterations=150, expected=[[0.988156, 2.0], [3.0, 3.988291]], optimizer=Lookahead( - RectifiedAdam(lr=1e-3, beta_1=0.95,), sync_period=6, slow_step_size=0.45, + RectifiedAdam( + lr=1e-3, + beta_1=0.95, + ), + sync_period=6, + slow_step_size=0.45, ), ) @@ -172,7 +188,10 @@ def test_get_config(): def test_serialization(): optimizer = RectifiedAdam( - lr=1e-3, total_steps=10000, warmup_proportion=0.1, min_lr=1e-5, + lr=1e-3, + total_steps=10000, + warmup_proportion=0.1, + min_lr=1e-5, ) config = tf.keras.optimizers.serialize(optimizer) new_optimizer = tf.keras.optimizers.deserialize(config) diff --git a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py index 6dd3d0106a..31a8b96fd3 100644 --- a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py +++ b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py @@ -68,11 +68,15 @@ def do_test( if do_sparse: grads0_np_indices = np.array([0, 1], dtype=np.int32) grads0 = tf.IndexedSlices( - tf.constant(grads0_np), tf.constant(grads0_np_indices), tf.constant([2]), + tf.constant(grads0_np), + tf.constant(grads0_np_indices), + tf.constant([2]), ) grads1_np_indices = np.array([0, 1], dtype=np.int32) grads1 = tf.IndexedSlices( - tf.constant(grads1_np), tf.constant(grads1_np_indices), tf.constant([2]), + tf.constant(grads1_np), + tf.constant(grads1_np_indices), + tf.constant([2]), ) else: grads0 = tf.constant(grads0_np) @@ -83,7 +87,8 @@ def do_test( for _ in range(3): if do_decay_var_list: opt.apply_gradients( - zip([grads0, grads1], [var0, var1]), decay_var_list=[var0, var1], + zip([grads0, grads1], [var0, var1]), + decay_var_list=[var0, var1], ) else: opt.apply_gradients(zip([grads0, grads1], [var0, var1])) @@ -374,7 +379,11 @@ def test_optimizer_basic(dtype, optimizer): @pytest.mark.parametrize("dtype", [tf.half, tf.float32, tf.float64]) def test_optimizer_sparse(dtype, optimizer): do_test_sparse_repeated_indices( - dtype, optimizer, learning_rate=0.001, momentum=0.9, weight_decay=WEIGHT_DECAY, + dtype, + optimizer, + learning_rate=0.001, + momentum=0.9, + weight_decay=WEIGHT_DECAY, ) diff --git a/tensorflow_addons/optimizers/tests/yogi_test.py b/tensorflow_addons/optimizers/tests/yogi_test.py index fcd98d49bb..47c9aab890 100644 --- a/tensorflow_addons/optimizers/tests/yogi_test.py +++ b/tensorflow_addons/optimizers/tests/yogi_test.py @@ -141,10 +141,12 @@ def do_test_sparse(beta1=0.0, l1reg=0.0, l2reg=0.0): # Validate updated params. test_utils.assert_allclose_according_to_type( - var0_np, var0.numpy(), + var0_np, + var0.numpy(), ) test_utils.assert_allclose_according_to_type( - var1_np, var1.numpy(), + var1_np, + var1.numpy(), ) @@ -186,7 +188,8 @@ def test_sparse_repeated_indices(): opt2 = yogi.Yogi() np.testing.assert_allclose( - aggregated_update_var.numpy(), repeated_index_update_var.numpy(), + aggregated_update_var.numpy(), + repeated_index_update_var.numpy(), ) for _ in range(3): @@ -194,7 +197,8 @@ def test_sparse_repeated_indices(): opt2.apply_gradients([(grad_aggregated, aggregated_update_var)]) np.testing.assert_allclose( - aggregated_update_var.numpy(), repeated_index_update_var.numpy(), + aggregated_update_var.numpy(), + repeated_index_update_var.numpy(), ) diff --git a/tensorflow_addons/optimizers/weight_decay_optimizers.py b/tensorflow_addons/optimizers/weight_decay_optimizers.py index 1f798b2474..7959d93585 100644 --- a/tensorflow_addons/optimizers/weight_decay_optimizers.py +++ b/tensorflow_addons/optimizers/weight_decay_optimizers.py @@ -89,7 +89,9 @@ def __init__(self, weight_decay: Union[FloatTensorLike, Callable], **kwargs): def get_config(self): config = super().get_config() config.update( - {"weight_decay": self._serialize_hyperparameter("weight_decay"),} + { + "weight_decay": self._serialize_hyperparameter("weight_decay"), + } ) return config diff --git a/tensorflow_addons/rnn/esn_cell.py b/tensorflow_addons/rnn/esn_cell.py index 640c8c88fd..d44c1a8257 100644 --- a/tensorflow_addons/rnn/esn_cell.py +++ b/tensorflow_addons/rnn/esn_cell.py @@ -118,7 +118,11 @@ def _esn_recurrent_initializer(shape, dtype, partition_info=None): ) connectivity_mask = tf.cast( - tf.math.less_equal(tf.random.uniform(shape), self.connectivity,), dtype + tf.math.less_equal( + tf.random.uniform(shape), + self.connectivity, + ), + dtype, ) recurrent_weights = tf.math.multiply(recurrent_weights, connectivity_mask) diff --git a/tensorflow_addons/rnn/tests/esn_cell_test.py b/tensorflow_addons/rnn/tests/esn_cell_test.py index d88d3d372b..5b0be18cae 100644 --- a/tensorflow_addons/rnn/tests/esn_cell_test.py +++ b/tensorflow_addons/rnn/tests/esn_cell_test.py @@ -24,7 +24,12 @@ def test_base_esn(): units = 3 expected_output = np.array( - [[2.77, 2.77, 2.77], [4.77, 4.77, 4.77], [6.77, 6.77, 6.77],], dtype=np.float32, + [ + [2.77, 2.77, 2.77], + [4.77, 4.77, 4.77], + [6.77, 6.77, 6.77], + ], + dtype=np.float32, ) const_initializer = tf.constant_initializer(0.5) diff --git a/tensorflow_addons/seq2seq/beam_search_decoder.py b/tensorflow_addons/seq2seq/beam_search_decoder.py index 9d5d3c30dc..6685d28eb7 100644 --- a/tensorflow_addons/seq2seq/beam_search_decoder.py +++ b/tensorflow_addons/seq2seq/beam_search_decoder.py @@ -63,7 +63,8 @@ class BeamSearchDecoderState( class BeamSearchDecoderOutput( collections.namedtuple( - "BeamSearchDecoderOutput", ("scores", "predicted_ids", "parent_ids"), + "BeamSearchDecoderOutput", + ("scores", "predicted_ids", "parent_ids"), ) ): """Outputs of a `BeamSearchDecoder` step. diff --git a/tensorflow_addons/seq2seq/decoder.py b/tensorflow_addons/seq2seq/decoder.py index 6c3c24c734..c098a80feb 100644 --- a/tensorflow_addons/seq2seq/decoder.py +++ b/tensorflow_addons/seq2seq/decoder.py @@ -308,8 +308,11 @@ def dynamic_decode( ValueError: if `maximum_iterations` is provided but is not a scalar. """ with tf.name_scope(scope or "decoder"): - is_xla = not tf.executing_eagerly() and control_flow_util.GraphOrParentsInXlaContext( - tf.compat.v1.get_default_graph() + is_xla = ( + not tf.executing_eagerly() + and control_flow_util.GraphOrParentsInXlaContext( + tf.compat.v1.get_default_graph() + ) ) if maximum_iterations is not None: diff --git a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py index 24c6f2aeda..03207de39a 100644 --- a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py @@ -63,9 +63,12 @@ def test_step_with_training_helper_output_layer(cell_class, use_output_layer): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) if isinstance(cell, tf.keras.layers.LSTMCell): assert len(first_state) == 2 @@ -88,14 +91,17 @@ def test_step_with_training_helper_output_layer(cell_class, use_output_layer): assert len(output_layer.variables) == 1 np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), first_finished, + np.asanyarray([False, False, False, False, True]), + first_finished, ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), step_finished, + np.asanyarray([False, False, False, True, True]), + step_finished, ) assert output_dtype.sample_id == step_outputs.sample_id.dtype np.testing.assert_equal( - np.argmax(step_outputs.rnn_output, -1), step_outputs.sample_id, + np.argmax(step_outputs.rnn_output, -1), + step_outputs.sample_id, ) @@ -131,7 +137,9 @@ def test_step_with_training_helper_masked_input(use_mask): ) else: (first_finished, first_inputs, first_state) = my_decoder.initialize( - input_t, initial_state=initial_state, sequence_length=sequence_length, + input_t, + initial_state=initial_state, + sequence_length=sequence_length, ) output_size = my_decoder.output_size @@ -143,9 +151,12 @@ def test_step_with_training_helper_masked_input(use_mask): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 @@ -163,7 +174,8 @@ def test_step_with_training_helper_masked_input(use_mask): np.testing.assert_equal((np.maximum(sequence_length - 1, 0) == 0), step_finished) assert output_dtype.sample_id == step_outputs.sample_id.dtype np.testing.assert_equal( - np.argmax(step_outputs.rnn_output, -1), step_outputs.sample_id, + np.argmax(step_outputs.rnn_output, -1), + step_outputs.sample_id, ) @@ -194,9 +206,12 @@ def test_step_with_greedy_embedding_helper(): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 @@ -212,7 +227,8 @@ def test_step_with_greedy_embedding_helper(): expected_step_finished = expected_sample_ids == end_token expected_step_next_inputs = embeddings[expected_sample_ids] np.testing.assert_equal( - np.asanyarray([False, False, False, False, False]), first_finished, + np.asanyarray([False, False, False, False, False]), + first_finished, ) np.testing.assert_equal(expected_step_finished, step_finished) assert output_dtype.sample_id == step_outputs.sample_id.dtype @@ -248,9 +264,12 @@ def test_step_with_sample_embedding_helper(): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 @@ -302,9 +321,12 @@ def test_step_with_scheduled_embedding_training_helper(): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 @@ -318,10 +340,12 @@ def test_step_with_scheduled_embedding_training_helper(): assert (batch_size, input_depth) == step_next_inputs.shape np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), first_finished, + np.asanyarray([False, False, False, False, True]), + first_finished, ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), step_finished, + np.asanyarray([False, False, False, True, True]), + step_finished, ) sample_ids = step_outputs.sample_id.numpy() assert output_dtype.sample_id == sample_ids.dtype @@ -394,9 +418,12 @@ def next_inputs_fn(outputs): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) if use_next_inputs_fn: output_after_next_inputs_fn = next_inputs_fn(step_outputs.rnn_output) @@ -412,10 +439,12 @@ def next_inputs_fn(outputs): assert (batch_size, cell_depth) == step_state[1].shape np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), first_finished, + np.asanyarray([False, False, False, False, True]), + first_finished, ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), step_finished, + np.asanyarray([False, False, False, True, True]), + step_finished, ) sample_ids = step_outputs.sample_id @@ -440,7 +469,8 @@ def next_inputs_fn(outputs): ) np.testing.assert_equal( - step_next_inputs.numpy()[batch_where_sampling], expected_next_sampling_inputs, + step_next_inputs.numpy()[batch_where_sampling], + expected_next_sampling_inputs, ) np.testing.assert_equal( @@ -498,9 +528,12 @@ def end_fn(sample_ids): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 @@ -561,9 +594,12 @@ def end_fn(sample_ids): assert basic_decoder.BasicDecoderOutput(cell_depth, cell_depth) == output_size assert basic_decoder.BasicDecoderOutput(tf.float32, tf.bool) == output_dtype - (step_outputs, step_state, step_next_inputs, step_finished,) = my_decoder.step( - tf.constant(0), first_inputs, first_state - ) + ( + step_outputs, + step_state, + step_next_inputs, + step_finished, + ) = my_decoder.step(tf.constant(0), first_inputs, first_state) assert len(first_state) == 2 assert len(step_state) == 2 diff --git a/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py b/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py index 962c225e3c..7e8bc110b6 100644 --- a/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py @@ -259,7 +259,11 @@ def test_eos_masking(): [-0.3, -0.3, -0.3, 3, 0], [5, 6, 0, 0, 0], ], - [[-0.2, -0.2, -0.2, -0.2, 0], [-0.3, -0.3, -0.1, 3, 0], [5, 6, 3, 0, 0],], + [ + [-0.2, -0.2, -0.2, -0.2, 0], + [-0.3, -0.3, -0.1, 3, 0], + [5, 6, 3, 0, 0], + ], ] ) diff --git a/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py b/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py index f2fca4d64c..6ff888c2e4 100644 --- a/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py +++ b/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py @@ -141,7 +141,8 @@ def test_gather_tree_batch(): # valid id and everything after it should be end_token. if found > 0: np.testing.assert_equal( - v[: found - 1] >= 0, np.ones_like(v[: found - 1], dtype=bool), + v[: found - 1] >= 0, + np.ones_like(v[: found - 1], dtype=bool), ) np.testing.assert_allclose( v[found + 1 :], end_token * np.ones_like(v[found + 1 :]) diff --git a/tensorflow_addons/seq2seq/tests/decoder_test.py b/tensorflow_addons/seq2seq/tests/decoder_test.py index ef869aa8bc..78712f73f8 100644 --- a/tensorflow_addons/seq2seq/tests/decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/decoder_test.py @@ -92,7 +92,10 @@ def test_dynamic_decode_tflite_conversion(): cell = tf.keras.layers.LSTMCell(units) sampler = sampler_py.GreedyEmbeddingSampler() embeddings = tf.random.uniform([vocab_size, units]) - my_decoder = basic_decoder.BasicDecoder(cell=cell, sampler=sampler,) + my_decoder = basic_decoder.BasicDecoder( + cell=cell, + sampler=sampler, + ) @tf.function def _decode(start_tokens, end_token): @@ -148,9 +151,11 @@ def test_dynamic_decode_rnn_with_training_helper_matches_dynamic_rnn( cell=cell, sampler=sampler, impute_finished=use_sequence_length ) - (final_decoder_outputs, final_decoder_state, _,) = my_decoder( - inputs, initial_state=zero_state, sequence_length=sequence_length - ) + ( + final_decoder_outputs, + final_decoder_state, + _, + ) = my_decoder(inputs, initial_state=zero_state, sequence_length=sequence_length) rnn = tf.keras.layers.RNN(cell, return_sequences=True, return_state=True) mask = ( @@ -168,7 +173,8 @@ def test_dynamic_decode_rnn_with_training_helper_matches_dynamic_rnn( # to dynamic_rnn, which also zeros out outputs and passes along # state. np.testing.assert_allclose( - final_decoder_outputs.rnn_output, final_rnn_outputs[:, 0:max_out, :], + final_decoder_outputs.rnn_output, + final_rnn_outputs[:, 0:max_out, :], ) if use_sequence_length: np.testing.assert_allclose(final_decoder_state, final_rnn_state) diff --git a/tensorflow_addons/seq2seq/tests/loss_test.py b/tensorflow_addons/seq2seq/tests/loss_test.py index 7da06b7f4b..6e595f1dd7 100644 --- a/tensorflow_addons/seq2seq/tests/loss_test.py +++ b/tensorflow_addons/seq2seq/tests/loss_test.py @@ -296,7 +296,8 @@ def return_logits(x): inp = tf.keras.layers.Input(shape=(sequence_length,)) out = tf.keras.layers.Lambda( - return_logits, output_shape=(sequence_length, number_of_classes), + return_logits, + output_shape=(sequence_length, number_of_classes), )(inp) model = tf.keras.models.Model(inp, out) @@ -307,7 +308,11 @@ def return_logits(x): x = tf.ones(shape=(batch_size, sequence_length)) h = model.fit( - x, targets, sample_weight=weights, batch_size=batch_size, steps_per_epoch=1, + x, + targets, + sample_weight=weights, + batch_size=batch_size, + steps_per_epoch=1, ) calculated_loss = h.history["loss"][0] diff --git a/tensorflow_addons/text/tests/parse_time_op_test.py b/tensorflow_addons/text/tests/parse_time_op_test.py index 0a576a1f22..bec5249ddc 100644 --- a/tensorflow_addons/text/tests/parse_time_op_test.py +++ b/tensorflow_addons/text/tests/parse_time_op_test.py @@ -49,7 +49,9 @@ def test_parse_time(): ] for time_string, time_format, output_unit, expected in items: result = text.parse_time( - time_string=time_string, time_format=time_format, output_unit=output_unit, + time_string=time_string, + time_format=time_format, + output_unit=output_unit, ) np.testing.assert_equal(expected, result.numpy()) diff --git a/tensorflow_addons/text/tests/skip_gram_ops_test.py b/tensorflow_addons/text/tests/skip_gram_ops_test.py index ee60b49091..c99f9939e7 100644 --- a/tensorflow_addons/text/tests/skip_gram_ops_test.py +++ b/tensorflow_addons/text/tests/skip_gram_ops_test.py @@ -108,7 +108,11 @@ def test_skip_gram_sample_skips_0(): input_tensor, min_skips=0, max_skips=0, emit_self_as_target=True ) expected_tokens, expected_labels = _split_tokens_labels( - [(b"the", b"the"), (b"quick", b"quick"), (b"brown", b"brown"),] + [ + (b"the", b"the"), + (b"quick", b"quick"), + (b"brown", b"brown"), + ] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) @@ -234,7 +238,12 @@ def test_skip_gram_sample_non_string_input(): input_tensor = tf.constant([1, 2, 3], dtype=tf.dtypes.int16) tokens, labels = text.skip_gram_sample(input_tensor, min_skips=1, max_skips=1) expected_tokens, expected_labels = _split_tokens_labels( - [(1, 2), (2, 1), (2, 3), (3, 2),] + [ + (1, 2), + (2, 1), + (2, 3), + (3, 2), + ] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) @@ -283,7 +292,10 @@ def test_skip_gram_sample_errors(): text.skip_gram_sample(dummy_input, vocab_freq_table=None, corpus_size=100) with pytest.raises(ValueError): text.skip_gram_sample( - dummy_input, vocab_freq_table=None, vocab_subsampling=1e-5, corpus_size=100, + dummy_input, + vocab_freq_table=None, + vocab_subsampling=1e-5, + corpus_size=100, ) # vocab_subsampling and corpus_size must both be present or absent. @@ -477,7 +489,12 @@ def _text_vocab_subsample_vocab_helper( ) expected_tokens, expected_labels = _split_tokens_labels( - [(b"the", b"to"), (b"to", b"the"), (b"to", b"life"), (b"life", b"to"),] + [ + (b"the", b"to"), + (b"to", b"the"), + (b"to", b"life"), + (b"life", b"to"), + ] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) @@ -601,7 +618,13 @@ def _make_text_vocab_freq_file(tmp_dir): with open(filepath, "w") as f: writer = csv.writer(f) writer.writerows( - [["and", 40], ["life", 8], ["the", 30], ["to", 20], ["universe", 2],] + [ + ["and", 40], + ["life", 8], + ["the", 30], + ["to", 20], + ["universe", 2], + ] ) return filepath diff --git a/tensorflow_addons/utils/keras_utils.py b/tensorflow_addons/utils/keras_utils.py index 8865e0623d..e480527c21 100644 --- a/tensorflow_addons/utils/keras_utils.py +++ b/tensorflow_addons/utils/keras_utils.py @@ -29,21 +29,21 @@ def __init__( ): """Initializes `LossFunctionWrapper` class. - Args: - fn: The loss function to wrap, with signature `fn(y_true, y_pred, - **kwargs)`. - reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to - loss. Default value is `AUTO`. `AUTO` indicates that the reduction - option will be determined by the usage context. For almost all cases - this defaults to `SUM_OVER_BATCH_SIZE`. When used with - `tf.distribute.Strategy`, outside of built-in training loops such as - `tf.keras` `compile` and `fit`, using `AUTO` or `SUM_OVER_BATCH_SIZE` - will raise an error. Please see this custom training [tutorial]( - https://www.tensorflow.org/tutorials/distribute/custom_training) - for more details. - name: (Optional) name for the loss. - **kwargs: The keyword arguments that are passed on to `fn`. - """ + Args: + fn: The loss function to wrap, with signature `fn(y_true, y_pred, + **kwargs)`. + reduction: (Optional) Type of `tf.keras.losses.Reduction` to apply to + loss. Default value is `AUTO`. `AUTO` indicates that the reduction + option will be determined by the usage context. For almost all cases + this defaults to `SUM_OVER_BATCH_SIZE`. When used with + `tf.distribute.Strategy`, outside of built-in training loops such as + `tf.keras` `compile` and `fit`, using `AUTO` or `SUM_OVER_BATCH_SIZE` + will raise an error. Please see this custom training [tutorial]( + https://www.tensorflow.org/tutorials/distribute/custom_training) + for more details. + name: (Optional) name for the loss. + **kwargs: The keyword arguments that are passed on to `fn`. + """ super().__init__(reduction=reduction, name=name) self.fn = fn self._fn_kwargs = kwargs @@ -51,13 +51,13 @@ def __init__( def call(self, y_true, y_pred): """Invokes the `LossFunctionWrapper` instance. - Args: - y_true: Ground truth values. - y_pred: The predicted values. + Args: + y_true: Ground truth values. + y_pred: The predicted values. - Returns: - Loss values per sample. - """ + Returns: + Loss values per sample. + """ return self.fn(y_true, y_pred, **self._fn_kwargs) def get_config(self): diff --git a/tensorflow_addons/version.py b/tensorflow_addons/version.py index 37e9362ffe..bb33c56754 100644 --- a/tensorflow_addons/version.py +++ b/tensorflow_addons/version.py @@ -27,6 +27,12 @@ _VERSION_SUFFIX = "dev" # Example, '0.1.0-dev' -__version__ = ".".join([_MAJOR_VERSION, _MINOR_VERSION, _PATCH_VERSION,]) +__version__ = ".".join( + [ + _MAJOR_VERSION, + _MINOR_VERSION, + _PATCH_VERSION, + ] +) if _VERSION_SUFFIX: __version__ = "{}-{}".format(__version__, _VERSION_SUFFIX) diff --git a/tools/install_deps/black.txt b/tools/install_deps/black.txt index 7c9d150acb..52ee1d9aa1 100644 --- a/tools/install_deps/black.txt +++ b/tools/install_deps/black.txt @@ -1 +1 @@ -black==19.10b0 +black==20.8b1 diff --git a/tools/testing/source_code_test.py b/tools/testing/source_code_test.py index cc1778b73b..ee96b2c1cb 100644 --- a/tools/testing/source_code_test.py +++ b/tools/testing/source_code_test.py @@ -45,7 +45,10 @@ def test_api_typed(): "https://github.com/tensorflow/addons/blob/master/CONTRIBUTING.md#about-type-hints" ) ensure_api_is_typed( - modules_list, exception_list, init_only=True, additional_message=help_message, + modules_list, + exception_list, + init_only=True, + additional_message=help_message, ) From d0c3d18218fcbb36d4e9e7efce4092ecd42c7030 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 20:50:52 +0000 Subject: [PATCH 02/24] Removed trailing commas. --- build_deps/toolchains/gpu/find_cuda_config.py | 6 +----- .../activations/tests/sparsemax_test.py | 12 ++---------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/build_deps/toolchains/gpu/find_cuda_config.py b/build_deps/toolchains/gpu/find_cuda_config.py index daffa05182..9209a7db72 100644 --- a/build_deps/toolchains/gpu/find_cuda_config.py +++ b/build_deps/toolchains/gpu/find_cuda_config.py @@ -289,11 +289,7 @@ def get_nvcc_version(path): nvvm_path = _find_file( base_paths, - [ - "nvvm/libdevice", - "share/cuda", - "lib/nvidia-cuda-toolkit/libdevice", - ], + ["nvvm/libdevice", "share/cuda", "lib/nvidia-cuda-toolkit/libdevice"], "libdevice*.10.bc", ) diff --git a/tensorflow_addons/activations/tests/sparsemax_test.py b/tensorflow_addons/activations/tests/sparsemax_test.py index 14245a8a41..0dabd13e07 100644 --- a/tensorflow_addons/activations/tests/sparsemax_test.py +++ b/tensorflow_addons/activations/tests/sparsemax_test.py @@ -112,11 +112,7 @@ def test_sparsemax_against_numpy_high_rank(dtype): def test_sparsemax_of_nan(dtype): """check sparsemax transfers nan.""" z_nan = np.asarray( - [ - [0, np.nan, 0], - [0, np.nan, np.nan], - [np.nan, np.nan, np.nan], - ] + [[0, np.nan, 0], [0, np.nan, np.nan], [np.nan, np.nan, np.nan]] ).astype(dtype) tf_sparsemax_nan = sparsemax(z_nan) @@ -136,11 +132,7 @@ def test_sparsemax_of_nan(dtype): def test_sparsemax_of_inf(dtype): """check sparsemax is infinity safe.""" z_neg = np.asarray( - [ - [0, -np.inf, 0], - [0, -np.inf, -np.inf], - [-np.inf, -np.inf, -np.inf], - ] + [[0, -np.inf, 0], [0, -np.inf, -np.inf], [-np.inf, -np.inf, -np.inf]] ).astype(dtype) z_pos = np.asarray( [[0, np.inf, 0], [0, np.inf, np.inf], [np.inf, np.inf, np.inf]] From 967c701269b501ea34b549214c03da774a81fc99 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 22:52:13 +0200 Subject: [PATCH 03/24] Update tensorflow_addons/image/filters.py --- tensorflow_addons/image/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 172335ccc3..0c0276bcc9 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -308,7 +308,7 @@ def gaussian_filter2d( image, filter_shape, mode=padding, - constant_values=constant_values, + constant_values=constant_values ) output = tf.nn.depthwise_conv2d( From 523b357e4562e3e8bee2d73cef621192f49a6055 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 22:52:20 +0200 Subject: [PATCH 04/24] Update tensorflow_addons/image/cutout_ops.py --- tensorflow_addons/image/cutout_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/image/cutout_ops.py b/tensorflow_addons/image/cutout_ops.py index 7c94145a7c..b18c3221cf 100644 --- a/tensorflow_addons/image/cutout_ops.py +++ b/tensorflow_addons/image/cutout_ops.py @@ -105,7 +105,7 @@ def random_cutout( mask_size, offset, constant_values, - data_format, + data_format ) From 62c3ad6237de45b89c34f4efa1e6756631b9100d Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 20:52:37 +0000 Subject: [PATCH 05/24] Removed trailing commas. --- tensorflow_addons/image/cutout_ops.py | 8 +------- tensorflow_addons/image/filters.py | 7 +------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/tensorflow_addons/image/cutout_ops.py b/tensorflow_addons/image/cutout_ops.py index b18c3221cf..6bdbbaf03c 100644 --- a/tensorflow_addons/image/cutout_ops.py +++ b/tensorflow_addons/image/cutout_ops.py @@ -100,13 +100,7 @@ def random_cutout( ) offset = tf.transpose([cutout_center_height, cutout_center_width], [1, 0]) - return cutout( - images, - mask_size, - offset, - constant_values, - data_format - ) + return cutout(images, mask_size, offset, constant_values, data_format) def cutout( diff --git a/tensorflow_addons/image/filters.py b/tensorflow_addons/image/filters.py index 0c0276bcc9..6e3da3e1ba 100644 --- a/tensorflow_addons/image/filters.py +++ b/tensorflow_addons/image/filters.py @@ -304,12 +304,7 @@ def gaussian_filter2d( gaussian_kernel_2d, [filter_shape[0], filter_shape[1], channels, 1] ) - image = _pad( - image, - filter_shape, - mode=padding, - constant_values=constant_values - ) + image = _pad(image, filter_shape, mode=padding, constant_values=constant_values) output = tf.nn.depthwise_conv2d( input=image, From 77830ab05679b4d9a46034534be545aaecfb0da0 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 20:55:52 +0000 Subject: [PATCH 06/24] Removed commas. --- tensorflow_addons/image/sparse_image_warp.py | 4 +--- tensorflow_addons/image/tests/connected_components_test.py | 3 +-- tensorflow_addons/image/tests/sparse_image_warp_test.py | 3 +-- tensorflow_addons/image/tests/transform_ops_test.py | 3 +-- .../layers/tests/spectral_normalization_test.py | 5 +---- tensorflow_addons/losses/tests/triplet_test.py | 5 +---- 6 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tensorflow_addons/image/sparse_image_warp.py b/tensorflow_addons/image/sparse_image_warp.py index f813f32e60..0470788897 100644 --- a/tensorflow_addons/image/sparse_image_warp.py +++ b/tensorflow_addons/image/sparse_image_warp.py @@ -39,9 +39,7 @@ def _expand_to_minibatch(np_array: TensorLike, batch_size: TensorLike) -> Tensor def _get_boundary_locations( - image_height: TensorLike, - image_width: TensorLike, - num_points_per_edge: TensorLike, + image_height: TensorLike, image_width: TensorLike, num_points_per_edge: TensorLike ) -> TensorLike: """Compute evenly-spaced indices along edge of image.""" y_range = np.linspace(0, image_height - 1, num_points_per_edge + 2) diff --git a/tensorflow_addons/image/tests/connected_components_test.py b/tensorflow_addons/image/tests/connected_components_test.py index 6240584923..82c42bddd6 100644 --- a/tensorflow_addons/image/tests/connected_components_test.py +++ b/tensorflow_addons/image/tests/connected_components_test.py @@ -118,8 +118,7 @@ def test_multiple_images(): @pytest.mark.usefixtures("maybe_run_functions_eagerly") def test_zeros(): np.testing.assert_equal( - connected_components(tf.zeros((100, 20, 50), tf.bool)), - np.zeros((100, 20, 50)), + connected_components(tf.zeros((100, 20, 50), tf.bool)), np.zeros((100, 20, 50)) ) diff --git a/tensorflow_addons/image/tests/sparse_image_warp_test.py b/tensorflow_addons/image/tests/sparse_image_warp_test.py index 3a89897f46..27e09dd1ef 100644 --- a/tensorflow_addons/image/tests/sparse_image_warp_test.py +++ b/tensorflow_addons/image/tests/sparse_image_warp_test.py @@ -121,8 +121,7 @@ def assert_move_single_pixel(order, num_boundary_points, type_to_use): # Shift it one pixel to the right. control_point_displacements = [[0.0, 1.0]] control_point_displacements = tf.constant( - np.float32(np.expand_dims(control_point_displacements, 0)), - dtype=type_to_use, + np.float32(np.expand_dims(control_point_displacements, 0)), dtype=type_to_use ) (warped_image, flow) = sparse_image_warp( diff --git a/tensorflow_addons/image/tests/transform_ops_test.py b/tensorflow_addons/image/tests/transform_ops_test.py index ca8470a9b0..63e8aa8952 100644 --- a/tensorflow_addons/image/tests/transform_ops_test.py +++ b/tensorflow_addons/image/tests/transform_ops_test.py @@ -36,8 +36,7 @@ @pytest.mark.parametrize("dtype", _DTYPES) def test_compose(dtype): image = tf.constant( - [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]], - dtype=dtype, + [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=dtype ) # Rotate counter-clockwise by pi / 2. rotation = transform_ops.angles_to_projective_transforms(np.pi / 2, 4, 4) diff --git a/tensorflow_addons/layers/tests/spectral_normalization_test.py b/tensorflow_addons/layers/tests/spectral_normalization_test.py index 3fbccb9160..a138728015 100644 --- a/tensorflow_addons/layers/tests/spectral_normalization_test.py +++ b/tensorflow_addons/layers/tests/spectral_normalization_test.py @@ -95,10 +95,7 @@ def test_model_fit(base_layer_fn, input_shape, output_shape): "base_layer_fn, input_shape", [ (lambda: tf.keras.layers.Dense(2), [3, 2]), - ( - lambda: tf.keras.layers.Conv2D(3, (2, 2), padding="same"), - [4, 4, 3], - ), + (lambda: tf.keras.layers.Conv2D(3, (2, 2), padding="same"), [4, 4, 3]), (lambda: tf.keras.layers.Embedding(2, 10), [2]), ], ) diff --git a/tensorflow_addons/losses/tests/triplet_test.py b/tensorflow_addons/losses/tests/triplet_test.py index ee98406a64..96fc161369 100644 --- a/tensorflow_addons/losses/tests/triplet_test.py +++ b/tensorflow_addons/losses/tests/triplet_test.py @@ -182,10 +182,7 @@ def test_semihard_tripled_loss_angular(dtype, dist_func, dist_metric): def test_keras_model_compile_semihard(): model = tf.keras.models.Sequential( - [ - tf.keras.layers.Input(shape=(784,)), - tf.keras.layers.Dense(10), - ] + [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10)] ) model.compile(loss="Addons>triplet_semihard_loss", optimizer="adam") From 83c0abf2e50da88dbd2aad4c82b29fa497050969 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 20:59:36 +0000 Subject: [PATCH 07/24] Removed some more commas. --- .../seq2seq/tests/beam_search_decoder_test.py | 6 +----- tensorflow_addons/seq2seq/tests/beam_search_ops_test.py | 3 +-- tensorflow_addons/seq2seq/tests/loss_test.py | 9 ++------- tensorflow_addons/text/tests/skip_gram_ops_test.py | 6 +----- tensorflow_addons/version.py | 8 +------- tools/testing/source_code_test.py | 5 +---- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py b/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py index 7e8bc110b6..80ec3a501b 100644 --- a/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/beam_search_decoder_test.py @@ -259,11 +259,7 @@ def test_eos_masking(): [-0.3, -0.3, -0.3, 3, 0], [5, 6, 0, 0, 0], ], - [ - [-0.2, -0.2, -0.2, -0.2, 0], - [-0.3, -0.3, -0.1, 3, 0], - [5, 6, 3, 0, 0], - ], + [[-0.2, -0.2, -0.2, -0.2, 0], [-0.3, -0.3, -0.1, 3, 0], [5, 6, 3, 0, 0]], ] ) diff --git a/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py b/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py index 6ff888c2e4..ddd2eaad0a 100644 --- a/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py +++ b/tensorflow_addons/seq2seq/tests/beam_search_ops_test.py @@ -141,8 +141,7 @@ def test_gather_tree_batch(): # valid id and everything after it should be end_token. if found > 0: np.testing.assert_equal( - v[: found - 1] >= 0, - np.ones_like(v[: found - 1], dtype=bool), + v[: found - 1] >= 0, np.ones_like(v[: found - 1], dtype=bool) ) np.testing.assert_allclose( v[found + 1 :], end_token * np.ones_like(v[found + 1 :]) diff --git a/tensorflow_addons/seq2seq/tests/loss_test.py b/tensorflow_addons/seq2seq/tests/loss_test.py index 6e595f1dd7..3188b7263d 100644 --- a/tensorflow_addons/seq2seq/tests/loss_test.py +++ b/tensorflow_addons/seq2seq/tests/loss_test.py @@ -296,8 +296,7 @@ def return_logits(x): inp = tf.keras.layers.Input(shape=(sequence_length,)) out = tf.keras.layers.Lambda( - return_logits, - output_shape=(sequence_length, number_of_classes), + return_logits, output_shape=(sequence_length, number_of_classes) )(inp) model = tf.keras.models.Model(inp, out) @@ -308,11 +307,7 @@ def return_logits(x): x = tf.ones(shape=(batch_size, sequence_length)) h = model.fit( - x, - targets, - sample_weight=weights, - batch_size=batch_size, - steps_per_epoch=1, + x, targets, sample_weight=weights, batch_size=batch_size, steps_per_epoch=1 ) calculated_loss = h.history["loss"][0] diff --git a/tensorflow_addons/text/tests/skip_gram_ops_test.py b/tensorflow_addons/text/tests/skip_gram_ops_test.py index c99f9939e7..761115c0a3 100644 --- a/tensorflow_addons/text/tests/skip_gram_ops_test.py +++ b/tensorflow_addons/text/tests/skip_gram_ops_test.py @@ -108,11 +108,7 @@ def test_skip_gram_sample_skips_0(): input_tensor, min_skips=0, max_skips=0, emit_self_as_target=True ) expected_tokens, expected_labels = _split_tokens_labels( - [ - (b"the", b"the"), - (b"quick", b"quick"), - (b"brown", b"brown"), - ] + [(b"the", b"the"), (b"quick", b"quick"), (b"brown", b"brown")] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) diff --git a/tensorflow_addons/version.py b/tensorflow_addons/version.py index bb33c56754..b85169a59f 100644 --- a/tensorflow_addons/version.py +++ b/tensorflow_addons/version.py @@ -27,12 +27,6 @@ _VERSION_SUFFIX = "dev" # Example, '0.1.0-dev' -__version__ = ".".join( - [ - _MAJOR_VERSION, - _MINOR_VERSION, - _PATCH_VERSION, - ] -) +__version__ = ".".join([_MAJOR_VERSION, _MINOR_VERSION, _PATCH_VERSION]) if _VERSION_SUFFIX: __version__ = "{}-{}".format(__version__, _VERSION_SUFFIX) diff --git a/tools/testing/source_code_test.py b/tools/testing/source_code_test.py index ee96b2c1cb..280ca61b01 100644 --- a/tools/testing/source_code_test.py +++ b/tools/testing/source_code_test.py @@ -45,10 +45,7 @@ def test_api_typed(): "https://github.com/tensorflow/addons/blob/master/CONTRIBUTING.md#about-type-hints" ) ensure_api_is_typed( - modules_list, - exception_list, - init_only=True, - additional_message=help_message, + modules_list, exception_list, init_only=True, additional_message=help_message ) From 1d20ddae4ab39c5b4f1cfc445086b332509c8135 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 21:04:04 +0000 Subject: [PATCH 08/24] Removed some commas. --- tensorflow_addons/losses/tests/lifted_test.py | 5 +---- .../optimizers/tests/conditional_gradient_test.py | 3 +-- tensorflow_addons/optimizers/tests/lookahead_test.py | 8 ++------ .../optimizers/tests/moving_average_test.py | 5 +---- .../optimizers/tests/rectified_adam_test.py | 10 ++-------- .../optimizers/tests/weight_decay_optimizers_test.py | 8 ++------ tensorflow_addons/optimizers/tests/yogi_test.py | 10 ++-------- 7 files changed, 11 insertions(+), 38 deletions(-) diff --git a/tensorflow_addons/losses/tests/lifted_test.py b/tensorflow_addons/losses/tests/lifted_test.py index a88e05a1ef..a6b986cd0f 100644 --- a/tensorflow_addons/losses/tests/lifted_test.py +++ b/tensorflow_addons/losses/tests/lifted_test.py @@ -112,10 +112,7 @@ def test_lifted_struct(dtype): def test_keras_model_compile(): model = tf.keras.models.Sequential( - [ - tf.keras.layers.Input(shape=(784,)), - tf.keras.layers.Dense(10), - ] + [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10)] ) model.compile(loss="Addons>lifted_struct_loss", optimizer="adam") diff --git a/tensorflow_addons/optimizers/tests/conditional_gradient_test.py b/tensorflow_addons/optimizers/tests/conditional_gradient_test.py index 2adf04cef5..069a394041 100644 --- a/tensorflow_addons/optimizers/tests/conditional_gradient_test.py +++ b/tensorflow_addons/optimizers/tests/conditional_gradient_test.py @@ -1355,8 +1355,7 @@ def test_sparse_nuclear(): tf.constant([4, 2]), ) top_singular_vector0 = tf.constant( - [[0.0, 0.0], [0.7071067, 0.7071067], [0.0, 0.0], [0.0, 0.0]], - dtype=dtype, + [[0.0, 0.0], [0.7071067, 0.7071067], [0.0, 0.0], [0.0, 0.0]], dtype=dtype ) top_singular_vector1 = tf.constant( [ diff --git a/tensorflow_addons/optimizers/tests/lookahead_test.py b/tensorflow_addons/optimizers/tests/lookahead_test.py index 6e4a760b7c..b315288094 100644 --- a/tensorflow_addons/optimizers/tests/lookahead_test.py +++ b/tensorflow_addons/optimizers/tests/lookahead_test.py @@ -55,14 +55,10 @@ def run_sparse_sample(iterations, optimizer, seed=0x2019): var_1 = tf.Variable(val_1, dtype=tf.dtypes.float32) grad_0 = tf.IndexedSlices( - tf.constant([np.random.standard_normal()]), - tf.constant([0]), - tf.constant([2]), + tf.constant([np.random.standard_normal()]), tf.constant([0]), tf.constant([2]) ) grad_1 = tf.IndexedSlices( - tf.constant([np.random.standard_normal()]), - tf.constant([1]), - tf.constant([2]), + tf.constant([np.random.standard_normal()]), tf.constant([1]), tf.constant([2]) ) grads_and_vars = list(zip([grad_0, grad_1], [var_0, var_1])) diff --git a/tensorflow_addons/optimizers/tests/moving_average_test.py b/tensorflow_addons/optimizers/tests/moving_average_test.py index 91ab8f892d..3914eb9b0e 100644 --- a/tensorflow_addons/optimizers/tests/moving_average_test.py +++ b/tensorflow_addons/optimizers/tests/moving_average_test.py @@ -31,10 +31,7 @@ def test_run(): grads_and_vars = list(zip([grads0, grads1], [var0, var1])) - opt = MovingAverage( - tf.keras.optimizers.SGD(lr=2.0), - average_decay=0.5, - ) + opt = MovingAverage(tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5) opt.apply_gradients(grads_and_vars) opt.apply_gradients(grads_and_vars) diff --git a/tensorflow_addons/optimizers/tests/rectified_adam_test.py b/tensorflow_addons/optimizers/tests/rectified_adam_test.py index 1e7b967066..2db66e4665 100644 --- a/tensorflow_addons/optimizers/tests/rectified_adam_test.py +++ b/tensorflow_addons/optimizers/tests/rectified_adam_test.py @@ -121,10 +121,7 @@ def test_dense_sample_with_warmup(): iterations=100, expected=[[0.994062, 1.993912], [2.994167, 3.994152]], optimizer=RectifiedAdam( - lr=1e-3, - total_steps=100, - warmup_proportion=0.1, - min_lr=1e-5, + lr=1e-3, total_steps=100, warmup_proportion=0.1, min_lr=1e-5 ), ) @@ -135,10 +132,7 @@ def test_sparse_sample_with_warmup(): iterations=200, expected=[[0.982629, 2.0], [3.0, 3.982674]], optimizer=RectifiedAdam( - lr=1e-3, - total_steps=200, - warmup_proportion=0.1, - min_lr=1e-5, + lr=1e-3, total_steps=200, warmup_proportion=0.1, min_lr=1e-5 ), ) diff --git a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py index 31a8b96fd3..e853d7cfd0 100644 --- a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py +++ b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py @@ -68,15 +68,11 @@ def do_test( if do_sparse: grads0_np_indices = np.array([0, 1], dtype=np.int32) grads0 = tf.IndexedSlices( - tf.constant(grads0_np), - tf.constant(grads0_np_indices), - tf.constant([2]), + tf.constant(grads0_np), tf.constant(grads0_np_indices), tf.constant([2]) ) grads1_np_indices = np.array([0, 1], dtype=np.int32) grads1 = tf.IndexedSlices( - tf.constant(grads1_np), - tf.constant(grads1_np_indices), - tf.constant([2]), + tf.constant(grads1_np), tf.constant(grads1_np_indices), tf.constant([2]) ) else: grads0 = tf.constant(grads0_np) diff --git a/tensorflow_addons/optimizers/tests/yogi_test.py b/tensorflow_addons/optimizers/tests/yogi_test.py index 47c9aab890..90edf085cb 100644 --- a/tensorflow_addons/optimizers/tests/yogi_test.py +++ b/tensorflow_addons/optimizers/tests/yogi_test.py @@ -140,14 +140,8 @@ def do_test_sparse(beta1=0.0, l1reg=0.0, l2reg=0.0): ) # Validate updated params. - test_utils.assert_allclose_according_to_type( - var0_np, - var0.numpy(), - ) - test_utils.assert_allclose_according_to_type( - var1_np, - var1.numpy(), - ) + test_utils.assert_allclose_according_to_type(var0_np, var0.numpy()) + test_utils.assert_allclose_according_to_type(var1_np, var1.numpy()) @pytest.mark.usefixtures("maybe_run_functions_eagerly") From 5df654ed58323cc45c5276d4625a6ec3eca1921d Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 21:07:07 +0000 Subject: [PATCH 09/24] Removed some commas. --- .../optimizers/average_wrapper.py | 3 +-- tensorflow_addons/optimizers/lookahead.py | 12 ++-------- .../optimizers/weight_decay_optimizers.py | 6 +---- tensorflow_addons/rnn/tests/esn_cell_test.py | 6 +---- .../seq2seq/tests/basic_decoder_test.py | 22 ++++++------------- 5 files changed, 12 insertions(+), 37 deletions(-) diff --git a/tensorflow_addons/optimizers/average_wrapper.py b/tensorflow_addons/optimizers/average_wrapper.py index 62751ffd47..444daf3dd6 100644 --- a/tensorflow_addons/optimizers/average_wrapper.py +++ b/tensorflow_addons/optimizers/average_wrapper.py @@ -137,8 +137,7 @@ def get_config(self): @classmethod def from_config(cls, config, custom_objects=None): optimizer = tf.keras.optimizers.deserialize( - config.pop("optimizer"), - custom_objects=custom_objects, + config.pop("optimizer"), custom_objects=custom_objects ) return cls(optimizer, **config) diff --git a/tensorflow_addons/optimizers/lookahead.py b/tensorflow_addons/optimizers/lookahead.py index 61c4170875..3b7fcd6e95 100644 --- a/tensorflow_addons/optimizers/lookahead.py +++ b/tensorflow_addons/optimizers/lookahead.py @@ -125,19 +125,11 @@ def _look_ahead_op(self, var): ) with tf.control_dependencies([step_back]): slow_update = slow_var.assign( - tf.where( - sync_cond, - step_back, - slow_var, - ), + tf.where(sync_cond, step_back, slow_var), use_locking=self._use_locking, ) var_update = var.assign( - tf.where( - sync_cond, - step_back, - var, - ), + tf.where(sync_cond, step_back, var), use_locking=self._use_locking, ) return tf.group(slow_update, var_update) diff --git a/tensorflow_addons/optimizers/weight_decay_optimizers.py b/tensorflow_addons/optimizers/weight_decay_optimizers.py index 7959d93585..5b70dec5be 100644 --- a/tensorflow_addons/optimizers/weight_decay_optimizers.py +++ b/tensorflow_addons/optimizers/weight_decay_optimizers.py @@ -88,11 +88,7 @@ def __init__(self, weight_decay: Union[FloatTensorLike, Callable], **kwargs): def get_config(self): config = super().get_config() - config.update( - { - "weight_decay": self._serialize_hyperparameter("weight_decay"), - } - ) + config.update({"weight_decay": self._serialize_hyperparameter("weight_decay")}) return config @classmethod diff --git a/tensorflow_addons/rnn/tests/esn_cell_test.py b/tensorflow_addons/rnn/tests/esn_cell_test.py index 5b0be18cae..c11243b6ac 100644 --- a/tensorflow_addons/rnn/tests/esn_cell_test.py +++ b/tensorflow_addons/rnn/tests/esn_cell_test.py @@ -24,11 +24,7 @@ def test_base_esn(): units = 3 expected_output = np.array( - [ - [2.77, 2.77, 2.77], - [4.77, 4.77, 4.77], - [6.77, 6.77, 6.77], - ], + [[2.77, 2.77, 2.77], [4.77, 4.77, 4.77], [6.77, 6.77, 6.77]], dtype=np.float32, ) diff --git a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py index 03207de39a..7c9350fa25 100644 --- a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py @@ -91,17 +91,14 @@ def test_step_with_training_helper_output_layer(cell_class, use_output_layer): assert len(output_layer.variables) == 1 np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), - first_finished, + np.asanyarray([False, False, False, False, True]), first_finished ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), - step_finished, + np.asanyarray([False, False, False, True, True]), step_finished ) assert output_dtype.sample_id == step_outputs.sample_id.dtype np.testing.assert_equal( - np.argmax(step_outputs.rnn_output, -1), - step_outputs.sample_id, + np.argmax(step_outputs.rnn_output, -1), step_outputs.sample_id ) @@ -137,9 +134,7 @@ def test_step_with_training_helper_masked_input(use_mask): ) else: (first_finished, first_inputs, first_state) = my_decoder.initialize( - input_t, - initial_state=initial_state, - sequence_length=sequence_length, + input_t, initial_state=initial_state, sequence_length=sequence_length ) output_size = my_decoder.output_size @@ -151,12 +146,9 @@ def test_step_with_training_helper_masked_input(use_mask): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 From 5bb8e7b147dac989436ff1ef727b6dacd6b61f69 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:10:54 +0200 Subject: [PATCH 10/24] Update tensorflow_addons/optimizers/moving_average.py --- tensorflow_addons/optimizers/moving_average.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/optimizers/moving_average.py b/tensorflow_addons/optimizers/moving_average.py index 4a0fd99fac..546ec11842 100644 --- a/tensorflow_addons/optimizers/moving_average.py +++ b/tensorflow_addons/optimizers/moving_average.py @@ -182,6 +182,6 @@ def swap(strategy, a, b): swap, args=( self._average_weights, - self._model_weights, + self._model_weights ), ) From f4af2271f98b473ba3e78afd140f1c511cc04302 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:11:06 +0200 Subject: [PATCH 11/24] Update tensorflow_addons/losses/tests/kappa_loss_test.py --- tensorflow_addons/losses/tests/kappa_loss_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/losses/tests/kappa_loss_test.py b/tensorflow_addons/losses/tests/kappa_loss_test.py index d6658a7918..51e22fed0f 100644 --- a/tensorflow_addons/losses/tests/kappa_loss_test.py +++ b/tensorflow_addons/losses/tests/kappa_loss_test.py @@ -82,7 +82,7 @@ def test_config(): num_classes=4, weightage="linear", name="kappa_loss", - epsilon=0.001, + epsilon=0.001 ) assert kappa_loss.num_classes == 4 assert kappa_loss.weightage == "linear" From d284c83e778373b89daf0fa2e59b6b49e5c91b02 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:11:20 +0200 Subject: [PATCH 12/24] Update tensorflow_addons/layers/tests/wrappers_test.py --- tensorflow_addons/layers/tests/wrappers_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/layers/tests/wrappers_test.py b/tensorflow_addons/layers/tests/wrappers_test.py index 50bbfdac31..002c134851 100644 --- a/tensorflow_addons/layers/tests/wrappers_test.py +++ b/tensorflow_addons/layers/tests/wrappers_test.py @@ -55,7 +55,7 @@ def _check_data_init(data_init, input_data, expected_output): wrappers.WeightNormalization, kwargs={ "layer": layer, - "data_init": data_init, + "data_init": data_init }, input_data=input_data, expected_output=expected_output, From fe70be5ba2d1c13872b4c4eacca7585a54279605 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:11:29 +0200 Subject: [PATCH 13/24] Update tensorflow_addons/layers/tests/wrappers_test.py --- tensorflow_addons/layers/tests/wrappers_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/layers/tests/wrappers_test.py b/tensorflow_addons/layers/tests/wrappers_test.py index 002c134851..2578bfb8e7 100644 --- a/tensorflow_addons/layers/tests/wrappers_test.py +++ b/tensorflow_addons/layers/tests/wrappers_test.py @@ -38,7 +38,7 @@ def test_no_bias(): test_utils.layer_test( wrappers.WeightNormalization, kwargs={ - "layer": tf.keras.layers.Dense(5, use_bias=False), + "layer": tf.keras.layers.Dense(5, use_bias=False) }, input_shape=(2, 4), ) From eb670f6ca2dd39420e6ad84a08f4aed2044347f4 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:11:39 +0200 Subject: [PATCH 14/24] Update tensorflow_addons/layers/tests/wrappers_test.py --- tensorflow_addons/layers/tests/wrappers_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/layers/tests/wrappers_test.py b/tensorflow_addons/layers/tests/wrappers_test.py index 2578bfb8e7..a505c88acc 100644 --- a/tensorflow_addons/layers/tests/wrappers_test.py +++ b/tensorflow_addons/layers/tests/wrappers_test.py @@ -28,7 +28,7 @@ def test_basic(): test_utils.layer_test( wrappers.WeightNormalization, kwargs={ - "layer": tf.keras.layers.Conv2D(5, (2, 2)), + "layer": tf.keras.layers.Conv2D(5, (2, 2)) }, input_shape=(2, 4, 4, 3), ) From f319f8c0706bf01e67ecff8e85402a9e2d4dc41f Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:12:01 +0200 Subject: [PATCH 15/24] Update tensorflow_addons/layers/tests/spectral_normalization_test.py --- tensorflow_addons/layers/tests/spectral_normalization_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/layers/tests/spectral_normalization_test.py b/tensorflow_addons/layers/tests/spectral_normalization_test.py index a138728015..d3e995b39c 100644 --- a/tensorflow_addons/layers/tests/spectral_normalization_test.py +++ b/tensorflow_addons/layers/tests/spectral_normalization_test.py @@ -115,7 +115,7 @@ def test_normalization(): base_layer = tf.keras.layers.Conv2D( 1, (2, 2), - kernel_initializer=tf.constant_initializer(value=2), + kernel_initializer=tf.constant_initializer(value=2) ) sn_layer = spectral_normalization.SpectralNormalization(base_layer) model = tf.keras.models.Sequential(layers=[inputs, sn_layer]) From c3ce210ffbb83f8dd9a51ab2d2bdd310637d58a6 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:12:08 +0200 Subject: [PATCH 16/24] Update tensorflow_addons/layers/tests/spectral_normalization_test.py --- tensorflow_addons/layers/tests/spectral_normalization_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/layers/tests/spectral_normalization_test.py b/tensorflow_addons/layers/tests/spectral_normalization_test.py index d3e995b39c..cc5345baca 100644 --- a/tensorflow_addons/layers/tests/spectral_normalization_test.py +++ b/tensorflow_addons/layers/tests/spectral_normalization_test.py @@ -128,7 +128,7 @@ def test_normalization(): for training in [False, True]: _ = model( tf.constant(np.ones((1, 2, 2, 1), dtype=np.float32)), - training=training, + training=training ) if training: w = weights_normalized From 628e0012a54d378232a7dc13d1a103b276e7ce45 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:12:30 +0200 Subject: [PATCH 17/24] Update tensorflow_addons/losses/tests/triplet_test.py --- tensorflow_addons/losses/tests/triplet_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/losses/tests/triplet_test.py b/tensorflow_addons/losses/tests/triplet_test.py index 96fc161369..fa7062b389 100644 --- a/tensorflow_addons/losses/tests/triplet_test.py +++ b/tensorflow_addons/losses/tests/triplet_test.py @@ -227,7 +227,7 @@ def test_keras_model_compile_hard(): model = tf.keras.models.Sequential( [ tf.keras.layers.Input(shape=(784,)), - tf.keras.layers.Dense(10), + tf.keras.layers.Dense(10) ] ) model.compile(loss="Addons>triplet_hard_loss", optimizer="adam") From 544c67b1c7cf45bd452c9c9fc002cae71979e5a0 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:12:38 +0200 Subject: [PATCH 18/24] Update tensorflow_addons/metrics/tests/hamming_test.py --- tensorflow_addons/metrics/tests/hamming_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/metrics/tests/hamming_test.py b/tensorflow_addons/metrics/tests/hamming_test.py index 8e63d6cb65..714abc2aa1 100644 --- a/tensorflow_addons/metrics/tests/hamming_test.py +++ b/tensorflow_addons/metrics/tests/hamming_test.py @@ -104,7 +104,7 @@ def test_ml_4_classes(): [ [0.97, 0.56, 0.83, 0.77], [0.34, 0.95, 0.7, 0.89], - [0.95, 0.45, 0.23, 0.56], + [0.95, 0.45, 0.23, 0.56] ], dtype=tf.float32, ) From a8dfbea4a44271846c98e4b6eda2461ddc5c5104 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:12:47 +0200 Subject: [PATCH 19/24] Update tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py --- .../metrics/tests/multilabel_confusion_matrix_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py index e9e6c5fb58..2d5f2f28b6 100644 --- a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py +++ b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py @@ -136,6 +136,6 @@ def test_multiclass(dtype): [[5, 2], [0, 3]], [[7, 1], [2, 0]], [[7, 0], [1, 2]], - [[8, 0], [0, 2]], + [[8, 0], [0, 2]] ], ) From c2c351ec3132936576c914f9fc93a10dd708dfa9 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:13:14 +0200 Subject: [PATCH 20/24] Update tensorflow_addons/optimizers/lookahead.py --- tensorflow_addons/optimizers/lookahead.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/optimizers/lookahead.py b/tensorflow_addons/optimizers/lookahead.py index 3b7fcd6e95..cc4045417d 100644 --- a/tensorflow_addons/optimizers/lookahead.py +++ b/tensorflow_addons/optimizers/lookahead.py @@ -187,6 +187,6 @@ def lr(self, lr): def from_config(cls, config, custom_objects=None): optimizer = tf.keras.optimizers.deserialize( config.pop("optimizer"), - custom_objects=custom_objects, + custom_objects=custom_objects ) return cls(optimizer, **config) From a9551aef61cd69ae9759090625bb1d70fb38b1af Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:13:21 +0200 Subject: [PATCH 21/24] Update tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py --- .../metrics/tests/multilabel_confusion_matrix_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py index 2d5f2f28b6..f07b950c56 100644 --- a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py +++ b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py @@ -88,7 +88,7 @@ def test_mcm_4_classes(dtype): [[4, 1], [1, 4]], [[6, 0], [2, 2]], [[6, 1], [1, 2]], - [[2, 0], [2, 6]], + [[2, 0], [2, 6]] ], ) From aa6d06c273b4fe6da068660d1813d6b6a6867249 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Fri, 28 Aug 2020 23:13:32 +0200 Subject: [PATCH 22/24] Update tensorflow_addons/metrics/r_square.py --- tensorflow_addons/metrics/r_square.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_addons/metrics/r_square.py b/tensorflow_addons/metrics/r_square.py index 20d5545dea..4226e806cf 100644 --- a/tensorflow_addons/metrics/r_square.py +++ b/tensorflow_addons/metrics/r_square.py @@ -117,7 +117,7 @@ def update_state(self, y_true, y_pred, sample_weight=None) -> None: self.res.assign_add( tf.reduce_sum( (y_true - y_pred) ** 2 * sample_weight, - axis=0, + axis=0 ) ) self.count.assign_add(tf.reduce_sum(sample_weight, axis=0)) From 9f7342881d8bd20fb57cd98a811e0e6d2b498d8a Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 21:13:57 +0000 Subject: [PATCH 23/24] Removed commas. --- .../layers/tests/spectral_normalization_test.py | 7 ++----- tensorflow_addons/layers/tests/wrappers_test.py | 13 +++---------- tensorflow_addons/losses/tests/kappa_loss_test.py | 5 +---- tensorflow_addons/losses/tests/triplet_test.py | 5 +---- tensorflow_addons/metrics/r_square.py | 5 +---- tensorflow_addons/metrics/tests/hamming_test.py | 6 +----- .../tests/multilabel_confusion_matrix_test.py | 14 ++------------ tensorflow_addons/optimizers/lookahead.py | 3 +-- tensorflow_addons/optimizers/moving_average.py | 5 +---- 9 files changed, 13 insertions(+), 50 deletions(-) diff --git a/tensorflow_addons/layers/tests/spectral_normalization_test.py b/tensorflow_addons/layers/tests/spectral_normalization_test.py index cc5345baca..a8aebab814 100644 --- a/tensorflow_addons/layers/tests/spectral_normalization_test.py +++ b/tensorflow_addons/layers/tests/spectral_normalization_test.py @@ -113,9 +113,7 @@ def test_normalization(): inputs = tf.keras.layers.Input(shape=[2, 2, 1]) base_layer = tf.keras.layers.Conv2D( - 1, - (2, 2), - kernel_initializer=tf.constant_initializer(value=2) + 1, (2, 2), kernel_initializer=tf.constant_initializer(value=2) ) sn_layer = spectral_normalization.SpectralNormalization(base_layer) model = tf.keras.models.Sequential(layers=[inputs, sn_layer]) @@ -127,8 +125,7 @@ def test_normalization(): for training in [False, True]: _ = model( - tf.constant(np.ones((1, 2, 2, 1), dtype=np.float32)), - training=training + tf.constant(np.ones((1, 2, 2, 1), dtype=np.float32)), training=training ) if training: w = weights_normalized diff --git a/tensorflow_addons/layers/tests/wrappers_test.py b/tensorflow_addons/layers/tests/wrappers_test.py index a505c88acc..448a02aaa0 100644 --- a/tensorflow_addons/layers/tests/wrappers_test.py +++ b/tensorflow_addons/layers/tests/wrappers_test.py @@ -27,9 +27,7 @@ def test_basic(): test_utils.layer_test( wrappers.WeightNormalization, - kwargs={ - "layer": tf.keras.layers.Conv2D(5, (2, 2)) - }, + kwargs={"layer": tf.keras.layers.Conv2D(5, (2, 2))}, input_shape=(2, 4, 4, 3), ) @@ -37,9 +35,7 @@ def test_basic(): def test_no_bias(): test_utils.layer_test( wrappers.WeightNormalization, - kwargs={ - "layer": tf.keras.layers.Dense(5, use_bias=False) - }, + kwargs={"layer": tf.keras.layers.Dense(5, use_bias=False)}, input_shape=(2, 4), ) @@ -53,10 +49,7 @@ def _check_data_init(data_init, input_data, expected_output): ) test_utils.layer_test( wrappers.WeightNormalization, - kwargs={ - "layer": layer, - "data_init": data_init - }, + kwargs={"layer": layer, "data_init": data_init}, input_data=input_data, expected_output=expected_output, ) diff --git a/tensorflow_addons/losses/tests/kappa_loss_test.py b/tensorflow_addons/losses/tests/kappa_loss_test.py index 51e22fed0f..706ebdf3f3 100644 --- a/tensorflow_addons/losses/tests/kappa_loss_test.py +++ b/tensorflow_addons/losses/tests/kappa_loss_test.py @@ -79,10 +79,7 @@ def test_quadratic_weighted_kappa_loss(np_seed): def test_config(): kappa_loss = WeightedKappaLoss( - num_classes=4, - weightage="linear", - name="kappa_loss", - epsilon=0.001 + num_classes=4, weightage="linear", name="kappa_loss", epsilon=0.001 ) assert kappa_loss.num_classes == 4 assert kappa_loss.weightage == "linear" diff --git a/tensorflow_addons/losses/tests/triplet_test.py b/tensorflow_addons/losses/tests/triplet_test.py index fa7062b389..abb0527100 100644 --- a/tensorflow_addons/losses/tests/triplet_test.py +++ b/tensorflow_addons/losses/tests/triplet_test.py @@ -225,10 +225,7 @@ def test_hard_tripled_loss_angular(dtype, soft, dist_func, dist_metric): def test_keras_model_compile_hard(): model = tf.keras.models.Sequential( - [ - tf.keras.layers.Input(shape=(784,)), - tf.keras.layers.Dense(10) - ] + [tf.keras.layers.Input(shape=(784,)), tf.keras.layers.Dense(10)] ) model.compile(loss="Addons>triplet_hard_loss", optimizer="adam") diff --git a/tensorflow_addons/metrics/r_square.py b/tensorflow_addons/metrics/r_square.py index 4226e806cf..04c3866dbc 100644 --- a/tensorflow_addons/metrics/r_square.py +++ b/tensorflow_addons/metrics/r_square.py @@ -115,10 +115,7 @@ def update_state(self, y_true, y_pred, sample_weight=None) -> None: self.sum.assign_add(tf.reduce_sum(weighted_y_true, axis=0)) self.squared_sum.assign_add(tf.reduce_sum(y_true * weighted_y_true, axis=0)) self.res.assign_add( - tf.reduce_sum( - (y_true - y_pred) ** 2 * sample_weight, - axis=0 - ) + tf.reduce_sum((y_true - y_pred) ** 2 * sample_weight, axis=0) ) self.count.assign_add(tf.reduce_sum(sample_weight, axis=0)) diff --git a/tensorflow_addons/metrics/tests/hamming_test.py b/tensorflow_addons/metrics/tests/hamming_test.py index 714abc2aa1..96be48675e 100644 --- a/tensorflow_addons/metrics/tests/hamming_test.py +++ b/tensorflow_addons/metrics/tests/hamming_test.py @@ -101,11 +101,7 @@ def test_mc_5_classes(): def test_ml_4_classes(): actuals = tf.constant([[1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 0, 1]], dtype=tf.float32) predictions = tf.constant( - [ - [0.97, 0.56, 0.83, 0.77], - [0.34, 0.95, 0.7, 0.89], - [0.95, 0.45, 0.23, 0.56] - ], + [[0.97, 0.56, 0.83, 0.77], [0.34, 0.95, 0.7, 0.89], [0.95, 0.45, 0.23, 0.56]], dtype=tf.float32, ) # Initialize diff --git a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py index f07b950c56..0edf76888a 100644 --- a/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py +++ b/tensorflow_addons/metrics/tests/multilabel_confusion_matrix_test.py @@ -84,12 +84,7 @@ def test_mcm_4_classes(dtype): # Check results check_results( mcm_obj, - [ - [[4, 1], [1, 4]], - [[6, 0], [2, 2]], - [[6, 1], [1, 2]], - [[2, 0], [2, 6]] - ], + [[[4, 1], [1, 4]], [[6, 0], [2, 2]], [[6, 1], [1, 2]], [[2, 0], [2, 6]]], ) @@ -132,10 +127,5 @@ def test_multiclass(dtype): # Check results check_results( mcm_obj, - [ - [[5, 2], [0, 3]], - [[7, 1], [2, 0]], - [[7, 0], [1, 2]], - [[8, 0], [0, 2]] - ], + [[[5, 2], [0, 3]], [[7, 1], [2, 0]], [[7, 0], [1, 2]], [[8, 0], [0, 2]]], ) diff --git a/tensorflow_addons/optimizers/lookahead.py b/tensorflow_addons/optimizers/lookahead.py index cc4045417d..6598350200 100644 --- a/tensorflow_addons/optimizers/lookahead.py +++ b/tensorflow_addons/optimizers/lookahead.py @@ -186,7 +186,6 @@ def lr(self, lr): @classmethod def from_config(cls, config, custom_objects=None): optimizer = tf.keras.optimizers.deserialize( - config.pop("optimizer"), - custom_objects=custom_objects + config.pop("optimizer"), custom_objects=custom_objects ) return cls(optimizer, **config) diff --git a/tensorflow_addons/optimizers/moving_average.py b/tensorflow_addons/optimizers/moving_average.py index 546ec11842..445d0bec2e 100644 --- a/tensorflow_addons/optimizers/moving_average.py +++ b/tensorflow_addons/optimizers/moving_average.py @@ -180,8 +180,5 @@ def swap(strategy, a, b): ctx = tf.distribute.get_replica_context() return ctx.merge_call( swap, - args=( - self._average_weights, - self._model_weights - ), + args=(self._average_weights, self._model_weights), ) From 5729af73425c803e0e731911b9e5b1b4fd3f85fd Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Fri, 28 Aug 2020 21:25:56 +0000 Subject: [PATCH 24/24] Removed commas. --- build_deps/toolchains/gpu/find_cuda_config.py | 5 +- .../image/tests/connected_components_test.py | 3 +- .../image/tests/dense_image_warp_test.py | 6 +- .../image/tests/distort_image_ops_test.py | 5 +- tensorflow_addons/image/tests/filters_test.py | 4 +- .../image/tests/transform_ops_test.py | 3 +- tensorflow_addons/layers/crf.py | 3 +- .../layers/spatial_pyramid_pooling.py | 14 +--- tensorflow_addons/layers/tests/maxout_test.py | 5 +- .../layers/tests/optical_flow_test.py | 18 +--- tensorflow_addons/optimizers/lookahead.py | 6 +- .../optimizers/moving_average.py | 5 +- .../optimizers/tests/moving_average_test.py | 25 ++---- .../optimizers/tests/rectified_adam_test.py | 19 +---- .../tests/weight_decay_optimizers_test.py | 9 +- tensorflow_addons/rnn/esn_cell.py | 5 +- tensorflow_addons/rnn/tests/esn_cell_test.py | 3 +- .../seq2seq/beam_search_decoder.py | 3 +- .../seq2seq/tests/basic_decoder_test.py | 84 +++++++------------ .../seq2seq/tests/decoder_test.py | 16 ++-- .../text/tests/parse_time_op_test.py | 4 +- .../text/tests/skip_gram_ops_test.py | 27 +----- 22 files changed, 68 insertions(+), 204 deletions(-) diff --git a/build_deps/toolchains/gpu/find_cuda_config.py b/build_deps/toolchains/gpu/find_cuda_config.py index 9209a7db72..dd814c309d 100644 --- a/build_deps/toolchains/gpu/find_cuda_config.py +++ b/build_deps/toolchains/gpu/find_cuda_config.py @@ -278,10 +278,7 @@ def get_nvcc_version(path): nvcc_name = "nvcc.exe" if _is_windows() else "nvcc" nvcc_path, nvcc_version = _find_versioned_file( base_paths, - [ - "", - "bin", - ], + ["", "bin"], nvcc_name, cuda_version, get_nvcc_version, diff --git a/tensorflow_addons/image/tests/connected_components_test.py b/tensorflow_addons/image/tests/connected_components_test.py index 82c42bddd6..e1c3d10bd1 100644 --- a/tensorflow_addons/image/tests/connected_components_test.py +++ b/tensorflow_addons/image/tests/connected_components_test.py @@ -134,8 +134,7 @@ def test_ones(): def test_ones_small(): np.testing.assert_equal( - connected_components(tf.ones((3, 5), tf.bool)).numpy(), - np.ones((3, 5)), + connected_components(tf.ones((3, 5), tf.bool)).numpy(), np.ones((3, 5)) ) diff --git a/tensorflow_addons/image/tests/dense_image_warp_test.py b/tensorflow_addons/image/tests/dense_image_warp_test.py index a09f964f3a..e883fbe9c3 100644 --- a/tensorflow_addons/image/tests/dense_image_warp_test.py +++ b/tensorflow_addons/image/tests/dense_image_warp_test.py @@ -30,8 +30,7 @@ def test_interpolate_small_grid_ij(): shape=[1, 4, 3, 1], ) query_points = tf.constant( - [[0.0, 0.0], [1.0, 0.0], [2.0, 0.5], [1.5, 1.5], [3.0, 2.0]], - shape=[1, 5, 2], + [[0.0, 0.0], [1.0, 0.0], [2.0, 0.5], [1.5, 1.5], [3.0, 2.0]], shape=[1, 5, 2] ) expected_results = np.reshape(np.array([0.0, 3.0, 6.5, 6.0, 11.0]), [1, 5, 1]) @@ -46,8 +45,7 @@ def test_interpolate_small_grid_xy(): shape=[1, 4, 3, 1], ) query_points = tf.constant( - [[0.0, 0.0], [0.0, 1.0], [0.5, 2.0], [1.5, 1.5], [2.0, 3.0]], - shape=[1, 5, 2], + [[0.0, 0.0], [0.0, 1.0], [0.5, 2.0], [1.5, 1.5], [2.0, 3.0]], shape=[1, 5, 2] ) expected_results = np.reshape(np.array([0.0, 3.0, 6.5, 6.0, 11.0]), [1, 5, 1]) diff --git a/tensorflow_addons/image/tests/distort_image_ops_test.py b/tensorflow_addons/image/tests/distort_image_ops_test.py index ae24ebe8e1..2409023302 100644 --- a/tensorflow_addons/image/tests/distort_image_ops_test.py +++ b/tensorflow_addons/image/tests/distort_image_ops_test.py @@ -125,10 +125,7 @@ def test_adjust_hsv_in_yiq_unknown_shape(): image_np = np.random.rand(*shape) * 255.0 image_tf = tf.constant(image_np) np.testing.assert_allclose( - _adjust_hue_in_yiq_np(image_np, 0), - fn(image_tf), - rtol=2e-4, - atol=1e-4, + _adjust_hue_in_yiq_np(image_np, 0), fn(image_tf), rtol=2e-4, atol=1e-4 ) diff --git a/tensorflow_addons/image/tests/filters_test.py b/tensorflow_addons/image/tests/filters_test.py index 819d246550..1c87c1111c 100644 --- a/tensorflow_addons/image/tests/filters_test.py +++ b/tensorflow_addons/image/tests/filters_test.py @@ -62,9 +62,7 @@ def setup_values( assert 3 <= len(image_shape) <= 4 height, width = image_shape[-3], image_shape[-2] plane = tf.constant( - [x for x in range(1, height * width + 1)], - shape=(height, width), - dtype=dtype, + [x for x in range(1, height * width + 1)], shape=(height, width), dtype=dtype ) image = tile_image(plane, image_shape=image_shape) diff --git a/tensorflow_addons/image/tests/transform_ops_test.py b/tensorflow_addons/image/tests/transform_ops_test.py index 63e8aa8952..1d626f83e8 100644 --- a/tensorflow_addons/image/tests/transform_ops_test.py +++ b/tensorflow_addons/image/tests/transform_ops_test.py @@ -56,8 +56,7 @@ def test_compose(dtype): @pytest.mark.parametrize("dtype", _DTYPES) def test_extreme_projective_transform(dtype): image = tf.constant( - [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], - dtype=dtype, + [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], dtype=dtype ) transformation = tf.constant([1, 0, 0, 0, 1, 0, -1, 0], tf.dtypes.float32) image_transformed = transform_ops.transform(image, transformation) diff --git a/tensorflow_addons/layers/crf.py b/tensorflow_addons/layers/crf.py index 3663eb5f56..22b3f9a2f4 100644 --- a/tensorflow_addons/layers/crf.py +++ b/tensorflow_addons/layers/crf.py @@ -77,8 +77,7 @@ def __init__( if self.use_kernel: self._dense_layer = tf.keras.layers.Dense( - units=self.units, - dtype=self.dtype, + units=self.units, dtype=self.dtype ) else: self._dense_layer = lambda x: tf.cast(x, dtype=self.dtype) diff --git a/tensorflow_addons/layers/spatial_pyramid_pooling.py b/tensorflow_addons/layers/spatial_pyramid_pooling.py index 3653813555..1514e34bd6 100644 --- a/tensorflow_addons/layers/spatial_pyramid_pooling.py +++ b/tensorflow_addons/layers/spatial_pyramid_pooling.py @@ -86,12 +86,7 @@ def call(self, inputs, **kwargs): new_input_height = dynamic_input_shape[1] - height_overflow new_input_width = dynamic_input_shape[2] - width_overflow - new_inp = inputs[ - :, - :new_input_height, - :new_input_width, - :, - ] + new_inp = inputs[:, :new_input_height, :new_input_width, :] output = self.pool_layers[index](new_inp) output = tf.reshape( output, [dynamic_input_shape[0], bin[0] * bin[1], inputs.shape[-1]] @@ -106,12 +101,7 @@ def call(self, inputs, **kwargs): new_input_height = dynamic_input_shape[2] - height_overflow new_input_width = dynamic_input_shape[3] - width_overflow - new_inp = inputs[ - :, - :, - :new_input_height, - :new_input_width, - ] + new_inp = inputs[:, :, :new_input_height, :new_input_width] output = self.pool_layers[index](new_inp) output = tf.reshape( output, [dynamic_input_shape[0], inputs.shape[1], bin[0] * bin[1]] diff --git a/tensorflow_addons/layers/tests/maxout_test.py b/tensorflow_addons/layers/tests/maxout_test.py index 07efadb6b9..90a612ed57 100644 --- a/tensorflow_addons/layers/tests/maxout_test.py +++ b/tensorflow_addons/layers/tests/maxout_test.py @@ -42,10 +42,7 @@ def test_nchw(): def test_unknown(): inputs = np.random.random((5, 4, 2, 18)).astype("float32") test_utils.layer_test( - Maxout, - kwargs={"num_units": 3}, - input_shape=(5, 4, 2, None), - input_data=inputs, + Maxout, kwargs={"num_units": 3}, input_shape=(5, 4, 2, None), input_data=inputs ) test_utils.layer_test( diff --git a/tensorflow_addons/layers/tests/optical_flow_test.py b/tensorflow_addons/layers/tests/optical_flow_test.py index eff642a6ee..f01c88cdb8 100644 --- a/tensorflow_addons/layers/tests/optical_flow_test.py +++ b/tensorflow_addons/layers/tests/optical_flow_test.py @@ -107,26 +107,14 @@ def test_forward_simple(data_format): # We can test fixed ids, as output is independent from data_format expected_ids = np.concatenate( [ - np.zeros( - 464, - ), - np.ones( - 464, - ), + np.zeros(464), + np.ones(464), ] ) np.testing.assert_allclose(tf.where(actual == 0)[:, 0].numpy(), expected_ids) counts = [54, 52, 54, 50, 44, 50, 54, 52, 54] - expected_ids = np.concatenate( - [ - k - * np.ones( - v, - ) - for k, v in enumerate(counts) - ] - ) + expected_ids = np.concatenate([k * np.ones(v) for k, v in enumerate(counts)]) expected_ids = np.concatenate([expected_ids, expected_ids]) np.testing.assert_allclose(tf.where(actual == 0)[:, 1], expected_ids) assert actual.shape == (2, 9, 7, 8) diff --git a/tensorflow_addons/optimizers/lookahead.py b/tensorflow_addons/optimizers/lookahead.py index 6598350200..31fe13b043 100644 --- a/tensorflow_addons/optimizers/lookahead.py +++ b/tensorflow_addons/optimizers/lookahead.py @@ -125,12 +125,10 @@ def _look_ahead_op(self, var): ) with tf.control_dependencies([step_back]): slow_update = slow_var.assign( - tf.where(sync_cond, step_back, slow_var), - use_locking=self._use_locking, + tf.where(sync_cond, step_back, slow_var), use_locking=self._use_locking ) var_update = var.assign( - tf.where(sync_cond, step_back, var), - use_locking=self._use_locking, + tf.where(sync_cond, step_back, var), use_locking=self._use_locking ) return tf.group(slow_update, var_update) diff --git a/tensorflow_addons/optimizers/moving_average.py b/tensorflow_addons/optimizers/moving_average.py index 445d0bec2e..db14979c12 100644 --- a/tensorflow_addons/optimizers/moving_average.py +++ b/tensorflow_addons/optimizers/moving_average.py @@ -178,7 +178,4 @@ def swap(strategy, a, b): ) # a = a - b ctx = tf.distribute.get_replica_context() - return ctx.merge_call( - swap, - args=(self._average_weights, self._model_weights), - ) + return ctx.merge_call(swap, args=(self._average_weights, self._model_weights)) diff --git a/tensorflow_addons/optimizers/tests/moving_average_test.py b/tensorflow_addons/optimizers/tests/moving_average_test.py index 3914eb9b0e..4e4b90983f 100644 --- a/tensorflow_addons/optimizers/tests/moving_average_test.py +++ b/tensorflow_addons/optimizers/tests/moving_average_test.py @@ -118,11 +118,7 @@ def test_optimizer_string(): def test_config(): sgd_opt = tf.keras.optimizers.SGD(lr=2.0, nesterov=True, momentum=0.3, decay=0.1) opt = MovingAverage( - sgd_opt, - average_decay=0.5, - num_updates=None, - start_step=5, - dynamic_decay=True, + sgd_opt, average_decay=0.5, num_updates=None, start_step=5, dynamic_decay=True ) config = opt.get_config() @@ -170,11 +166,7 @@ def test_fit_simple_linear_model(): def test_serialization(): sgd_opt = tf.keras.optimizers.SGD(lr=2.0, nesterov=True, momentum=0.3, decay=0.1) optimizer = MovingAverage( - sgd_opt, - average_decay=0.5, - num_updates=None, - start_step=5, - dynamic_decay=True, + sgd_opt, average_decay=0.5, num_updates=None, start_step=5, dynamic_decay=True ) config = tf.keras.optimizers.serialize(optimizer) new_optimizer = tf.keras.optimizers.deserialize(config) @@ -188,9 +180,7 @@ def test_start_step(): grads_and_vars = [(grads0, var0)] opt = MovingAverage( - tf.keras.optimizers.SGD(lr=1.0), - average_decay=0.5, - start_step=1, + tf.keras.optimizers.SGD(lr=1.0), average_decay=0.5, start_step=1 ) opt.apply_gradients(grads_and_vars) @@ -213,9 +203,7 @@ def test_dynamic_decay(): grads_and_vars = [(grads0, var0)] opt = MovingAverage( - tf.keras.optimizers.SGD(lr=2.0), - average_decay=0.5, - dynamic_decay=True, + tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5, dynamic_decay=True ) opt.apply_gradients(grads_and_vars) @@ -234,10 +222,7 @@ def test_swap_weights(device): var = tf.Variable([1.0, 2.0]) grads = tf.constant([0.1, 0.1]) - opt = MovingAverage( - tf.keras.optimizers.SGD(lr=2.0), - average_decay=0.5, - ) + opt = MovingAverage(tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5) @tf.function def apply_gradients(): diff --git a/tensorflow_addons/optimizers/tests/rectified_adam_test.py b/tensorflow_addons/optimizers/tests/rectified_adam_test.py index 2db66e4665..040e5e638e 100644 --- a/tensorflow_addons/optimizers/tests/rectified_adam_test.py +++ b/tensorflow_addons/optimizers/tests/rectified_adam_test.py @@ -145,12 +145,7 @@ def test_dense_sample_with_lookahead(): iterations=100, expected=[[0.993126, 1.992901], [2.993283, 3.993261]], optimizer=Lookahead( - RectifiedAdam( - lr=1e-3, - beta_1=0.95, - ), - sync_period=6, - slow_step_size=0.45, + RectifiedAdam(lr=1e-3, beta_1=0.95), sync_period=6, slow_step_size=0.45 ), ) @@ -163,12 +158,7 @@ def test_sparse_sample_with_lookahead(): iterations=150, expected=[[0.988156, 2.0], [3.0, 3.988291]], optimizer=Lookahead( - RectifiedAdam( - lr=1e-3, - beta_1=0.95, - ), - sync_period=6, - slow_step_size=0.45, + RectifiedAdam(lr=1e-3, beta_1=0.95), sync_period=6, slow_step_size=0.45 ), ) @@ -182,10 +172,7 @@ def test_get_config(): def test_serialization(): optimizer = RectifiedAdam( - lr=1e-3, - total_steps=10000, - warmup_proportion=0.1, - min_lr=1e-5, + lr=1e-3, total_steps=10000, warmup_proportion=0.1, min_lr=1e-5 ) config = tf.keras.optimizers.serialize(optimizer) new_optimizer = tf.keras.optimizers.deserialize(config) diff --git a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py index e853d7cfd0..25f81f7350 100644 --- a/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py +++ b/tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py @@ -83,8 +83,7 @@ def do_test( for _ in range(3): if do_decay_var_list: opt.apply_gradients( - zip([grads0, grads1], [var0, var1]), - decay_var_list=[var0, var1], + zip([grads0, grads1], [var0, var1]), decay_var_list=[var0, var1] ) else: opt.apply_gradients(zip([grads0, grads1], [var0, var1])) @@ -375,11 +374,7 @@ def test_optimizer_basic(dtype, optimizer): @pytest.mark.parametrize("dtype", [tf.half, tf.float32, tf.float64]) def test_optimizer_sparse(dtype, optimizer): do_test_sparse_repeated_indices( - dtype, - optimizer, - learning_rate=0.001, - momentum=0.9, - weight_decay=WEIGHT_DECAY, + dtype, optimizer, learning_rate=0.001, momentum=0.9, weight_decay=WEIGHT_DECAY ) diff --git a/tensorflow_addons/rnn/esn_cell.py b/tensorflow_addons/rnn/esn_cell.py index d44c1a8257..d36be9f369 100644 --- a/tensorflow_addons/rnn/esn_cell.py +++ b/tensorflow_addons/rnn/esn_cell.py @@ -118,10 +118,7 @@ def _esn_recurrent_initializer(shape, dtype, partition_info=None): ) connectivity_mask = tf.cast( - tf.math.less_equal( - tf.random.uniform(shape), - self.connectivity, - ), + tf.math.less_equal(tf.random.uniform(shape), self.connectivity), dtype, ) recurrent_weights = tf.math.multiply(recurrent_weights, connectivity_mask) diff --git a/tensorflow_addons/rnn/tests/esn_cell_test.py b/tensorflow_addons/rnn/tests/esn_cell_test.py index c11243b6ac..ae695fd658 100644 --- a/tensorflow_addons/rnn/tests/esn_cell_test.py +++ b/tensorflow_addons/rnn/tests/esn_cell_test.py @@ -24,8 +24,7 @@ def test_base_esn(): units = 3 expected_output = np.array( - [[2.77, 2.77, 2.77], [4.77, 4.77, 4.77], [6.77, 6.77, 6.77]], - dtype=np.float32, + [[2.77, 2.77, 2.77], [4.77, 4.77, 4.77], [6.77, 6.77, 6.77]], dtype=np.float32 ) const_initializer = tf.constant_initializer(0.5) diff --git a/tensorflow_addons/seq2seq/beam_search_decoder.py b/tensorflow_addons/seq2seq/beam_search_decoder.py index 6685d28eb7..73897b6607 100644 --- a/tensorflow_addons/seq2seq/beam_search_decoder.py +++ b/tensorflow_addons/seq2seq/beam_search_decoder.py @@ -63,8 +63,7 @@ class BeamSearchDecoderState( class BeamSearchDecoderOutput( collections.namedtuple( - "BeamSearchDecoderOutput", - ("scores", "predicted_ids", "parent_ids"), + "BeamSearchDecoderOutput", ("scores", "predicted_ids", "parent_ids") ) ): """Outputs of a `BeamSearchDecoder` step. diff --git a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py index 7c9350fa25..e2606027a8 100644 --- a/tensorflow_addons/seq2seq/tests/basic_decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/basic_decoder_test.py @@ -63,12 +63,9 @@ def test_step_with_training_helper_output_layer(cell_class, use_output_layer): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) if isinstance(cell, tf.keras.layers.LSTMCell): assert len(first_state) == 2 @@ -166,8 +163,7 @@ def test_step_with_training_helper_masked_input(use_mask): np.testing.assert_equal((np.maximum(sequence_length - 1, 0) == 0), step_finished) assert output_dtype.sample_id == step_outputs.sample_id.dtype np.testing.assert_equal( - np.argmax(step_outputs.rnn_output, -1), - step_outputs.sample_id, + np.argmax(step_outputs.rnn_output, -1), step_outputs.sample_id ) @@ -198,12 +194,9 @@ def test_step_with_greedy_embedding_helper(): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 @@ -219,8 +212,7 @@ def test_step_with_greedy_embedding_helper(): expected_step_finished = expected_sample_ids == end_token expected_step_next_inputs = embeddings[expected_sample_ids] np.testing.assert_equal( - np.asanyarray([False, False, False, False, False]), - first_finished, + np.asanyarray([False, False, False, False, False]), first_finished ) np.testing.assert_equal(expected_step_finished, step_finished) assert output_dtype.sample_id == step_outputs.sample_id.dtype @@ -256,12 +248,9 @@ def test_step_with_sample_embedding_helper(): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 @@ -313,12 +302,9 @@ def test_step_with_scheduled_embedding_training_helper(): assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 @@ -332,12 +318,10 @@ def test_step_with_scheduled_embedding_training_helper(): assert (batch_size, input_depth) == step_next_inputs.shape np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), - first_finished, + np.asanyarray([False, False, False, False, True]), first_finished ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), - step_finished, + np.asanyarray([False, False, False, True, True]), step_finished ) sample_ids = step_outputs.sample_id.numpy() assert output_dtype.sample_id == sample_ids.dtype @@ -410,12 +394,9 @@ def next_inputs_fn(outputs): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) if use_next_inputs_fn: output_after_next_inputs_fn = next_inputs_fn(step_outputs.rnn_output) @@ -431,12 +412,10 @@ def next_inputs_fn(outputs): assert (batch_size, cell_depth) == step_state[1].shape np.testing.assert_equal( - np.asanyarray([False, False, False, False, True]), - first_finished, + np.asanyarray([False, False, False, False, True]), first_finished ) np.testing.assert_equal( - np.asanyarray([False, False, False, True, True]), - step_finished, + np.asanyarray([False, False, False, True, True]), step_finished ) sample_ids = step_outputs.sample_id @@ -461,8 +440,7 @@ def next_inputs_fn(outputs): ) np.testing.assert_equal( - step_next_inputs.numpy()[batch_where_sampling], - expected_next_sampling_inputs, + step_next_inputs.numpy()[batch_where_sampling], expected_next_sampling_inputs ) np.testing.assert_equal( @@ -520,12 +498,9 @@ def end_fn(sample_ids): ) assert basic_decoder.BasicDecoderOutput(tf.float32, tf.int32) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 @@ -586,12 +561,9 @@ def end_fn(sample_ids): assert basic_decoder.BasicDecoderOutput(cell_depth, cell_depth) == output_size assert basic_decoder.BasicDecoderOutput(tf.float32, tf.bool) == output_dtype - ( - step_outputs, - step_state, - step_next_inputs, - step_finished, - ) = my_decoder.step(tf.constant(0), first_inputs, first_state) + (step_outputs, step_state, step_next_inputs, step_finished) = my_decoder.step( + tf.constant(0), first_inputs, first_state + ) assert len(first_state) == 2 assert len(step_state) == 2 diff --git a/tensorflow_addons/seq2seq/tests/decoder_test.py b/tensorflow_addons/seq2seq/tests/decoder_test.py index 78712f73f8..e30f338ee7 100644 --- a/tensorflow_addons/seq2seq/tests/decoder_test.py +++ b/tensorflow_addons/seq2seq/tests/decoder_test.py @@ -92,10 +92,7 @@ def test_dynamic_decode_tflite_conversion(): cell = tf.keras.layers.LSTMCell(units) sampler = sampler_py.GreedyEmbeddingSampler() embeddings = tf.random.uniform([vocab_size, units]) - my_decoder = basic_decoder.BasicDecoder( - cell=cell, - sampler=sampler, - ) + my_decoder = basic_decoder.BasicDecoder(cell=cell, sampler=sampler) @tf.function def _decode(start_tokens, end_token): @@ -151,11 +148,9 @@ def test_dynamic_decode_rnn_with_training_helper_matches_dynamic_rnn( cell=cell, sampler=sampler, impute_finished=use_sequence_length ) - ( - final_decoder_outputs, - final_decoder_state, - _, - ) = my_decoder(inputs, initial_state=zero_state, sequence_length=sequence_length) + (final_decoder_outputs, final_decoder_state, _) = my_decoder( + inputs, initial_state=zero_state, sequence_length=sequence_length + ) rnn = tf.keras.layers.RNN(cell, return_sequences=True, return_state=True) mask = ( @@ -173,8 +168,7 @@ def test_dynamic_decode_rnn_with_training_helper_matches_dynamic_rnn( # to dynamic_rnn, which also zeros out outputs and passes along # state. np.testing.assert_allclose( - final_decoder_outputs.rnn_output, - final_rnn_outputs[:, 0:max_out, :], + final_decoder_outputs.rnn_output, final_rnn_outputs[:, 0:max_out, :] ) if use_sequence_length: np.testing.assert_allclose(final_decoder_state, final_rnn_state) diff --git a/tensorflow_addons/text/tests/parse_time_op_test.py b/tensorflow_addons/text/tests/parse_time_op_test.py index bec5249ddc..f976800e7b 100644 --- a/tensorflow_addons/text/tests/parse_time_op_test.py +++ b/tensorflow_addons/text/tests/parse_time_op_test.py @@ -49,9 +49,7 @@ def test_parse_time(): ] for time_string, time_format, output_unit, expected in items: result = text.parse_time( - time_string=time_string, - time_format=time_format, - output_unit=output_unit, + time_string=time_string, time_format=time_format, output_unit=output_unit ) np.testing.assert_equal(expected, result.numpy()) diff --git a/tensorflow_addons/text/tests/skip_gram_ops_test.py b/tensorflow_addons/text/tests/skip_gram_ops_test.py index 761115c0a3..e60656c780 100644 --- a/tensorflow_addons/text/tests/skip_gram_ops_test.py +++ b/tensorflow_addons/text/tests/skip_gram_ops_test.py @@ -234,12 +234,7 @@ def test_skip_gram_sample_non_string_input(): input_tensor = tf.constant([1, 2, 3], dtype=tf.dtypes.int16) tokens, labels = text.skip_gram_sample(input_tensor, min_skips=1, max_skips=1) expected_tokens, expected_labels = _split_tokens_labels( - [ - (1, 2), - (2, 1), - (2, 3), - (3, 2), - ] + [(1, 2), (2, 1), (2, 3), (3, 2)] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) @@ -288,10 +283,7 @@ def test_skip_gram_sample_errors(): text.skip_gram_sample(dummy_input, vocab_freq_table=None, corpus_size=100) with pytest.raises(ValueError): text.skip_gram_sample( - dummy_input, - vocab_freq_table=None, - vocab_subsampling=1e-5, - corpus_size=100, + dummy_input, vocab_freq_table=None, vocab_subsampling=1e-5, corpus_size=100 ) # vocab_subsampling and corpus_size must both be present or absent. @@ -485,12 +477,7 @@ def _text_vocab_subsample_vocab_helper( ) expected_tokens, expected_labels = _split_tokens_labels( - [ - (b"the", b"to"), - (b"to", b"the"), - (b"to", b"life"), - (b"life", b"to"), - ] + [(b"the", b"to"), (b"to", b"the"), (b"to", b"life"), (b"life", b"to")] ) np.testing.assert_equal(np.asanyarray(expected_tokens), tokens.numpy()) np.testing.assert_equal(np.asanyarray(expected_labels), labels.numpy()) @@ -614,13 +601,7 @@ def _make_text_vocab_freq_file(tmp_dir): with open(filepath, "w") as f: writer = csv.writer(f) writer.writerows( - [ - ["and", 40], - ["life", 8], - ["the", 30], - ["to", 20], - ["universe", 2], - ] + [["and", 40], ["life", 8], ["the", 30], ["to", 20], ["universe", 2]] ) return filepath