Skip to content
Open
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_recommenders/examples/movielens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -65,14 +65,14 @@ def evaluate(user_model: tf.keras.Model,

movie_embeddings = np.concatenate(
list(movies.batch(4096).map(
lambda x: movie_model({"movie_id": x["movie_id"]})
lambda x: movie_model({"movie_id": x["movie_id"]}) # pyrefly: ignore[not-callable]
).as_numpy_iterator()))

precision_values = []
recall_values = []

for user_id, test_movies in test_user_to_movies.items():
user_embedding = user_model({"user_id": np.array([user_id])}).numpy()
user_embedding = user_model({"user_id": np.array([user_id])}).numpy() # pyrefly: ignore[not-callable]
scores = (user_embedding @ movie_embeddings.T).flatten()

test_movies = np.frombuffer(test_movies, dtype=np.int32)
Expand Down Expand Up @@ -189,4 +189,4 @@ def sample_listwise(
tensor_slices["movie_title"].append(sampled_movie_titles)
tensor_slices["user_rating"].append(sampled_ratings)

return tf.data.Dataset.from_tensor_slices(tensor_slices)
return tf.data.Dataset.from_tensor_slices(tensor_slices) # pyrefly: ignore[bad-argument-type]
2 changes: 1 addition & 1 deletion tensorflow_recommenders/examples/nbtool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/experimental/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/experimental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
12 changes: 6 additions & 6 deletions tensorflow_recommenders/experimental/models/ranking.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -192,7 +192,7 @@ def compute_loss(self,
"Got a length {len(inputs)} tuple instead: {inputs}."
)

outputs = self(features, training=training)
outputs = self(features, training=training) # pyrefly: ignore[not-callable]

loss = self._task(labels, outputs, sample_weight=sample_weight)
loss = tf.reduce_mean(loss)
Expand All @@ -212,26 +212,26 @@ def call(self, inputs: Dict[str, tf.Tensor]) -> tf.Tensor:
dense_features = inputs["dense_features"]
sparse_features = inputs["sparse_features"]

sparse_embeddings = self._embedding_layer(sparse_features)
sparse_embeddings = self._embedding_layer(sparse_features) # pyrefly: ignore[not-callable]
# Combine a dictionary into a vector and squeeze dimension from
# (batch_size, 1, emb) to (batch_size, emb).
sparse_embeddings = tf.nest.flatten(sparse_embeddings)

sparse_embedding_vecs = [
tf.squeeze(sparse_embedding) for sparse_embedding in sparse_embeddings
]
dense_embedding_vec = self._bottom_stack(dense_features)
dense_embedding_vec = self._bottom_stack(dense_features) # pyrefly: ignore[not-callable]

interaction_args = sparse_embedding_vecs + [dense_embedding_vec]
interaction_output = self._feature_interaction(interaction_args)
interaction_output = self._feature_interaction(interaction_args) # pyrefly: ignore[not-callable]
if self._concat_dense:
feature_interaction_output = tf.concat(
[dense_embedding_vec, interaction_output], axis=1
)
else:
feature_interaction_output = interaction_output

prediction = self._top_stack(feature_interaction_output)
prediction = self._top_stack(feature_interaction_output) # pyrefly: ignore[not-callable]

return tf.reshape(prediction, [-1])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -175,7 +175,7 @@ def build(self, var_list: Sequence[tf.Variable]) -> None:
self.add_variable_from_reference(
var,
"accumulator",
initial_value=initializer(shape=var.shape, dtype=var.dtype),
initial_value=initializer(shape=var.shape, dtype=var.dtype), # pyrefly: ignore[not-callable]
))
if self.export_clipping_factors:
self.clipping_factors.append(
Expand Down Expand Up @@ -220,7 +220,7 @@ def update_step(self, grad: Union[tf.Tensor, tf.IndexedSlices],
delta = lr * grad_values * precondition
clipped_delta, clipping_factor = shrink_by_references(
delta,
references=[variable_values, precondition],
references=[variable_values, precondition], # pyrefly: ignore[bad-argument-type]
relative_factors=[
self.variable_relative_threshold,
self.accumulator_relative_threshold
Expand All @@ -235,7 +235,7 @@ def update_step(self, grad: Union[tf.Tensor, tf.IndexedSlices],
# Clip the accumulator update: this acts like clipping the gradient
# before sending it to the optimizer. This is a good option when the
# gradient is an outlier.
accumulator_update = grad_values * clipping_factor
accumulator_update = grad_values * clipping_factor # pyrefly: ignore[unsupported-operation]
else:
# Does not clip the accumulator update: This is a good option in cases
# where the gradient increases during training, and allows for quicker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/layers/blocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_recommenders/layers/embedding/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
16 changes: 8 additions & 8 deletions tensorflow_recommenders/layers/factorized_top_k.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -215,7 +215,7 @@ def index_from_dataset(self, candidates: tf.data.Dataset) -> "TopK":
return self.index(candidates, identifiers)

@abc.abstractmethod
def call(
def call( # pyrefly: ignore[bad-override]
self,
queries: Union[tf.Tensor, Dict[Text, tf.Tensor]],
k: Optional[int] = None,
Expand Down Expand Up @@ -284,7 +284,7 @@ def query_with_exclusions(
k = k if k is not None else self._k

adjusted_k = k + exclusions.shape[1]
x, y = self(queries=queries, k=adjusted_k)
x, y = self(queries=queries, k=adjusted_k) # pyrefly: ignore[not-callable]
return _exclude(x, y, exclude=exclusions, k=k)

@abc.abstractmethod
Expand Down Expand Up @@ -416,7 +416,7 @@ def call(
)

if self.query_model is not None:
queries = self.query_model(queries)
queries = self.query_model(queries) # pyrefly: ignore[not-callable]

# Reset the element counter.
self._counter.assign(0)
Expand All @@ -426,7 +426,7 @@ def top_scores(
) -> Tuple[tf.Tensor, tf.Tensor]:
"""Computes top scores and indices for a batch of candidates."""

scores = self._compute_score(queries, candidate_batch)
scores = self._compute_score(queries, candidate_batch) # pyrefly: ignore[bad-argument-type]

if self._handle_incomplete_batches:
k_ = tf.math.minimum(k, tf.shape(scores)[1])
Expand Down Expand Up @@ -598,9 +598,9 @@ def call(
)

if self.query_model is not None:
queries = self.query_model(queries)
queries = self.query_model(queries) # pyrefly: ignore[not-callable]

scores = self._compute_score(queries, self._candidates)
scores = self._compute_score(queries, self._candidates) # pyrefly: ignore[bad-argument-type]

values, indices = tf.math.top_k(scores, k=k)

Expand Down Expand Up @@ -764,7 +764,7 @@ def call(
searcher = scann_ops.searcher_from_module(self._serialized_searcher)

if self.query_model is not None:
queries = self.query_model(queries)
queries = self.query_model(queries) # pyrefly: ignore[not-callable]

if not isinstance(queries, tf.Tensor):
raise ValueError(f"Queries must be a tensor, got {type(queries)}.")
Expand Down
22 changes: 11 additions & 11 deletions tensorflow_recommenders/layers/factorized_top_k_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -80,7 +80,7 @@ def run_save_and_restore_test(self, layer, query, num):
for _ in range(num):
post_serialization_results = restored(tf.constant(query))

self.assertAllEqual(post_serialization_results, pre_serialization_results)
self.assertAllEqual(post_serialization_results, pre_serialization_results) # pyrefly: ignore[unbound-name]

def run_top_k_test(self,
layer_class,
Expand Down Expand Up @@ -121,13 +121,13 @@ def run_top_k_test(self,
expected_top_scores = np.take_along_axis(scores, indices, 1)
expected_top_indices = candidate_indices[indices]

candidates = tf.data.Dataset.from_tensor_slices(candidates).batch(
candidates = tf.data.Dataset.from_tensor_slices(candidates).batch( # pyrefly: ignore[bad-argument-type]
batch_size)

if indices_dtype is not None:
identifiers = tf.data.Dataset.from_tensor_slices(candidate_indices).batch(
identifiers = tf.data.Dataset.from_tensor_slices(candidate_indices).batch( # pyrefly: ignore[bad-argument-type]
batch_size)
candidates = tf.data.Dataset.zip((identifiers, candidates))
candidates = tf.data.Dataset.zip((identifiers, candidates)) # pyrefly: ignore[bad-argument-type]

# Call twice to ensure the results are repeatable.
for _ in range(2):
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_scann_dataset_arg_no_identifiers(self):

rng = np.random.RandomState(42)
candidates = tf.data.Dataset.from_tensor_slices(
rng.normal(size=(num_candidates, 4)).astype(np.float32))
rng.normal(size=(num_candidates, 4)).astype(np.float32)) # pyrefly: ignore[bad-argument-type]
query = rng.normal(size=(num_queries, 4)).astype(np.float32)

scann = factorized_top_k.ScaNN()
Expand All @@ -217,9 +217,9 @@ def test_scann_dataset_arg_with_identifiers(self):

rng = np.random.RandomState(42)
candidates = tf.data.Dataset.from_tensor_slices(
rng.normal(size=(num_candidates, 4)).astype(np.float32))
rng.normal(size=(num_candidates, 4)).astype(np.float32)) # pyrefly: ignore[bad-argument-type]
query = rng.normal(size=(num_queries, 4)).astype(np.float32)
identifiers = tf.data.Dataset.from_tensor_slices(np.arange(num_candidates))
identifiers = tf.data.Dataset.from_tensor_slices(np.arange(num_candidates)) # pyrefly: ignore[bad-argument-type]

index = factorized_top_k.ScaNN()
index.index_from_dataset(identifiers.zip(candidates).batch(100))
Expand All @@ -232,14 +232,14 @@ def test_raise_on_incorrect_input_shape(

num_candidates = 100
candidates = tf.data.Dataset.from_tensor_slices(
np.random.normal(size=(num_candidates, 4)).astype(np.float32))
np.random.normal(size=(num_candidates, 4)).astype(np.float32)) # pyrefly: ignore[bad-argument-type]
identifiers = tf.data.Dataset.from_tensor_slices(
np.arange(num_candidates - 1))
np.arange(num_candidates - 1)) # pyrefly: ignore[bad-argument-type]

with self.assertRaises(ValueError):
index = layer_class()
index.index_from_dataset(
tf.data.Dataset.zip((identifiers.batch(20), candidates.batch(100)))
tf.data.Dataset.zip((identifiers.batch(20), candidates.batch(100))) # pyrefly: ignore[bad-argument-type]
)

@parameterized.parameters(test_cases())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_recommenders/layers/feature_interaction/dcn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down Expand Up @@ -174,14 +174,14 @@ def call(self, x0: tf.Tensor, x: Optional[tf.Tensor] = None) -> tf.Tensor:
x0.shape[-1], x.shape[-1]))

if self._projection_dim is None:
prod_output = self._dense(x)
prod_output = self._dense(x) # pyrefly: ignore[not-callable]
else:
prod_output = self._dense_v(self._dense_u(x))
prod_output = self._dense_v(self._dense_u(x)) # pyrefly: ignore[not-callable]

prod_output = tf.cast(prod_output, self.compute_dtype)

if self._diag_scale:
prod_output = prod_output + self._diag_scale * x
prod_output = prod_output + self._diag_scale * x # pyrefly: ignore[unsupported-operation]

return x0 * prod_output + x

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 The TensorFlow Recommenders Authors.
# Copyright 2026 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.
Expand Down
Loading
Loading