Returns the function that builds a whole batch of a task, i.e. both the features x and the
target y.
This is how task_dataset loads its batches.
The returned function takes the arguments
data, adata.tablewith the feature and target columns of the batch, andcache, a rather internalhashtabthat can be used as a cache when loading multiplelazy_tensorcolumns.
It returns a list() with elements x (a named list() of
torch_tensors) and y (a torch_tensor or
NULL).
The default method applies the ingress tokens to obtain x and the target batchgetter to obtain
y.
Arguments
- task
(
Task)
The task.- feature_ingress_tokens
(named
list()ofTorchIngressToken)
The ingress tokens that definex. Their features are already resolved, i.e. they arecharacter()vectors and notSelectors.- target_batchgetter
(
function()orNULL)
Converts the target columns of a batch into the target tensorythat the loss is applied to. Takes an argumentdata, adata.tablewith only the target columns, and optionally an argumentx, the named list of feature tensors of the batch, which is what a target that is a function of the input needs, seeget_target_batchgetter(). IfNULL(default), the batches have noyelement.- ...
(any)
Additional arguments. Not used yet.
Examples
task = tsk("iris")
token = TorchIngressToken(task$feature_names, batchgetter_num, c(NA, 4))
# the token's features are a `Selector`; `task_dataset()` resolves them for you
token$features = token$features(task)
batch_constructor = get_batch_constructor(
task,
feature_ingress_tokens = list(input = token),
target_batchgetter = get_target_batchgetter(task)
)
batch = batch_constructor(data = task$data(rows = 1:2))
batch$x$input
#> torch_tensor
#> 1.4000 0.2000 5.1000 3.5000
#> 1.4000 0.2000 4.9000 3.0000
#> [ CPUFloatType{2,4} ]
batch$y
#> torch_tensor
#> 1
#> 1
#> [ CPULongType{2} ]