Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Depends:
R (>= 3.5.0)
Imports:
backports,
cli,
checkmate (>= 2.2.0),
data.table,
lgr,
Expand Down
8 changes: 5 additions & 3 deletions R/LearnerTorch.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ LearnerTorch = R6Class("LearnerTorch",
#' Currently unused.
print = function(...) {
super$print(...)
catn(str_indent("* Optimizer:", private$.optimizer$id))
catn(str_indent("* Loss:", private$.loss$id))
catn(str_indent("* Callbacks:", if (length(private$.callbacks)) as_short_string(paste0(ids(private$.callbacks), collapse = ","), 1000L) else "-"))
mlr3misc::cat_cli({
cli::cli_li("Optimizer: {private$.optimizer$id}")
cli::cli_li("Loss: {private$.loss$id}")
cli::cli_li(paste0("Callbacks: ", if (length(private$.callbacks)) as_short_string(paste0(ids(private$.callbacks), collapse = ","), 1000L) else "-"))
})
},
#' @description
#' Marshal the learner.
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/_snaps/LearnerTorch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# printer

Code
lrn("classif.mlp", callbacks = list(t_clbk("history"), t_clbk("progress")))
Output

-- <LearnerTorchMLP> (classif.mlp): Multi Layer Perceptron ---------------------
* Model: -
* Parameters: device=auto, num_threads=1, num_interop_threads=1, seed=random,
eval_freq=1, measures_train=<list>, measures_valid=<list>, patience=0,
min_delta=0, shuffle=TRUE, tensor_dataset=FALSE, jit_trace=FALSE,
neurons=integer(0), p=0.5, activation=<nn_relu>, activation_args=<list>
* Validate: NULL
* Packages: mlr3, mlr3torch, torch, and progress
* Predict Types: [response] and prob
* Feature Types: integer, numeric, and lazy_tensor
* Encapsulation: none (fallback: -)
* Properties: internal_tuning, marshal, multiclass, twoclass, and validation
* Other settings: use_weights = 'error'
* Optimizer: adam
* Loss: cross_entropy
* Callbacks: history,progress

5 changes: 5 additions & 0 deletions tests/testthat/test_LearnerTorch.R
Original file line number Diff line number Diff line change
Expand Up @@ -1042,3 +1042,8 @@ test_that("NA prediction during validation does not cause issues.", {
is.na(learner$model$callbacks$history$valid.regr.mse[1L]),
)
})

test_that("printer", {
expect_snapshot(lrn("classif.mlp",
callbacks = list(t_clbk("history"), t_clbk("progress"))))
})
Loading