# Predict the output of a text - Sentiment Analysis

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpredict-the-output-of-a-text-sentiment-analysis%2F19631%3E%5C
**Category:** Models\
**Created:** [June 26, 2022, 8:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpredict-the-output-of-a-text-sentiment-analysis%2F19631 "2022-06-26T08:38:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zArabi](https://avatars.discourse-cdn.com/v4/letter/z/a88e57/32.png) [@zArabi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FzArabi)%5C
**Post date:** [June 26, 2022, 8:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpredict-the-output-of-a-text-sentiment-analysis%2F19631%2F1 "2022-06-26T08:38:55Z")

</div>

Hi everyone,  
I fine tuned distilbert sequence classification class on an English corpus with about 40,000 texts.  
the model resulted the accuracy of 88 percent, but I can’t get true predicts for a text as an input.  
Please help me, what should I do to fix this conflict.

this is the function I use to predict the output:  
def predict\_text(model,text):  
inputs = tokenizer(text, return\_tensors=“pt”)  
inputs = {k:v.to(device) for k,v in inputs.items()}  
with torch.no\_grad():  
outputs = model(\*\*inputs)  
y\_out = np.argmax(outputs.logits.cpu(),axis=1)  
return outputs

this is the way I call the function and it gives me positive class for this sentence:  
predict\_text(trainer.model,“Let’s try something else. It doesn’t work properly.”)

---

<div class="post-metadata">

**Author:** ![Shawon](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@Shawon](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FShawon)%5C
**Post date:** [June 27, 2022, 7:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpredict-the-output-of-a-text-sentiment-analysis%2F19631%2F2 "2022-06-27T19:30:17Z")

</div>

Your predict function is fine. The prediction returns a wrong result probably because the trained model can’t find a good fit for it. (Since you’ve already said that the accuracy is 0.88)

---

<div class="post-metadata">

**Author:** ![zArabi](https://avatars.discourse-cdn.com/v4/letter/z/a88e57/32.png) [@zArabi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FzArabi)%5C
**Post date:** [July 2, 2022, 10:55am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fpredict-the-output-of-a-text-sentiment-analysis%2F19631%2F3 "2022-07-02T10:55:07Z")

</div>

Thank you for your answer. What can I do to predict the right label in the output?
