text_plain_output_1.png
from keras.layers import Dense, Dropout

from keras.layers import Flatten

from keras.layers.embeddings import Embedding

from keras.models import Sequential

from keras.preprocessing.sequence import pad_sequences

from keras.preprocessing.sequence import pad_sequences

from keras.preprocessing.text import one_hot

from keras.preprocessing.text import one_hot

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

dataset = pd.read_csv('../input/emotions-in-text/Emotion_final.csv')
dataset.sample(5)

def get_longest_text(texts):
    longest_input = 0
    for text in texts:
        text_len = len(text.split())
        longest_input = max(longest_input, text_len)
    return longest_input
longest_input = get_longest_text(dataset['Text'])
longest_input

vocab_size = 21000
encoded_docs = [one_hot(d, vocab_size) for d in dataset['Text']]

max_length = longest_input
padded_docs = pad_sequences(encoded_docs, maxlen=max_length, padding='post')

model = Sequential()
model.add(Embedding(vocab_size, 132, input_length=max_length))
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(6, activation='relu'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

(X_train.shape, y_train.shape)

history = model.fit(X_train, y_train, epochs=50, validation_data=(X_test, y_test))