Я должен передать ввод в RNN как встраивание слов + POS-теги.Но встраивание слов генерируется только кодом.Поэтому я не могу согласиться с встраиванием и POS одним горячим вектором.Как лучше всего выполнить эту задачу?
def BidLstm(maxlen, N_TAGS, EMBEDDING_DIM, embedding_matrix):
inp = Input(shape=(maxlen,), dtype='int32')
x = Embedding(len(word2int) + 1,
EMBEDDING_DIM,
weights=[embedding_matrix],
input_length=maxlen,
trainable=False)(inp)
x = Bidirectional(LSTM(300, return_sequences=True, dropout=0.25,
recurrent_dropout=0.25))(x)
xa = Attention(maxlen)(x)
xd = Dense(256, activation="relu")(xa)
xdp = Dropout(0.25)(xd)
xd1 = Dense(5, activation="softmax")(xdp)
#x = TimeDistributed(Dense(N_TAGS + 1, activation='softmax'))(x)
model = Model(inputs=inp, outputs=xd1)
return model
model = BidLstm(max(sentence_length_list),5, EMBEDDING_DIM, embedding_matrix)
model.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['accuracy'])
file_path = ".model.hdf5"
ckpt = ModelCheckpoint(file_path, monitor='val_loss', verbose=1,
save_best_only=True, mode='min')
early = EarlyStopping(monitor="val_loss", mode="min", patience=1)
model.fit(X_train, Y_train_onehot, batch_size=32, epochs=15, validation_split=0.1, callbacks=[ckpt, early])