繁体   English   中英

我们可以将 Keras 中的特征设为变量而不是固定的吗?

[英]can we make no of features in Keras Input shape as variable and not fixed?

我正在实现一个链分类器,它将 lstm model 作为多类问题的二元分类器链。 由于一个二元分类器的 output 作为特征馈送到下一个二元分类器,因此我们不能在 model 的输入层中固定输入形状。 我的代码在这里:

def create_model():
  input_size=length_long_sentence  #107 in my case
  embedding_size=128
  lstm_size=64
  output_size=len(unique_tag_set)
    #----------------------------Model--------------------------------
  current_input=Input(shape=(input_size,)) 
  emb_current = Embedding(vocab_size, embedding_size, input_length=input_size)(current_input)
  out_current=Bidirectional(LSTM(units=lstm_size))(emb_current )
  output = Dense(units=1, activation=  'sigmoid')(out_current)
  model = Model(inputs=current_input, outputs=output)
  #-------------------------------compile-------------
  model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['accuracy'])
  return model
model = KerasClassifier(build_fn=create_model, epochs=1,batch_size=256, shuffle = True, verbose = 1,validation_split=0.2)
chain=ClassifierChain(model, order='random', random_state=42)
history=chain.fit(X_train, y_train)

在训练时,我收到了链中具有不同输入形状的分类器的警告:

在此处输入图像描述

每次训练二元分类器时,都会在 (None,108)、(none,109) 等输入上调用它。

Model总结在这里:

在此处输入图像描述

有什么方法可以在 keras model 的输入层中使这个大小(无,107)可变?

使用None表示Input层中的可变形状。

  current_input=Input(shape=(None,)) 

暂无
暂无

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

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