TorchIngressToken: Torch Ingress Token

View source: R/PipeOpTorchIngress.R

TorchIngressTokenR Documentation

Torch Ingress Token

Description

This function creates an S3 class of class "TorchIngressToken", which is an internal data structure. It contains the (meta-)information of how a batch is generated from a Task and fed into an entry point of the neural network. It is stored as the ingress field in a ModelDescriptor.

Usage

TorchIngressToken(features, batchgetter, shape = NULL)

Arguments

features

(character or mlr3pipelines::Selector)
Features on which the batchgetter will operate or a selector (such as mlr3pipelines::selector_type).

batchgetter

(function)
Function with two arguments: data and device. This function is given the output of Task$data(rows = batch_indices, cols = features) and it should produce a tensor of shape shape_out.

shape

(integer)
Shape that batchgetter will produce. Batch dimension must be included as NA (but other dimensions can also be NA, i.e., unknown).

Value

TorchIngressToken object.

See Also

Other Graph Network: ModelDescriptor(), mlr_learners_torch_model, mlr_pipeops_module, mlr_pipeops_torch, mlr_pipeops_torch_ingress, mlr_pipeops_torch_ingress_categ, mlr_pipeops_torch_ingress_ltnsr, mlr_pipeops_torch_ingress_num, model_descriptor_to_learner(), model_descriptor_to_module(), model_descriptor_union(), nn_graph()

Examples


# Define a task for which we want to define an ingress token
task = tsk("iris")

# We create an ingress token for two feature Sepal.Length and Petal.Length:
# We have to specify the features, the batchgetter and the shape
features = c("Sepal.Length", "Petal.Length")
# As a batchgetter we use batchgetter_num

batch_dt = task$data(rows = 1:10, cols =features)
batch_dt
batch_tensor = batchgetter_num(batch_dt, "cpu")
batch_tensor

# The shape is unknown in the first dimension (batch dimension)

ingress_token = TorchIngressToken(
  features = features,
  batchgetter = batchgetter_num,
  shape = c(NA, 2)
)
ingress_token


mlr3torch documentation built on Aug. 26, 2025, 5:09 p.m.