diff --git a/dev/articles/callbacks.html b/dev/articles/callbacks.html index e9f6a059..9fd157cb 100644 --- a/dev/articles/callbacks.html +++ b/dev/articles/callbacks.html @@ -225,7 +225,7 @@
torch
Primerinput = torch_randn(2, 3)
input
#> torch_tensor
-#> -0.0922 -0.7069 -0.6839
-#> -0.8342 0.7515 0.0459
+#> -0.6687 -2.4004 -1.4578
+#> 0.9376 -0.9994 -0.3993
#> [ 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.1557 0.3401 -0.2068 -1.1674
-#> -0.5995 0.2244 -0.2694 -0.1591
+#> 0.0980 0.3119 -1.4607 -0.4350
+#> 0.2679 0.8104 0.1816 0.0485
#> [ 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.2584 0.2372 0.5043
-#> 0.2826 0.2323 0.4850
+#> 0.2918 0.1502 0.5579
+#> 0.2890 0.1217 0.5893
#> [ 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.2584 0.2372 0.5043
-#> 0.2826 0.2323 0.4850
+#> 0.2918 0.1502 0.5579
+#> 0.2890 0.1217 0.5893
#> [ CPUFloatType{2,3} ][ grad_fn = <SoftmaxBackward0> ]
ModelDescriptor
to
small_module(batch$x[[1]])
#> torch_tensor
-#> 1.3063 -2.6567 -0.8676 -0.7079
-#> 1.1566 -2.4779 -0.7330 -0.6347
-#> 1.1751 -2.4444 -0.7673 -0.6908
+#> -0.9548 2.4764 1.7547 -0.4855
+#> -1.1006 2.1895 1.5184 -0.5936
+#> -0.8588 2.2540 1.5650 -0.4339
#> [ 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 fc15fb03..e3bde776 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-11-26T10:46Z
+last_built: 2024-11-26T10:52Z
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 175545f5..0b6c3171 100644
--- a/dev/reference/DataDescriptor.html
+++ b/dev/reference/DataDescriptor.html
@@ -263,14 +263,14 @@
lt1 = as_lazy_tensor(torch_randn(10, 3))
materialize(lt1, rbind = TRUE)
#> torch_tensor
-#> -0.3503 -1.5936 -0.4580
-#> -1.2469 -1.2043 0.1949
-#> 0.1620 0.9485 0.0272
-#> -0.2014 0.6833 0.5749
-#> 1.7380 -0.0768 -1.3763
-#> -1.7971 1.1258 -0.8986
-#> -0.4809 -0.2205 -0.0133
-#> -0.7515 0.6839 -2.4631
-#> -0.7843 0.0904 -1.1838
-#> 0.1124 0.3099 -0.0470
+#> 0.7209 -0.7791 -0.1200
+#> -0.8322 -0.3782 -1.4658
+#> 2.9278 0.1341 -2.9706
+#> 0.4715 0.3795 2.1664
+#> 0.3711 -1.0344 -0.5415
+#> 1.6425 -0.0933 1.2480
+#> 0.0744 0.1560 -0.1901
+#> 1.9826 -1.4531 -0.8456
+#> 0.5194 0.4390 -0.9260
+#> 0.2598 0.4431 -0.5103
#> [ CPUFloatType{10,3} ]
materialize(lt1, rbind = FALSE)
#> [[1]]
#> torch_tensor
-#> -0.3503
-#> -1.5936
-#> -0.4580
+#> 0.7209
+#> -0.7791
+#> -0.1200
#> [ CPUFloatType{3} ]
#>
#> [[2]]
#> torch_tensor
-#> -1.2469
-#> -1.2043
-#> 0.1949
+#> -0.8322
+#> -0.3782
+#> -1.4658
#> [ CPUFloatType{3} ]
#>
#> [[3]]
#> torch_tensor
-#> 0.1620
-#> 0.9485
-#> 0.0272
+#> 2.9278
+#> 0.1341
+#> -2.9706
#> [ CPUFloatType{3} ]
#>
#> [[4]]
#> torch_tensor
-#> -0.2014
-#> 0.6833
-#> 0.5749
+#> 0.4715
+#> 0.3795
+#> 2.1664
#> [ CPUFloatType{3} ]
#>
#> [[5]]
#> torch_tensor
-#> 1.7380
-#> -0.0768
-#> -1.3763
+#> 0.3711
+#> -1.0344
+#> -0.5415
#> [ CPUFloatType{3} ]
#>
#> [[6]]
#> torch_tensor
-#> -1.7971
-#> 1.1258
-#> -0.8986
+#> 1.6425
+#> -0.0933
+#> 1.2480
#> [ CPUFloatType{3} ]
#>
#> [[7]]
#> torch_tensor
-#> -0.4809
-#> -0.2205
-#> -0.0133
+#> 0.0744
+#> 0.1560
+#> -0.1901
#> [ CPUFloatType{3} ]
#>
#> [[8]]
#> torch_tensor
-#> -0.7515
-#> 0.6839
-#> -2.4631
+#> 1.9826
+#> -1.4531
+#> -0.8456
#> [ CPUFloatType{3} ]
#>
#> [[9]]
#> torch_tensor
-#> -0.7843
-#> 0.0904
-#> -1.1838
+#> 0.5194
+#> 0.4390
+#> -0.9260
#> [ CPUFloatType{3} ]
#>
#> [[10]]
#> torch_tensor
-#> 0.1124
-#> 0.3099
-#> -0.0470
+#> 0.2598
+#> 0.4431
+#> -0.5103
#> [ CPUFloatType{3} ]
#>
lt2 = as_lazy_tensor(torch_randn(10, 4))
@@ -219,184 +219,184 @@ Examplesmaterialize(d, rbind = TRUE)
#> $lt1
#> torch_tensor
-#> -0.3503 -1.5936 -0.4580
-#> -1.2469 -1.2043 0.1949
-#> 0.1620 0.9485 0.0272
-#> -0.2014 0.6833 0.5749
-#> 1.7380 -0.0768 -1.3763
-#> -1.7971 1.1258 -0.8986
-#> -0.4809 -0.2205 -0.0133
-#> -0.7515 0.6839 -2.4631
-#> -0.7843 0.0904 -1.1838
-#> 0.1124 0.3099 -0.0470
+#> 0.7209 -0.7791 -0.1200
+#> -0.8322 -0.3782 -1.4658
+#> 2.9278 0.1341 -2.9706
+#> 0.4715 0.3795 2.1664
+#> 0.3711 -1.0344 -0.5415
+#> 1.6425 -0.0933 1.2480
+#> 0.0744 0.1560 -0.1901
+#> 1.9826 -1.4531 -0.8456
+#> 0.5194 0.4390 -0.9260
+#> 0.2598 0.4431 -0.5103
#> [ CPUFloatType{10,3} ]
#>
#> $lt2
#> torch_tensor
-#> 0.2267 -2.0751 0.1697 0.7999
-#> -0.5549 -0.1520 -0.2387 -1.5185
-#> 0.4732 1.7500 0.4675 0.2341
-#> -0.2406 0.1501 -1.5753 0.3590
-#> -0.4962 0.3795 1.0312 -1.0629
-#> 0.1440 -0.6074 0.1706 0.1594
-#> -0.9185 0.3343 -0.1752 -1.3991
-#> 1.4602 0.4684 0.7303 0.0359
-#> -0.0988 -0.0042 3.0536 1.6303
-#> 0.6268 -0.5274 1.3453 -0.5464
+#> -0.9499 1.2267 0.3966 -0.1104
+#> -1.7213 0.0694 0.6292 0.4429
+#> 0.1034 -0.2247 -1.0382 -0.8711
+#> 1.3446 -0.7110 -0.2305 1.1702
+#> -0.4673 -1.1430 0.0230 0.2525
+#> -0.2598 0.9152 -1.4227 -0.0557
+#> -2.2192 2.6817 1.2324 0.2709
+#> -1.2812 -0.9407 0.8546 1.1632
+#> 0.8758 -1.2456 -1.4916 0.2601
+#> -0.5359 -0.7665 0.9438 0.1353
#> [ CPUFloatType{10,4} ]
#>
materialize(d, rbind = FALSE)
#> $lt1
#> $lt1[[1]]
#> torch_tensor
-#> -0.3503
-#> -1.5936
-#> -0.4580
+#> 0.7209
+#> -0.7791
+#> -0.1200
#> [ CPUFloatType{3} ]
#>
#> $lt1[[2]]
#> torch_tensor
-#> -1.2469
-#> -1.2043
-#> 0.1949
+#> -0.8322
+#> -0.3782
+#> -1.4658
#> [ CPUFloatType{3} ]
#>
#> $lt1[[3]]
#> torch_tensor
-#> 0.1620
-#> 0.9485
-#> 0.0272
+#> 2.9278
+#> 0.1341
+#> -2.9706
#> [ CPUFloatType{3} ]
#>
#> $lt1[[4]]
#> torch_tensor
-#> -0.2014
-#> 0.6833
-#> 0.5749
+#> 0.4715
+#> 0.3795
+#> 2.1664
#> [ CPUFloatType{3} ]
#>
#> $lt1[[5]]
#> torch_tensor
-#> 1.7380
-#> -0.0768
-#> -1.3763
+#> 0.3711
+#> -1.0344
+#> -0.5415
#> [ CPUFloatType{3} ]
#>
#> $lt1[[6]]
#> torch_tensor
-#> -1.7971
-#> 1.1258
-#> -0.8986
+#> 1.6425
+#> -0.0933
+#> 1.2480
#> [ CPUFloatType{3} ]
#>
#> $lt1[[7]]
#> torch_tensor
-#> -0.4809
-#> -0.2205
-#> -0.0133
+#> 0.0744
+#> 0.1560
+#> -0.1901
#> [ CPUFloatType{3} ]
#>
#> $lt1[[8]]
#> torch_tensor
-#> -0.7515
-#> 0.6839
-#> -2.4631
+#> 1.9826
+#> -1.4531
+#> -0.8456
#> [ CPUFloatType{3} ]
#>
#> $lt1[[9]]
#> torch_tensor
-#> -0.7843
-#> 0.0904
-#> -1.1838
+#> 0.5194
+#> 0.4390
+#> -0.9260
#> [ CPUFloatType{3} ]
#>
#> $lt1[[10]]
#> torch_tensor
-#> 0.1124
-#> 0.3099
-#> -0.0470
+#> 0.2598
+#> 0.4431
+#> -0.5103
#> [ CPUFloatType{3} ]
#>
#>
#> $lt2
#> $lt2[[1]]
#> torch_tensor
-#> 0.2267
-#> -2.0751
-#> 0.1697
-#> 0.7999
+#> -0.9499
+#> 1.2267
+#> 0.3966
+#> -0.1104
#> [ CPUFloatType{4} ]
#>
#> $lt2[[2]]
#> torch_tensor
-#> -0.5549
-#> -0.1520
-#> -0.2387
-#> -1.5185
+#> -1.7213
+#> 0.0694
+#> 0.6292
+#> 0.4429
#> [ CPUFloatType{4} ]
#>
#> $lt2[[3]]
#> torch_tensor
-#> 0.4732
-#> 1.7500
-#> 0.4675
-#> 0.2341
+#> 0.1034
+#> -0.2247
+#> -1.0382
+#> -0.8711
#> [ CPUFloatType{4} ]
#>
#> $lt2[[4]]
#> torch_tensor
-#> -0.2406
-#> 0.1501
-#> -1.5753
-#> 0.3590
+#> 1.3446
+#> -0.7110
+#> -0.2305
+#> 1.1702
#> [ CPUFloatType{4} ]
#>
#> $lt2[[5]]
#> torch_tensor
-#> -0.4962
-#> 0.3795
-#> 1.0312
-#> -1.0629
+#> -0.4673
+#> -1.1430
+#> 0.0230
+#> 0.2525
#> [ CPUFloatType{4} ]
#>
#> $lt2[[6]]
#> torch_tensor
-#> 0.1440
-#> -0.6074
-#> 0.1706
-#> 0.1594
+#> -0.2598
+#> 0.9152
+#> -1.4227
+#> -0.0557
#> [ CPUFloatType{4} ]
#>
#> $lt2[[7]]
#> torch_tensor
-#> -0.9185
-#> 0.3343
-#> -0.1752
-#> -1.3991
+#> -2.2192
+#> 2.6817
+#> 1.2324
+#> 0.2709
#> [ CPUFloatType{4} ]
#>
#> $lt2[[8]]
#> torch_tensor
-#> 1.4602
-#> 0.4684
-#> 0.7303
-#> 0.0359
+#> -1.2812
+#> -0.9407
+#> 0.8546
+#> 1.1632
#> [ CPUFloatType{4} ]
#>
#> $lt2[[9]]
#> torch_tensor
-#> -0.0988
-#> -0.0042
-#> 3.0536
-#> 1.6303
+#> 0.8758
+#> -1.2456
+#> -1.4916
+#> 0.2601
#> [ CPUFloatType{4} ]
#>
#> $lt2[[10]]
#> torch_tensor
-#> 0.6268
-#> -0.5274
-#> 1.3453
-#> -0.5464
+#> -0.5359
+#> -0.7665
+#> 0.9438
+#> 0.1353
#> [ CPUFloatType{4} ]
#>
#>
diff --git a/dev/reference/mlr_learners_torch_model.html b/dev/reference/mlr_learners_torch_model.html
index 2d7914e2..7291dd12 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 virginica
-#> 149 virginica virginica
-#> 150 virginica virginica
+#> row_ids truth response
+#> 3 setosa setosa
+#> 9 setosa setosa
+#> 10 setosa setosa
+#> --- --- ---
+#> 147 virginica setosa
+#> 149 virginica setosa
+#> 150 virginica setosa