Skip to content

Instantly share code, notes, and snippets.

@AdroitAnandAI
Created February 10, 2021 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdroitAnandAI/f7f2613f2611096a8db96be44a7c3689 to your computer and use it in GitHub Desktop.
Save AdroitAnandAI/f7f2613f2611096a8db96be44a7c3689 to your computer and use it in GitHub Desktop.
Sentimental Analysis
# Training Module of LSTM 2 layer stack
max_review_length = 600
X_train = sequence.pad_sequences(X_train, maxlen=max_review_length)
X_test = sequence.pad_sequences(X_test, maxlen=max_review_length)
# To train the Model
def trainModel(model):
history = model.fit(numpy.array(X_train), numpy.array(y_train), \
validation_split=0.33, epochs=30, batch_size=64)
# Final evaluation of the model
scores = model.evaluate(numpy.array(X_test), numpy.array(y_test), verbose=0)
print("Accuracy: %.2f%%" % (scores[1]*100))
model.save('getEmotions_2LSTM.h5')
# Model Definition
embedding_vector_length = 32
model = Sequential()
model.add(Embedding(top_words_count, embedding_vector_length, input_length=max_review_length))
model.add(Dropout(0.75))
model.add(LSTM(200, bias_regularizer=L1L2(l1=0.0, l2=0.05), return_sequences=True))
model.add(Dropout(0.75))
model.add(LSTM(150, bias_regularizer=L1L2(l1=0.0, l2=0.05)))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
trainModel(model=model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment