From 718a7f31792edbb6b981bda1ee0953e3e80e5fd4 Mon Sep 17 00:00:00 2001 From: TensorFlow Recommenders Authors Date: Thu, 26 Jan 2023 15:47:34 -0800 Subject: [PATCH] Enable tfrs models to handle non-scalar regularization losses by applying reduce_sum instead of sum on regularization losses. PiperOrigin-RevId: 504961825 --- setup.py | 2 +- tensorflow_recommenders/__init__.py | 2 +- tensorflow_recommenders/examples/__init__.py | 2 +- tensorflow_recommenders/examples/movielens.py | 2 +- tensorflow_recommenders/examples/nbtool.py | 2 +- tensorflow_recommenders/experimental/__init__.py | 2 +- .../experimental/layers/__init__.py | 2 +- .../experimental/layers/embedding/__init__.py | 2 +- .../layers/embedding/partial_tpu_embedding.py | 2 +- .../layers/embedding/partial_tpu_embedding_test.py | 2 +- .../experimental/models/__init__.py | 2 +- .../experimental/models/ranking.py | 2 +- .../experimental/models/ranking_test.py | 2 +- .../experimental/optimizers/__init__.py | 2 +- .../experimental/optimizers/clippy_adagrad.py | 2 +- .../experimental/optimizers/clippy_adagrad_test.py | 2 +- .../experimental/optimizers/composite_optimizer.py | 2 +- .../optimizers/composite_optimizer_test.py | 2 +- tensorflow_recommenders/layers/__init__.py | 2 +- tensorflow_recommenders/layers/blocks.py | 2 +- .../layers/embedding/__init__.py | 2 +- .../layers/embedding/tpu_embedding_layer.py | 2 +- .../layers/embedding/tpu_embedding_layer_test.py | 2 +- tensorflow_recommenders/layers/factorized_top_k.py | 2 +- .../layers/factorized_top_k_test.py | 2 +- .../layers/feature_interaction/__init__.py | 2 +- .../layers/feature_interaction/dcn.py | 2 +- .../layers/feature_interaction/dcn_test.py | 2 +- .../layers/feature_interaction/dot_interaction.py | 2 +- .../feature_interaction/dot_interaction_test.py | 2 +- tensorflow_recommenders/layers/loss.py | 2 +- tensorflow_recommenders/layers/loss_test.py | 2 +- tensorflow_recommenders/metrics/__init__.py | 2 +- tensorflow_recommenders/metrics/factorized_top_k.py | 2 +- .../metrics/factorized_top_k_test.py | 2 +- tensorflow_recommenders/models/__init__.py | 2 +- tensorflow_recommenders/models/base.py | 13 +++++++++---- tensorflow_recommenders/models/base_test.py | 2 +- tensorflow_recommenders/tasks/__init__.py | 2 +- tensorflow_recommenders/tasks/base.py | 2 +- tensorflow_recommenders/tasks/ranking.py | 2 +- tensorflow_recommenders/tasks/ranking_test.py | 2 +- tensorflow_recommenders/tasks/retrieval.py | 2 +- tensorflow_recommenders/tasks/retrieval_test.py | 2 +- tensorflow_recommenders/types.py | 2 +- tools/build_api_docs.py | 2 +- 46 files changed, 54 insertions(+), 49 deletions(-) diff --git a/setup.py b/setup.py index b3fa5cc0..4f44f960 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/__init__.py b/tensorflow_recommenders/__init__.py index 63e3a057..12071bd7 100644 --- a/tensorflow_recommenders/__init__.py +++ b/tensorflow_recommenders/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/examples/__init__.py b/tensorflow_recommenders/examples/__init__.py index 05bef911..a56ffedc 100644 --- a/tensorflow_recommenders/examples/__init__.py +++ b/tensorflow_recommenders/examples/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/examples/movielens.py b/tensorflow_recommenders/examples/movielens.py index c92aeb9f..a9d42eb3 100644 --- a/tensorflow_recommenders/examples/movielens.py +++ b/tensorflow_recommenders/examples/movielens.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/examples/nbtool.py b/tensorflow_recommenders/examples/nbtool.py index 11929199..f1c4ac93 100644 --- a/tensorflow_recommenders/examples/nbtool.py +++ b/tensorflow_recommenders/examples/nbtool.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/__init__.py b/tensorflow_recommenders/experimental/__init__.py index 4b4ba62c..fec3eb1e 100644 --- a/tensorflow_recommenders/experimental/__init__.py +++ b/tensorflow_recommenders/experimental/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/layers/__init__.py b/tensorflow_recommenders/experimental/layers/__init__.py index 3ca4d532..3eab649e 100644 --- a/tensorflow_recommenders/experimental/layers/__init__.py +++ b/tensorflow_recommenders/experimental/layers/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/layers/embedding/__init__.py b/tensorflow_recommenders/experimental/layers/embedding/__init__.py index d7de7a1d..eebe7fca 100644 --- a/tensorflow_recommenders/experimental/layers/embedding/__init__.py +++ b/tensorflow_recommenders/experimental/layers/embedding/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding.py b/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding.py index 500d5466..9d0256ed 100644 --- a/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding.py +++ b/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding_test.py b/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding_test.py index 14430363..1b4627f0 100644 --- a/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding_test.py +++ b/tensorflow_recommenders/experimental/layers/embedding/partial_tpu_embedding_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/models/__init__.py b/tensorflow_recommenders/experimental/models/__init__.py index 08ce00ea..679bae48 100644 --- a/tensorflow_recommenders/experimental/models/__init__.py +++ b/tensorflow_recommenders/experimental/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/models/ranking.py b/tensorflow_recommenders/experimental/models/ranking.py index f234861d..1cf8f941 100644 --- a/tensorflow_recommenders/experimental/models/ranking.py +++ b/tensorflow_recommenders/experimental/models/ranking.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/models/ranking_test.py b/tensorflow_recommenders/experimental/models/ranking_test.py index 64be9c74..c8d06e9d 100644 --- a/tensorflow_recommenders/experimental/models/ranking_test.py +++ b/tensorflow_recommenders/experimental/models/ranking_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/optimizers/__init__.py b/tensorflow_recommenders/experimental/optimizers/__init__.py index 35bdafe1..1a7d80d9 100644 --- a/tensorflow_recommenders/experimental/optimizers/__init__.py +++ b/tensorflow_recommenders/experimental/optimizers/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/optimizers/clippy_adagrad.py b/tensorflow_recommenders/experimental/optimizers/clippy_adagrad.py index 29c1be78..a359ed34 100644 --- a/tensorflow_recommenders/experimental/optimizers/clippy_adagrad.py +++ b/tensorflow_recommenders/experimental/optimizers/clippy_adagrad.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/optimizers/clippy_adagrad_test.py b/tensorflow_recommenders/experimental/optimizers/clippy_adagrad_test.py index f6ec3bdf..f95f3720 100644 --- a/tensorflow_recommenders/experimental/optimizers/clippy_adagrad_test.py +++ b/tensorflow_recommenders/experimental/optimizers/clippy_adagrad_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/optimizers/composite_optimizer.py b/tensorflow_recommenders/experimental/optimizers/composite_optimizer.py index 750f0dae..2aabb8a9 100644 --- a/tensorflow_recommenders/experimental/optimizers/composite_optimizer.py +++ b/tensorflow_recommenders/experimental/optimizers/composite_optimizer.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/experimental/optimizers/composite_optimizer_test.py b/tensorflow_recommenders/experimental/optimizers/composite_optimizer_test.py index bf434279..53ebf760 100644 --- a/tensorflow_recommenders/experimental/optimizers/composite_optimizer_test.py +++ b/tensorflow_recommenders/experimental/optimizers/composite_optimizer_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/__init__.py b/tensorflow_recommenders/layers/__init__.py index 2b791fe6..d859a850 100644 --- a/tensorflow_recommenders/layers/__init__.py +++ b/tensorflow_recommenders/layers/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/blocks.py b/tensorflow_recommenders/layers/blocks.py index 333f2cbb..b38fcdfd 100644 --- a/tensorflow_recommenders/layers/blocks.py +++ b/tensorflow_recommenders/layers/blocks.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/embedding/__init__.py b/tensorflow_recommenders/layers/embedding/__init__.py index d02175e5..4ea029aa 100644 --- a/tensorflow_recommenders/layers/embedding/__init__.py +++ b/tensorflow_recommenders/layers/embedding/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/embedding/tpu_embedding_layer.py b/tensorflow_recommenders/layers/embedding/tpu_embedding_layer.py index f67f56b9..49e0cd32 100644 --- a/tensorflow_recommenders/layers/embedding/tpu_embedding_layer.py +++ b/tensorflow_recommenders/layers/embedding/tpu_embedding_layer.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/embedding/tpu_embedding_layer_test.py b/tensorflow_recommenders/layers/embedding/tpu_embedding_layer_test.py index 1d134289..804a0bd1 100644 --- a/tensorflow_recommenders/layers/embedding/tpu_embedding_layer_test.py +++ b/tensorflow_recommenders/layers/embedding/tpu_embedding_layer_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/factorized_top_k.py b/tensorflow_recommenders/layers/factorized_top_k.py index 82de45cc..056be4d3 100644 --- a/tensorflow_recommenders/layers/factorized_top_k.py +++ b/tensorflow_recommenders/layers/factorized_top_k.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/factorized_top_k_test.py b/tensorflow_recommenders/layers/factorized_top_k_test.py index bccf43f6..4e7b5b7e 100644 --- a/tensorflow_recommenders/layers/factorized_top_k_test.py +++ b/tensorflow_recommenders/layers/factorized_top_k_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/feature_interaction/__init__.py b/tensorflow_recommenders/layers/feature_interaction/__init__.py index 2c5bc2dd..57edcfd3 100644 --- a/tensorflow_recommenders/layers/feature_interaction/__init__.py +++ b/tensorflow_recommenders/layers/feature_interaction/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/feature_interaction/dcn.py b/tensorflow_recommenders/layers/feature_interaction/dcn.py index cea09aac..4de85d3f 100644 --- a/tensorflow_recommenders/layers/feature_interaction/dcn.py +++ b/tensorflow_recommenders/layers/feature_interaction/dcn.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/feature_interaction/dcn_test.py b/tensorflow_recommenders/layers/feature_interaction/dcn_test.py index c564be1a..2f3e0bea 100644 --- a/tensorflow_recommenders/layers/feature_interaction/dcn_test.py +++ b/tensorflow_recommenders/layers/feature_interaction/dcn_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/feature_interaction/dot_interaction.py b/tensorflow_recommenders/layers/feature_interaction/dot_interaction.py index 56e85155..2cea56e0 100644 --- a/tensorflow_recommenders/layers/feature_interaction/dot_interaction.py +++ b/tensorflow_recommenders/layers/feature_interaction/dot_interaction.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/feature_interaction/dot_interaction_test.py b/tensorflow_recommenders/layers/feature_interaction/dot_interaction_test.py index e7c906c2..d170e17d 100644 --- a/tensorflow_recommenders/layers/feature_interaction/dot_interaction_test.py +++ b/tensorflow_recommenders/layers/feature_interaction/dot_interaction_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/loss.py b/tensorflow_recommenders/layers/loss.py index f7615a3b..2cd3300f 100644 --- a/tensorflow_recommenders/layers/loss.py +++ b/tensorflow_recommenders/layers/loss.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/layers/loss_test.py b/tensorflow_recommenders/layers/loss_test.py index b00c8a71..1d23d527 100644 --- a/tensorflow_recommenders/layers/loss_test.py +++ b/tensorflow_recommenders/layers/loss_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/metrics/__init__.py b/tensorflow_recommenders/metrics/__init__.py index 51f3ee37..461479d0 100644 --- a/tensorflow_recommenders/metrics/__init__.py +++ b/tensorflow_recommenders/metrics/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/metrics/factorized_top_k.py b/tensorflow_recommenders/metrics/factorized_top_k.py index 00eb4350..7d169425 100644 --- a/tensorflow_recommenders/metrics/factorized_top_k.py +++ b/tensorflow_recommenders/metrics/factorized_top_k.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/metrics/factorized_top_k_test.py b/tensorflow_recommenders/metrics/factorized_top_k_test.py index a3f564c2..2ef75715 100644 --- a/tensorflow_recommenders/metrics/factorized_top_k_test.py +++ b/tensorflow_recommenders/metrics/factorized_top_k_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/models/__init__.py b/tensorflow_recommenders/models/__init__.py index 82e2dda4..1ee5370a 100644 --- a/tensorflow_recommenders/models/__init__.py +++ b/tensorflow_recommenders/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/models/base.py b/tensorflow_recommenders/models/base.py index 432f9342..dc285b42 100644 --- a/tensorflow_recommenders/models/base.py +++ b/tensorflow_recommenders/models/base.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,7 +59,8 @@ def compute_loss(self, inputs, training: bool = False) -> tf.Tensor: """ raise NotImplementedError( - "Implementers must implement the `compute_loss` method.") + "Implementers must implement the `compute_loss` method." + ) def train_step(self, inputs): """Custom train step using the `compute_loss` method.""" @@ -68,7 +69,9 @@ def train_step(self, inputs): loss = self.compute_loss(inputs, training=True) # Handle regularization losses as well. - regularization_loss = sum(self.losses) + regularization_loss = tf.reduce_sum( + [tf.reduce_sum(loss) for loss in self.losses] + ) total_loss = loss + regularization_loss @@ -88,7 +91,9 @@ def test_step(self, inputs): loss = self.compute_loss(inputs, training=False) # Handle regularization losses as well. - regularization_loss = sum(self.losses) + regularization_loss = tf.reduce_sum( + [tf.reduce_sum(loss) for loss in self.losses] + ) total_loss = loss + regularization_loss diff --git a/tensorflow_recommenders/models/base_test.py b/tensorflow_recommenders/models/base_test.py index c0cfa838..270412cb 100644 --- a/tensorflow_recommenders/models/base_test.py +++ b/tensorflow_recommenders/models/base_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/__init__.py b/tensorflow_recommenders/tasks/__init__.py index 88ed31d2..c5cfa2a3 100644 --- a/tensorflow_recommenders/tasks/__init__.py +++ b/tensorflow_recommenders/tasks/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/base.py b/tensorflow_recommenders/tasks/base.py index dcafe532..068a8b18 100644 --- a/tensorflow_recommenders/tasks/base.py +++ b/tensorflow_recommenders/tasks/base.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/ranking.py b/tensorflow_recommenders/tasks/ranking.py index 891b9753..675066c9 100644 --- a/tensorflow_recommenders/tasks/ranking.py +++ b/tensorflow_recommenders/tasks/ranking.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/ranking_test.py b/tensorflow_recommenders/tasks/ranking_test.py index 314ec379..f6e6419d 100644 --- a/tensorflow_recommenders/tasks/ranking_test.py +++ b/tensorflow_recommenders/tasks/ranking_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/retrieval.py b/tensorflow_recommenders/tasks/retrieval.py index bd44e05d..34445d20 100644 --- a/tensorflow_recommenders/tasks/retrieval.py +++ b/tensorflow_recommenders/tasks/retrieval.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/tasks/retrieval_test.py b/tensorflow_recommenders/tasks/retrieval_test.py index 4c7df6dd..94215588 100644 --- a/tensorflow_recommenders/tasks/retrieval_test.py +++ b/tensorflow_recommenders/tasks/retrieval_test.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tensorflow_recommenders/types.py b/tensorflow_recommenders/types.py index 02c47c06..880acc40 100644 --- a/tensorflow_recommenders/types.py +++ b/tensorflow_recommenders/types.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tools/build_api_docs.py b/tools/build_api_docs.py index 5bdb71ea..cfe464f5 100644 --- a/tools/build_api_docs.py +++ b/tools/build_api_docs.py @@ -1,4 +1,4 @@ -# Copyright 2022 The TensorFlow Recommenders Authors. +# Copyright 2023 The TensorFlow Recommenders Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.