text_plain_output_1.png image_output_1.png
from keras.layers import Bidirectional

from keras.layers import Dense

from keras.layers import Dense,Dropout,Embedding,LSTM

from keras.layers import Embedding

from keras.layers import LSTM

from keras.models import Sequential

from keras.models import Sequential

from keras.preprocessing.text import Tokenizer

from tensorflow.keras.layers import Dense, Embedding

from tensorflow.keras.layers import LSTM

from tensorflow.keras.models import Sequential

from tensorflow.keras.preprocessing.sequence import pad_sequences

from tensorflow.keras.preprocessing.text import Tokenizer

import cudf as pd

import keras

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

train_df = pd.read_csv('/kaggle/input/sentiment-analysis-on-movie-reviews/train.tsv.zip', sep='\t')
test_df = pd.read_csv('/kaggle/input/sentiment-analysis-on-movie-reviews/test.tsv.zip', sep='\t')

train_df.shape

test_df.shape

train_df.isnull().sum()

test_df.isnull().sum()

train_df.isnull().any().any()

test_df.isnull().any().any()

train = train_df.to_pandas()

test = test_df.to_pandas()

X_train = train.Phrase
Y_train = train.Sentiment
tokenize = Tokenizer()
tokenize.fit_on_texts(X_train.values)

X_test = test.Phrase
X_train = tokenize.texts_to_sequences(X_train)
X_test = tokenize.texts_to_sequences(X_test)

max_lenght = max([len(s.split()) for s in train['Phrase']])
X_train = pad_sequences(X_train, max_lenght)
X_test = pad_sequences(X_test, max_lenght)

model = Sequential()
inputs = keras.Input(shape=(None,), dtype='int32')
model.add(inputs)
model.add(Embedding(50000, 128))
model.add(Bidirectional(LSTM(64, return_sequences=True)))
model.add(Bidirectional(LSTM(64)))
model.add(Dense(5, activation='softmax'))
model.summary()

model.compile('adam', 'sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(X_train, Y_train, batch_size=256, epochs=30)

y_pred = model.predict(X_test)
y_pred