<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data=pd.read_csv('IMDB Dataset.csv')

data.head()
print(data.shape)
data['review'][0]
data.isnull().sum()
data['sentiment'].value_counts()<jupyter_output><empty_output><jupyter_text>Cleaning datasets<jupyter_code>#cleaning the dataset
import re
def process_tweet(review):
    return " ".join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])", "",review.lower()).split())
process_tweet(data['review'][49999])

processed_text=[]
for item in range(data.shape[0]):
  processed_text.append(process_tweet(data['review'][item]))
data['processed_review']=processed_text

data.head()
data.isnull().sum()
data['sentiment']=data['sentiment'].map({'positive':1,'negative':0})
data['sentiment'].value_counts()
vocab_size = 10000
embedding_dim = 16
max_length = 120
trunc_type='post'
oov_tok = "<OOV>"

from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split

max_feature=10000
tokenizer=Tokenizer(num_words=max_feature,oov_token=oov_tok)
tokenizer.fit_on_texts(data['processed_review'].values)
X=tokenizer.texts_to_sequences(data['processed_review'].values)
#padded = pad_sequences(sequences,maxlen=max_length, truncating=trunc_type)

X=pad_sequences(X,maxlen=max_length, truncating=trunc_type)

y=pd.get_dummies(data['sentiment']).values

print(X.shape)
print(y.shape)
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)

print(X_train.shape,y_train.shape)
print(X_test.shape,y_test.shape)
import tensorflow as tf


model = tf.keras.Sequential([
    tf.keras.layers.Embedding(vocab_size, embedding_dim, input_length=max_length),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(2, activation='sigmoid')
])
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
model.summary()
# # batch_size = 32
model.fit(X_train, y_train, epochs = 5,validation_data=(X_test ,y_test))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15654648956356737, 'fraction_numerical': 0.018500948766603416, 'mean_word_length': 9.139423076923077, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '306344', 'license': 'MIT', 'n_tokens_mistral': 828, 'n_tokens_neox': 786, 'n_words': 101, 'path': 'NLP/TOP PROJECTS/IMDB dataset/IMDB_DATASET_prediction.ipynb', 'repo_name': 'saurabhsingh1411/100-Days-Of-ML-Code', 'size': '2108'}