'How to get the predictions of a multi text classifier model using a csv file as test data?

I have created a multi class text classification model using TF and Bert by following this blog post: https://towardsdatascience.com/multi-label-text-classification-using-bert-and-tensorflow-d2e88d8f488d

For the model I used a test a dataset with 2 columns; sentence and sentiment (neg, neu, pos) enter image description here

After I trained the model I saved it.

model.save('keras_model/sentiment_model')

Then I opened a new notebook and I uploaded the model:

loaded_model = tf.keras.models.load_model(r'keras_model/sentiment_model', compile = False)

Despite the warning the model seems to be working. For testing I created 2 sentences in a list.

tweet_sentences=['De overheid wil windmolens in de Noorzee plaatsen', 'De demonstranten zijn tegen kerncentrales']

And tested the model:

def predict_class(reviews):
return [np.argmax(pred) for pred in loaded_model.predict(tweet_sentence)]

predict_class(tweet_sentence)

So basically the model works. But instead of using a list of strings for testing I like to use a csv with 2 columns: id and sentences. enter image description here

Output should look like: enter image description here

How can I do that??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source