我正在做一个项目,我必须在神经网络中使用数字和文本数据的组合来预测下一个小时系统的可用性。我决定尝试使用Keras的合并层和两个网络(一个用于数字数据,一个用于文本),而不是尝试使用单独的神经网络并最终做一些奇怪/不清楚的事情(对我来说)以产生所需的输出。我的想法是,我以(batch_size,6hrs,num_features)的形式向模型提供了前6小时的一系列性能指标。除了提供给处理数字数据的网络的输入外,我还给第二个网络提供了另一个大小序列(batch_size,max_alerts_per_sequence,max_sentence长度)。
一个时间范围内的任何数字数据序列都可以具有与之关联的可变数量的事件(文本数据)。为简单起见,我最多只允许50个事件伴随一系列性能数据。每个事件均按单词进行哈希编码并填充。我尝试使用平坦层将输入形状从(50,30)减少到(1500),以便模型可以针对这些“序列”中的每个事件进行训练(以澄清:我通过50个带有30个编码元素的句子来传递模型每个效果数据序列)。
我的问题是:由于我需要NN来查看给定性能指标序列的所有事件,因此如何使基于文本的数据训练的NN能够基于句子序列?
我的模特:
#LSTM Module for performance metrics
input = Input(shape=(shape[1], shape[2]))
lstm1 = Bidirectional(LSTM(units=lstm_layer_count, activation='tanh', return_sequences=True, input_shape=shape))(input)
dropout1 = Dropout(rate=0.2)(lstm1)
lstm2 = Bidirectional(LSTM(units=lstm_layer_count, activation='tanh', return_sequences=False))(dropout1)
dropout2 = Dropout(rate=0.2)(lstm2)
#LSTM Module for text based data
tInput = Input(shape=(50, 30))
flatten = Flatten()(tInput)
embed = Embedding(input_dim=vocabsize + 1, output_dim= 50 * 30, input_length=30*50)(flatten)
magic = Bidirectional(LSTM(100))(embed)
tOut = Dense(1, activation='relu')(magic)
#Merge the layers
concat = Concatenate()([dropout2, tOut])
output = Dense(units=1, activation='sigmoid')(concat)
nn = keras.models.Model(inputs=[input, tInput], outputs = output) …
Run Code Online (Sandbox Code Playgroud)