Shape error Keras, but no error on Kaggle

Viewed 28

I made a 8-class sentence classificator using Keras and when I try to predict the output on my local machine i get the following error (input was 'something'):

ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 50), found shape=(None, 9)

This is the model:

model = Sequential()          #21           100                50
model.add(layers.Embedding(vocab_size, embedding_dim, input_length=maxlen))
model.add(layers.Conv1D(128, 5, activation='relu'))
model.add(layers.GlobalMaxPooling1D())
model.add(layers.Dense(16, activation='relu'))
model.add(layers.Dense(8, activation='softmax'))
model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
model.summary()

This is the piece of code:

    tokenizer = Tokenizer(num_words=120,char_level=True)
    ...
    text='something'
    tst=tokenizer.texts_to_sequences([text])
    print(tst)
    print(type(tst))
    print(np.argmax(model.predict(tst)))

I get this output on kaggle:

    >>> [[4, 1, 9, 3, 5, 17, 2, 13, 11]]
    >>> <class 'list'>
    >>> 5

My input isn't padded and varies in length, but it runs on kaggle. I'm wondering if Keras on Kaggle somehow auto-pads shorter output or smth.

How can i fix it ?

0 Answers
Related