<jupyter_start><jupyter_text>IMDB Movie Reviews Sentiment Analysis using Jointly Learned Embeddings  Preprocessed IMDB data that comes packaged with Keras is used here.<jupyter_code># Imports required packages

from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, Flatten, Dense

import matplotlib.pyplot as plt
max_features = 10000     # count of most common words
embedding_dim = 100      # dimension of embedding
max_input_length = 500   # number of review words to into consideration
# Loads train and test data from preprocessed IMDB database that comes with Keras

(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words = max_features)
print("Train samples count:", x_train.shape[0],
      "\nTest samples count:", x_test.shape[0])
# Pads reviews to be of same size

x_train = pad_sequences(x_train, maxlen = max_input_length)
x_test = pad_sequences(x_test, maxlen = max_input_length)
# Creates model

model = Sequential()
model.add(Embedding(max_features, embedding_dim, input_length = max_input_length))
model.add(Flatten())
model.add(Dense(32, activation = "relu"))
model.add(Dense(1, activation = "sigmoid"))

model.compile(optimizer = "rmsprop", loss = "binary_crossentropy", metrics = ["acc"])
# Shows the model summary

model.summary()
epochs = 10
batch_size = 32

history = model.fit(x_train, y_train, epochs = epochs, batch_size = batch_size, validation_split = .2)
# Evaluates training and validation performance

history_dict = history.history

epoch_range = range(1, len(history_dict["acc"]) + 1)

train_losses = history_dict["loss"]
val_losses = history_dict["val_loss"]

train_accuracies = history_dict["acc"]
val_accuracies = history_dict["val_acc"]

plt.plot(epoch_range, val_losses, "b", label = "Validation Loss")
plt.plot(epoch_range, train_losses, "bo", label = "Training Loss")
plt.xlabel("Epochs")
plt.ylabel("Loss")
plt.legend()
plt.title("Validation & Training Loss")


plt.figure()

plt.plot(epoch_range, val_accuracies, "b", label = "Validation Accuracy")
plt.plot(epoch_range, train_accuracies, "bo", label = "Training Accuracy")
plt.xlabel("Epochs")
plt.ylabel("Accuracy")
plt.legend()
plt.title("Validation & Training Accuracy")

plt.show()
print("Validation Loss:", history_dict["val_loss"][-1],
      "\nValidation Accuracy:", history_dict["val_acc"][-1])
eval_result = model.evaluate(x_test, y_test)
print("Test Loss:", eval_result[0],
      "\nTest Accuracy:", eval_result[1])<jupyter_output>Test Loss: 1.425144076347351 
Test Accuracy: 0.8327999711036682
{'fraction_non_alphanumeric': 0.1176027139087825, 'fraction_numerical': 0.022615906520919715, 'mean_word_length': 6.351800554016621, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '279735', 'license': 'MIT', 'n_tokens_mistral': 938, 'n_tokens_neox': 870, 'n_words': 224, 'path': 'Deep_Learning/IMDB_Movie_Reviews_Sentiment_Analysis/2_IMDB_Movie_Review_Sentiment_Analysis_using_Jointly_Learned_Embeddings.ipynb', 'repo_name': 'PradipKumarDas/GettingStarted', 'size': '2653'}