Closed m-developer96 closed 4 years ago
Perhaps there might be an error if your data is not reshaped as the same size as the example.
@hkvision please take a look.
Hi @m-developer96,
The error is due to you have different embedding dim and sequence length as the example you refer to, you need to change the model structure accordingly.
To be more specific, when the embedding dim and sequence length are both 50 in the example we give,
model = Sequential()
model.add(Reshape([embedding_dim, 1, sequence_len]))
model.add(SpatialConvolution(embedding_dim, 128, 5, 1).set_name('conv1'))
model.add(ReLU())
model.add(SpatialMaxPooling(5, 1, 5, 1))
model.add(SpatialConvolution(128, 128, 5, 1).set_name('conv2'))
model.add(ReLU())
model.add(SpatialMaxPooling(5, 1, 5, 1))
The model output before the Reshape([128])
layer is of shape (batch, 128, 1, 1)
and therefore you can do the reshape to let the output become (batch, 128)
However, if you change your embedding dim and sequence length to 100, the model output before the Reshape([128])
layer becomes of the shape (batch, 128, 1, 3)
, and therefore you can't reshape it to (batch, 128)
and that's why you get the error.
To fix this, one simplest choice is to change the Reshape layer to Reshape([128 * 3])
, but I don't think this is the best choice for such a network architecture. Probably you need to change the parameters of the convolution layers to make the output before the reshape layer have the shape (batch, 128, 1, 1)
.
Hi @m-developer96,
Also as you may see, using the old interface of BigDL, you need to calculate the output shape of every layer in the model carefully to avoid certain errors. Thus, if you wish, you are recommended to use the Keras-Style APIs here for model definition: https://github.com/intel-analytics/analytics-zoo/tree/master/pyzoo/zoo/pipeline/api/keras , which supports shape inference and prevents you constructing a shape-incompatible model before you train it.
BTW, the example you are referring to is BigDL 0.1, which is probably a bit too old. We have newer examples for you to have a reference: https://github.com/intel-analytics/analytics-zoo/tree/master/pyzoo/zoo/examples/textclassification https://github.com/intel-analytics/analytics-zoo/tree/master/apps/sentiment-analysis
Enjoy your coding and feel free to tell us if you have further problems.
hi @hkvision Thank you so much for your help.
@m-developer96 You are welcome. I will close this issue first. Feel free to tell us if you have further issues.
Hi everyone. I used this tutorial to build a simple text classifier. I used Sentiment-140 dataset and FastText pre-trained word embeddings for this model and just change below variables: embedding_dim = 100 sequence_len = 100 But my model doesn't run successfully and I faced with this error :
How can I fix this error? Help me plz. Thanks :)