How to predict in Tensorflow
Hi,I have just finetuned RoBERTa for a classification problem, trained and stored the model. I have used native Tensorflow throughout, but I can’t find any examples anywhere related to finally predicting in TF. The only ones I found were all for PyTorch.Can someone please guide me to some snippet of code for prediction? The official example has no such code…EDIT:- I tried usingmodel.predict()method that is used normally and even the PyTorch one which reports missing config.  I am really confused as to how we are supposed to serve predictions. IMO the docs need updating
2021-02-17T11:07:56Z
Hi@Neel-Gupta,The steps are usually as followsYou load your trained model similar to thisloaded_model = TFDistilBertForSequenceClassification.from_pretrained("./sentiment")Then you usually have to run your text through the preprocessing in the same way you did for your training. Usually some kind of tokenizing involvedpredict_input = tokenizer.encode(test_sentence,
                                 truncation=True,
                                 padding=True,
                                 return_tensors="tf")And then you finally can predict based on your loaded model and the preprocessed texttf_output = loaded_model.predict(predict_input)[0]Disclaimer, I am the author of this article, but It covers the process from data to deployment.https://blog.doit-intl.com/performing-surprisingly-easy-sentiment-analysis-on-google-cloud-platform-fc26b2e2b4b