O'Reilly logo

R Deep Learning Projects by Pablo Maldonado, Yuxi Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementation as an R6 class

First, let's show the skeleton of this class. We need a number of functions here. First, we need to import the R6 package and create two auxiliary functions:

library(R6)set.seed(1234)softmax <- function(x){ xt <- exp(x-max(x)) return(xt/sum(xt))}zeros_like <- function(M){ return(matrix(0,dim(as.matrix(M))[1],dim(as.matrix(M))[2])) }

This will come in handy during the code to calculate the softmax and initialize matrices with the correct sizes. As before, our program needs the following basic functions:

  • Forward propagation
  • Backward propagation
  • A sample from the obtained probability distribution
  • Train the model

The structure of the class should look like:

RNN <- R6Class("RNN",          public = list( hidden_size = NULL, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required