How to predict with the ML model I created? (receiving Error)

Hi everyone,

I’m very sorry to ask this beginner question but I just don’t know how to make model.predict() works.
I know that I can use model.predict() to predict new input and return a class/label, but I’m getting Errors due to the incompatibility of the shape of my input with the model… But I don’t know how to make the shape of the sentence i wanted to predict compatible with my model…

Can someone pls take a look at my Colab Workbook (which is for Course 3 Week 2 final coding assessment) and pls help me predict a sentence “Jack scored 2 goals tonight at New York Stadium” at this part of the Notebook?

Also, could you pls teach me what’s the proper steps/ways in how to predict a trained ML model? How do I make sure that the input I want to predict is compatible with my model? (ex. looking at the shape, reshape…)

Thank you so much!!

#EDIT, as you can see in my note book part I did attempt to reshape the sentences I want to predict but to no avail! Somehow, all the predictions given for different sentences are the same…There’s no way “Democrats passed historic law” can be categorized as “sport”…

Hey,
We will surely help you out with your query but please ensure that you dont post your assignment solution codes out here directly as it violates the Coursera Honor Code
You can send them via Personal Message to the mentors by clicking on their name
Let me take a look at the notebook you have linked in your query
Thanks and Regards,
Mayank Ghogale

I checked your notebook and you do have different number of sentences in the dataset (so ofc the labels are different in number)and also different number of words
Hence your shapes dont match from the beginning
Let me take a closer look on why this is happening

Hello,

This is a suggestion from my fellow mentor and I think you can follow this
Regarding the difference in datasets,we will get back to you in a while
Thanks and Regards,
Mayank Ghogale

Ok, thank you very much! I won’t be posting more of my solution code directly here and instead will be messaging you.

Hi,

About the different number of sentences, it’s just because I added more sentences in to test out how good the model is in predicting :)) The model was able to predict the CNN news but couldn’t predict the short sentences like “Jack scored 2 goals tonight at New York Stadium”. Maybe the problem was not with the model but its acurracy is only high if the input is long enough? And could you pls help me with another issue at Why shift 370 time steps and not let say 365 time steps??

Thank you so much for always supporting my questions!!

I think short sentences might cause an issue cause the padding would be way too more than in other cases…Coming to your second query,I will look into it and get back to you sir
Thank you

1 Like