Need help to give inputs to my fine tuned model

I finetuned a distilbert-base-uncased model in google colab. I also downloaded it (h5 file) to my laptop. But I don’t understand how to load it on my laptop and give some inputs to check how it performs.

Hi,

You can check out the code example in the docs of TFDistilBertForSequenceClassification.

The model outputs logits, which are unnormalized scores for each of the classes, for every example in the batch. It’s a tensor of shape (batch_size, num_labels).

To turn it into an actual prediction, one takes the highest score, as follows:

from transformers import DistilBertTokenizer, TFDistilBertForSequenceClassification
import tensorflow as tf

tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
model = TFDistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')

inputs = tokenizer("Hello world ", return_tensors="tf")

outputs = model(inputs)
logits = outputs.logits
predicted_class_idx = tf.math.argmax(logits, axis=-1)[0]
print("Predicted class:", model.config.id2label[int(predicted_class_idx)])

Note that you can set the id2label dictionary as an attribute of the model’s configuration, to map integers to actual class names.