O'Reilly logo

R Deep Learning Cookbook by Achyutuni Sri Krishna Rao, Dr. PKS Prakash

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

How to do it...

Here is how you can proceed with sentiment prediction using LSTM:

  1. Load the required packages and movie reviews dataset:
load_packages=c("text2vec","tidytext","tensorflow") 
lapply(load_packages, require, character.only = TRUE) 
data("movie_review") 
  1. Extract the movie reviews and labels as a dataframe and matrix respectively. In movie reviews, add an additional attribute "Sno" denoting the review number. In the labels matrix, add an additional attribute related to negative flag.
reviews <- data.frame("Sno" = 1:nrow(movie_review), 
                         "text"=movie_review$review, 
                         stringsAsFactors=F) 
 
labels <- as.matrix(data.frame("Positive_flag" = movie_review$sentiment,"negative_flag" = (1                    movie_review$sentiment)))
  1. Extract all the unique words ...

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