From the course: Deep Learning: Getting Started
Unlock this course with a free trial
Join today to access over 25,900 courses taught by industry experts.
Predictions for text
From the course: Deep Learning: Getting Started
Predictions for text
Now, let's use our trained model to classify new text messages. This demonstrates the complete pipeline from raw text to prediction. The code is available in section 6.5, predicting for text. We start with two test messages. The first message, free entry to a fun contest, sounds like a spam message. The second message, yep, I will come over, sounds like a normal message. Here is the crucial step. We must transform these new messages using the exact same vectorizer we trained with. We call vectorizer.transform to convert it to an array. We don't want to use fit transform as before because we don't want to relearn the vocabulary. This applies the same tokenization, stopword removal, lemmatization, and TF-IDF calculation that we used during training. Then we print the shape to verify the right dimensions. Next we call model.predict() with the transformed messages. This returns probabilities for both classes for each message. We use np.argmax with axis equals 1 to find the highest…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
