我正在为使用KerasClassifier模型的多类问题构建链分类器。我有17个标签作为分类目标,X_train的形状为(111300,107),y_train的形状为(111300,17)我的代码在这里:
def create_model():
input_size=length_long_sentence
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 )
#out_current = Reshape((1,2*lstm_size))(out_current)
output = Dense(units=len(unique_tag_set), activation='softmax')(out_current)
model = Model(inputs=current_input, outputs=output)
model.compile(optimizer='Adam', loss='categorical_crossentropy', metrics=['accuracy'])
print(model.summary())
return model
model = KerasClassifier(build_fn=create_model, epochs=1,batch_size=256)
print(type(model))
chain=ClassifierChain(model, order='random', random_state=42)
history=chain.fit(X_train, y_train)
模型摘要在这里:
当尝试在ClassifierChain上使用fit方法时,出现此错误:
任何人都可以指导我这个错误,什么是(None,2)?
从链式分类器的记录中:
将二元分类器排列成一个链的多标签模型。
因此,使用最后一层中的单个节点将keras模型转换为二进制分类器,并将损失函数转换为binary_crossentropy
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句