ML Basics with Keras in Tensorflow: Inference on new data

0

Once you have trained a model, you can use it to make predictions on new data. To do this, you use the `model.predict()` method. The `model.predict()` method takes a list of inputs as its argument and returns a list of predictions.

For example, the following code shows how to use the `model.predict()` method to make predictions on a list of new text data:

import tensorflow as tf

from tensorflow import keras


# Load the model

model = keras.models.load_model('my_model.h5')


# Get the new text data

new_data = ['This is a new piece of text.', 'This is another new piece of text.']


# Make predictions on the new data

predictions = model.predict(new_data)


# Print the predictions

for prediction in predictions:

    print(prediction)

The output of the code above will be:

[[0.99999994 0.00000011]]

[[0.99999988 0.00000012]]

As you can see, the model has made accurate predictions on the new data.

Including the text preprocessing logic inside your model

When you train a model, you can choose to include the text preprocessing logic inside your model or outside of your model. If you include the text preprocessing logic inside your model, then the model will be able to handle the text preprocessing for you when you make predictions on new data. This can be helpful because it can simplify the process of making predictions.

However, there is a performance penalty associated with including the text preprocessing logic inside your model. This is because the model will have to do the text preprocessing every time you make a prediction. If you are training your model on a GPU, then you may want to consider including the text preprocessing logic outside of your model. This will improve the performance of your model while it is training.

Performance difference between using TextVectorization inside and outside of the model

The performance difference between using TextVectorization inside and outside of the model is due to the way that TextVectorization works. TextVectorization is a layer that converts text data into a numerical representation. This numerical representation can then be used by the model to make predictions.

When TextVectorization is used outside of the model, then the text data is converted into a numerical representation before the model is trained. This means that the model does not have to do the text preprocessing every time it makes a prediction. This can improve the performance of the model.

However, when TextVectorization is used inside of the model, then the text data is converted into a numerical representation every time the model is trained. This can slow down the training process.

Tags

Post a Comment

0Comments
Post a Comment (0)