# How to predict in Tensorflow

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-predict-in-tensorflow%2F3630%3E%5C
**Category:** 🤗Transformers\
**Created:** [February 14, 2021, 12:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-predict-in-tensorflow%2F3630 "2021-02-14T00:01:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neel-Gupta](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@Neel-Gupta](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNeel-Gupta)%5C
**Post date:** [February 14, 2021, 12:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-predict-in-tensorflow%2F3630%2F1 "2021-02-14T00:01:20Z")

</div>

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 using `model.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

---

<div class="post-metadata">

**Author:** ![saschaheyer](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saschaheyer/32/1029_2.png) [@saschaheyer](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsaschaheyer)%5C
**Post date:** [February 17, 2021, 11:07am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-predict-in-tensorflow%2F3630%2F2 "2021-02-17T11:07:56Z")

</div>

Hi @Neel-Gupta,

The steps are usually as follows

You load your trained model similar to this

```auto
loaded_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 involved

```auto
predict_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 text

```auto
tf_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](https://blog.doit-intl.com/performing-surprisingly-easy-sentiment-analysis-on-google-cloud-platform-fc26b2e2b4b)
