A general-purpose Task that can be used for modeling arbitrary problems, including
supervised and unsupervised problems.
The article on Custom Learning Problems covers all of this in more detail.
The problem this generic task solves is that it is rather complicated to register new task
types with mlr3, so this class makes this easier.
The price of this flexibility is the loss of some compatibility checks.
Super class
mlr3::Task -> TaskTorch
Active bindings
hash(
character(1))
The hash of the task.default_encoder(
function()orNULL)
The default prediction encoder. Read-only.default_measure(
MeasureorNULL)
See the construction argument. Read-only, for the same reason asdefault_encoder.output_dim(
function()orNULL)
See the construction argument. Called byoutput_dim_for().
Methods
Inherited methods
mlr3::Task$add_strata()mlr3::Task$cbind()mlr3::Task$data()mlr3::Task$divide()mlr3::Task$droplevels()mlr3::Task$filter()mlr3::Task$format()mlr3::Task$formula()mlr3::Task$head()mlr3::Task$help()mlr3::Task$levels()mlr3::Task$materialize_view()mlr3::Task$missings()mlr3::Task$print()mlr3::Task$rbind()mlr3::Task$rename()mlr3::Task$select()mlr3::Task$set_col_roles()mlr3::Task$set_levels()mlr3::Task$set_row_roles()
TaskTorch$new()
Creates a new instance of this R6 class.
Usage
TaskTorch$new(
id,
backend,
target = NULL,
label = NA_character_,
output_dim = NULL,
default_encoder = NULL,
default_measure = NULL
)Arguments
id(
character(1))
The id of the task.backend(
DataBackendordata.frame())
The data.target(
character()orNULL)
The names of the target columns.NULL(default) for a task without a target, see section Tasks without a Target ofTaskTorch.label(
character(1))
The label of the task.output_dim(
function()orNULL)
Returns the number of output units the network needs. Takes an argumenttaskand returns a single positive integer. May beNULL(default), in which case any caller ofoutput_dim_for()errors.default_encoder(
function()orNULL)
The default prediction encoder for the task. This can be overwritten by a learner's private$.encode_predictionmethod. SeeLearnerTorchfor more information.default_measure(
MeasureorNULL)
The default measure of the task, i.e. whatmsr("torch.default")resolves to.
TaskTorch$truth()
The ground truth, see section Scoring.
Might return NULL for unsupervised problems.
Arguments
rows(
integer())
The rows to return the truth for. All rows ifNULL.
Examples
# multi-label classification: one logical column per label
d = data.frame(x1 = rnorm(50), x2 = rnorm(50))
d$a = d$x1 > 0
d$b = d$x2 > 0
task = as_task_torch(d, target = c("a", "b"), id = "labels",
output_dim = function(task) length(task$target_names),
default_encoder = function(task, network_output, predict_type) {
prob = as.matrix(torch::nnf_sigmoid(network_output)$cpu())
colnames(prob) = task$target_names
list(response = prob > 0.5, prob = if (predict_type == "prob") prob)
})
task
#>
#> ── <TaskTorch> (50x4) ──────────────────────────────────────────────────────────
#> • Target: a and b
#> • Properties: -
#> • Features (2):
#> • dbl (2): x1, x2
output_dim_for(task)