<jupyter_start><jupyter_text>Sentiment Classifier of Sentiment140  Load Data<jupyter_code>import pandas as pd
data = pd.read_csv('./data/training.1600000.processed.noemoticon.csv', 
                   header=None)
data = data.sample(frac=1) 
# train-test split
train_size = int(0.7*len(data))
features = data[5]
targets = data[0]
X_train, X_test = features.values[:train_size], features.values[train_size:]
y_train, y_test = targets.values[:train_size], targets.values[train_size:]

y_train[y_train==2] = 1
y_train[y_train==4] = 2

y_test[y_test==2] = 1
y_test[y_test==4] = 2<jupyter_output><empty_output><jupyter_text>Data Preprocessing<jupyter_code>from sklearn.feature_extraction.text import CountVectorizer

count_vectorizer = CountVectorizer(max_features=100)
X_train_num = count_vectorizer.fit_transform(X_train).toarray()
X_test_num = count_vectorizer.transform(X_test).toarray()
instance = 46544
print(X_train[instance])
print(X_train_num[instance])<jupyter_output>I ran outta bathroom passes.  maybe mrs. French will be nice today?
[0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]<jupyter_text>Text classifier<jupyter_code>import tensorflow as tf
from sklearn.preprocessing import StandardScaler

model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(256, activation=tf.nn.leaky_relu), 
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(3)
])

adam_optimizer = tf.keras.optimizers.Adam()
model.compile(
    optimizer=adam_optimizer,
    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    metrics=[
      'accuracy',
    ]
)

print(y_train)
model.fit(X_train_num, 
          y_train,
          batch_size=64,
          epochs=2,
          validation_split=0.1,
          verbose=1)<jupyter_output>[0 2 2 ... 2 0 0]
Train on 1008000 samples, validate on 112000 samples
Epoch 1/2
1008000/1008000 [==============================] - 43s 43us/sample - loss: 0.6168 - accuracy: 0.6578 - val_loss: 0.6042 - val_accuracy: 0.6704
Epoch 2/2
1008000/1008000 [==============================] - 43s 43us/sample - loss: 0.6095 - accuracy: 0.6638 - val_loss: 0.6022 - val_accuracy: 0.6719
{'fraction_non_alphanumeric': 0.13432835820895522, 'fraction_numerical': 0.10623353819139596, 'mean_word_length': 3.9978070175438596, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '383605', 'license': 'MIT', 'n_tokens_mistral': 1066, 'n_tokens_neox': 855, 'n_words': 230, 'path': 'Sentiment_140_Data_Analysis/Sentiment_Classifier.ipynb', 'repo_name': 'LasalJayawardena/RNN-Projects', 'size': '2278'}