DEV Community

Mahesh K
Mahesh K

Posted on

Torch Package for R

In this post, we take a look at the Torch package for R.

This package is emulating the PyTorch framework for deep learning. However it's area of focus is bringing the deep learning in the R language.

I created a video that covers the basics of the Torch package. You can take a look at it below.

Let's briefly cover some of the basics.

You can install the packages shown below.

install.packages("torch")

Check if the CUDA is available.

cuda_is_available()

and then use :

torch_tensor(1, device = "cuda")

Then you can create a tensor based on the available CUDA device.

Let's create a tensor from the R objects.

library(torch)
x <- array(runif(8), dim = c(2, 4, 6))
y <- torch_tensor(x, dtype = torch_float64())
y

That's it for a brief example. You would find the whole process video documented in the video linked above. You should give it a try. From there onwards you can check some of the examples out there in the kaggle for inspiration.

I hope this helps anyone who is trying to learn the data science and exploring the dataset on their own.

Top comments (0)