0
$\begingroup$

I am doing a toy example with mushroom dataset to learn class embedding with keras:

I am trying to embed a single feature:

inputs = Input(shape=[1])
emb = Embedding(input_dim=cap_shape_dummy.shape[1], output_dim=3)(inputs)
output = Dense(units=1,activation='sigmoid')(emb)
model = Model(inputs=inputs,outputs=output)

However I always receive the same error when I try to fit the model:

Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (8124, 1)

Am I doing anything wrong? Did I miss anything with category embedding?
Thanks.

$\endgroup$
2
  • $\begingroup$ I think your problem can be solved by adding 'model.add(Flatten())' before the dense layer, or see the answer of this question: stackoverflow.com/questions/48674881/… $\endgroup$ – Hunar Apr 11 '19 at 9:01
  • $\begingroup$ Why would I need to Flatten? the output fronm my embedding is not multi dim? Would you please explain me what each param mean? because maybe is not clear $\endgroup$ – 3nomis Apr 11 '19 at 12:15
0
$\begingroup$

inputs = Input(shape=[1]) emb = Embedding(input_dim=cap_shape_dummy.shape[1], output_dim=3)(inputs) x = Flatten()(emb) output = Dense(units=1,activation='sigmoid')(x) model = Model(inputs=inputs,outputs=output)

$\endgroup$
1
  • $\begingroup$ Please format your code as code, and add some explanation behind it. $\endgroup$ – Itamar Mushkin Jul 16 '20 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.