Question: Course: Machine Learning a) this code tries to do a 6 class emotion detection from text. Its only in CNN+BiLSTM. Rewrite two individual codes with

Course: Machine Learning

Course: Machine Learning a) this code tries to do a 6 classemotion detection from text. Its only in CNN+BiLSTM. Rewrite two individual codeswith same hyperparameters in CNN + Attention + BiLSTM + CNN and

a) this code tries to do a 6 class emotion detection from text. Its only in CNN+BiLSTM. Rewrite two individual codes with same hyperparameters in CNN + Attention + BiLSTM + CNN and CNN + Attention + LSTM + CNN.

def get_embedding_vectors (tokenizer, dim=300): embedding_index = {} with open('glove.840B.300d.txt', 'r', encoding="cp437", errors='ignore') as f: for line in tqdm.tqdm(f, "Reading fasttext"): values = line.split() word = ".join(values[:-300]) vectors = np.asarray(values[-300:], dtype='float32') embedding_index[word] = vectors word_index = tokenizer.word_index embedding_matrix = np.zeros((len(word_index)+1, dim)) for word, i in word_index.items(): embedding_vector = embedding_index.get(word) if embedding_vector is not None: # words not found will be es embedding_matrix[i] = embedding_vector return embedding_matrix embedding_matrix get_embedding_vectors (tokenizer) #defining CNN-BILSTM model embedding_dim = 300 model = Sequential() model.add(layers. Embedding(input_dim=vocab_size, output_dim=embedding_dim, weights = [embedding_matrix], input_length=maxlen)) model.add(layers. Dropout(0.3)) model.add(layers.Conv1D(filters=64, kernel_size=3, activation=act)) model.add(layers. MaxPool1D(pool_size=3)) model.add(layers. Dropout(0.3)) model.add(layers. Conv1D(filters=64, kernel_size=3, activation=act)) model.add(layers.MaxPool1D(pool_size=3)) model.add(layers. Dropout(0.3)) model.add(layers. Bidirectional(layers.LSTM(256, recurrent_dropout=0.3))) model.add(layers. Dropout(0.3)) model.add(layers. Dense(256, activation=act)) model.add(layers. Dropout(0.3)) model.add(layers. Dense(6, activation='softmax")) model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"]) model. summary() checkpoint_filepath = './Checkpoint/checkpoint' model_checkpoint_callback = tf.keras.callbacks. ModelCheckpoint filepath=checkpoint_filepath, save_weights_only=True, monitor='test_accuracy', mode='max', save_best_only=True) history = model.fit(X_train, dummy_y_train, epochs=EPOCHS, verbose=1, validation_data=(X_test, dummy_y_test), batch_size=128, callbacks[model_checkp loss, accuracy = model.evaluate (X_train, dummy_y_train, verbose=0) print("Training Accuracy: {:.4f}".format(accuracy)) loss, accuracy = model. evaluate (x_test, dummy_y_test, verbose=0) print("Testing Accuracy: {:.4f}".format(accuracy))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!