简体   繁体   English

Keras中具有不同数据类型的深度学习模型

[英]Deep Learning model with Different data types in Keras

I trying to make a classification model with Keras. 我试图用Keras制作分类模型。 My data contains some numeric features and some text features. 我的数据包含一些数字功能和一些文本功能。 By text features I mean comments or something similar. 通过文字功能我的意思是评论或类似的东西。 Numeric features will be category, age so on. 数字功能将是类别,年龄等。

I want to pass the text feature to a Embedding layer and then to a LSTM layer. 我想将文本特征传递给嵌入层,然后传递给LSTM层。 The numeric feature needed to be passed to a series of Dense Layers. 需要将数字要素传递给一系列密集图层。 After that both layers needed to be concatenated. 之后,两个层都需要连接。 After that a Dense Layer to make the output. 之后是密集层来进行输出。

How can I implement this type of model in Keras.? 如何在Keras中实现这种类型的模型?

Or is there any other way to use both numeric features and text based features in the model at the same time.? 或者是否有其他方法可以同时在模型中同时使用数字特征和基于文本的特征。

It is fairly easy to implement such a network using keras functional API. 使用keras功能API实现这样的网络相当容易。 suppose you have defined two sequential models to process your textual and numerical features, you can then merge the output and continue with more layers: 假设您已经定义了两个连续模型来处理文本和数字特征,那么您可以合并输出并继续更多层:

txt_input = keras.layers.Input(shape=(n,))
txt_feat = text_network(txt_input)
num_input = keras.layers.Input(shape=(m,))
num_feat = num_network(input2)
concatinated = keras.layers.Concatenate()([txt_feat, num_feat])

out = keras.layers.Dense(nodes)(concatinated)
model = keras.models.Model(inputs=[input1, input2], outputs=out)

you can also use other types of merge using any merge layer from keras. 您还可以使用keras中的任何合并层来使用其他类型的合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM