Converts a Graph representing a deep learning pipeline into a
GraphLearnerTorch.
The advantage over using as_learner() is that the resulting learner exposes methods like
$dataset() and fields like $network.
Usage
as_learner_torch(x, ...)
# S3 method for class 'Graph'
as_learner_torch(x, id = NULL, ...)
# S3 method for class 'PipeOp'
as_learner_torch(x, ...)
# S3 method for class 'GraphLearner'
as_learner_torch(x, id = x$id, ...)Arguments
- x
(any)
The object to convert, e.g. aGraph.- ...
(any)
Unused.- id
(
character(1))
The id of the learner. Defaults to"<task_type>.graph".
See also
Other Graph Network:
ModelDescriptor(),
TorchIngressToken(),
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(),
pipeop_torch()
Other Learner:
GraphLearnerTorch,
mlr_learners.ft_transformer,
mlr_learners.mlp,
mlr_learners.module,
mlr_learners.tab_resnet,
mlr_learners.tabm,
mlr_learners.torch_featureless,
mlr_learners_torch,
mlr_learners_torch_image,
mlr_learners_torch_model
Examples
graph = po("scale") %>>%
po("torch_ingress_num") %>>%
nn("linear", out_features = 10) %>>%
nn("relu") %>>%
nn("head") %>>%
po("torch_loss", "cross_entropy") %>>%
po("torch_optimizer", "adam", lr = 0.1) %>>%
po("torch_model_classif", epochs = 1, batch_size = 32)
learner = as_learner_torch(graph)
learner$id
#> [1] "classif.graph"
learner$param_set$set_values(linear.out_features = 20, torch_optimizer.lr = 0.01)
task = tsk("iris")
learner$train(task)
learner$network
#> An `nn_module` containing 163 parameters.
#>
#> ── Modules ─────────────────────────────────────────────────────────────────────
#> • module_list: <nn_module_list> #163 parameters
learner$predict(task)
#>
#> ── <PredictionClassif> for 150 observations: ───────────────────────────────────
#> row_ids truth response
#> 1 setosa setosa
#> 2 setosa setosa
#> 3 setosa setosa
#> --- --- ---
#> 148 virginica virginica
#> 149 virginica virginica
#> 150 virginica virginica
learner$dataset(task, "train")
#> <task_dataset>
#> Inherits from: <dataset>
#> Public:
#> .getbatch: function (index)
#> .getitem: function (index)
#> .length: function ()
#> all_features: Petal.Length Petal.Width Sepal.Length Sepal.Width Species
#> batch_constructor: function (data, cache = NULL)
#> cache_lazy_tensors: FALSE
#> clone: function (deep = FALSE)
#> feature_ingress_tokens: list
#> initialize: function (task, feature_ingress_tokens, target_batchgetter = NULL)
#> load_state_dict: function (x, ..., .refer_to_state_dict = FALSE)
#> state_dict: function ()
#> target_batchgetter: function (data)
#> task: TaskClassif, TaskSupervised, Task, R6