我在喀拉拉邦有这个模型,可以对评论进行情感分类。
embedding_layer = Embedding(vocabulary_size +1,
embeddings_dim,
weights=[embedding_weights],
input_length=max_sent_len,
trainable=False)
sentence_input = Input(shape=(max_sent_len,), dtype='int32')
embedded_sequences = embedding_layer(sentence_input)
gru_ = GRU(300, input_shape =(timesteps, embeddings_dim), return_sequences=True, dropout_W = 0.3,dropout_U = 0.3)(embedded_sequences)
attention, word_score = AttLayer(return_attention= True)(gru_)
preds=Dense(1, activation='sigmoid')(attention)
model= Model(sentence_input,preds)
adam = Adam(lr=0.001,decay=1e-6,clipvalue=5)
model.compile(loss='binary_crossentropy',
optimizer=adam,
metrics=['accuracy'])
history=model.fit(train_sequences,train_labels,batch_size=32, nb_epoch=5, validation_data=(test_sequences, test_labels), verbose=1, shuffle=True)
在关注层之后,我需要绘制输入复查的所有序列的表示形式。在热图中,我需要绘制将当前单词嵌入与以前的构建嵌入相结合后获得的表示形式。每列应对应于每个时间步的输出。现在,每个时间步长我只有一个浮点数得分。