get_target_batchgetter: Target Batchgetter for a Task

View source: R/task_dataset.R

get_target_batchgetterR Documentation

Target Batchgetter for a Task

Description

Returns the function that converts the target column(s) of a task into the target tensor y of a batch, i.e. the tensor that the loss is applied to. The returned function takes an argument data, a data.table containing only the target column(s), and returns a torch_tensor. It is NULL for a task with no target at all, whose batches have no y element and whose loss is called as loss(y_hat).

For the target encodings of the built-in task types, see section Network Head and Target Encoding of LearnerTorch.

When adding support for a custom task type, implement a method for the corresponding Task class.

Usage

get_target_batchgetter(task, ...)

Arguments

task

(Task)
The task.

...

(any)
Additional arguments. Not used yet.

Value

⁠function(data)⁠, ⁠function(data, x)⁠, or NULL for a task with no target

Examples


batchgetter = get_target_batchgetter(tsk("iris"))
batchgetter(data.table::data.table(Species = factor(c("setosa", "virginica"))))


mlr3torch documentation built on Oct. 30, 2026, 5:10 p.m.