Skip to content
Closed
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
10 changes: 9 additions & 1 deletion merlin/models/tf/core/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
TensorLike = Union[tf.Tensor, tf.SparseTensor, tf.RaggedTensor]


class Features:
def __init__(self, values: Dict[str, TensorLike]):
self.values = values

def __getitem__(self, key: str) -> TensorLike:
return self.values[key]


class PredictionContext(NamedTuple):
features: Dict[str, TensorLike]
features: Features
targets: Optional[Union[tf.Tensor, Dict[str, tf.Tensor]]] = None
mask: tf.Tensor = (None,)
training: bool = False
Expand Down
6 changes: 4 additions & 2 deletions merlin/models/tf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import merlin.io
from merlin.models.tf.core.base import Block, ModelContext, PredictionOutput, is_input_block
from merlin.models.tf.core.combinators import SequentialBlock
from merlin.models.tf.core.prediction import Prediction, PredictionContext
from merlin.models.tf.core.prediction import Features, Prediction, PredictionContext
from merlin.models.tf.core.tabular import TabularBlock
from merlin.models.tf.core.transformations import AsDenseFeatures, AsRaggedFeatures
from merlin.models.tf.dataset import BatchedDataset
Expand Down Expand Up @@ -730,7 +730,9 @@ def call(self, inputs, targets=None, training=False, testing=False, output_conte
def _create_context(
self, inputs, targets=None, training=False, testing=False
) -> PredictionContext:
context = PredictionContext(inputs, targets=targets, training=training, testing=testing)
context = PredictionContext(
Features(inputs), targets=targets, training=training, testing=testing
)

return context

Expand Down