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, ...

Get Deep Learning with R for Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.