I'm building a chain classifier for a multiclass problem that uses KerasClassifier model. I have 17 labels as classification target and shape of X_train is (111300,107) and y_train is (111300,17) My code is here:
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)
The Model summary is here:
When tried to ti use the fit method on ClassifierChain, I'm getting this error:
Any one can guide me about this error and what is (None,2)?
From documention of chain classifier:
A multi-label model that arranges binary classifiers into a chain.
Hence convert your keras model as binary classifier using a single node in final layer and loss function as binary_crossentropy