Here is how you can proceed with sentiment prediction using LSTM:
- Load the required packages and movie reviews dataset:
load_packages=c("text2vec","tidytext","tensorflow") lapply(load_packages, require, character.only = TRUE) data("movie_review")
- 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)))
- Extract all the unique words ...