Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tensorflow_recommenders/layers/factorized_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(self,
self._num_parallel_calls = num_parallel_calls
self._sorted = sorted_order

self._counter = self.add_weight("counter", dtype=tf.int32, trainable=False)
self._counter = self.add_weight(name="counter", dtype=tf.int32, trainable=False)

def index_from_dataset(
self,
Expand Down Expand Up @@ -466,7 +466,7 @@ def top_k(state: Tuple[tf.Tensor, tf.Tensor],
def enumerate_rows(batch: tf.Tensor) -> Tuple[tf.Tensor, tf.Tensor]:
"""Enumerates rows in each batch using a total element counter."""

starting_counter = self._counter.read_value()
starting_counter = self._counter.value
end_counter = self._counter.assign_add(tf.shape(batch)[0])

return tf.range(starting_counter, end_counter), batch
Expand Down Expand Up @@ -545,7 +545,7 @@ def index(
)

# We need any value that has the correct dtype.
identifiers_initial_value = tf.zeros((), dtype=identifiers.dtype)
identifiers_initial_value = tf.zeros(identifiers.shape, dtype=identifiers.dtype)

self._identifiers = self.add_weight(
name="identifiers",
Expand Down
6 changes: 4 additions & 2 deletions tensorflow_recommenders/metrics/factorized_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def update_state(
tf.reduce_sum(ids_match[:, :k], axis=1, keepdims=True),
0.0, 1.0
)
update_ops.append(metric.update_state(match_found, sample_weight))
metric.update_state(match_found, sample_weight)
update_ops.append(metric.result())
else:
# Score-based evaluation.
y_pred = tf.concat([positive_scores, top_k_predictions], axis=1)
Expand All @@ -189,7 +190,8 @@ def update_state(
predictions=y_pred,
k=k
)
update_ops.append(metric.update_state(top_k_accuracy, sample_weight))
metric.update_state(top_k_accuracy, sample_weight)
update_ops.append(metric.result())

return tf.group(update_ops)