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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.