Question: Hello. I m getting a couple of errors below when I try to create base line RNN model and second RNN model. Any sugguestions on
Hello. Im getting a couple of errors below when I try to create base line RNN model and second RNN model. Any sugguestions on how to fix?
You are a data scientist in an AI company. You are given a dataset of restaurant reviews. This is the sentiment dataset. It contains tweets with six columns:
target: the polarity of the tweet negative, neutral, positive
ids: The id of the tweet for example,
date: the date of the tweet for example, Sat May :: UTC
flag: The query lyx If there is no query, then this value is NOQUERY.
user: the user that tweeted for example, robotickilldozr
text: the text of the tweet for example, Lyx is cool"
Data Source: Sentiment DatasetLinks to an external site.
The target is the polarity of the tweet. The features are the text. You are asked to perform sentiment analysis using deep learning by using the attached Jupyter Notebook and writing a Python script, and running all the cells. You only need to submit a JupyterNotebook.
Download the dataset that is about MB from Kaggle into the local disk and unzip it
Clean and preprocess the text data and split into training and test dataset.
Build a baseline RNN model using embedding layer and GRU on the training dataset and evaluate it on the test dataset.
Build a second RNN model using embedding layer and LSTM and evaluate it on the test dataset.
Build a third RNN model using embedding layer and GRU and LSTM and evaluate it on the test dataset.
Which model do you recommend for the model in Q Q and Q Justify your answer.
import zipfile
# Unzip the downloaded file
with zipfile.ZipFilepathtodownloadedfile.zip', r as zipref:
zipref.extractallpathtoextractdataset'
import pandas as pd
from sklearn.modelselection import traintestsplit
import re
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import padsequences
# Load the dataset into a pandas DataFrame
datapath 'pathtoextractdatasettrainingprocessed.noemoticon.csv
columns target 'ids', 'date', 'flag', 'user', 'text'
df pdreadcsvdatapath, encoding'latin headerNone, namescolumns
# Clean the text by removing unnecessary characters
dftext dftextapplylambda x: resubrws strxlower
# Split the data into training and test datasets
traindf testdf traintestsplitdf testsize randomstate
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, GRU, Dense
# Tokenize the text data
tokenizer Tokenizer
tokenizer.fitontextstraindftext
vocabsize lentokenizerwordindex
# Convert text data to sequences
trainsequences tokenizer.textstosequencestraindftext
testsequences tokenizer.textstosequencestestdftext
# Pad sequences to a fixed length
maxlen
traindata padsequencestrainsequences, maxlenmaxlen, padding'post'
testdata padsequencestestsequences, maxlenmaxlen, padding'post'
# Build the baseline RNN model
model Sequential
modeladdEmbeddingvocabsize, inputlengthmaxlen
modeladdGRU
modeladdDense activation'sigmoid'
modelcompileoptimizer'adam', loss'binarycrossentropy', metricsaccuracy
# Train the model
modelfittraindata, traindftarget validationdatatestdata, testdftarget epochs
Error aboveValueError: Unrecognized keyword arguments passed to Embedding: inputlenght':
from tensorflow.keras.layers import LSTM
# Build the second RNN model
model Sequential
modeladdEmbeddingvocabsize, inputlengthmaxlen
modeladdLSTM
modeladdDense activation'sigmoid'
modelcompileoptimizer'adam', loss'binarycrossentropy', metricsaccuracy
# Train the model
modelfittraindata, traindftarget validationdatatestdata, testdftarget epochs
ERROR ABOVE ValueError: Unrecognized keyword arguments passed to Embedding: inputlength':
# Evaluate the models on the test dataset
acc modelevaluatetestdata, testdftarget
acc modelevaluatetestdata, testdftarget
acc modelevaluatetestda
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
