diff --git a/dev/articles/callbacks.html b/dev/articles/callbacks.html index 75a64039..274d8aea 100644 --- a/dev/articles/callbacks.html +++ b/dev/articles/callbacks.html @@ -225,7 +225,7 @@
torch
Primerinput = torch_randn(2, 3)
input
#> torch_tensor
-#> 1.4462 -0.4322 0.2945
-#> -1.4414 -1.0909 0.0804
+#> 0.9070 -2.7058 0.9525
+#> -0.6046 -0.8117 -0.4933
#> [ CPUFloatType{2,3} ]
A nn_module
is constructed from a
nn_module_generator
. nn_linear
is one of the
@@ -117,8 +117,8 @@
torch
Primeroutput = module_1(input)
output
#> torch_tensor
-#> -0.8440 0.2178 -1.0613 0.0279
-#> 0.3387 -0.6332 -0.3840 -0.1144
+#> 0.2788 1.2324 -0.4626 -0.5106
+#> 0.5439 0.4810 0.3413 -0.0922
#> [ CPUFloatType{2,4} ][ grad_fn = <AddmmBackward0> ]
A neural network with one (4-unit) hidden layer and two outputs needs the following ingredients
@@ -134,8 +134,8 @@torch
Primeroutput = softmax(output)
output
#> torch_tensor
-#> 0.2715 0.3477 0.3808
-#> 0.2549 0.3680 0.3771
+#> 0.5970 0.2588 0.1442
+#> 0.5811 0.2891 0.1298
#> [ CPUFloatType{2,3} ][ grad_fn = <SoftmaxBackward0> ]
We will now continue with showing how such a neural network can be
represented in mlr3torch
.
Note we only use the $train()
, since torch modules do
not have anything that maps to the state
(it is filled by
@@ -196,8 +196,8 @@
While this object allows to easily perform a forward pass, it does
not inherit from nn_module
, which is useful for various
@@ -245,8 +245,8 @@
graph_module(input)
#> torch_tensor
-#> 0.2715 0.3477 0.3808
-#> 0.2549 0.3680 0.3771
+#> 0.5970 0.2588 0.1442
+#> 0.5811 0.2891 0.1298
#> [ CPUFloatType{2,3} ][ grad_fn = <SoftmaxBackward0> ]
ModelDescriptor
to
small_module(batch$x[[1]])
#> torch_tensor
-#> -1.1461 1.7293 0.9483 -3.5494
-#> -0.9435 1.5987 0.9821 -3.2417
-#> -1.0713 1.5527 0.8862 -3.2914
+#> -2.7629 0.9494 -0.5337 -0.3909
+#> -2.4095 0.8402 -0.4640 -0.1927
+#> -2.4897 0.8274 -0.5014 -0.3388
#> [ CPUFloatType{3,4} ][ grad_fn = <AddmmBackward0> ]The first linear layer that takes “Sepal” input
("linear1"
) creates a 2x4 tensor (batch size 2, 4 units),
@@ -689,14 +689,14 @@
We observe that the po("nn_merge_cat")
concatenates
these, as expected:
The printed output of the data descriptor informs us about:
What happens during materialize(lt[1])
is the
following:
We see that the $graph
has a new pipeop with id
"poly.x"
and the output pointer
points to
poly.x
. Also we see that the shape of the tensor is now
diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml
index 572c2f11..5c8b5fb9 100644
--- a/dev/pkgdown.yml
+++ b/dev/pkgdown.yml
@@ -7,7 +7,7 @@ articles:
articles/internals_pipeop_torch: internals_pipeop_torch.html
articles/lazy_tensor: lazy_tensor.html
articles/pipeop_torch: pipeop_torch.html
-last_built: 2024-12-03T12:21Z
+last_built: 2024-12-06T17:46Z
urls:
reference: https://mlr3torch.mlr-org.com/reference
article: https://mlr3torch.mlr-org.com/articles
diff --git a/dev/reference/DataDescriptor.html b/dev/reference/DataDescriptor.html
index ccf8b71a..e43a2407 100644
--- a/dev/reference/DataDescriptor.html
+++ b/dev/reference/DataDescriptor.html
@@ -263,14 +263,14 @@
mlr_tasks_melanoma
+
+ mlr_tasks_mnist
lt1 = as_lazy_tensor(torch_randn(10, 3))
materialize(lt1, rbind = TRUE)
#> torch_tensor
-#> -0.3348 1.4210 0.8009
-#> 0.7746 0.5623 2.2623
-#> -0.1902 2.1175 -0.3915
-#> -0.7237 -0.1544 -0.2881
-#> -0.3098 -0.0992 -1.1412
-#> 0.7800 0.0201 -1.5458
-#> -0.2970 -1.7984 -0.4474
-#> 0.1641 -0.6251 -0.8492
-#> 0.6476 -0.5456 -0.1217
-#> -0.7156 -0.2956 0.4669
+#> -0.7162 -1.5608 -0.0387
+#> -1.7247 -1.4741 1.3326
+#> 0.4829 0.6899 0.9543
+#> -0.2733 0.1417 0.6729
+#> 0.4039 -0.1466 0.0637
+#> -0.0182 -0.4875 0.1285
+#> -0.2003 0.0778 -0.6773
+#> 0.1149 -1.0739 0.5195
+#> 1.2412 0.2692 -1.2110
+#> 1.0595 0.8234 -0.4103
#> [ CPUFloatType{10,3} ]
materialize(lt1, rbind = FALSE)
#> [[1]]
#> torch_tensor
-#> -0.3348
-#> 1.4210
-#> 0.8009
+#> -0.7162
+#> -1.5608
+#> -0.0387
#> [ CPUFloatType{3} ]
#>
#> [[2]]
#> torch_tensor
-#> 0.7746
-#> 0.5623
-#> 2.2623
+#> -1.7247
+#> -1.4741
+#> 1.3326
#> [ CPUFloatType{3} ]
#>
#> [[3]]
#> torch_tensor
-#> -0.1902
-#> 2.1175
-#> -0.3915
+#> 0.4829
+#> 0.6899
+#> 0.9543
#> [ CPUFloatType{3} ]
#>
#> [[4]]
#> torch_tensor
-#> -0.7237
-#> -0.1544
-#> -0.2881
+#> -0.2733
+#> 0.1417
+#> 0.6729
#> [ CPUFloatType{3} ]
#>
#> [[5]]
#> torch_tensor
-#> -0.3098
-#> -0.0992
-#> -1.1412
+#> 0.4039
+#> -0.1466
+#> 0.0637
#> [ CPUFloatType{3} ]
#>
#> [[6]]
#> torch_tensor
-#> 0.7800
-#> 0.0201
-#> -1.5458
+#> -0.0182
+#> -0.4875
+#> 0.1285
#> [ CPUFloatType{3} ]
#>
#> [[7]]
#> torch_tensor
-#> -0.2970
-#> -1.7984
-#> -0.4474
+#> -0.2003
+#> 0.0778
+#> -0.6773
#> [ CPUFloatType{3} ]
#>
#> [[8]]
#> torch_tensor
-#> 0.1641
-#> -0.6251
-#> -0.8492
+#> 0.1149
+#> -1.0739
+#> 0.5195
#> [ CPUFloatType{3} ]
#>
#> [[9]]
#> torch_tensor
-#> 0.6476
-#> -0.5456
-#> -0.1217
+#> 1.2412
+#> 0.2692
+#> -1.2110
#> [ CPUFloatType{3} ]
#>
#> [[10]]
#> torch_tensor
-#> -0.7156
-#> -0.2956
-#> 0.4669
+#> 1.0595
+#> 0.8234
+#> -0.4103
#> [ CPUFloatType{3} ]
#>
lt2 = as_lazy_tensor(torch_randn(10, 4))
@@ -219,184 +219,184 @@ Examplesmaterialize(d, rbind = TRUE)
#> $lt1
#> torch_tensor
-#> -0.3348 1.4210 0.8009
-#> 0.7746 0.5623 2.2623
-#> -0.1902 2.1175 -0.3915
-#> -0.7237 -0.1544 -0.2881
-#> -0.3098 -0.0992 -1.1412
-#> 0.7800 0.0201 -1.5458
-#> -0.2970 -1.7984 -0.4474
-#> 0.1641 -0.6251 -0.8492
-#> 0.6476 -0.5456 -0.1217
-#> -0.7156 -0.2956 0.4669
+#> -0.7162 -1.5608 -0.0387
+#> -1.7247 -1.4741 1.3326
+#> 0.4829 0.6899 0.9543
+#> -0.2733 0.1417 0.6729
+#> 0.4039 -0.1466 0.0637
+#> -0.0182 -0.4875 0.1285
+#> -0.2003 0.0778 -0.6773
+#> 0.1149 -1.0739 0.5195
+#> 1.2412 0.2692 -1.2110
+#> 1.0595 0.8234 -0.4103
#> [ CPUFloatType{10,3} ]
#>
#> $lt2
#> torch_tensor
-#> 0.2774 1.3915 0.8820 1.9193
-#> -0.3799 0.8260 -1.3040 -0.1960
-#> -0.3386 -0.2669 -0.5234 -1.0550
-#> 1.2111 0.3119 0.7306 -1.6741
-#> 1.5288 0.6568 0.2191 -0.1331
-#> 0.2411 0.1115 0.4595 -0.3194
-#> 1.9619 -0.2382 -0.1638 -1.4965
-#> 0.1152 -1.3747 0.1618 1.2559
-#> -0.5370 1.3188 -0.6477 -1.6232
-#> 1.5394 0.6299 -1.1973 -1.3131
+#> 0.3112 2.5506 -0.6576 -1.2956
+#> -0.3208 -0.4852 -0.1543 -0.8971
+#> 0.8473 0.4315 -0.5415 1.6736
+#> 0.8951 -1.0780 0.0980 -2.4735
+#> 0.2695 -0.4690 0.5026 1.1351
+#> 0.2739 1.1301 0.6285 0.0885
+#> -0.9818 -0.1536 0.7535 1.0964
+#> -1.2323 1.3288 -0.0503 -1.1760
+#> 1.4108 -1.3069 0.1260 -0.0153
+#> 0.1052 0.9547 0.1382 0.8248
#> [ CPUFloatType{10,4} ]
#>
materialize(d, rbind = FALSE)
#> $lt1
#> $lt1[[1]]
#> torch_tensor
-#> -0.3348
-#> 1.4210
-#> 0.8009
+#> -0.7162
+#> -1.5608
+#> -0.0387
#> [ CPUFloatType{3} ]
#>
#> $lt1[[2]]
#> torch_tensor
-#> 0.7746
-#> 0.5623
-#> 2.2623
+#> -1.7247
+#> -1.4741
+#> 1.3326
#> [ CPUFloatType{3} ]
#>
#> $lt1[[3]]
#> torch_tensor
-#> -0.1902
-#> 2.1175
-#> -0.3915
+#> 0.4829
+#> 0.6899
+#> 0.9543
#> [ CPUFloatType{3} ]
#>
#> $lt1[[4]]
#> torch_tensor
-#> -0.7237
-#> -0.1544
-#> -0.2881
+#> -0.2733
+#> 0.1417
+#> 0.6729
#> [ CPUFloatType{3} ]
#>
#> $lt1[[5]]
#> torch_tensor
-#> -0.3098
-#> -0.0992
-#> -1.1412
+#> 0.4039
+#> -0.1466
+#> 0.0637
#> [ CPUFloatType{3} ]
#>
#> $lt1[[6]]
#> torch_tensor
-#> 0.7800
-#> 0.0201
-#> -1.5458
+#> -0.0182
+#> -0.4875
+#> 0.1285
#> [ CPUFloatType{3} ]
#>
#> $lt1[[7]]
#> torch_tensor
-#> -0.2970
-#> -1.7984
-#> -0.4474
+#> -0.2003
+#> 0.0778
+#> -0.6773
#> [ CPUFloatType{3} ]
#>
#> $lt1[[8]]
#> torch_tensor
-#> 0.1641
-#> -0.6251
-#> -0.8492
+#> 0.1149
+#> -1.0739
+#> 0.5195
#> [ CPUFloatType{3} ]
#>
#> $lt1[[9]]
#> torch_tensor
-#> 0.6476
-#> -0.5456
-#> -0.1217
+#> 1.2412
+#> 0.2692
+#> -1.2110
#> [ CPUFloatType{3} ]
#>
#> $lt1[[10]]
#> torch_tensor
-#> -0.7156
-#> -0.2956
-#> 0.4669
+#> 1.0595
+#> 0.8234
+#> -0.4103
#> [ CPUFloatType{3} ]
#>
#>
#> $lt2
#> $lt2[[1]]
#> torch_tensor
-#> 0.2774
-#> 1.3915
-#> 0.8820
-#> 1.9193
+#> 0.3112
+#> 2.5506
+#> -0.6576
+#> -1.2956
#> [ CPUFloatType{4} ]
#>
#> $lt2[[2]]
#> torch_tensor
-#> -0.3799
-#> 0.8260
-#> -1.3040
-#> -0.1960
+#> -0.3208
+#> -0.4852
+#> -0.1543
+#> -0.8971
#> [ CPUFloatType{4} ]
#>
#> $lt2[[3]]
#> torch_tensor
-#> -0.3386
-#> -0.2669
-#> -0.5234
-#> -1.0550
+#> 0.8473
+#> 0.4315
+#> -0.5415
+#> 1.6736
#> [ CPUFloatType{4} ]
#>
#> $lt2[[4]]
#> torch_tensor
-#> 1.2111
-#> 0.3119
-#> 0.7306
-#> -1.6741
+#> 0.8951
+#> -1.0780
+#> 0.0980
+#> -2.4735
#> [ CPUFloatType{4} ]
#>
#> $lt2[[5]]
#> torch_tensor
-#> 1.5288
-#> 0.6568
-#> 0.2191
-#> -0.1331
+#> 0.2695
+#> -0.4690
+#> 0.5026
+#> 1.1351
#> [ CPUFloatType{4} ]
#>
#> $lt2[[6]]
#> torch_tensor
-#> 0.2411
-#> 0.1115
-#> 0.4595
-#> -0.3194
+#> 0.2739
+#> 1.1301
+#> 0.6285
+#> 0.0885
#> [ CPUFloatType{4} ]
#>
#> $lt2[[7]]
#> torch_tensor
-#> 1.9619
-#> -0.2382
-#> -0.1638
-#> -1.4965
+#> -0.9818
+#> -0.1536
+#> 0.7535
+#> 1.0964
#> [ CPUFloatType{4} ]
#>
#> $lt2[[8]]
#> torch_tensor
-#> 0.1152
-#> -1.3747
-#> 0.1618
-#> 1.2559
+#> -1.2323
+#> 1.3288
+#> -0.0503
+#> -1.1760
#> [ CPUFloatType{4} ]
#>
#> $lt2[[9]]
#> torch_tensor
-#> -0.5370
-#> 1.3188
-#> -0.6477
-#> -1.6232
+#> 1.4108
+#> -1.3069
+#> 0.1260
+#> -0.0153
#> [ CPUFloatType{4} ]
#>
#> $lt2[[10]]
#> torch_tensor
-#> 1.5394
-#> 0.6299
-#> -1.1973
-#> -1.3131
+#> 0.1052
+#> 0.9547
+#> 0.1382
+#> 0.8248
#> [ CPUFloatType{4} ]
#>
#>
diff --git a/dev/reference/mlr_learners_torch_model.html b/dev/reference/mlr_learners_torch_model.html
index 7291dd12..ce5f0ecf 100644
--- a/dev/reference/mlr_learners_torch_model.html
+++ b/dev/reference/mlr_learners_torch_model.html
@@ -243,14 +243,14 @@ Exampleslearner$train(task, ids$train)
learner$predict(task, ids$test)
#> <PredictionClassif> for 50 observations:
-#> row_ids truth response
-#> 3 setosa setosa
-#> 9 setosa setosa
-#> 10 setosa setosa
-#> --- --- ---
-#> 147 virginica setosa
-#> 149 virginica setosa
-#> 150 virginica setosa
+#> row_ids truth response
+#> 3 setosa virginica
+#> 9 setosa virginica
+#> 10 setosa virginica
+#> --- --- ---
+#> 147 virginica virginica
+#> 149 virginica virginica
+#> 150 virginica virginica